blob: e2bfb05088b8ece646ebac88502e10e10a9e14b0 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +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.
7//===----------------------------------------------------------------------===/
8//
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//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000037using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000038
Douglas Gregord6ff3322009-08-04 16:50:30 +000039/// \brief A semantic tree transformation that allows one to transform one
40/// abstract syntax tree into another.
41///
Mike Stump11289f42009-09-09 15:08:12 +000042/// A new tree transformation is defined by creating a new subclass \c X of
43/// \c TreeTransform<X> and then overriding certain operations to provide
44/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000045/// instantiation is implemented as a tree transformation where the
46/// transformation of TemplateTypeParmType nodes involves substituting the
47/// template arguments for their corresponding template parameters; a similar
48/// transformation is performed for non-type template parameters and
49/// template template parameters.
50///
51/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000053/// override any of the transformation or rebuild operators by providing an
54/// operation with the same signature as the default implementation. The
55/// overridding function should not be virtual.
56///
57/// Semantic tree transformations are split into two stages, either of which
58/// can be replaced by a subclass. The "transform" step transforms an AST node
59/// or the parts of an AST node using the various transformation functions,
60/// then passes the pieces on to the "rebuild" step, which constructs a new AST
61/// node of the appropriate kind from the pieces. The default transformation
62/// routines recursively transform the operands to composite AST nodes (e.g.,
63/// the pointee type of a PointerType node) and, if any of those operand nodes
64/// were changed by the transformation, invokes the rebuild operation to create
65/// a new AST node.
66///
Mike Stump11289f42009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000069/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
70/// TransformTemplateName(), or TransformTemplateArgument() with entirely
71/// new implementations.
72///
73/// For more fine-grained transformations, subclasses can replace any of the
74/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000078/// parameters. Additionally, subclasses can override the \c RebuildXXX
79/// functions to control how AST nodes are rebuilt when their operands change.
80/// By default, \c TreeTransform will invoke semantic analysis to rebuild
81/// AST nodes. However, certain other tree transformations (e.g, cloning) may
82/// be able to use more efficient rebuild steps.
83///
84/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000086/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
87/// operands have not changed (\c AlwaysRebuild()), and customize the
88/// default locations and entity names used for type-checking
89/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
92protected:
93 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +000094
Mike Stump11289f42009-09-09 15:08:12 +000095public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000096 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +000097 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000098
Douglas Gregord6ff3322009-08-04 16:50:30 +000099 /// \brief Retrieves a reference to the derived class.
100 Derived &getDerived() { return static_cast<Derived&>(*this); }
101
102 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000103 const Derived &getDerived() const {
104 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000105 }
106
John McCalldadc5752010-08-24 06:29:42 +0000107 static inline ExprResult Owned(Expr *E) { return E; }
108 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110 /// \brief Retrieves a reference to the semantic analysis object used for
111 /// this tree transform.
112 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000113
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Whether the transformation should always rebuild AST nodes, even
115 /// if none of the children have changed.
116 ///
117 /// Subclasses may override this function to specify when the transformation
118 /// should rebuild all AST nodes.
119 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000120
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Returns the location of the entity being transformed, if that
122 /// information was not available elsewhere in the AST.
123 ///
Mike Stump11289f42009-09-09 15:08:12 +0000124 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// provide an alternative implementation that provides better location
126 /// information.
127 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Returns the name of the entity being transformed, if that
130 /// information was not available elsewhere in the AST.
131 ///
132 /// By default, returns an empty name. Subclasses can provide an alternative
133 /// implementation with a more precise name.
134 DeclarationName getBaseEntity() { return DeclarationName(); }
135
Douglas Gregora16548e2009-08-11 05:31:07 +0000136 /// \brief Sets the "base" location and entity when that
137 /// information is known based on another transformation.
138 ///
139 /// By default, the source location and entity are ignored. Subclasses can
140 /// override this function to provide a customized implementation.
141 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000142
Douglas Gregora16548e2009-08-11 05:31:07 +0000143 /// \brief RAII object that temporarily sets the base location and entity
144 /// used for reporting diagnostics in types.
145 class TemporaryBase {
146 TreeTransform &Self;
147 SourceLocation OldLocation;
148 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregora16548e2009-08-11 05:31:07 +0000150 public:
151 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000152 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000153 OldLocation = Self.getDerived().getBaseLocation();
154 OldEntity = Self.getDerived().getBaseEntity();
155 Self.getDerived().setBase(Location, Entity);
156 }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregora16548e2009-08-11 05:31:07 +0000158 ~TemporaryBase() {
159 Self.getDerived().setBase(OldLocation, OldEntity);
160 }
161 };
Mike Stump11289f42009-09-09 15:08:12 +0000162
163 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000164 /// transformed.
165 ///
166 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000167 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000168 /// not change. For example, template instantiation need not traverse
169 /// non-dependent types.
170 bool AlreadyTransformed(QualType T) {
171 return T.isNull();
172 }
173
Douglas Gregord196a582009-12-14 19:27:10 +0000174 /// \brief Determine whether the given call argument should be dropped, e.g.,
175 /// because it is a default argument.
176 ///
177 /// Subclasses can provide an alternative implementation of this routine to
178 /// determine which kinds of call arguments get dropped. By default,
179 /// CXXDefaultArgument nodes are dropped (prior to transformation).
180 bool DropCallArgument(Expr *E) {
181 return E->isDefaultArgument();
182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000183
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000184 /// \brief Determine whether we should expand a pack expansion with the
185 /// given set of parameter packs into separate arguments by repeatedly
186 /// transforming the pattern.
187 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000188 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000189 /// Subclasses can override this routine to provide different behavior.
190 ///
191 /// \param EllipsisLoc The location of the ellipsis that identifies the
192 /// pack expansion.
193 ///
194 /// \param PatternRange The source range that covers the entire pattern of
195 /// the pack expansion.
196 ///
197 /// \param Unexpanded The set of unexpanded parameter packs within the
198 /// pattern.
199 ///
200 /// \param NumUnexpanded The number of unexpanded parameter packs in
201 /// \p Unexpanded.
202 ///
203 /// \param ShouldExpand Will be set to \c true if the transformer should
204 /// expand the corresponding pack expansions into separate arguments. When
205 /// set, \c NumExpansions must also be set.
206 ///
207 /// \param NumExpansions The number of separate arguments that will be in
208 /// the expanded form of the corresponding pack expansion. Must be set when
209 /// \c ShouldExpand is \c true.
210 ///
211 /// \returns true if an error occurred (e.g., because the parameter packs
212 /// are to be instantiated with arguments of different lengths), false
213 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
214 /// must be set.
215 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
216 SourceRange PatternRange,
217 const UnexpandedParameterPack *Unexpanded,
218 unsigned NumUnexpanded,
219 bool &ShouldExpand,
220 unsigned &NumExpansions) {
221 ShouldExpand = false;
222 return false;
223 }
224
Douglas Gregorf3010112011-01-07 16:43:16 +0000225 /// \brief Note to the derived class when a function parameter pack is
226 /// being expanded.
227 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
228
Douglas Gregord6ff3322009-08-04 16:50:30 +0000229 /// \brief Transforms the given type into another type.
230 ///
John McCall550e0c22009-10-21 00:40:46 +0000231 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000232 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000233 /// function. This is expensive, but we don't mind, because
234 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000235 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000236 ///
237 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000238 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000239
John McCall550e0c22009-10-21 00:40:46 +0000240 /// \brief Transforms the given type-with-location into a new
241 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000242 ///
John McCall550e0c22009-10-21 00:40:46 +0000243 /// By default, this routine transforms a type by delegating to the
244 /// appropriate TransformXXXType to build a new type. Subclasses
245 /// may override this function (to take over all type
246 /// transformations) or some set of the TransformXXXType functions
247 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000248 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000249
250 /// \brief Transform the given type-with-location into a new
251 /// type, collecting location information in the given builder
252 /// as necessary.
253 ///
John McCall31f82722010-11-12 08:19:04 +0000254 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000255
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000256 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000257 ///
Mike Stump11289f42009-09-09 15:08:12 +0000258 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000259 /// appropriate TransformXXXStmt function to transform a specific kind of
260 /// statement or the TransformExpr() function to transform an expression.
261 /// Subclasses may override this function to transform statements using some
262 /// other mechanism.
263 ///
264 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000265 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000266
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000267 /// \brief Transform the given expression.
268 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000269 /// By default, this routine transforms an expression by delegating to the
270 /// appropriate TransformXXXExpr function to build a new expression.
271 /// Subclasses may override this function to transform expressions using some
272 /// other mechanism.
273 ///
274 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000275 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000276
Douglas Gregora3efea12011-01-03 19:04:46 +0000277 /// \brief Transform the given list of expressions.
278 ///
279 /// This routine transforms a list of expressions by invoking
280 /// \c TransformExpr() for each subexpression. However, it also provides
281 /// support for variadic templates by expanding any pack expansions (if the
282 /// derived class permits such expansion) along the way. When pack expansions
283 /// are present, the number of outputs may not equal the number of inputs.
284 ///
285 /// \param Inputs The set of expressions to be transformed.
286 ///
287 /// \param NumInputs The number of expressions in \c Inputs.
288 ///
289 /// \param IsCall If \c true, then this transform is being performed on
290 /// function-call arguments, and any arguments that should be dropped, will
291 /// be.
292 ///
293 /// \param Outputs The transformed input expressions will be added to this
294 /// vector.
295 ///
296 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
297 /// due to transformation.
298 ///
299 /// \returns true if an error occurred, false otherwise.
300 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
301 llvm::SmallVectorImpl<Expr *> &Outputs,
302 bool *ArgChanged = 0);
303
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 /// \brief Transform the given declaration, which is referenced from a type
305 /// or expression.
306 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000307 /// By default, acts as the identity function on declarations. Subclasses
308 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000309 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000310
311 /// \brief Transform the definition of the given declaration.
312 ///
Mike Stump11289f42009-09-09 15:08:12 +0000313 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000314 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000315 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
316 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000317 }
Mike Stump11289f42009-09-09 15:08:12 +0000318
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000319 /// \brief Transform the given declaration, which was the first part of a
320 /// nested-name-specifier in a member access expression.
321 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000322 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000323 /// identifier in a nested-name-specifier of a member access expression, e.g.,
324 /// the \c T in \c x->T::member
325 ///
326 /// By default, invokes TransformDecl() to transform the declaration.
327 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000328 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
329 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000330 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000331
Douglas Gregord6ff3322009-08-04 16:50:30 +0000332 /// \brief Transform the given nested-name-specifier.
333 ///
Mike Stump11289f42009-09-09 15:08:12 +0000334 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000335 /// nested-name-specifier. Subclasses may override this function to provide
336 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000337 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000338 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000339 QualType ObjectType = QualType(),
340 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000341
Douglas Gregorf816bd72009-09-03 22:13:48 +0000342 /// \brief Transform the given declaration name.
343 ///
344 /// By default, transforms the types of conversion function, constructor,
345 /// and destructor names and then (if needed) rebuilds the declaration name.
346 /// Identifiers and selectors are returned unmodified. Sublcasses may
347 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000348 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000349 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000350
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000352 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000353 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000354 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000355 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000356 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000357 QualType ObjectType = QualType(),
358 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000359
Douglas Gregord6ff3322009-08-04 16:50:30 +0000360 /// \brief Transform the given template argument.
361 ///
Mike Stump11289f42009-09-09 15:08:12 +0000362 /// By default, this operation transforms the type, expression, or
363 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000364 /// new template argument from the transformed result. Subclasses may
365 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000366 ///
367 /// Returns true if there was an error.
368 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
369 TemplateArgumentLoc &Output);
370
Douglas Gregor62e06f22010-12-20 17:31:10 +0000371 /// \brief Transform the given set of template arguments.
372 ///
373 /// By default, this operation transforms all of the template arguments
374 /// in the input set using \c TransformTemplateArgument(), and appends
375 /// the transformed arguments to the output list.
376 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000377 /// Note that this overload of \c TransformTemplateArguments() is merely
378 /// a convenience function. Subclasses that wish to override this behavior
379 /// should override the iterator-based member template version.
380 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000381 /// \param Inputs The set of template arguments to be transformed.
382 ///
383 /// \param NumInputs The number of template arguments in \p Inputs.
384 ///
385 /// \param Outputs The set of transformed template arguments output by this
386 /// routine.
387 ///
388 /// Returns true if an error occurred.
389 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
390 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000391 TemplateArgumentListInfo &Outputs) {
392 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
393 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000394
395 /// \brief Transform the given set of template arguments.
396 ///
397 /// By default, this operation transforms all of the template arguments
398 /// in the input set using \c TransformTemplateArgument(), and appends
399 /// the transformed arguments to the output list.
400 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000401 /// \param First An iterator to the first template argument.
402 ///
403 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000404 ///
405 /// \param Outputs The set of transformed template arguments output by this
406 /// routine.
407 ///
408 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000409 template<typename InputIterator>
410 bool TransformTemplateArguments(InputIterator First,
411 InputIterator Last,
412 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000413
John McCall0ad16662009-10-29 08:12:44 +0000414 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
415 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
416 TemplateArgumentLoc &ArgLoc);
417
John McCallbcd03502009-12-07 02:54:59 +0000418 /// \brief Fakes up a TypeSourceInfo for a type.
419 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
420 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000421 getDerived().getBaseLocation());
422 }
Mike Stump11289f42009-09-09 15:08:12 +0000423
John McCall550e0c22009-10-21 00:40:46 +0000424#define ABSTRACT_TYPELOC(CLASS, PARENT)
425#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000426 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000427#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000428
John McCall31f82722010-11-12 08:19:04 +0000429 QualType
430 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
431 TemplateSpecializationTypeLoc TL,
432 TemplateName Template);
433
434 QualType
435 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
436 DependentTemplateSpecializationTypeLoc TL,
437 NestedNameSpecifier *Prefix);
438
John McCall58f10c32010-03-11 09:03:00 +0000439 /// \brief Transforms the parameters of a function type into the
440 /// given vectors.
441 ///
442 /// The result vectors should be kept in sync; null entries in the
443 /// variables vector are acceptable.
444 ///
445 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000446 bool TransformFunctionTypeParams(SourceLocation Loc,
447 ParmVarDecl **Params, unsigned NumParams,
448 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000449 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000450 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000451
452 /// \brief Transforms a single function-type parameter. Return null
453 /// on error.
454 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
455
John McCall31f82722010-11-12 08:19:04 +0000456 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000457
John McCalldadc5752010-08-24 06:29:42 +0000458 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
459 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000460
Douglas Gregorebe10102009-08-20 07:17:43 +0000461#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000462 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000463#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000464 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000465#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000466#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000467
Douglas Gregord6ff3322009-08-04 16:50:30 +0000468 /// \brief Build a new pointer type given its pointee type.
469 ///
470 /// By default, performs semantic analysis when building the pointer type.
471 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000472 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000473
474 /// \brief Build a new block pointer type given its pointee type.
475 ///
Mike Stump11289f42009-09-09 15:08:12 +0000476 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000477 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000478 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000479
John McCall70dd5f62009-10-30 00:06:24 +0000480 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481 ///
John McCall70dd5f62009-10-30 00:06:24 +0000482 /// By default, performs semantic analysis when building the
483 /// reference type. Subclasses may override this routine to provide
484 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000485 ///
John McCall70dd5f62009-10-30 00:06:24 +0000486 /// \param LValue whether the type was written with an lvalue sigil
487 /// or an rvalue sigil.
488 QualType RebuildReferenceType(QualType ReferentType,
489 bool LValue,
490 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000491
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492 /// \brief Build a new member pointer type given the pointee type and the
493 /// class type it refers into.
494 ///
495 /// By default, performs semantic analysis when building the member pointer
496 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000497 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
498 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000499
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500 /// \brief Build a new array type given the element type, size
501 /// modifier, size of the array (if known), size expression, and index type
502 /// qualifiers.
503 ///
504 /// By default, performs semantic analysis when building the array type.
505 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 QualType RebuildArrayType(QualType ElementType,
508 ArrayType::ArraySizeModifier SizeMod,
509 const llvm::APInt *Size,
510 Expr *SizeExpr,
511 unsigned IndexTypeQuals,
512 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000513
Douglas Gregord6ff3322009-08-04 16:50:30 +0000514 /// \brief Build a new constant array type given the element type, size
515 /// modifier, (known) size of the array, and index type qualifiers.
516 ///
517 /// By default, performs semantic analysis when building the array type.
518 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000519 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 ArrayType::ArraySizeModifier SizeMod,
521 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000522 unsigned IndexTypeQuals,
523 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000524
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 /// \brief Build a new incomplete array type given the element type, size
526 /// modifier, and index type qualifiers.
527 ///
528 /// By default, performs semantic analysis when building the array type.
529 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000530 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000532 unsigned IndexTypeQuals,
533 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534
Mike Stump11289f42009-09-09 15:08:12 +0000535 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 /// size modifier, size expression, and index type qualifiers.
537 ///
538 /// By default, performs semantic analysis when building the array type.
539 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000540 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000541 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000542 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000543 unsigned IndexTypeQuals,
544 SourceRange BracketsRange);
545
Mike Stump11289f42009-09-09 15:08:12 +0000546 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// size modifier, size expression, and index type qualifiers.
548 ///
549 /// By default, performs semantic analysis when building the array type.
550 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000551 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000553 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000554 unsigned IndexTypeQuals,
555 SourceRange BracketsRange);
556
557 /// \brief Build a new vector type given the element type and
558 /// number of elements.
559 ///
560 /// By default, performs semantic analysis when building the vector type.
561 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000562 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000563 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000564
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565 /// \brief Build a new extended vector type given the element type and
566 /// number of elements.
567 ///
568 /// By default, performs semantic analysis when building the vector type.
569 /// Subclasses may override this routine to provide different behavior.
570 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
571 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000572
573 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000574 /// given the element type and number of elements.
575 ///
576 /// By default, performs semantic analysis when building the vector type.
577 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000578 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000579 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000580 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000581
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582 /// \brief Build a new function type.
583 ///
584 /// By default, performs semantic analysis when building the function type.
585 /// Subclasses may override this routine to provide different behavior.
586 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000587 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000588 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000589 bool Variadic, unsigned Quals,
590 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000591
John McCall550e0c22009-10-21 00:40:46 +0000592 /// \brief Build a new unprototyped function type.
593 QualType RebuildFunctionNoProtoType(QualType ResultType);
594
John McCallb96ec562009-12-04 22:46:56 +0000595 /// \brief Rebuild an unresolved typename type, given the decl that
596 /// the UnresolvedUsingTypenameDecl was transformed to.
597 QualType RebuildUnresolvedUsingType(Decl *D);
598
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 /// \brief Build a new typedef type.
600 QualType RebuildTypedefType(TypedefDecl *Typedef) {
601 return SemaRef.Context.getTypeDeclType(Typedef);
602 }
603
604 /// \brief Build a new class/struct/union type.
605 QualType RebuildRecordType(RecordDecl *Record) {
606 return SemaRef.Context.getTypeDeclType(Record);
607 }
608
609 /// \brief Build a new Enum type.
610 QualType RebuildEnumType(EnumDecl *Enum) {
611 return SemaRef.Context.getTypeDeclType(Enum);
612 }
John McCallfcc33b02009-09-05 00:15:47 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 ///
616 /// By default, performs semantic analysis when building the typeof type.
617 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000618 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000619
Mike Stump11289f42009-09-09 15:08:12 +0000620 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000621 ///
622 /// By default, builds a new TypeOfType with the given underlying type.
623 QualType RebuildTypeOfType(QualType Underlying);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 ///
627 /// By default, performs semantic analysis when building the decltype type.
628 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000629 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000630
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 /// \brief Build a new template specialization type.
632 ///
633 /// By default, performs semantic analysis when building the template
634 /// specialization type. Subclasses may override this routine to provide
635 /// different behavior.
636 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000637 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000638 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000639
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000640 /// \brief Build a new parenthesized type.
641 ///
642 /// By default, builds a new ParenType type from the inner type.
643 /// Subclasses may override this routine to provide different behavior.
644 QualType RebuildParenType(QualType InnerType) {
645 return SemaRef.Context.getParenType(InnerType);
646 }
647
Douglas Gregord6ff3322009-08-04 16:50:30 +0000648 /// \brief Build a new qualified name type.
649 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000650 /// By default, builds a new ElaboratedType type from the keyword,
651 /// the nested-name-specifier and the named type.
652 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000653 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
654 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000655 NestedNameSpecifier *NNS, QualType Named) {
656 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000657 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658
659 /// \brief Build a new typename type that refers to a template-id.
660 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000661 /// By default, builds a new DependentNameType type from the
662 /// nested-name-specifier and the given type. Subclasses may override
663 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000664 QualType RebuildDependentTemplateSpecializationType(
665 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000666 NestedNameSpecifier *Qualifier,
667 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000668 const IdentifierInfo *Name,
669 SourceLocation NameLoc,
670 const TemplateArgumentListInfo &Args) {
671 // Rebuild the template name.
672 // TODO: avoid TemplateName abstraction
673 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000674 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000675 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000676
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000677 if (InstName.isNull())
678 return QualType();
679
John McCallc392f372010-06-11 00:33:02 +0000680 // If it's still dependent, make a dependent specialization.
681 if (InstName.getAsDependentTemplateName())
682 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000683 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000684
685 // Otherwise, make an elaborated type wrapping a non-dependent
686 // specialization.
687 QualType T =
688 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
689 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000690
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000691 // NOTE: NNS is already recorded in template specialization type T.
692 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000693 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694
695 /// \brief Build a new typename type that refers to an identifier.
696 ///
697 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000698 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000700 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000701 NestedNameSpecifier *NNS,
702 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000703 SourceLocation KeywordLoc,
704 SourceRange NNSRange,
705 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000706 CXXScopeSpec SS;
707 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000708 SS.setRange(NNSRange);
709
Douglas Gregore677daf2010-03-31 22:19:08 +0000710 if (NNS->isDependent()) {
711 // If the name is still dependent, just build a new dependent name type.
712 if (!SemaRef.computeDeclContext(SS))
713 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
714 }
715
Abramo Bagnara6150c882010-05-11 21:36:43 +0000716 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000717 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
718 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000719
720 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
721
Abramo Bagnarad7548482010-05-19 21:37:53 +0000722 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000723 // into a non-dependent elaborated-type-specifier. Find the tag we're
724 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000725 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000726 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
727 if (!DC)
728 return QualType();
729
John McCallbf8c5192010-05-27 06:40:31 +0000730 if (SemaRef.RequireCompleteDeclContext(SS, DC))
731 return QualType();
732
Douglas Gregore677daf2010-03-31 22:19:08 +0000733 TagDecl *Tag = 0;
734 SemaRef.LookupQualifiedName(Result, DC);
735 switch (Result.getResultKind()) {
736 case LookupResult::NotFound:
737 case LookupResult::NotFoundInCurrentInstantiation:
738 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000739
Douglas Gregore677daf2010-03-31 22:19:08 +0000740 case LookupResult::Found:
741 Tag = Result.getAsSingle<TagDecl>();
742 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000743
Douglas Gregore677daf2010-03-31 22:19:08 +0000744 case LookupResult::FoundOverloaded:
745 case LookupResult::FoundUnresolvedValue:
746 llvm_unreachable("Tag lookup cannot find non-tags");
747 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000748
Douglas Gregore677daf2010-03-31 22:19:08 +0000749 case LookupResult::Ambiguous:
750 // Let the LookupResult structure handle ambiguities.
751 return QualType();
752 }
753
754 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000755 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000757 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000758 return QualType();
759 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000760
Abramo Bagnarad7548482010-05-19 21:37:53 +0000761 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
762 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000763 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
764 return QualType();
765 }
766
767 // Build the elaborated-type-specifier type.
768 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000769 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000770 }
Mike Stump11289f42009-09-09 15:08:12 +0000771
Douglas Gregor1135c352009-08-06 05:28:30 +0000772 /// \brief Build a new nested-name-specifier given the prefix and an
773 /// identifier that names the next step in the nested-name-specifier.
774 ///
775 /// By default, performs semantic analysis when building the new
776 /// nested-name-specifier. Subclasses may override this routine to provide
777 /// different behavior.
778 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
779 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000780 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000781 QualType ObjectType,
782 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000783
784 /// \brief Build a new nested-name-specifier given the prefix and the
785 /// namespace named in the next step in the nested-name-specifier.
786 ///
787 /// By default, performs semantic analysis when building the new
788 /// nested-name-specifier. Subclasses may override this routine to provide
789 /// different behavior.
790 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
791 SourceRange Range,
792 NamespaceDecl *NS);
793
794 /// \brief Build a new nested-name-specifier given the prefix and the
795 /// type named in the next step in the nested-name-specifier.
796 ///
797 /// By default, performs semantic analysis when building the new
798 /// nested-name-specifier. Subclasses may override this routine to provide
799 /// different behavior.
800 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
801 SourceRange Range,
802 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000803 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000804
805 /// \brief Build a new template name given a nested name specifier, a flag
806 /// indicating whether the "template" keyword was provided, and the template
807 /// that the template name refers to.
808 ///
809 /// By default, builds the new template name directly. Subclasses may override
810 /// this routine to provide different behavior.
811 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
812 bool TemplateKW,
813 TemplateDecl *Template);
814
Douglas Gregor71dc5092009-08-06 06:41:21 +0000815 /// \brief Build a new template name given a nested name specifier and the
816 /// name that is referred to as a template.
817 ///
818 /// By default, performs semantic analysis to determine whether the name can
819 /// be resolved to a specific template, then builds the appropriate kind of
820 /// template name. Subclasses may override this routine to provide different
821 /// behavior.
822 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000823 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000824 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000825 QualType ObjectType,
826 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000827
Douglas Gregor71395fa2009-11-04 00:56:37 +0000828 /// \brief Build a new template name given a nested name specifier and the
829 /// overloaded operator name that is referred to as a template.
830 ///
831 /// By default, performs semantic analysis to determine whether the name can
832 /// be resolved to a specific template, then builds the appropriate kind of
833 /// template name. Subclasses may override this routine to provide different
834 /// behavior.
835 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
836 OverloadedOperatorKind Operator,
837 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000838
Douglas Gregorebe10102009-08-20 07:17:43 +0000839 /// \brief Build a new compound statement.
840 ///
841 /// By default, performs semantic analysis to build the new statement.
842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000843 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 MultiStmtArg Statements,
845 SourceLocation RBraceLoc,
846 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000847 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000848 IsStmtExpr);
849 }
850
851 /// \brief Build a new case statement.
852 ///
853 /// By default, performs semantic analysis to build the new statement.
854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000855 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000856 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000858 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000859 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000860 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000861 ColonLoc);
862 }
Mike Stump11289f42009-09-09 15:08:12 +0000863
Douglas Gregorebe10102009-08-20 07:17:43 +0000864 /// \brief Attach the body to a new case statement.
865 ///
866 /// By default, performs semantic analysis to build the new statement.
867 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000868 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000869 getSema().ActOnCaseStmtBody(S, Body);
870 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000871 }
Mike Stump11289f42009-09-09 15:08:12 +0000872
Douglas Gregorebe10102009-08-20 07:17:43 +0000873 /// \brief Build a new default statement.
874 ///
875 /// By default, performs semantic analysis to build the new statement.
876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000877 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000878 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000879 Stmt *SubStmt) {
880 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000881 /*CurScope=*/0);
882 }
Mike Stump11289f42009-09-09 15:08:12 +0000883
Douglas Gregorebe10102009-08-20 07:17:43 +0000884 /// \brief Build a new label statement.
885 ///
886 /// By default, performs semantic analysis to build the new statement.
887 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000888 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000889 IdentifierInfo *Id,
890 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000891 Stmt *SubStmt, bool HasUnusedAttr) {
892 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
893 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Douglas Gregorebe10102009-08-20 07:17:43 +0000896 /// \brief Build a new "if" statement.
897 ///
898 /// By default, performs semantic analysis to build the new statement.
899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000900 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000901 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000902 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000903 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000904 }
Mike Stump11289f42009-09-09 15:08:12 +0000905
Douglas Gregorebe10102009-08-20 07:17:43 +0000906 /// \brief Start building a new switch statement.
907 ///
908 /// By default, performs semantic analysis to build the new statement.
909 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000910 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000911 Expr *Cond, VarDecl *CondVar) {
912 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000913 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000914 }
Mike Stump11289f42009-09-09 15:08:12 +0000915
Douglas Gregorebe10102009-08-20 07:17:43 +0000916 /// \brief Attach the body to the switch statement.
917 ///
918 /// By default, performs semantic analysis to build the new statement.
919 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000920 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000921 Stmt *Switch, Stmt *Body) {
922 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000923 }
924
925 /// \brief Build a new while statement.
926 ///
927 /// By default, performs semantic analysis to build the new statement.
928 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000929 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000930 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000931 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000932 Stmt *Body) {
933 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000934 }
Mike Stump11289f42009-09-09 15:08:12 +0000935
Douglas Gregorebe10102009-08-20 07:17:43 +0000936 /// \brief Build a new do-while statement.
937 ///
938 /// By default, performs semantic analysis to build the new statement.
939 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000940 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000941 SourceLocation WhileLoc,
942 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000943 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000944 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000945 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
946 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000947 }
948
949 /// \brief Build a new for statement.
950 ///
951 /// By default, performs semantic analysis to build the new statement.
952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000953 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000954 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000955 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000956 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000957 SourceLocation RParenLoc, Stmt *Body) {
958 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000959 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000960 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 }
Mike Stump11289f42009-09-09 15:08:12 +0000962
Douglas Gregorebe10102009-08-20 07:17:43 +0000963 /// \brief Build a new goto statement.
964 ///
965 /// By default, performs semantic analysis to build the new statement.
966 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000967 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000968 SourceLocation LabelLoc,
969 LabelStmt *Label) {
970 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
971 }
972
973 /// \brief Build a new indirect goto statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000978 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000979 Expr *Target) {
980 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 }
Mike Stump11289f42009-09-09 15:08:12 +0000982
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 /// \brief Build a new return statement.
984 ///
985 /// By default, performs semantic analysis to build the new statement.
986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000987 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000988 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000989
John McCallb268a282010-08-23 23:25:46 +0000990 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 }
Mike Stump11289f42009-09-09 15:08:12 +0000992
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 /// \brief Build a new declaration statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000997 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000998 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 SourceLocation EndLoc) {
1000 return getSema().Owned(
1001 new (getSema().Context) DeclStmt(
1002 DeclGroupRef::Create(getSema().Context,
1003 Decls, NumDecls),
1004 StartLoc, EndLoc));
1005 }
Mike Stump11289f42009-09-09 15:08:12 +00001006
Anders Carlssonaaeef072010-01-24 05:50:09 +00001007 /// \brief Build a new inline asm statement.
1008 ///
1009 /// By default, performs semantic analysis to build the new statement.
1010 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001011 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001012 bool IsSimple,
1013 bool IsVolatile,
1014 unsigned NumOutputs,
1015 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001016 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001017 MultiExprArg Constraints,
1018 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001019 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001020 MultiExprArg Clobbers,
1021 SourceLocation RParenLoc,
1022 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001023 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001024 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001025 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001026 RParenLoc, MSAsm);
1027 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001028
1029 /// \brief Build a new Objective-C @try 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 RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001034 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001035 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001036 Stmt *Finally) {
1037 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1038 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001039 }
1040
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001041 /// \brief Rebuild an Objective-C exception declaration.
1042 ///
1043 /// By default, performs semantic analysis to build the new declaration.
1044 /// Subclasses may override this routine to provide different behavior.
1045 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1046 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001047 return getSema().BuildObjCExceptionDecl(TInfo, T,
1048 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001049 ExceptionDecl->getLocation());
1050 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001051
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001052 /// \brief Build a new Objective-C @catch statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001056 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001057 SourceLocation RParenLoc,
1058 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001059 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001060 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001061 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001062 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001063
Douglas Gregor306de2f2010-04-22 23:59:56 +00001064 /// \brief Build a new Objective-C @finally statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001068 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001069 Stmt *Body) {
1070 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001071 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001072
Douglas Gregor6148de72010-04-22 22:01:21 +00001073 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001078 Expr *Operand) {
1079 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001080 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001081
Douglas Gregor6148de72010-04-22 22:01:21 +00001082 /// \brief Build a new Objective-C @synchronized statement.
1083 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Expr *Object,
1088 Stmt *Body) {
1089 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1090 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001091 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001092
1093 /// \brief Build a new Objective-C fast enumeration statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001097 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001098 SourceLocation LParenLoc,
1099 Stmt *Element,
1100 Expr *Collection,
1101 SourceLocation RParenLoc,
1102 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001103 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001104 Element,
1105 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001106 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001107 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001108 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001109
Douglas Gregorebe10102009-08-20 07:17:43 +00001110 /// \brief Build a new C++ exception declaration.
1111 ///
1112 /// By default, performs semantic analysis to build the new decaration.
1113 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001114 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001115 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001117 SourceLocation Loc) {
1118 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001119 }
1120
1121 /// \brief Build a new C++ catch statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001126 VarDecl *ExceptionDecl,
1127 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001128 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1129 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 }
Mike Stump11289f42009-09-09 15:08:12 +00001131
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 /// \brief Build a new C++ try statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001137 Stmt *TryBlock,
1138 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001139 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// \brief Build a new expression that references a declaration.
1143 ///
1144 /// By default, performs semantic analysis to build the new expression.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001147 LookupResult &R,
1148 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001149 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1150 }
1151
1152
1153 /// \brief Build a new expression that references a declaration.
1154 ///
1155 /// By default, performs semantic analysis to build the new expression.
1156 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001157 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001158 SourceRange QualifierRange,
1159 ValueDecl *VD,
1160 const DeclarationNameInfo &NameInfo,
1161 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001162 CXXScopeSpec SS;
1163 SS.setScopeRep(Qualifier);
1164 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001165
1166 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001167
1168 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001169 }
Mike Stump11289f42009-09-09 15:08:12 +00001170
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001172 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001173 /// By default, performs semantic analysis to build the new expression.
1174 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001175 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001176 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001177 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001178 }
1179
Douglas Gregorad8a3362009-09-04 17:36:40 +00001180 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001181 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001182 /// By default, performs semantic analysis to build the new expression.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001185 SourceLocation OperatorLoc,
1186 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001187 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001188 SourceRange QualifierRange,
1189 TypeSourceInfo *ScopeType,
1190 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001191 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001192 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001195 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001198 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001199 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001200 Expr *SubExpr) {
1201 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 }
Mike Stump11289f42009-09-09 15:08:12 +00001203
Douglas Gregor882211c2010-04-28 22:16:22 +00001204 /// \brief Build a new builtin offsetof expression.
1205 ///
1206 /// By default, performs semantic analysis to build the new expression.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001209 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001210 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001211 unsigned NumComponents,
1212 SourceLocation RParenLoc) {
1213 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1214 NumComponents, RParenLoc);
1215 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001216
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001218 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 /// By default, performs semantic analysis to build the new expression.
1220 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001221 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001222 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001224 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 }
1226
Mike Stump11289f42009-09-09 15:08:12 +00001227 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001229 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 /// By default, performs semantic analysis to build the new expression.
1231 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001232 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001234 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001235 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001238
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 return move(Result);
1240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001243 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001248 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001250 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1251 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 RBracketLoc);
1253 }
1254
1255 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001256 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 /// By default, performs semantic analysis to build the new expression.
1258 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001259 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001262 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001263 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 }
1265
1266 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001267 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 /// By default, performs semantic analysis to build the new expression.
1269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001270 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001271 bool isArrow,
1272 NestedNameSpecifier *Qualifier,
1273 SourceRange QualifierRange,
1274 const DeclarationNameInfo &MemberNameInfo,
1275 ValueDecl *Member,
1276 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001277 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001278 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001279 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001280 // We have a reference to an unnamed field. This is always the
1281 // base of an anonymous struct/union member access, i.e. the
1282 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001283 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001284 assert(Member->getType()->isRecordType() &&
1285 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001286
John McCallb268a282010-08-23 23:25:46 +00001287 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001288 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001289 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001290
John McCall7decc9e2010-11-18 06:31:45 +00001291 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001292 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001293 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001294 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001295 cast<FieldDecl>(Member)->getType(),
1296 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001297 return getSema().Owned(ME);
1298 }
Mike Stump11289f42009-09-09 15:08:12 +00001299
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001300 CXXScopeSpec SS;
1301 if (Qualifier) {
1302 SS.setRange(QualifierRange);
1303 SS.setScopeRep(Qualifier);
1304 }
1305
John McCallb268a282010-08-23 23:25:46 +00001306 getSema().DefaultFunctionArrayConversion(Base);
1307 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001308
John McCall16df1e52010-03-30 21:47:33 +00001309 // FIXME: this involves duplicating earlier analysis in a lot of
1310 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001311 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001312 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001313 R.resolveKind();
1314
John McCallb268a282010-08-23 23:25:46 +00001315 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001316 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001317 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 }
Mike Stump11289f42009-09-09 15:08:12 +00001319
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001321 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// By default, performs semantic analysis to build the new expression.
1323 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001324 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001325 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001326 Expr *LHS, Expr *RHS) {
1327 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 }
1329
1330 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001336 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001338 Expr *RHS) {
1339 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1340 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 }
1342
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001344 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001347 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001348 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001350 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001351 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001352 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001356 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001359 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001360 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001362 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001363 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001364 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 }
Mike Stump11289f42009-09-09 15:08:12 +00001366
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001368 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 /// By default, performs semantic analysis to build the new expression.
1370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001371 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 SourceLocation OpLoc,
1373 SourceLocation AccessorLoc,
1374 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001375
John McCall10eae182009-11-30 22:42:35 +00001376 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001377 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001378 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001379 OpLoc, /*IsArrow*/ false,
1380 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001381 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001382 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 }
Mike Stump11289f42009-09-09 15:08:12 +00001384
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001386 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001389 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001391 SourceLocation RBraceLoc,
1392 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001393 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001394 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1395 if (Result.isInvalid() || ResultTy->isDependentType())
1396 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001397
Douglas Gregord3d93062009-11-09 17:16:50 +00001398 // Patch in the result type we were given, which may have been computed
1399 // when the initial InitListExpr was built.
1400 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1401 ILE->setType(ResultTy);
1402 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 }
Mike Stump11289f42009-09-09 15:08:12 +00001404
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001406 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 /// By default, performs semantic analysis to build the new expression.
1408 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001409 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 MultiExprArg ArrayExprs,
1411 SourceLocation EqualOrColonLoc,
1412 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001413 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001414 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001416 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001418 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001419
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 ArrayExprs.release();
1421 return move(Result);
1422 }
Mike Stump11289f42009-09-09 15:08:12 +00001423
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001425 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// By default, builds the implicit value initialization without performing
1427 /// any semantic analysis. Subclasses may override this routine to provide
1428 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001429 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1431 }
Mike Stump11289f42009-09-09 15:08:12 +00001432
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001434 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 /// By default, performs semantic analysis to build the new expression.
1436 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001437 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001438 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001439 SourceLocation RParenLoc) {
1440 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001441 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001442 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 }
1444
1445 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001446 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 /// By default, performs semantic analysis to build the new expression.
1448 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001449 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 MultiExprArg SubExprs,
1451 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001452 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001453 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 }
Mike Stump11289f42009-09-09 15:08:12 +00001455
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001457 ///
1458 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 /// rather than attempting to map the label statement itself.
1460 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001461 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation LabelLoc,
1463 LabelStmt *Label) {
1464 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1465 }
Mike Stump11289f42009-09-09 15:08:12 +00001466
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001468 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 /// By default, performs semantic analysis to build the new expression.
1470 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001471 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001472 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001474 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 }
Mike Stump11289f42009-09-09 15:08:12 +00001476
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 /// \brief Build a new __builtin_choose_expr expression.
1478 ///
1479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001481 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001482 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 SourceLocation RParenLoc) {
1484 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001485 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 RParenLoc);
1487 }
Mike Stump11289f42009-09-09 15:08:12 +00001488
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// \brief Build a new overloaded operator call expression.
1490 ///
1491 /// By default, performs semantic analysis to build the new expression.
1492 /// The semantic analysis provides the behavior of template instantiation,
1493 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001494 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 /// argument-dependent lookup, etc. Subclasses may override this routine to
1496 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001497 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001499 Expr *Callee,
1500 Expr *First,
1501 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001502
1503 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// reinterpret_cast.
1505 ///
1506 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001507 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001509 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 Stmt::StmtClass Class,
1511 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001512 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 SourceLocation RAngleLoc,
1514 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001515 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 SourceLocation RParenLoc) {
1517 switch (Class) {
1518 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001519 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001520 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001521 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001522
1523 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001524 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001525 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001526 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001529 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001530 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001531 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001533
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001535 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001536 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001537 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001538
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 default:
1540 assert(false && "Invalid C++ named cast");
1541 break;
1542 }
Mike Stump11289f42009-09-09 15:08:12 +00001543
John McCallfaf5fb42010-08-26 23:41:50 +00001544 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 }
Mike Stump11289f42009-09-09 15:08:12 +00001546
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 /// \brief Build a new C++ static_cast expression.
1548 ///
1549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001551 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001553 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 SourceLocation RAngleLoc,
1555 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001556 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001558 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001559 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001560 SourceRange(LAngleLoc, RAngleLoc),
1561 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 }
1563
1564 /// \brief Build a new C++ dynamic_cast expression.
1565 ///
1566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001568 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001570 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 SourceLocation RAngleLoc,
1572 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001573 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001575 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001576 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001577 SourceRange(LAngleLoc, RAngleLoc),
1578 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 }
1580
1581 /// \brief Build a new C++ reinterpret_cast expression.
1582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001585 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001587 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 SourceLocation RAngleLoc,
1589 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001590 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001592 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001593 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001594 SourceRange(LAngleLoc, RAngleLoc),
1595 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 }
1597
1598 /// \brief Build a new C++ const_cast expression.
1599 ///
1600 /// By default, performs semantic analysis to build the new expression.
1601 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001602 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001604 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 SourceLocation RAngleLoc,
1606 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001607 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001609 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001610 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001611 SourceRange(LAngleLoc, RAngleLoc),
1612 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 }
Mike Stump11289f42009-09-09 15:08:12 +00001614
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 /// \brief Build a new C++ functional-style cast expression.
1616 ///
1617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001619 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1620 SourceLocation LParenLoc,
1621 Expr *Sub,
1622 SourceLocation RParenLoc) {
1623 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001624 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 RParenLoc);
1626 }
Mike Stump11289f42009-09-09 15:08:12 +00001627
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// \brief Build a new C++ typeid(type) expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001632 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001633 SourceLocation TypeidLoc,
1634 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001636 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001637 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 }
Mike Stump11289f42009-09-09 15:08:12 +00001639
Francois Pichet9f4f2072010-09-08 12:20:18 +00001640
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 /// \brief Build a new C++ typeid(expr) expression.
1642 ///
1643 /// By default, performs semantic analysis to build the new expression.
1644 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001645 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001646 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001647 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001649 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001650 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001651 }
1652
Francois Pichet9f4f2072010-09-08 12:20:18 +00001653 /// \brief Build a new C++ __uuidof(type) expression.
1654 ///
1655 /// By default, performs semantic analysis to build the new expression.
1656 /// Subclasses may override this routine to provide different behavior.
1657 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1658 SourceLocation TypeidLoc,
1659 TypeSourceInfo *Operand,
1660 SourceLocation RParenLoc) {
1661 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1662 RParenLoc);
1663 }
1664
1665 /// \brief Build a new C++ __uuidof(expr) expression.
1666 ///
1667 /// By default, performs semantic analysis to build the new expression.
1668 /// Subclasses may override this routine to provide different behavior.
1669 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1670 SourceLocation TypeidLoc,
1671 Expr *Operand,
1672 SourceLocation RParenLoc) {
1673 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1674 RParenLoc);
1675 }
1676
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 /// \brief Build a new C++ "this" expression.
1678 ///
1679 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001680 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001682 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001683 QualType ThisType,
1684 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001686 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1687 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 }
1689
1690 /// \brief Build a new C++ throw expression.
1691 ///
1692 /// By default, performs semantic analysis to build the new expression.
1693 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001694 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001695 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 }
1697
1698 /// \brief Build a new C++ default-argument expression.
1699 ///
1700 /// By default, builds a new default-argument expression, which does not
1701 /// require any semantic analysis. Subclasses may override this routine to
1702 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001703 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001704 ParmVarDecl *Param) {
1705 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1706 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 }
1708
1709 /// \brief Build a new C++ zero-initialization expression.
1710 ///
1711 /// By default, performs semantic analysis to build the new expression.
1712 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001713 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1714 SourceLocation LParenLoc,
1715 SourceLocation RParenLoc) {
1716 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001717 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001718 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 }
Mike Stump11289f42009-09-09 15:08:12 +00001720
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 /// \brief Build a new C++ "new" expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001725 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001726 bool UseGlobal,
1727 SourceLocation PlacementLParen,
1728 MultiExprArg PlacementArgs,
1729 SourceLocation PlacementRParen,
1730 SourceRange TypeIdParens,
1731 QualType AllocatedType,
1732 TypeSourceInfo *AllocatedTypeInfo,
1733 Expr *ArraySize,
1734 SourceLocation ConstructorLParen,
1735 MultiExprArg ConstructorArgs,
1736 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001737 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 PlacementLParen,
1739 move(PlacementArgs),
1740 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001741 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001742 AllocatedType,
1743 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001744 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 ConstructorLParen,
1746 move(ConstructorArgs),
1747 ConstructorRParen);
1748 }
Mike Stump11289f42009-09-09 15:08:12 +00001749
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 /// \brief Build a new C++ "delete" expression.
1751 ///
1752 /// By default, performs semantic analysis to build the new expression.
1753 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001754 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 bool IsGlobalDelete,
1756 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001757 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001759 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 }
Mike Stump11289f42009-09-09 15:08:12 +00001761
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 /// \brief Build a new unary type trait expression.
1763 ///
1764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001766 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001767 SourceLocation StartLoc,
1768 TypeSourceInfo *T,
1769 SourceLocation RParenLoc) {
1770 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
1772
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001773 /// \brief Build a new binary type trait expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
1777 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1778 SourceLocation StartLoc,
1779 TypeSourceInfo *LhsT,
1780 TypeSourceInfo *RhsT,
1781 SourceLocation RParenLoc) {
1782 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1783 }
1784
Mike Stump11289f42009-09-09 15:08:12 +00001785 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 /// expression.
1787 ///
1788 /// By default, performs semantic analysis to build the new expression.
1789 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001790 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001792 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001793 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 CXXScopeSpec SS;
1795 SS.setRange(QualifierRange);
1796 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001797
1798 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001799 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001800 *TemplateArgs);
1801
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001802 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 }
1804
1805 /// \brief Build a new template-id expression.
1806 ///
1807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001809 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001810 LookupResult &R,
1811 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001812 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001813 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 }
1815
1816 /// \brief Build a new object-construction 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 RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001821 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 CXXConstructorDecl *Constructor,
1823 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001824 MultiExprArg Args,
1825 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001826 CXXConstructExpr::ConstructionKind ConstructKind,
1827 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001828 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001829 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001830 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001831 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001832
Douglas Gregordb121ba2009-12-14 16:27:04 +00001833 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001834 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001835 RequiresZeroInit, ConstructKind,
1836 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 }
1838
1839 /// \brief Build a new object-construction expression.
1840 ///
1841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001843 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1844 SourceLocation LParenLoc,
1845 MultiExprArg Args,
1846 SourceLocation RParenLoc) {
1847 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 LParenLoc,
1849 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 RParenLoc);
1851 }
1852
1853 /// \brief Build a new object-construction expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001857 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1858 SourceLocation LParenLoc,
1859 MultiExprArg Args,
1860 SourceLocation RParenLoc) {
1861 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 LParenLoc,
1863 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 RParenLoc);
1865 }
Mike Stump11289f42009-09-09 15:08:12 +00001866
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 /// \brief Build a new member reference expression.
1868 ///
1869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001871 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001872 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 bool IsArrow,
1874 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001875 NestedNameSpecifier *Qualifier,
1876 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001877 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001878 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001879 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001881 SS.setRange(QualifierRange);
1882 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001883
John McCallb268a282010-08-23 23:25:46 +00001884 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001885 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001886 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001887 MemberNameInfo,
1888 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 }
1890
John McCall10eae182009-11-30 22:42:35 +00001891 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001892 ///
1893 /// By default, performs semantic analysis to build the new expression.
1894 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001895 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001896 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001897 SourceLocation OperatorLoc,
1898 bool IsArrow,
1899 NestedNameSpecifier *Qualifier,
1900 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001901 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001902 LookupResult &R,
1903 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001904 CXXScopeSpec SS;
1905 SS.setRange(QualifierRange);
1906 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001907
John McCallb268a282010-08-23 23:25:46 +00001908 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001909 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001910 SS, FirstQualifierInScope,
1911 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001912 }
Mike Stump11289f42009-09-09 15:08:12 +00001913
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001914 /// \brief Build a new noexcept expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
1918 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1919 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1920 }
1921
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001922 /// \brief Build a new expression to compute the length of a parameter pack.
1923 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1924 SourceLocation PackLoc,
1925 SourceLocation RParenLoc,
1926 unsigned Length) {
1927 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
1928 OperatorLoc, Pack, PackLoc,
1929 RParenLoc, Length);
1930 }
1931
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 /// \brief Build a new Objective-C @encode expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001936 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001937 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001939 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001941 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001942
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001943 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001944 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001945 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001946 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001947 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001948 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001949 MultiExprArg Args,
1950 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001951 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1952 ReceiverTypeInfo->getType(),
1953 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001954 Sel, Method, LBracLoc, SelectorLoc,
1955 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001956 }
1957
1958 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001959 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001960 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001961 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001962 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001963 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001964 MultiExprArg Args,
1965 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001966 return SemaRef.BuildInstanceMessage(Receiver,
1967 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001968 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001969 Sel, Method, LBracLoc, SelectorLoc,
1970 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001971 }
1972
Douglas Gregord51d90d2010-04-26 20:11:03 +00001973 /// \brief Build a new Objective-C ivar reference expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001977 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001978 SourceLocation IvarLoc,
1979 bool IsArrow, bool IsFreeIvar) {
1980 // FIXME: We lose track of the IsFreeIvar bit.
1981 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001982 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001983 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1984 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001985 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001986 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001987 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001988 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001989 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001990 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001991
Douglas Gregord51d90d2010-04-26 20:11:03 +00001992 if (Result.get())
1993 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001994
John McCallb268a282010-08-23 23:25:46 +00001995 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001996 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001997 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001998 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001999 /*TemplateArgs=*/0);
2000 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002001
2002 /// \brief Build a new Objective-C property reference 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 RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002007 ObjCPropertyDecl *Property,
2008 SourceLocation PropertyLoc) {
2009 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002010 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002011 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2012 Sema::LookupMemberName);
2013 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002014 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002015 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002016 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002017 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002018 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002019
Douglas Gregor9faee212010-04-26 20:47:02 +00002020 if (Result.get())
2021 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002022
John McCallb268a282010-08-23 23:25:46 +00002023 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002024 /*FIXME:*/PropertyLoc, IsArrow,
2025 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002026 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002027 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002028 /*TemplateArgs=*/0);
2029 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002030
John McCallb7bd14f2010-12-02 01:19:52 +00002031 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002032 ///
2033 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002034 /// Subclasses may override this routine to provide different behavior.
2035 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2036 ObjCMethodDecl *Getter,
2037 ObjCMethodDecl *Setter,
2038 SourceLocation PropertyLoc) {
2039 // Since these expressions can only be value-dependent, we do not
2040 // need to perform semantic analysis again.
2041 return Owned(
2042 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2043 VK_LValue, OK_ObjCProperty,
2044 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002045 }
2046
Douglas Gregord51d90d2010-04-26 20:11:03 +00002047 /// \brief Build a new Objective-C "isa" expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002052 bool IsArrow) {
2053 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002054 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002055 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2056 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002057 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002058 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002059 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002060 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002061 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002062
Douglas Gregord51d90d2010-04-26 20:11:03 +00002063 if (Result.get())
2064 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002065
John McCallb268a282010-08-23 23:25:46 +00002066 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002067 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002068 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002069 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002070 /*TemplateArgs=*/0);
2071 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002072
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// \brief Build a new shuffle vector expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002077 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002078 MultiExprArg SubExprs,
2079 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002081 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2083 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2084 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2085 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 // Build a reference to the __builtin_shufflevector builtin
2088 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002089 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002091 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002093
2094 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 unsigned NumSubExprs = SubExprs.size();
2096 Expr **Subs = (Expr **)SubExprs.release();
2097 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2098 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002099 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002100 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002102 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002103
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002105 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002108
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002110 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 }
John McCall31f82722010-11-12 08:19:04 +00002112
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002113 /// \brief Build a new template argument pack expansion.
2114 ///
2115 /// By default, performs semantic analysis to build a new pack expansion
2116 /// for a template argument. Subclasses may override this routine to provide
2117 /// different behavior.
2118 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2119 SourceLocation EllipsisLoc) {
2120 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002121 case TemplateArgument::Expression: {
2122 ExprResult Result
2123 = getSema().ActOnPackExpansion(Pattern.getSourceExpression(),
2124 EllipsisLoc);
2125 if (Result.isInvalid())
2126 return TemplateArgumentLoc();
2127
2128 return TemplateArgumentLoc(Result.get(), Result.get());
2129 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002130
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002131 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002132 return TemplateArgumentLoc(TemplateArgument(
2133 Pattern.getArgument().getAsTemplate(),
2134 true),
2135 Pattern.getTemplateQualifierRange(),
2136 Pattern.getTemplateNameLoc(),
2137 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002138
2139 case TemplateArgument::Null:
2140 case TemplateArgument::Integral:
2141 case TemplateArgument::Declaration:
2142 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002143 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002144 llvm_unreachable("Pack expansion pattern has no parameter packs");
2145
2146 case TemplateArgument::Type:
2147 if (TypeSourceInfo *Expansion
2148 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2149 EllipsisLoc))
2150 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2151 Expansion);
2152 break;
2153 }
2154
2155 return TemplateArgumentLoc();
2156 }
2157
Douglas Gregor968f23a2011-01-03 19:31:53 +00002158 /// \brief Build a new expression pack expansion.
2159 ///
2160 /// By default, performs semantic analysis to build a new pack expansion
2161 /// for an expression. Subclasses may override this routine to provide
2162 /// different behavior.
2163 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
2164 return getSema().ActOnPackExpansion(Pattern, EllipsisLoc);
2165 }
2166
John McCall31f82722010-11-12 08:19:04 +00002167private:
2168 QualType TransformTypeInObjectScope(QualType T,
2169 QualType ObjectType,
2170 NamedDecl *FirstQualifierInScope,
2171 NestedNameSpecifier *Prefix);
2172
2173 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2174 QualType ObjectType,
2175 NamedDecl *FirstQualifierInScope,
2176 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002177};
Douglas Gregora16548e2009-08-11 05:31:07 +00002178
Douglas Gregorebe10102009-08-20 07:17:43 +00002179template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002180StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002181 if (!S)
2182 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregorebe10102009-08-20 07:17:43 +00002184 switch (S->getStmtClass()) {
2185 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregorebe10102009-08-20 07:17:43 +00002187 // Transform individual statement nodes
2188#define STMT(Node, Parent) \
2189 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2190#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002191#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002192
Douglas Gregorebe10102009-08-20 07:17:43 +00002193 // Transform expressions by calling TransformExpr.
2194#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002195#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002196#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002197#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002198 {
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002200 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002201 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002202
John McCallb268a282010-08-23 23:25:46 +00002203 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002204 }
Mike Stump11289f42009-09-09 15:08:12 +00002205 }
2206
John McCallc3007a22010-10-26 07:05:15 +00002207 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002208}
Mike Stump11289f42009-09-09 15:08:12 +00002209
2210
Douglas Gregore922c772009-08-04 22:27:00 +00002211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002212ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 if (!E)
2214 return SemaRef.Owned(E);
2215
2216 switch (E->getStmtClass()) {
2217 case Stmt::NoStmtClass: break;
2218#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002219#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002220#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002221 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002222#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002223 }
2224
John McCallc3007a22010-10-26 07:05:15 +00002225 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002226}
2227
2228template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002229bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2230 unsigned NumInputs,
2231 bool IsCall,
2232 llvm::SmallVectorImpl<Expr *> &Outputs,
2233 bool *ArgChanged) {
2234 for (unsigned I = 0; I != NumInputs; ++I) {
2235 // If requested, drop call arguments that need to be dropped.
2236 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2237 if (ArgChanged)
2238 *ArgChanged = true;
2239
2240 break;
2241 }
2242
Douglas Gregor968f23a2011-01-03 19:31:53 +00002243 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2244 Expr *Pattern = Expansion->getPattern();
2245
2246 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2247 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2248 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2249
2250 // Determine whether the set of unexpanded parameter packs can and should
2251 // be expanded.
2252 bool Expand = true;
2253 unsigned NumExpansions = 0;
2254 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2255 Pattern->getSourceRange(),
2256 Unexpanded.data(),
2257 Unexpanded.size(),
2258 Expand, NumExpansions))
2259 return true;
2260
2261 if (!Expand) {
2262 // The transform has determined that we should perform a simple
2263 // transformation on the pack expansion, producing another pack
2264 // expansion.
2265 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2266 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2267 if (OutPattern.isInvalid())
2268 return true;
2269
2270 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2271 Expansion->getEllipsisLoc());
2272 if (Out.isInvalid())
2273 return true;
2274
2275 if (ArgChanged)
2276 *ArgChanged = true;
2277 Outputs.push_back(Out.get());
2278 continue;
2279 }
2280
2281 // The transform has determined that we should perform an elementwise
2282 // expansion of the pattern. Do so.
2283 for (unsigned I = 0; I != NumExpansions; ++I) {
2284 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2285 ExprResult Out = getDerived().TransformExpr(Pattern);
2286 if (Out.isInvalid())
2287 return true;
2288
2289 if (ArgChanged)
2290 *ArgChanged = true;
2291 Outputs.push_back(Out.get());
2292 }
2293
2294 continue;
2295 }
2296
Douglas Gregora3efea12011-01-03 19:04:46 +00002297 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2298 if (Result.isInvalid())
2299 return true;
2300
2301 if (Result.get() != Inputs[I] && ArgChanged)
2302 *ArgChanged = true;
2303
2304 Outputs.push_back(Result.get());
2305 }
2306
2307 return false;
2308}
2309
2310template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002311NestedNameSpecifier *
2312TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002313 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002314 QualType ObjectType,
2315 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002316 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002317
Douglas Gregorebe10102009-08-20 07:17:43 +00002318 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002319 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002320 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002321 ObjectType,
2322 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002323 if (!Prefix)
2324 return 0;
2325 }
Mike Stump11289f42009-09-09 15:08:12 +00002326
Douglas Gregor1135c352009-08-06 05:28:30 +00002327 switch (NNS->getKind()) {
2328 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002329 if (Prefix) {
2330 // The object type and qualifier-in-scope really apply to the
2331 // leftmost entity.
2332 ObjectType = QualType();
2333 FirstQualifierInScope = 0;
2334 }
2335
Mike Stump11289f42009-09-09 15:08:12 +00002336 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002337 "Identifier nested-name-specifier with no prefix or object type");
2338 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2339 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002340 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002341
2342 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002343 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002344 ObjectType,
2345 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002346
Douglas Gregor1135c352009-08-06 05:28:30 +00002347 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002348 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002349 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002350 getDerived().TransformDecl(Range.getBegin(),
2351 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002352 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002353 Prefix == NNS->getPrefix() &&
2354 NS == NNS->getAsNamespace())
2355 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregor1135c352009-08-06 05:28:30 +00002357 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2358 }
Mike Stump11289f42009-09-09 15:08:12 +00002359
Douglas Gregor1135c352009-08-06 05:28:30 +00002360 case NestedNameSpecifier::Global:
2361 // There is no meaningful transformation that one could perform on the
2362 // global scope.
2363 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002364
Douglas Gregor1135c352009-08-06 05:28:30 +00002365 case NestedNameSpecifier::TypeSpecWithTemplate:
2366 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002367 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002368 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2369 ObjectType,
2370 FirstQualifierInScope,
2371 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002372 if (T.isNull())
2373 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002374
Douglas Gregor1135c352009-08-06 05:28:30 +00002375 if (!getDerived().AlwaysRebuild() &&
2376 Prefix == NNS->getPrefix() &&
2377 T == QualType(NNS->getAsType(), 0))
2378 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002379
2380 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2381 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002382 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002383 }
2384 }
Mike Stump11289f42009-09-09 15:08:12 +00002385
Douglas Gregor1135c352009-08-06 05:28:30 +00002386 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002387 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002388}
2389
2390template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002391DeclarationNameInfo
2392TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002393::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002394 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002395 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002396 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002397
2398 switch (Name.getNameKind()) {
2399 case DeclarationName::Identifier:
2400 case DeclarationName::ObjCZeroArgSelector:
2401 case DeclarationName::ObjCOneArgSelector:
2402 case DeclarationName::ObjCMultiArgSelector:
2403 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002404 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002405 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002406 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002407
Douglas Gregorf816bd72009-09-03 22:13:48 +00002408 case DeclarationName::CXXConstructorName:
2409 case DeclarationName::CXXDestructorName:
2410 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002411 TypeSourceInfo *NewTInfo;
2412 CanQualType NewCanTy;
2413 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002414 NewTInfo = getDerived().TransformType(OldTInfo);
2415 if (!NewTInfo)
2416 return DeclarationNameInfo();
2417 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002418 }
2419 else {
2420 NewTInfo = 0;
2421 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002422 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002423 if (NewT.isNull())
2424 return DeclarationNameInfo();
2425 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2426 }
Mike Stump11289f42009-09-09 15:08:12 +00002427
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002428 DeclarationName NewName
2429 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2430 NewCanTy);
2431 DeclarationNameInfo NewNameInfo(NameInfo);
2432 NewNameInfo.setName(NewName);
2433 NewNameInfo.setNamedTypeInfo(NewTInfo);
2434 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002435 }
Mike Stump11289f42009-09-09 15:08:12 +00002436 }
2437
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002438 assert(0 && "Unknown name kind.");
2439 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002440}
2441
2442template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002443TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002444TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002445 QualType ObjectType,
2446 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002447 SourceLocation Loc = getDerived().getBaseLocation();
2448
Douglas Gregor71dc5092009-08-06 06:41:21 +00002449 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002450 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002451 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002452 /*FIXME*/ SourceRange(Loc),
2453 ObjectType,
2454 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002455 if (!NNS)
2456 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002457
Douglas Gregor71dc5092009-08-06 06:41:21 +00002458 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002459 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002460 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002461 if (!TransTemplate)
2462 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002463
Douglas Gregor71dc5092009-08-06 06:41:21 +00002464 if (!getDerived().AlwaysRebuild() &&
2465 NNS == QTN->getQualifier() &&
2466 TransTemplate == Template)
2467 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002468
Douglas Gregor71dc5092009-08-06 06:41:21 +00002469 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2470 TransTemplate);
2471 }
Mike Stump11289f42009-09-09 15:08:12 +00002472
John McCalle66edc12009-11-24 19:00:30 +00002473 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002474 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002475 }
Mike Stump11289f42009-09-09 15:08:12 +00002476
Douglas Gregor71dc5092009-08-06 06:41:21 +00002477 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002478 NestedNameSpecifier *NNS = DTN->getQualifier();
2479 if (NNS) {
2480 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2481 /*FIXME:*/SourceRange(Loc),
2482 ObjectType,
2483 FirstQualifierInScope);
2484 if (!NNS) return TemplateName();
2485
2486 // These apply to the scope specifier, not the template.
2487 ObjectType = QualType();
2488 FirstQualifierInScope = 0;
2489 }
Mike Stump11289f42009-09-09 15:08:12 +00002490
Douglas Gregor71dc5092009-08-06 06:41:21 +00002491 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002492 NNS == DTN->getQualifier() &&
2493 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002494 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002495
Douglas Gregora5614c52010-09-08 23:56:00 +00002496 if (DTN->isIdentifier()) {
2497 // FIXME: Bad range
2498 SourceRange QualifierRange(getDerived().getBaseLocation());
2499 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2500 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002501 ObjectType,
2502 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002503 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002504
2505 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002506 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002507 }
Mike Stump11289f42009-09-09 15:08:12 +00002508
Douglas Gregor71dc5092009-08-06 06:41:21 +00002509 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002510 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002511 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002512 if (!TransTemplate)
2513 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002514
Douglas Gregor71dc5092009-08-06 06:41:21 +00002515 if (!getDerived().AlwaysRebuild() &&
2516 TransTemplate == Template)
2517 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002518
Douglas Gregor71dc5092009-08-06 06:41:21 +00002519 return TemplateName(TransTemplate);
2520 }
Mike Stump11289f42009-09-09 15:08:12 +00002521
John McCalle66edc12009-11-24 19:00:30 +00002522 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002523 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002524 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002525}
2526
2527template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002528void TreeTransform<Derived>::InventTemplateArgumentLoc(
2529 const TemplateArgument &Arg,
2530 TemplateArgumentLoc &Output) {
2531 SourceLocation Loc = getDerived().getBaseLocation();
2532 switch (Arg.getKind()) {
2533 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002534 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002535 break;
2536
2537 case TemplateArgument::Type:
2538 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002539 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002540
John McCall0ad16662009-10-29 08:12:44 +00002541 break;
2542
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002543 case TemplateArgument::Template:
2544 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2545 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002546
2547 case TemplateArgument::TemplateExpansion:
2548 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2549 break;
2550
John McCall0ad16662009-10-29 08:12:44 +00002551 case TemplateArgument::Expression:
2552 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2553 break;
2554
2555 case TemplateArgument::Declaration:
2556 case TemplateArgument::Integral:
2557 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002558 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002559 break;
2560 }
2561}
2562
2563template<typename Derived>
2564bool TreeTransform<Derived>::TransformTemplateArgument(
2565 const TemplateArgumentLoc &Input,
2566 TemplateArgumentLoc &Output) {
2567 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002568 switch (Arg.getKind()) {
2569 case TemplateArgument::Null:
2570 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002571 Output = Input;
2572 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002573
Douglas Gregore922c772009-08-04 22:27:00 +00002574 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002575 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002576 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002577 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002578
2579 DI = getDerived().TransformType(DI);
2580 if (!DI) return true;
2581
2582 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2583 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002584 }
Mike Stump11289f42009-09-09 15:08:12 +00002585
Douglas Gregore922c772009-08-04 22:27:00 +00002586 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002587 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002588 DeclarationName Name;
2589 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2590 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002591 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002592 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002593 if (!D) return true;
2594
John McCall0d07eb32009-10-29 18:45:58 +00002595 Expr *SourceExpr = Input.getSourceDeclExpression();
2596 if (SourceExpr) {
2597 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002598 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002599 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002600 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002601 }
2602
2603 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002604 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002605 }
Mike Stump11289f42009-09-09 15:08:12 +00002606
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002607 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002608 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002609 TemplateName Template
2610 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2611 if (Template.isNull())
2612 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002613
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002614 Output = TemplateArgumentLoc(TemplateArgument(Template),
2615 Input.getTemplateQualifierRange(),
2616 Input.getTemplateNameLoc());
2617 return false;
2618 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002619
2620 case TemplateArgument::TemplateExpansion:
2621 llvm_unreachable("Caller should expand pack expansions");
2622
Douglas Gregore922c772009-08-04 22:27:00 +00002623 case TemplateArgument::Expression: {
2624 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002625 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002626 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002627
John McCall0ad16662009-10-29 08:12:44 +00002628 Expr *InputExpr = Input.getSourceExpression();
2629 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2630
John McCalldadc5752010-08-24 06:29:42 +00002631 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002632 = getDerived().TransformExpr(InputExpr);
2633 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002634 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002635 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002636 }
Mike Stump11289f42009-09-09 15:08:12 +00002637
Douglas Gregore922c772009-08-04 22:27:00 +00002638 case TemplateArgument::Pack: {
2639 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2640 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002641 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002642 AEnd = Arg.pack_end();
2643 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002644
John McCall0ad16662009-10-29 08:12:44 +00002645 // FIXME: preserve source information here when we start
2646 // caring about parameter packs.
2647
John McCall0d07eb32009-10-29 18:45:58 +00002648 TemplateArgumentLoc InputArg;
2649 TemplateArgumentLoc OutputArg;
2650 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2651 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002652 return true;
2653
John McCall0d07eb32009-10-29 18:45:58 +00002654 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002655 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002656
2657 TemplateArgument *TransformedArgsPtr
2658 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2659 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2660 TransformedArgsPtr);
2661 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2662 TransformedArgs.size()),
2663 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002664 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002665 }
2666 }
Mike Stump11289f42009-09-09 15:08:12 +00002667
Douglas Gregore922c772009-08-04 22:27:00 +00002668 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002669 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002670}
2671
Douglas Gregorfe921a72010-12-20 23:36:19 +00002672/// \brief Iterator adaptor that invents template argument location information
2673/// for each of the template arguments in its underlying iterator.
2674template<typename Derived, typename InputIterator>
2675class TemplateArgumentLocInventIterator {
2676 TreeTransform<Derived> &Self;
2677 InputIterator Iter;
2678
2679public:
2680 typedef TemplateArgumentLoc value_type;
2681 typedef TemplateArgumentLoc reference;
2682 typedef typename std::iterator_traits<InputIterator>::difference_type
2683 difference_type;
2684 typedef std::input_iterator_tag iterator_category;
2685
2686 class pointer {
2687 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002688
Douglas Gregorfe921a72010-12-20 23:36:19 +00002689 public:
2690 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2691
2692 const TemplateArgumentLoc *operator->() const { return &Arg; }
2693 };
2694
2695 TemplateArgumentLocInventIterator() { }
2696
2697 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2698 InputIterator Iter)
2699 : Self(Self), Iter(Iter) { }
2700
2701 TemplateArgumentLocInventIterator &operator++() {
2702 ++Iter;
2703 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002704 }
2705
Douglas Gregorfe921a72010-12-20 23:36:19 +00002706 TemplateArgumentLocInventIterator operator++(int) {
2707 TemplateArgumentLocInventIterator Old(*this);
2708 ++(*this);
2709 return Old;
2710 }
2711
2712 reference operator*() const {
2713 TemplateArgumentLoc Result;
2714 Self.InventTemplateArgumentLoc(*Iter, Result);
2715 return Result;
2716 }
2717
2718 pointer operator->() const { return pointer(**this); }
2719
2720 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2721 const TemplateArgumentLocInventIterator &Y) {
2722 return X.Iter == Y.Iter;
2723 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002724
Douglas Gregorfe921a72010-12-20 23:36:19 +00002725 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2726 const TemplateArgumentLocInventIterator &Y) {
2727 return X.Iter != Y.Iter;
2728 }
2729};
2730
Douglas Gregor42cafa82010-12-20 17:42:22 +00002731template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002732template<typename InputIterator>
2733bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2734 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002735 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002736 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002737 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002738 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002739
2740 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2741 // Unpack argument packs, which we translate them into separate
2742 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002743 // FIXME: We could do much better if we could guarantee that the
2744 // TemplateArgumentLocInfo for the pack expansion would be usable for
2745 // all of the template arguments in the argument pack.
2746 typedef TemplateArgumentLocInventIterator<Derived,
2747 TemplateArgument::pack_iterator>
2748 PackLocIterator;
2749 if (TransformTemplateArguments(PackLocIterator(*this,
2750 In.getArgument().pack_begin()),
2751 PackLocIterator(*this,
2752 In.getArgument().pack_end()),
2753 Outputs))
2754 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002755
2756 continue;
2757 }
2758
2759 if (In.getArgument().isPackExpansion()) {
2760 // We have a pack expansion, for which we will be substituting into
2761 // the pattern.
2762 SourceLocation Ellipsis;
2763 TemplateArgumentLoc Pattern
2764 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2765
2766 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2767 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2768 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2769
2770 // Determine whether the set of unexpanded parameter packs can and should
2771 // be expanded.
2772 bool Expand = true;
2773 unsigned NumExpansions = 0;
2774 if (getDerived().TryExpandParameterPacks(Ellipsis,
2775 Pattern.getSourceRange(),
2776 Unexpanded.data(),
2777 Unexpanded.size(),
2778 Expand, NumExpansions))
2779 return true;
2780
2781 if (!Expand) {
2782 // The transform has determined that we should perform a simple
2783 // transformation on the pack expansion, producing another pack
2784 // expansion.
2785 TemplateArgumentLoc OutPattern;
2786 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2787 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2788 return true;
2789
2790 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2791 if (Out.getArgument().isNull())
2792 return true;
2793
2794 Outputs.addArgument(Out);
2795 continue;
2796 }
2797
2798 // The transform has determined that we should perform an elementwise
2799 // expansion of the pattern. Do so.
2800 for (unsigned I = 0; I != NumExpansions; ++I) {
2801 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2802
2803 if (getDerived().TransformTemplateArgument(Pattern, Out))
2804 return true;
2805
2806 Outputs.addArgument(Out);
2807 }
2808
2809 continue;
2810 }
2811
2812 // The simple case:
2813 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002814 return true;
2815
2816 Outputs.addArgument(Out);
2817 }
2818
2819 return false;
2820
2821}
2822
Douglas Gregord6ff3322009-08-04 16:50:30 +00002823//===----------------------------------------------------------------------===//
2824// Type transformation
2825//===----------------------------------------------------------------------===//
2826
2827template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002828QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002829 if (getDerived().AlreadyTransformed(T))
2830 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002831
John McCall550e0c22009-10-21 00:40:46 +00002832 // Temporary workaround. All of these transformations should
2833 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002834 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002835 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002836
John McCall31f82722010-11-12 08:19:04 +00002837 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002838
John McCall550e0c22009-10-21 00:40:46 +00002839 if (!NewDI)
2840 return QualType();
2841
2842 return NewDI->getType();
2843}
2844
2845template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002846TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002847 if (getDerived().AlreadyTransformed(DI->getType()))
2848 return DI;
2849
2850 TypeLocBuilder TLB;
2851
2852 TypeLoc TL = DI->getTypeLoc();
2853 TLB.reserve(TL.getFullDataSize());
2854
John McCall31f82722010-11-12 08:19:04 +00002855 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002856 if (Result.isNull())
2857 return 0;
2858
John McCallbcd03502009-12-07 02:54:59 +00002859 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002860}
2861
2862template<typename Derived>
2863QualType
John McCall31f82722010-11-12 08:19:04 +00002864TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002865 switch (T.getTypeLocClass()) {
2866#define ABSTRACT_TYPELOC(CLASS, PARENT)
2867#define TYPELOC(CLASS, PARENT) \
2868 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002869 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002870#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002871 }
Mike Stump11289f42009-09-09 15:08:12 +00002872
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002873 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002874 return QualType();
2875}
2876
2877/// FIXME: By default, this routine adds type qualifiers only to types
2878/// that can have qualifiers, and silently suppresses those qualifiers
2879/// that are not permitted (e.g., qualifiers on reference or function
2880/// types). This is the right thing for template instantiation, but
2881/// probably not for other clients.
2882template<typename Derived>
2883QualType
2884TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002885 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002886 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002887
John McCall31f82722010-11-12 08:19:04 +00002888 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002889 if (Result.isNull())
2890 return QualType();
2891
2892 // Silently suppress qualifiers if the result type can't be qualified.
2893 // FIXME: this is the right thing for template instantiation, but
2894 // probably not for other clients.
2895 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002896 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002897
John McCallcb0f89a2010-06-05 06:41:15 +00002898 if (!Quals.empty()) {
2899 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2900 TLB.push<QualifiedTypeLoc>(Result);
2901 // No location information to preserve.
2902 }
John McCall550e0c22009-10-21 00:40:46 +00002903
2904 return Result;
2905}
2906
John McCall31f82722010-11-12 08:19:04 +00002907/// \brief Transforms a type that was written in a scope specifier,
2908/// given an object type, the results of unqualified lookup, and
2909/// an already-instantiated prefix.
2910///
2911/// The object type is provided iff the scope specifier qualifies the
2912/// member of a dependent member-access expression. The prefix is
2913/// provided iff the the scope specifier in which this appears has a
2914/// prefix.
2915///
2916/// This is private to TreeTransform.
2917template<typename Derived>
2918QualType
2919TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2920 QualType ObjectType,
2921 NamedDecl *UnqualLookup,
2922 NestedNameSpecifier *Prefix) {
2923 if (getDerived().AlreadyTransformed(T))
2924 return T;
2925
2926 TypeSourceInfo *TSI =
2927 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2928
2929 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2930 UnqualLookup, Prefix);
2931 if (!TSI) return QualType();
2932 return TSI->getType();
2933}
2934
2935template<typename Derived>
2936TypeSourceInfo *
2937TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2938 QualType ObjectType,
2939 NamedDecl *UnqualLookup,
2940 NestedNameSpecifier *Prefix) {
2941 // TODO: in some cases, we might be some verification to do here.
2942 if (ObjectType.isNull())
2943 return getDerived().TransformType(TSI);
2944
2945 QualType T = TSI->getType();
2946 if (getDerived().AlreadyTransformed(T))
2947 return TSI;
2948
2949 TypeLocBuilder TLB;
2950 QualType Result;
2951
2952 if (isa<TemplateSpecializationType>(T)) {
2953 TemplateSpecializationTypeLoc TL
2954 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2955
2956 TemplateName Template =
2957 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2958 ObjectType, UnqualLookup);
2959 if (Template.isNull()) return 0;
2960
2961 Result = getDerived()
2962 .TransformTemplateSpecializationType(TLB, TL, Template);
2963 } else if (isa<DependentTemplateSpecializationType>(T)) {
2964 DependentTemplateSpecializationTypeLoc TL
2965 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2966
2967 Result = getDerived()
2968 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2969 } else {
2970 // Nothing special needs to be done for these.
2971 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2972 }
2973
2974 if (Result.isNull()) return 0;
2975 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2976}
2977
John McCall550e0c22009-10-21 00:40:46 +00002978template <class TyLoc> static inline
2979QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2980 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2981 NewT.setNameLoc(T.getNameLoc());
2982 return T.getType();
2983}
2984
John McCall550e0c22009-10-21 00:40:46 +00002985template<typename Derived>
2986QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002987 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002988 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2989 NewT.setBuiltinLoc(T.getBuiltinLoc());
2990 if (T.needsExtraLocalData())
2991 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2992 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002993}
Mike Stump11289f42009-09-09 15:08:12 +00002994
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002996QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002997 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002998 // FIXME: recurse?
2999 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003000}
Mike Stump11289f42009-09-09 15:08:12 +00003001
Douglas Gregord6ff3322009-08-04 16:50:30 +00003002template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003003QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003004 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003005 QualType PointeeType
3006 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003007 if (PointeeType.isNull())
3008 return QualType();
3009
3010 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003011 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003012 // A dependent pointer type 'T *' has is being transformed such
3013 // that an Objective-C class type is being replaced for 'T'. The
3014 // resulting pointer type is an ObjCObjectPointerType, not a
3015 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003016 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003017
John McCall8b07ec22010-05-15 11:32:37 +00003018 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3019 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003020 return Result;
3021 }
John McCall31f82722010-11-12 08:19:04 +00003022
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003023 if (getDerived().AlwaysRebuild() ||
3024 PointeeType != TL.getPointeeLoc().getType()) {
3025 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3026 if (Result.isNull())
3027 return QualType();
3028 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003029
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003030 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3031 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003032 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003033}
Mike Stump11289f42009-09-09 15:08:12 +00003034
3035template<typename Derived>
3036QualType
John McCall550e0c22009-10-21 00:40:46 +00003037TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003038 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003039 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003040 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3041 if (PointeeType.isNull())
3042 return QualType();
3043
3044 QualType Result = TL.getType();
3045 if (getDerived().AlwaysRebuild() ||
3046 PointeeType != TL.getPointeeLoc().getType()) {
3047 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003048 TL.getSigilLoc());
3049 if (Result.isNull())
3050 return QualType();
3051 }
3052
Douglas Gregor049211a2010-04-22 16:50:51 +00003053 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003054 NewT.setSigilLoc(TL.getSigilLoc());
3055 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003056}
3057
John McCall70dd5f62009-10-30 00:06:24 +00003058/// Transforms a reference type. Note that somewhat paradoxically we
3059/// don't care whether the type itself is an l-value type or an r-value
3060/// type; we only care if the type was *written* as an l-value type
3061/// or an r-value type.
3062template<typename Derived>
3063QualType
3064TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003065 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003066 const ReferenceType *T = TL.getTypePtr();
3067
3068 // Note that this works with the pointee-as-written.
3069 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3070 if (PointeeType.isNull())
3071 return QualType();
3072
3073 QualType Result = TL.getType();
3074 if (getDerived().AlwaysRebuild() ||
3075 PointeeType != T->getPointeeTypeAsWritten()) {
3076 Result = getDerived().RebuildReferenceType(PointeeType,
3077 T->isSpelledAsLValue(),
3078 TL.getSigilLoc());
3079 if (Result.isNull())
3080 return QualType();
3081 }
3082
3083 // r-value references can be rebuilt as l-value references.
3084 ReferenceTypeLoc NewTL;
3085 if (isa<LValueReferenceType>(Result))
3086 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3087 else
3088 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3089 NewTL.setSigilLoc(TL.getSigilLoc());
3090
3091 return Result;
3092}
3093
Mike Stump11289f42009-09-09 15:08:12 +00003094template<typename Derived>
3095QualType
John McCall550e0c22009-10-21 00:40:46 +00003096TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003097 LValueReferenceTypeLoc TL) {
3098 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003099}
3100
Mike Stump11289f42009-09-09 15:08:12 +00003101template<typename Derived>
3102QualType
John McCall550e0c22009-10-21 00:40:46 +00003103TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003104 RValueReferenceTypeLoc TL) {
3105 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003106}
Mike Stump11289f42009-09-09 15:08:12 +00003107
Douglas Gregord6ff3322009-08-04 16:50:30 +00003108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003109QualType
John McCall550e0c22009-10-21 00:40:46 +00003110TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003111 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003112 MemberPointerType *T = TL.getTypePtr();
3113
3114 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003115 if (PointeeType.isNull())
3116 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003117
John McCall550e0c22009-10-21 00:40:46 +00003118 // TODO: preserve source information for this.
3119 QualType ClassType
3120 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003121 if (ClassType.isNull())
3122 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003123
John McCall550e0c22009-10-21 00:40:46 +00003124 QualType Result = TL.getType();
3125 if (getDerived().AlwaysRebuild() ||
3126 PointeeType != T->getPointeeType() ||
3127 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003128 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3129 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003130 if (Result.isNull())
3131 return QualType();
3132 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003133
John McCall550e0c22009-10-21 00:40:46 +00003134 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3135 NewTL.setSigilLoc(TL.getSigilLoc());
3136
3137 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003138}
3139
Mike Stump11289f42009-09-09 15:08:12 +00003140template<typename Derived>
3141QualType
John McCall550e0c22009-10-21 00:40:46 +00003142TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003143 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003144 ConstantArrayType *T = TL.getTypePtr();
3145 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146 if (ElementType.isNull())
3147 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003148
John McCall550e0c22009-10-21 00:40:46 +00003149 QualType Result = TL.getType();
3150 if (getDerived().AlwaysRebuild() ||
3151 ElementType != T->getElementType()) {
3152 Result = getDerived().RebuildConstantArrayType(ElementType,
3153 T->getSizeModifier(),
3154 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003155 T->getIndexTypeCVRQualifiers(),
3156 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003157 if (Result.isNull())
3158 return QualType();
3159 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003160
John McCall550e0c22009-10-21 00:40:46 +00003161 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3162 NewTL.setLBracketLoc(TL.getLBracketLoc());
3163 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003164
John McCall550e0c22009-10-21 00:40:46 +00003165 Expr *Size = TL.getSizeExpr();
3166 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003167 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003168 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3169 }
3170 NewTL.setSizeExpr(Size);
3171
3172 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003173}
Mike Stump11289f42009-09-09 15:08:12 +00003174
Douglas Gregord6ff3322009-08-04 16:50:30 +00003175template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003176QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003177 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003178 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003179 IncompleteArrayType *T = TL.getTypePtr();
3180 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003181 if (ElementType.isNull())
3182 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003183
John McCall550e0c22009-10-21 00:40:46 +00003184 QualType Result = TL.getType();
3185 if (getDerived().AlwaysRebuild() ||
3186 ElementType != T->getElementType()) {
3187 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003188 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003189 T->getIndexTypeCVRQualifiers(),
3190 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003191 if (Result.isNull())
3192 return QualType();
3193 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003194
John McCall550e0c22009-10-21 00:40:46 +00003195 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3196 NewTL.setLBracketLoc(TL.getLBracketLoc());
3197 NewTL.setRBracketLoc(TL.getRBracketLoc());
3198 NewTL.setSizeExpr(0);
3199
3200 return Result;
3201}
3202
3203template<typename Derived>
3204QualType
3205TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003206 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003207 VariableArrayType *T = TL.getTypePtr();
3208 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3209 if (ElementType.isNull())
3210 return QualType();
3211
3212 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003213 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003214
John McCalldadc5752010-08-24 06:29:42 +00003215 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003216 = getDerived().TransformExpr(T->getSizeExpr());
3217 if (SizeResult.isInvalid())
3218 return QualType();
3219
John McCallb268a282010-08-23 23:25:46 +00003220 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003221
3222 QualType Result = TL.getType();
3223 if (getDerived().AlwaysRebuild() ||
3224 ElementType != T->getElementType() ||
3225 Size != T->getSizeExpr()) {
3226 Result = getDerived().RebuildVariableArrayType(ElementType,
3227 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003228 Size,
John McCall550e0c22009-10-21 00:40:46 +00003229 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003230 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003231 if (Result.isNull())
3232 return QualType();
3233 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003234
John McCall550e0c22009-10-21 00:40:46 +00003235 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3236 NewTL.setLBracketLoc(TL.getLBracketLoc());
3237 NewTL.setRBracketLoc(TL.getRBracketLoc());
3238 NewTL.setSizeExpr(Size);
3239
3240 return Result;
3241}
3242
3243template<typename Derived>
3244QualType
3245TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003246 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003247 DependentSizedArrayType *T = TL.getTypePtr();
3248 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3249 if (ElementType.isNull())
3250 return QualType();
3251
3252 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003253 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003254
John McCalldadc5752010-08-24 06:29:42 +00003255 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003256 = getDerived().TransformExpr(T->getSizeExpr());
3257 if (SizeResult.isInvalid())
3258 return QualType();
3259
3260 Expr *Size = static_cast<Expr*>(SizeResult.get());
3261
3262 QualType Result = TL.getType();
3263 if (getDerived().AlwaysRebuild() ||
3264 ElementType != T->getElementType() ||
3265 Size != T->getSizeExpr()) {
3266 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3267 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003268 Size,
John McCall550e0c22009-10-21 00:40:46 +00003269 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003270 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003271 if (Result.isNull())
3272 return QualType();
3273 }
3274 else SizeResult.take();
3275
3276 // We might have any sort of array type now, but fortunately they
3277 // all have the same location layout.
3278 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3279 NewTL.setLBracketLoc(TL.getLBracketLoc());
3280 NewTL.setRBracketLoc(TL.getRBracketLoc());
3281 NewTL.setSizeExpr(Size);
3282
3283 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003284}
Mike Stump11289f42009-09-09 15:08:12 +00003285
3286template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003287QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003288 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003289 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003290 DependentSizedExtVectorType *T = TL.getTypePtr();
3291
3292 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293 QualType ElementType = getDerived().TransformType(T->getElementType());
3294 if (ElementType.isNull())
3295 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003296
Douglas Gregore922c772009-08-04 22:27:00 +00003297 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003298 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003299
John McCalldadc5752010-08-24 06:29:42 +00003300 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003301 if (Size.isInvalid())
3302 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003303
John McCall550e0c22009-10-21 00:40:46 +00003304 QualType Result = TL.getType();
3305 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003306 ElementType != T->getElementType() ||
3307 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003308 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003309 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003310 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003311 if (Result.isNull())
3312 return QualType();
3313 }
John McCall550e0c22009-10-21 00:40:46 +00003314
3315 // Result might be dependent or not.
3316 if (isa<DependentSizedExtVectorType>(Result)) {
3317 DependentSizedExtVectorTypeLoc NewTL
3318 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3319 NewTL.setNameLoc(TL.getNameLoc());
3320 } else {
3321 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3322 NewTL.setNameLoc(TL.getNameLoc());
3323 }
3324
3325 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003326}
Mike Stump11289f42009-09-09 15:08:12 +00003327
3328template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003329QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003330 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003331 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003332 QualType ElementType = getDerived().TransformType(T->getElementType());
3333 if (ElementType.isNull())
3334 return QualType();
3335
John McCall550e0c22009-10-21 00:40:46 +00003336 QualType Result = TL.getType();
3337 if (getDerived().AlwaysRebuild() ||
3338 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003339 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003340 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003341 if (Result.isNull())
3342 return QualType();
3343 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003344
John McCall550e0c22009-10-21 00:40:46 +00003345 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3346 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003347
John McCall550e0c22009-10-21 00:40:46 +00003348 return Result;
3349}
3350
3351template<typename Derived>
3352QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003353 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003354 VectorType *T = TL.getTypePtr();
3355 QualType ElementType = getDerived().TransformType(T->getElementType());
3356 if (ElementType.isNull())
3357 return QualType();
3358
3359 QualType Result = TL.getType();
3360 if (getDerived().AlwaysRebuild() ||
3361 ElementType != T->getElementType()) {
3362 Result = getDerived().RebuildExtVectorType(ElementType,
3363 T->getNumElements(),
3364 /*FIXME*/ SourceLocation());
3365 if (Result.isNull())
3366 return QualType();
3367 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003368
John McCall550e0c22009-10-21 00:40:46 +00003369 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3370 NewTL.setNameLoc(TL.getNameLoc());
3371
3372 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003373}
Mike Stump11289f42009-09-09 15:08:12 +00003374
3375template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003376ParmVarDecl *
3377TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3378 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3379 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3380 if (!NewDI)
3381 return 0;
3382
3383 if (NewDI == OldDI)
3384 return OldParm;
3385 else
3386 return ParmVarDecl::Create(SemaRef.Context,
3387 OldParm->getDeclContext(),
3388 OldParm->getLocation(),
3389 OldParm->getIdentifier(),
3390 NewDI->getType(),
3391 NewDI,
3392 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003393 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003394 /* DefArg */ NULL);
3395}
3396
3397template<typename Derived>
3398bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003399 TransformFunctionTypeParams(SourceLocation Loc,
3400 ParmVarDecl **Params, unsigned NumParams,
3401 const QualType *ParamTypes,
3402 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3403 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3404 for (unsigned i = 0; i != NumParams; ++i) {
3405 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003406 if (OldParm->isParameterPack()) {
3407 // We have a function parameter pack that may need to be expanded.
3408 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003409
Douglas Gregor5499af42011-01-05 23:12:31 +00003410 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003411 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3412 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3413 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3414 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003415
3416 // Determine whether we should expand the parameter packs.
3417 bool ShouldExpand = false;
3418 unsigned NumExpansions = 0;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003419 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3420 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003421 Unexpanded.data(),
3422 Unexpanded.size(),
3423 ShouldExpand, NumExpansions)) {
3424 return true;
3425 }
3426
3427 if (ShouldExpand) {
3428 // Expand the function parameter pack into multiple, separate
3429 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003430 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003431 for (unsigned I = 0; I != NumExpansions; ++I) {
3432 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3433 ParmVarDecl *NewParm
3434 = getDerived().TransformFunctionTypeParam(OldParm);
3435 if (!NewParm)
3436 return true;
3437
Douglas Gregordd472162011-01-07 00:20:55 +00003438 OutParamTypes.push_back(NewParm->getType());
3439 if (PVars)
3440 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003441 }
3442
3443 // We're done with the pack expansion.
3444 continue;
3445 }
3446
3447 // We'll substitute the parameter now without expanding the pack
3448 // expansion.
3449 }
3450
3451 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3452 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
John McCall58f10c32010-03-11 09:03:00 +00003453 if (!NewParm)
3454 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003455
Douglas Gregordd472162011-01-07 00:20:55 +00003456 OutParamTypes.push_back(NewParm->getType());
3457 if (PVars)
3458 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003459 continue;
3460 }
John McCall58f10c32010-03-11 09:03:00 +00003461
3462 // Deal with the possibility that we don't have a parameter
3463 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003464 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003465 bool IsPackExpansion = false;
3466 if (const PackExpansionType *Expansion
3467 = dyn_cast<PackExpansionType>(OldType)) {
3468 // We have a function parameter pack that may need to be expanded.
3469 QualType Pattern = Expansion->getPattern();
3470 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3471 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3472
3473 // Determine whether we should expand the parameter packs.
3474 bool ShouldExpand = false;
3475 unsigned NumExpansions = 0;
Douglas Gregordd472162011-01-07 00:20:55 +00003476 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003477 Unexpanded.data(),
3478 Unexpanded.size(),
3479 ShouldExpand, NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003480 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003481 }
3482
3483 if (ShouldExpand) {
3484 // Expand the function parameter pack into multiple, separate
3485 // parameters.
3486 for (unsigned I = 0; I != NumExpansions; ++I) {
3487 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3488 QualType NewType = getDerived().TransformType(Pattern);
3489 if (NewType.isNull())
3490 return true;
John McCall58f10c32010-03-11 09:03:00 +00003491
Douglas Gregordd472162011-01-07 00:20:55 +00003492 OutParamTypes.push_back(NewType);
3493 if (PVars)
3494 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003495 }
3496
3497 // We're done with the pack expansion.
3498 continue;
3499 }
3500
3501 // We'll substitute the parameter now without expanding the pack
3502 // expansion.
3503 OldType = Expansion->getPattern();
3504 IsPackExpansion = true;
3505 }
3506
3507 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3508 QualType NewType = getDerived().TransformType(OldType);
3509 if (NewType.isNull())
3510 return true;
3511
3512 if (IsPackExpansion)
3513 NewType = getSema().Context.getPackExpansionType(NewType);
3514
Douglas Gregordd472162011-01-07 00:20:55 +00003515 OutParamTypes.push_back(NewType);
3516 if (PVars)
3517 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003518 }
3519
3520 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003521 }
John McCall58f10c32010-03-11 09:03:00 +00003522
3523template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003524QualType
John McCall550e0c22009-10-21 00:40:46 +00003525TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003526 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003527 // Transform the parameters and return type.
3528 //
3529 // We instantiate in source order, with the return type first followed by
3530 // the parameters, because users tend to expect this (even if they shouldn't
3531 // rely on it!).
3532 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003533 // When the function has a trailing return type, we instantiate the
3534 // parameters before the return type, since the return type can then refer
3535 // to the parameters themselves (via decltype, sizeof, etc.).
3536 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003537 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003538 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003539 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003540
Douglas Gregor7fb25412010-10-01 18:44:50 +00003541 QualType ResultType;
3542
3543 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003544 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3545 TL.getParmArray(),
3546 TL.getNumArgs(),
3547 TL.getTypePtr()->arg_type_begin(),
3548 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003549 return QualType();
3550
3551 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3552 if (ResultType.isNull())
3553 return QualType();
3554 }
3555 else {
3556 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3557 if (ResultType.isNull())
3558 return QualType();
3559
Douglas Gregordd472162011-01-07 00:20:55 +00003560 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3561 TL.getParmArray(),
3562 TL.getNumArgs(),
3563 TL.getTypePtr()->arg_type_begin(),
3564 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003565 return QualType();
3566 }
3567
John McCall550e0c22009-10-21 00:40:46 +00003568 QualType Result = TL.getType();
3569 if (getDerived().AlwaysRebuild() ||
3570 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003571 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003572 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3573 Result = getDerived().RebuildFunctionProtoType(ResultType,
3574 ParamTypes.data(),
3575 ParamTypes.size(),
3576 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003577 T->getTypeQuals(),
3578 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003579 if (Result.isNull())
3580 return QualType();
3581 }
Mike Stump11289f42009-09-09 15:08:12 +00003582
John McCall550e0c22009-10-21 00:40:46 +00003583 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3584 NewTL.setLParenLoc(TL.getLParenLoc());
3585 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003586 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003587 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3588 NewTL.setArg(i, ParamDecls[i]);
3589
3590 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003591}
Mike Stump11289f42009-09-09 15:08:12 +00003592
Douglas Gregord6ff3322009-08-04 16:50:30 +00003593template<typename Derived>
3594QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003595 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003596 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003597 FunctionNoProtoType *T = TL.getTypePtr();
3598 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3599 if (ResultType.isNull())
3600 return QualType();
3601
3602 QualType Result = TL.getType();
3603 if (getDerived().AlwaysRebuild() ||
3604 ResultType != T->getResultType())
3605 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3606
3607 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3608 NewTL.setLParenLoc(TL.getLParenLoc());
3609 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003610 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003611
3612 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003613}
Mike Stump11289f42009-09-09 15:08:12 +00003614
John McCallb96ec562009-12-04 22:46:56 +00003615template<typename Derived> QualType
3616TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003617 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003618 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003619 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003620 if (!D)
3621 return QualType();
3622
3623 QualType Result = TL.getType();
3624 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3625 Result = getDerived().RebuildUnresolvedUsingType(D);
3626 if (Result.isNull())
3627 return QualType();
3628 }
3629
3630 // We might get an arbitrary type spec type back. We should at
3631 // least always get a type spec type, though.
3632 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3633 NewTL.setNameLoc(TL.getNameLoc());
3634
3635 return Result;
3636}
3637
Douglas Gregord6ff3322009-08-04 16:50:30 +00003638template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003639QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003640 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003641 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003642 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003643 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3644 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003645 if (!Typedef)
3646 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003647
John McCall550e0c22009-10-21 00:40:46 +00003648 QualType Result = TL.getType();
3649 if (getDerived().AlwaysRebuild() ||
3650 Typedef != T->getDecl()) {
3651 Result = getDerived().RebuildTypedefType(Typedef);
3652 if (Result.isNull())
3653 return QualType();
3654 }
Mike Stump11289f42009-09-09 15:08:12 +00003655
John McCall550e0c22009-10-21 00:40:46 +00003656 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3657 NewTL.setNameLoc(TL.getNameLoc());
3658
3659 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003660}
Mike Stump11289f42009-09-09 15:08:12 +00003661
Douglas Gregord6ff3322009-08-04 16:50:30 +00003662template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003663QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003664 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003665 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003666 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003667
John McCalldadc5752010-08-24 06:29:42 +00003668 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003669 if (E.isInvalid())
3670 return QualType();
3671
John McCall550e0c22009-10-21 00:40:46 +00003672 QualType Result = TL.getType();
3673 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003674 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003675 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003676 if (Result.isNull())
3677 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003678 }
John McCall550e0c22009-10-21 00:40:46 +00003679 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003680
John McCall550e0c22009-10-21 00:40:46 +00003681 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003682 NewTL.setTypeofLoc(TL.getTypeofLoc());
3683 NewTL.setLParenLoc(TL.getLParenLoc());
3684 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003685
3686 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003687}
Mike Stump11289f42009-09-09 15:08:12 +00003688
3689template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003690QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003691 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003692 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3693 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3694 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003695 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003696
John McCall550e0c22009-10-21 00:40:46 +00003697 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003698 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3699 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003700 if (Result.isNull())
3701 return QualType();
3702 }
Mike Stump11289f42009-09-09 15:08:12 +00003703
John McCall550e0c22009-10-21 00:40:46 +00003704 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003705 NewTL.setTypeofLoc(TL.getTypeofLoc());
3706 NewTL.setLParenLoc(TL.getLParenLoc());
3707 NewTL.setRParenLoc(TL.getRParenLoc());
3708 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003709
3710 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003711}
Mike Stump11289f42009-09-09 15:08:12 +00003712
3713template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003714QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003715 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003716 DecltypeType *T = TL.getTypePtr();
3717
Douglas Gregore922c772009-08-04 22:27:00 +00003718 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003719 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003720
John McCalldadc5752010-08-24 06:29:42 +00003721 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003722 if (E.isInvalid())
3723 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003724
John McCall550e0c22009-10-21 00:40:46 +00003725 QualType Result = TL.getType();
3726 if (getDerived().AlwaysRebuild() ||
3727 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003728 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003729 if (Result.isNull())
3730 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003731 }
John McCall550e0c22009-10-21 00:40:46 +00003732 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003733
John McCall550e0c22009-10-21 00:40:46 +00003734 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3735 NewTL.setNameLoc(TL.getNameLoc());
3736
3737 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003738}
3739
3740template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003741QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003742 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003743 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003744 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003745 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3746 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003747 if (!Record)
3748 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003749
John McCall550e0c22009-10-21 00:40:46 +00003750 QualType Result = TL.getType();
3751 if (getDerived().AlwaysRebuild() ||
3752 Record != T->getDecl()) {
3753 Result = getDerived().RebuildRecordType(Record);
3754 if (Result.isNull())
3755 return QualType();
3756 }
Mike Stump11289f42009-09-09 15:08:12 +00003757
John McCall550e0c22009-10-21 00:40:46 +00003758 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3759 NewTL.setNameLoc(TL.getNameLoc());
3760
3761 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003762}
Mike Stump11289f42009-09-09 15:08:12 +00003763
3764template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003765QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003766 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003767 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003768 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003769 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3770 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003771 if (!Enum)
3772 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003773
John McCall550e0c22009-10-21 00:40:46 +00003774 QualType Result = TL.getType();
3775 if (getDerived().AlwaysRebuild() ||
3776 Enum != T->getDecl()) {
3777 Result = getDerived().RebuildEnumType(Enum);
3778 if (Result.isNull())
3779 return QualType();
3780 }
Mike Stump11289f42009-09-09 15:08:12 +00003781
John McCall550e0c22009-10-21 00:40:46 +00003782 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3783 NewTL.setNameLoc(TL.getNameLoc());
3784
3785 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003786}
John McCallfcc33b02009-09-05 00:15:47 +00003787
John McCalle78aac42010-03-10 03:28:59 +00003788template<typename Derived>
3789QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3790 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003791 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003792 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3793 TL.getTypePtr()->getDecl());
3794 if (!D) return QualType();
3795
3796 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3797 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3798 return T;
3799}
3800
Douglas Gregord6ff3322009-08-04 16:50:30 +00003801template<typename Derived>
3802QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003803 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003804 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003805 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003806}
3807
Mike Stump11289f42009-09-09 15:08:12 +00003808template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003809QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003810 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003811 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003812 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003813}
3814
3815template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003816QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003817 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003818 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003819 const TemplateSpecializationType *T = TL.getTypePtr();
3820
Mike Stump11289f42009-09-09 15:08:12 +00003821 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003822 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003823 if (Template.isNull())
3824 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003825
John McCall31f82722010-11-12 08:19:04 +00003826 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3827}
3828
Douglas Gregorfe921a72010-12-20 23:36:19 +00003829namespace {
3830 /// \brief Simple iterator that traverses the template arguments in a
3831 /// container that provides a \c getArgLoc() member function.
3832 ///
3833 /// This iterator is intended to be used with the iterator form of
3834 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3835 template<typename ArgLocContainer>
3836 class TemplateArgumentLocContainerIterator {
3837 ArgLocContainer *Container;
3838 unsigned Index;
3839
3840 public:
3841 typedef TemplateArgumentLoc value_type;
3842 typedef TemplateArgumentLoc reference;
3843 typedef int difference_type;
3844 typedef std::input_iterator_tag iterator_category;
3845
3846 class pointer {
3847 TemplateArgumentLoc Arg;
3848
3849 public:
3850 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3851
3852 const TemplateArgumentLoc *operator->() const {
3853 return &Arg;
3854 }
3855 };
3856
3857
3858 TemplateArgumentLocContainerIterator() {}
3859
3860 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3861 unsigned Index)
3862 : Container(&Container), Index(Index) { }
3863
3864 TemplateArgumentLocContainerIterator &operator++() {
3865 ++Index;
3866 return *this;
3867 }
3868
3869 TemplateArgumentLocContainerIterator operator++(int) {
3870 TemplateArgumentLocContainerIterator Old(*this);
3871 ++(*this);
3872 return Old;
3873 }
3874
3875 TemplateArgumentLoc operator*() const {
3876 return Container->getArgLoc(Index);
3877 }
3878
3879 pointer operator->() const {
3880 return pointer(Container->getArgLoc(Index));
3881 }
3882
3883 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003884 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003885 return X.Container == Y.Container && X.Index == Y.Index;
3886 }
3887
3888 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003889 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003890 return !(X == Y);
3891 }
3892 };
3893}
3894
3895
John McCall31f82722010-11-12 08:19:04 +00003896template <typename Derived>
3897QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3898 TypeLocBuilder &TLB,
3899 TemplateSpecializationTypeLoc TL,
3900 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00003901 TemplateArgumentListInfo NewTemplateArgs;
3902 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3903 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003904 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3905 ArgIterator;
3906 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3907 ArgIterator(TL, TL.getNumArgs()),
3908 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003909 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003910
John McCall0ad16662009-10-29 08:12:44 +00003911 // FIXME: maybe don't rebuild if all the template arguments are the same.
3912
3913 QualType Result =
3914 getDerived().RebuildTemplateSpecializationType(Template,
3915 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003916 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003917
3918 if (!Result.isNull()) {
3919 TemplateSpecializationTypeLoc NewTL
3920 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3921 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3922 NewTL.setLAngleLoc(TL.getLAngleLoc());
3923 NewTL.setRAngleLoc(TL.getRAngleLoc());
3924 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3925 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003926 }
Mike Stump11289f42009-09-09 15:08:12 +00003927
John McCall0ad16662009-10-29 08:12:44 +00003928 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003929}
Mike Stump11289f42009-09-09 15:08:12 +00003930
3931template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003932QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003933TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003934 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003935 ElaboratedType *T = TL.getTypePtr();
3936
3937 NestedNameSpecifier *NNS = 0;
3938 // NOTE: the qualifier in an ElaboratedType is optional.
3939 if (T->getQualifier() != 0) {
3940 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003941 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003942 if (!NNS)
3943 return QualType();
3944 }
Mike Stump11289f42009-09-09 15:08:12 +00003945
John McCall31f82722010-11-12 08:19:04 +00003946 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3947 if (NamedT.isNull())
3948 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003949
John McCall550e0c22009-10-21 00:40:46 +00003950 QualType Result = TL.getType();
3951 if (getDerived().AlwaysRebuild() ||
3952 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003953 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003954 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3955 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003956 if (Result.isNull())
3957 return QualType();
3958 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003959
Abramo Bagnara6150c882010-05-11 21:36:43 +00003960 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003961 NewTL.setKeywordLoc(TL.getKeywordLoc());
3962 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003963
3964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003965}
Mike Stump11289f42009-09-09 15:08:12 +00003966
3967template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00003968QualType TreeTransform<Derived>::TransformAttributedType(
3969 TypeLocBuilder &TLB,
3970 AttributedTypeLoc TL) {
3971 const AttributedType *oldType = TL.getTypePtr();
3972 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
3973 if (modifiedType.isNull())
3974 return QualType();
3975
3976 QualType result = TL.getType();
3977
3978 // FIXME: dependent operand expressions?
3979 if (getDerived().AlwaysRebuild() ||
3980 modifiedType != oldType->getModifiedType()) {
3981 // TODO: this is really lame; we should really be rebuilding the
3982 // equivalent type from first principles.
3983 QualType equivalentType
3984 = getDerived().TransformType(oldType->getEquivalentType());
3985 if (equivalentType.isNull())
3986 return QualType();
3987 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
3988 modifiedType,
3989 equivalentType);
3990 }
3991
3992 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
3993 newTL.setAttrNameLoc(TL.getAttrNameLoc());
3994 if (TL.hasAttrOperand())
3995 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
3996 if (TL.hasAttrExprOperand())
3997 newTL.setAttrExprOperand(TL.getAttrExprOperand());
3998 else if (TL.hasAttrEnumOperand())
3999 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4000
4001 return result;
4002}
4003
4004template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004005QualType
4006TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4007 ParenTypeLoc TL) {
4008 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4009 if (Inner.isNull())
4010 return QualType();
4011
4012 QualType Result = TL.getType();
4013 if (getDerived().AlwaysRebuild() ||
4014 Inner != TL.getInnerLoc().getType()) {
4015 Result = getDerived().RebuildParenType(Inner);
4016 if (Result.isNull())
4017 return QualType();
4018 }
4019
4020 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4021 NewTL.setLParenLoc(TL.getLParenLoc());
4022 NewTL.setRParenLoc(TL.getRParenLoc());
4023 return Result;
4024}
4025
4026template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004027QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004028 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004029 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004030
Douglas Gregord6ff3322009-08-04 16:50:30 +00004031 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004032 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004033 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004034 if (!NNS)
4035 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004036
John McCallc392f372010-06-11 00:33:02 +00004037 QualType Result
4038 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4039 T->getIdentifier(),
4040 TL.getKeywordLoc(),
4041 TL.getQualifierRange(),
4042 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004043 if (Result.isNull())
4044 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045
Abramo Bagnarad7548482010-05-19 21:37:53 +00004046 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4047 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004048 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4049
Abramo Bagnarad7548482010-05-19 21:37:53 +00004050 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4051 NewTL.setKeywordLoc(TL.getKeywordLoc());
4052 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004053 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004054 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4055 NewTL.setKeywordLoc(TL.getKeywordLoc());
4056 NewTL.setQualifierRange(TL.getQualifierRange());
4057 NewTL.setNameLoc(TL.getNameLoc());
4058 }
John McCall550e0c22009-10-21 00:40:46 +00004059 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004060}
Mike Stump11289f42009-09-09 15:08:12 +00004061
Douglas Gregord6ff3322009-08-04 16:50:30 +00004062template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004063QualType TreeTransform<Derived>::
4064 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004065 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00004066 DependentTemplateSpecializationType *T = TL.getTypePtr();
4067
4068 NestedNameSpecifier *NNS
4069 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004070 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004071 if (!NNS)
4072 return QualType();
4073
John McCall31f82722010-11-12 08:19:04 +00004074 return getDerived()
4075 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4076}
4077
4078template<typename Derived>
4079QualType TreeTransform<Derived>::
4080 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4081 DependentTemplateSpecializationTypeLoc TL,
4082 NestedNameSpecifier *NNS) {
4083 DependentTemplateSpecializationType *T = TL.getTypePtr();
4084
John McCallc392f372010-06-11 00:33:02 +00004085 TemplateArgumentListInfo NewTemplateArgs;
4086 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4087 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004088
4089 typedef TemplateArgumentLocContainerIterator<
4090 DependentTemplateSpecializationTypeLoc> ArgIterator;
4091 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4092 ArgIterator(TL, TL.getNumArgs()),
4093 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004094 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004095
Douglas Gregora5614c52010-09-08 23:56:00 +00004096 QualType Result
4097 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4098 NNS,
4099 TL.getQualifierRange(),
4100 T->getIdentifier(),
4101 TL.getNameLoc(),
4102 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004103 if (Result.isNull())
4104 return QualType();
4105
4106 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4107 QualType NamedT = ElabT->getNamedType();
4108
4109 // Copy information relevant to the template specialization.
4110 TemplateSpecializationTypeLoc NamedTL
4111 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4112 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4113 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4114 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4115 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4116
4117 // Copy information relevant to the elaborated type.
4118 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4119 NewTL.setKeywordLoc(TL.getKeywordLoc());
4120 NewTL.setQualifierRange(TL.getQualifierRange());
4121 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004122 TypeLoc NewTL(Result, TL.getOpaqueData());
4123 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004124 }
4125 return Result;
4126}
4127
4128template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004129QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4130 PackExpansionTypeLoc TL) {
Douglas Gregor79aaca42011-01-05 19:06:29 +00004131 llvm_unreachable("Caller must expansion pack expansion types");
Douglas Gregord2fa7662010-12-20 02:24:11 +00004132 return QualType();
4133}
4134
4135template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004136QualType
4137TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004138 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004139 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004140 TLB.pushFullCopy(TL);
4141 return TL.getType();
4142}
4143
4144template<typename Derived>
4145QualType
4146TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004147 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004148 // ObjCObjectType is never dependent.
4149 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004150 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004151}
Mike Stump11289f42009-09-09 15:08:12 +00004152
4153template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004154QualType
4155TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004156 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004157 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004158 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004159 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004160}
4161
Douglas Gregord6ff3322009-08-04 16:50:30 +00004162//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004163// Statement transformation
4164//===----------------------------------------------------------------------===//
4165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004166StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004167TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004168 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004169}
4170
4171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004172StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004173TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4174 return getDerived().TransformCompoundStmt(S, false);
4175}
4176
4177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004178StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004179TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004180 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004181 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004182 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004183 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004184 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4185 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004186 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004187 if (Result.isInvalid()) {
4188 // Immediately fail if this was a DeclStmt, since it's very
4189 // likely that this will cause problems for future statements.
4190 if (isa<DeclStmt>(*B))
4191 return StmtError();
4192
4193 // Otherwise, just keep processing substatements and fail later.
4194 SubStmtInvalid = true;
4195 continue;
4196 }
Mike Stump11289f42009-09-09 15:08:12 +00004197
Douglas Gregorebe10102009-08-20 07:17:43 +00004198 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4199 Statements.push_back(Result.takeAs<Stmt>());
4200 }
Mike Stump11289f42009-09-09 15:08:12 +00004201
John McCall1ababa62010-08-27 19:56:05 +00004202 if (SubStmtInvalid)
4203 return StmtError();
4204
Douglas Gregorebe10102009-08-20 07:17:43 +00004205 if (!getDerived().AlwaysRebuild() &&
4206 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004207 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004208
4209 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4210 move_arg(Statements),
4211 S->getRBracLoc(),
4212 IsStmtExpr);
4213}
Mike Stump11289f42009-09-09 15:08:12 +00004214
Douglas Gregorebe10102009-08-20 07:17:43 +00004215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004216StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004217TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004218 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004219 {
4220 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004221 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004222
Eli Friedman06577382009-11-19 03:14:00 +00004223 // Transform the left-hand case value.
4224 LHS = getDerived().TransformExpr(S->getLHS());
4225 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004226 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004227
Eli Friedman06577382009-11-19 03:14:00 +00004228 // Transform the right-hand case value (for the GNU case-range extension).
4229 RHS = getDerived().TransformExpr(S->getRHS());
4230 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004231 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004232 }
Mike Stump11289f42009-09-09 15:08:12 +00004233
Douglas Gregorebe10102009-08-20 07:17:43 +00004234 // Build the case statement.
4235 // Case statements are always rebuilt so that they will attached to their
4236 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004237 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004238 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004239 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004240 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004241 S->getColonLoc());
4242 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004243 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004244
Douglas Gregorebe10102009-08-20 07:17:43 +00004245 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004246 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004247 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004248 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004249
Douglas Gregorebe10102009-08-20 07:17:43 +00004250 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004251 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004252}
4253
4254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004255StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004256TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004257 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004258 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004259 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004260 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregorebe10102009-08-20 07:17:43 +00004262 // Default statements are always rebuilt
4263 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004264 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004265}
Mike Stump11289f42009-09-09 15:08:12 +00004266
Douglas Gregorebe10102009-08-20 07:17:43 +00004267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004268StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004269TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004270 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004271 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004272 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004273
Douglas Gregorebe10102009-08-20 07:17:43 +00004274 // FIXME: Pass the real colon location in.
4275 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4276 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004277 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004278}
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregorebe10102009-08-20 07:17:43 +00004280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004281StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004282TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004283 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004284 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004285 VarDecl *ConditionVar = 0;
4286 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004287 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004288 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004289 getDerived().TransformDefinition(
4290 S->getConditionVariable()->getLocation(),
4291 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004292 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004293 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004294 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004295 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004296
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004297 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004298 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004299
4300 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004301 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004302 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4303 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004304 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004305 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004306
John McCallb268a282010-08-23 23:25:46 +00004307 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004308 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004309 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004310
John McCallb268a282010-08-23 23:25:46 +00004311 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4312 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004313 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004314
Douglas Gregorebe10102009-08-20 07:17:43 +00004315 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004316 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004317 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004318 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004319
Douglas Gregorebe10102009-08-20 07:17:43 +00004320 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004321 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004322 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004323 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregorebe10102009-08-20 07:17:43 +00004325 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004326 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004327 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004328 Then.get() == S->getThen() &&
4329 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004330 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004331
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004332 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004333 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004334 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004335}
4336
4337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004338StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004339TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004340 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004341 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004342 VarDecl *ConditionVar = 0;
4343 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004344 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004345 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004346 getDerived().TransformDefinition(
4347 S->getConditionVariable()->getLocation(),
4348 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004349 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004350 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004351 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004352 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004353
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004354 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004355 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004356 }
Mike Stump11289f42009-09-09 15:08:12 +00004357
Douglas Gregorebe10102009-08-20 07:17:43 +00004358 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004359 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004360 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004361 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004362 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004363 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregorebe10102009-08-20 07:17:43 +00004365 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004366 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004367 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004368 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004369
Douglas Gregorebe10102009-08-20 07:17:43 +00004370 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004371 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4372 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004373}
Mike Stump11289f42009-09-09 15:08:12 +00004374
Douglas Gregorebe10102009-08-20 07:17:43 +00004375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004376StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004377TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004378 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004379 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004380 VarDecl *ConditionVar = 0;
4381 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004382 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004383 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004384 getDerived().TransformDefinition(
4385 S->getConditionVariable()->getLocation(),
4386 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004387 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004388 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004389 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004390 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004391
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004392 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004393 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004394
4395 if (S->getCond()) {
4396 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004397 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4398 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004399 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004400 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004401 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004402 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004403 }
Mike Stump11289f42009-09-09 15:08:12 +00004404
John McCallb268a282010-08-23 23:25:46 +00004405 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4406 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004407 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004408
Douglas Gregorebe10102009-08-20 07:17:43 +00004409 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004410 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004411 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004412 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregorebe10102009-08-20 07:17:43 +00004414 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004415 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004416 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004417 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004418 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004420 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004421 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004422}
Mike Stump11289f42009-09-09 15:08:12 +00004423
Douglas Gregorebe10102009-08-20 07:17:43 +00004424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004425StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004426TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004427 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004428 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004429 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004430 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004431
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004432 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004433 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004434 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004435 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004436
Douglas Gregorebe10102009-08-20 07:17:43 +00004437 if (!getDerived().AlwaysRebuild() &&
4438 Cond.get() == S->getCond() &&
4439 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004440 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004441
John McCallb268a282010-08-23 23:25:46 +00004442 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4443 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004444 S->getRParenLoc());
4445}
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregorebe10102009-08-20 07:17:43 +00004447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004448StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004449TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004450 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004451 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004452 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004453 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004454
Douglas Gregorebe10102009-08-20 07:17:43 +00004455 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004456 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004457 VarDecl *ConditionVar = 0;
4458 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004459 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004460 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004461 getDerived().TransformDefinition(
4462 S->getConditionVariable()->getLocation(),
4463 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004464 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004465 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004466 } else {
4467 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004468
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004469 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004470 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004471
4472 if (S->getCond()) {
4473 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004474 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4475 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004476 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004477 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004478
John McCallb268a282010-08-23 23:25:46 +00004479 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004480 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004481 }
Mike Stump11289f42009-09-09 15:08:12 +00004482
John McCallb268a282010-08-23 23:25:46 +00004483 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4484 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004485 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004486
Douglas Gregorebe10102009-08-20 07:17:43 +00004487 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004488 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004489 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004490 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004491
John McCallb268a282010-08-23 23:25:46 +00004492 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4493 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004494 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004495
Douglas Gregorebe10102009-08-20 07:17:43 +00004496 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004497 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004498 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004499 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004500
Douglas Gregorebe10102009-08-20 07:17:43 +00004501 if (!getDerived().AlwaysRebuild() &&
4502 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004503 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004504 Inc.get() == S->getInc() &&
4505 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004506 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004507
Douglas Gregorebe10102009-08-20 07:17:43 +00004508 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004509 Init.get(), FullCond, ConditionVar,
4510 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004511}
4512
4513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004514StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004515TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004516 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004517 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004518 S->getLabel());
4519}
4520
4521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004522StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004523TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004524 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004525 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004526 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregorebe10102009-08-20 07:17:43 +00004528 if (!getDerived().AlwaysRebuild() &&
4529 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004530 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004531
4532 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004533 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004534}
4535
4536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004537StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004538TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004539 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004540}
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregorebe10102009-08-20 07:17:43 +00004542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004543StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004544TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004545 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004546}
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregorebe10102009-08-20 07:17:43 +00004548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004549StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004550TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004551 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004552 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004553 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004554
Mike Stump11289f42009-09-09 15:08:12 +00004555 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004556 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004557 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004558}
Mike Stump11289f42009-09-09 15:08:12 +00004559
Douglas Gregorebe10102009-08-20 07:17:43 +00004560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004561StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004562TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004563 bool DeclChanged = false;
4564 llvm::SmallVector<Decl *, 4> Decls;
4565 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4566 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004567 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4568 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004569 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004570 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregorebe10102009-08-20 07:17:43 +00004572 if (Transformed != *D)
4573 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregorebe10102009-08-20 07:17:43 +00004575 Decls.push_back(Transformed);
4576 }
Mike Stump11289f42009-09-09 15:08:12 +00004577
Douglas Gregorebe10102009-08-20 07:17:43 +00004578 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004579 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004580
4581 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004582 S->getStartLoc(), S->getEndLoc());
4583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregorebe10102009-08-20 07:17:43 +00004585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004586StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004587TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004588 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004589 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004590}
4591
4592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004593StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004594TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004595
John McCall37ad5512010-08-23 06:44:23 +00004596 ASTOwningVector<Expr*> Constraints(getSema());
4597 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004598 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004599
John McCalldadc5752010-08-24 06:29:42 +00004600 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004601 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004602
4603 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004604
Anders Carlssonaaeef072010-01-24 05:50:09 +00004605 // Go through the outputs.
4606 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004607 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004608
Anders Carlssonaaeef072010-01-24 05:50:09 +00004609 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004610 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004611
Anders Carlssonaaeef072010-01-24 05:50:09 +00004612 // Transform the output expr.
4613 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004614 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004615 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004616 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004617
Anders Carlssonaaeef072010-01-24 05:50:09 +00004618 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004619
John McCallb268a282010-08-23 23:25:46 +00004620 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004621 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004622
Anders Carlssonaaeef072010-01-24 05:50:09 +00004623 // Go through the inputs.
4624 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004625 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004626
Anders Carlssonaaeef072010-01-24 05:50:09 +00004627 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004628 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004629
Anders Carlssonaaeef072010-01-24 05:50:09 +00004630 // Transform the input expr.
4631 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004632 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004633 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004634 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004635
Anders Carlssonaaeef072010-01-24 05:50:09 +00004636 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004637
John McCallb268a282010-08-23 23:25:46 +00004638 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004639 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004640
Anders Carlssonaaeef072010-01-24 05:50:09 +00004641 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004642 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004643
4644 // Go through the clobbers.
4645 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004646 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004647
4648 // No need to transform the asm string literal.
4649 AsmString = SemaRef.Owned(S->getAsmString());
4650
4651 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4652 S->isSimple(),
4653 S->isVolatile(),
4654 S->getNumOutputs(),
4655 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004656 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004657 move_arg(Constraints),
4658 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004659 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004660 move_arg(Clobbers),
4661 S->getRParenLoc(),
4662 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004663}
4664
4665
4666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004667StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004668TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004669 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004670 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004671 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004672 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004673
Douglas Gregor96c79492010-04-23 22:50:49 +00004674 // Transform the @catch statements (if present).
4675 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004676 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004677 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004678 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004679 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004680 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004681 if (Catch.get() != S->getCatchStmt(I))
4682 AnyCatchChanged = true;
4683 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004684 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004685
Douglas Gregor306de2f2010-04-22 23:59:56 +00004686 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004687 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004688 if (S->getFinallyStmt()) {
4689 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4690 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004691 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004692 }
4693
4694 // If nothing changed, just retain this statement.
4695 if (!getDerived().AlwaysRebuild() &&
4696 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004697 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004698 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004699 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004700
Douglas Gregor306de2f2010-04-22 23:59:56 +00004701 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004702 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4703 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004704}
Mike Stump11289f42009-09-09 15:08:12 +00004705
Douglas Gregorebe10102009-08-20 07:17:43 +00004706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004707StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004708TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004709 // Transform the @catch parameter, if there is one.
4710 VarDecl *Var = 0;
4711 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4712 TypeSourceInfo *TSInfo = 0;
4713 if (FromVar->getTypeSourceInfo()) {
4714 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4715 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004716 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004717 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004718
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004719 QualType T;
4720 if (TSInfo)
4721 T = TSInfo->getType();
4722 else {
4723 T = getDerived().TransformType(FromVar->getType());
4724 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004725 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004726 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004727
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004728 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4729 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004730 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004731 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004732
John McCalldadc5752010-08-24 06:29:42 +00004733 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004734 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004735 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004736
4737 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004738 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004739 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004740}
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregorebe10102009-08-20 07:17:43 +00004742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004743StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004744TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004745 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004746 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004747 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004749
Douglas Gregor306de2f2010-04-22 23:59:56 +00004750 // If nothing changed, just retain this statement.
4751 if (!getDerived().AlwaysRebuild() &&
4752 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004753 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004754
4755 // Build a new statement.
4756 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004757 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004758}
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregorebe10102009-08-20 07:17:43 +00004760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004761StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004762TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004763 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004764 if (S->getThrowExpr()) {
4765 Operand = getDerived().TransformExpr(S->getThrowExpr());
4766 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004767 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004768 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004769
Douglas Gregor2900c162010-04-22 21:44:01 +00004770 if (!getDerived().AlwaysRebuild() &&
4771 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004772 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004773
John McCallb268a282010-08-23 23:25:46 +00004774 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004775}
Mike Stump11289f42009-09-09 15:08:12 +00004776
Douglas Gregorebe10102009-08-20 07:17:43 +00004777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004778StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004779TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004780 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004781 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004782 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004783 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004784 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004785
Douglas Gregor6148de72010-04-22 22:01:21 +00004786 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004787 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004788 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004789 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004790
Douglas Gregor6148de72010-04-22 22:01:21 +00004791 // If nothing change, just retain the current statement.
4792 if (!getDerived().AlwaysRebuild() &&
4793 Object.get() == S->getSynchExpr() &&
4794 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004795 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004796
4797 // Build a new statement.
4798 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004799 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004800}
4801
4802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004803StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004804TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004805 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004806 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004807 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004808 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004809 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004810
Douglas Gregorf68a5082010-04-22 23:10:45 +00004811 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004812 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004813 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004814 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004815
Douglas Gregorf68a5082010-04-22 23:10:45 +00004816 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004817 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004818 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004819 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004820
Douglas Gregorf68a5082010-04-22 23:10:45 +00004821 // If nothing changed, just retain this statement.
4822 if (!getDerived().AlwaysRebuild() &&
4823 Element.get() == S->getElement() &&
4824 Collection.get() == S->getCollection() &&
4825 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004826 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004827
Douglas Gregorf68a5082010-04-22 23:10:45 +00004828 // Build a new statement.
4829 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4830 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004831 Element.get(),
4832 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004833 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004834 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004835}
4836
4837
4838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004839StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004840TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4841 // Transform the exception declaration, if any.
4842 VarDecl *Var = 0;
4843 if (S->getExceptionDecl()) {
4844 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004845 TypeSourceInfo *T = getDerived().TransformType(
4846 ExceptionDecl->getTypeSourceInfo());
4847 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004848 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004850 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004851 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004852 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004853 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004854 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004855 }
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregorebe10102009-08-20 07:17:43 +00004857 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004858 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004859 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004860 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregorebe10102009-08-20 07:17:43 +00004862 if (!getDerived().AlwaysRebuild() &&
4863 !Var &&
4864 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004865 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004866
4867 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4868 Var,
John McCallb268a282010-08-23 23:25:46 +00004869 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004870}
Mike Stump11289f42009-09-09 15:08:12 +00004871
Douglas Gregorebe10102009-08-20 07:17:43 +00004872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004873StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004874TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4875 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004876 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004877 = getDerived().TransformCompoundStmt(S->getTryBlock());
4878 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004879 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004880
Douglas Gregorebe10102009-08-20 07:17:43 +00004881 // Transform the handlers.
4882 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004883 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004884 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004885 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004886 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4887 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004888 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4891 Handlers.push_back(Handler.takeAs<Stmt>());
4892 }
Mike Stump11289f42009-09-09 15:08:12 +00004893
Douglas Gregorebe10102009-08-20 07:17:43 +00004894 if (!getDerived().AlwaysRebuild() &&
4895 TryBlock.get() == S->getTryBlock() &&
4896 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004897 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004898
John McCallb268a282010-08-23 23:25:46 +00004899 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004900 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004901}
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregorebe10102009-08-20 07:17:43 +00004903//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004904// Expression transformation
4905//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004907ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004908TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004909 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004910}
Mike Stump11289f42009-09-09 15:08:12 +00004911
4912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004913ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004914TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004915 NestedNameSpecifier *Qualifier = 0;
4916 if (E->getQualifier()) {
4917 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004918 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004919 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004920 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004921 }
John McCallce546572009-12-08 09:08:17 +00004922
4923 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004924 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4925 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004926 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004927 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004928
John McCall815039a2010-08-17 21:27:17 +00004929 DeclarationNameInfo NameInfo = E->getNameInfo();
4930 if (NameInfo.getName()) {
4931 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4932 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004933 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004934 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004935
4936 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004937 Qualifier == E->getQualifier() &&
4938 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004939 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004940 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004941
4942 // Mark it referenced in the new context regardless.
4943 // FIXME: this is a bit instantiation-specific.
4944 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4945
John McCallc3007a22010-10-26 07:05:15 +00004946 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004947 }
John McCallce546572009-12-08 09:08:17 +00004948
4949 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004950 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004951 TemplateArgs = &TransArgs;
4952 TransArgs.setLAngleLoc(E->getLAngleLoc());
4953 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004954 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4955 E->getNumTemplateArgs(),
4956 TransArgs))
4957 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004958 }
4959
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004960 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004961 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004962}
Mike Stump11289f42009-09-09 15:08:12 +00004963
Douglas Gregora16548e2009-08-11 05:31:07 +00004964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004965ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004966TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004967 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004968}
Mike Stump11289f42009-09-09 15:08:12 +00004969
Douglas Gregora16548e2009-08-11 05:31:07 +00004970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004972TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004973 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004974}
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregora16548e2009-08-11 05:31:07 +00004976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004978TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004979 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004980}
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregora16548e2009-08-11 05:31:07 +00004982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004984TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004985 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004986}
Mike Stump11289f42009-09-09 15:08:12 +00004987
Douglas Gregora16548e2009-08-11 05:31:07 +00004988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004989ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004990TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004991 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004992}
4993
4994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004995ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004996TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004997 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004998 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004999 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005000
Douglas Gregora16548e2009-08-11 05:31:07 +00005001 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005002 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005003
John McCallb268a282010-08-23 23:25:46 +00005004 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 E->getRParen());
5006}
5007
Mike Stump11289f42009-09-09 15:08:12 +00005008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005010TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005011 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005012 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005014
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005016 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregora16548e2009-08-11 05:31:07 +00005018 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5019 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005020 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005021}
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregora16548e2009-08-11 05:31:07 +00005023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005024ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005025TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5026 // Transform the type.
5027 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5028 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005029 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005030
Douglas Gregor882211c2010-04-28 22:16:22 +00005031 // Transform all of the components into components similar to what the
5032 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005033 // FIXME: It would be slightly more efficient in the non-dependent case to
5034 // just map FieldDecls, rather than requiring the rebuilder to look for
5035 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005036 // template code that we don't care.
5037 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005038 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005039 typedef OffsetOfExpr::OffsetOfNode Node;
5040 llvm::SmallVector<Component, 4> Components;
5041 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5042 const Node &ON = E->getComponent(I);
5043 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005044 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005045 Comp.LocStart = ON.getRange().getBegin();
5046 Comp.LocEnd = ON.getRange().getEnd();
5047 switch (ON.getKind()) {
5048 case Node::Array: {
5049 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005050 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005051 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005052 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005053
Douglas Gregor882211c2010-04-28 22:16:22 +00005054 ExprChanged = ExprChanged || Index.get() != FromIndex;
5055 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005056 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005057 break;
5058 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005059
Douglas Gregor882211c2010-04-28 22:16:22 +00005060 case Node::Field:
5061 case Node::Identifier:
5062 Comp.isBrackets = false;
5063 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005064 if (!Comp.U.IdentInfo)
5065 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005066
Douglas Gregor882211c2010-04-28 22:16:22 +00005067 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005068
Douglas Gregord1702062010-04-29 00:18:15 +00005069 case Node::Base:
5070 // Will be recomputed during the rebuild.
5071 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005072 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005073
Douglas Gregor882211c2010-04-28 22:16:22 +00005074 Components.push_back(Comp);
5075 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005076
Douglas Gregor882211c2010-04-28 22:16:22 +00005077 // If nothing changed, retain the existing expression.
5078 if (!getDerived().AlwaysRebuild() &&
5079 Type == E->getTypeSourceInfo() &&
5080 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005081 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005082
Douglas Gregor882211c2010-04-28 22:16:22 +00005083 // Build a new offsetof expression.
5084 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5085 Components.data(), Components.size(),
5086 E->getRParenLoc());
5087}
5088
5089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005090ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005091TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5092 assert(getDerived().AlreadyTransformed(E->getType()) &&
5093 "opaque value expression requires transformation");
5094 return SemaRef.Owned(E);
5095}
5096
5097template<typename Derived>
5098ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005099TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005101 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005102
John McCallbcd03502009-12-07 02:54:59 +00005103 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005104 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005106
John McCall4c98fd82009-11-04 07:28:41 +00005107 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005108 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005109
John McCall4c98fd82009-11-04 07:28:41 +00005110 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005111 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 E->getSourceRange());
5113 }
Mike Stump11289f42009-09-09 15:08:12 +00005114
John McCalldadc5752010-08-24 06:29:42 +00005115 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005116 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 // C++0x [expr.sizeof]p1:
5118 // The operand is either an expression, which is an unevaluated operand
5119 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005120 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5123 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005125
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005127 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 }
Mike Stump11289f42009-09-09 15:08:12 +00005129
John McCallb268a282010-08-23 23:25:46 +00005130 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 E->isSizeOf(),
5132 E->getSourceRange());
5133}
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregora16548e2009-08-11 05:31:07 +00005135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005137TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005138 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005140 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005141
John McCalldadc5752010-08-24 06:29:42 +00005142 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005143 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005144 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005145
5146
Douglas Gregora16548e2009-08-11 05:31:07 +00005147 if (!getDerived().AlwaysRebuild() &&
5148 LHS.get() == E->getLHS() &&
5149 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005150 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005151
John McCallb268a282010-08-23 23:25:46 +00005152 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005154 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 E->getRBracketLoc());
5156}
Mike Stump11289f42009-09-09 15:08:12 +00005157
5158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005159ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005160TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005162 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005164 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005165
5166 // Transform arguments.
5167 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005168 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005169 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5170 &ArgChanged))
5171 return ExprError();
5172
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 if (!getDerived().AlwaysRebuild() &&
5174 Callee.get() == E->getCallee() &&
5175 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005176 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005179 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005180 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005181 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005182 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005183 E->getRParenLoc());
5184}
Mike Stump11289f42009-09-09 15:08:12 +00005185
5186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005188TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005189 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005190 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005193 NestedNameSpecifier *Qualifier = 0;
5194 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005195 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005196 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005197 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005198 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005199 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005200 }
Mike Stump11289f42009-09-09 15:08:12 +00005201
Eli Friedman2cfcef62009-12-04 06:40:45 +00005202 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005203 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5204 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005205 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005207
John McCall16df1e52010-03-30 21:47:33 +00005208 NamedDecl *FoundDecl = E->getFoundDecl();
5209 if (FoundDecl == E->getMemberDecl()) {
5210 FoundDecl = Member;
5211 } else {
5212 FoundDecl = cast_or_null<NamedDecl>(
5213 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5214 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005215 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005216 }
5217
Douglas Gregora16548e2009-08-11 05:31:07 +00005218 if (!getDerived().AlwaysRebuild() &&
5219 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005220 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005221 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005222 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005223 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005224
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005225 // Mark it referenced in the new context regardless.
5226 // FIXME: this is a bit instantiation-specific.
5227 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005228 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005229 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005230
John McCall6b51f282009-11-23 01:53:49 +00005231 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005232 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005233 TransArgs.setLAngleLoc(E->getLAngleLoc());
5234 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005235 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5236 E->getNumTemplateArgs(),
5237 TransArgs))
5238 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005239 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005240
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 // FIXME: Bogus source location for the operator
5242 SourceLocation FakeOperatorLoc
5243 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5244
John McCall38836f02010-01-15 08:34:02 +00005245 // FIXME: to do this check properly, we will need to preserve the
5246 // first-qualifier-in-scope here, just in case we had a dependent
5247 // base (and therefore couldn't do the check) and a
5248 // nested-name-qualifier (and therefore could do the lookup).
5249 NamedDecl *FirstQualifierInScope = 0;
5250
John McCallb268a282010-08-23 23:25:46 +00005251 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005252 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005253 Qualifier,
5254 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005255 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005256 Member,
John McCall16df1e52010-03-30 21:47:33 +00005257 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005258 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005259 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005260 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005261}
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregora16548e2009-08-11 05:31:07 +00005263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005265TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005266 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005267 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005269
John McCalldadc5752010-08-24 06:29:42 +00005270 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005271 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 if (!getDerived().AlwaysRebuild() &&
5275 LHS.get() == E->getLHS() &&
5276 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005277 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005278
Douglas Gregora16548e2009-08-11 05:31:07 +00005279 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005280 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005281}
5282
Mike Stump11289f42009-09-09 15:08:12 +00005283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005284ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005285TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005286 CompoundAssignOperator *E) {
5287 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005288}
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregora16548e2009-08-11 05:31:07 +00005290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005292TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005293 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005296
John McCalldadc5752010-08-24 06:29:42 +00005297 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005298 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005300
John McCalldadc5752010-08-24 06:29:42 +00005301 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005302 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregora16548e2009-08-11 05:31:07 +00005305 if (!getDerived().AlwaysRebuild() &&
5306 Cond.get() == E->getCond() &&
5307 LHS.get() == E->getLHS() &&
5308 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005309 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005310
John McCallb268a282010-08-23 23:25:46 +00005311 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005312 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005313 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005314 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005315 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005316}
Mike Stump11289f42009-09-09 15:08:12 +00005317
5318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005319ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005320TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005321 // Implicit casts are eliminated during transformation, since they
5322 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005323 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005324}
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregora16548e2009-08-11 05:31:07 +00005326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005328TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005329 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5330 if (!Type)
5331 return ExprError();
5332
John McCalldadc5752010-08-24 06:29:42 +00005333 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005334 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005335 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005337
Douglas Gregora16548e2009-08-11 05:31:07 +00005338 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005339 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005340 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005341 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005342
John McCall97513962010-01-15 18:39:57 +00005343 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005344 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005345 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005346 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005347}
Mike Stump11289f42009-09-09 15:08:12 +00005348
Douglas Gregora16548e2009-08-11 05:31:07 +00005349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005351TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005352 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5353 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5354 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005356
John McCalldadc5752010-08-24 06:29:42 +00005357 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005360
Douglas Gregora16548e2009-08-11 05:31:07 +00005361 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005362 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005363 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005364 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005365
John McCall5d7aa7f2010-01-19 22:33:45 +00005366 // Note: the expression type doesn't necessarily match the
5367 // type-as-written, but that's okay, because it should always be
5368 // derivable from the initializer.
5369
John McCalle15bbff2010-01-18 19:35:47 +00005370 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005372 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005373}
Mike Stump11289f42009-09-09 15:08:12 +00005374
Douglas Gregora16548e2009-08-11 05:31:07 +00005375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005376ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005377TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005378 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005379 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 if (!getDerived().AlwaysRebuild() &&
5383 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005384 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005385
Douglas Gregora16548e2009-08-11 05:31:07 +00005386 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005387 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005388 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005389 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005390 E->getAccessorLoc(),
5391 E->getAccessor());
5392}
Mike Stump11289f42009-09-09 15:08:12 +00005393
Douglas Gregora16548e2009-08-11 05:31:07 +00005394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005396TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005398
John McCall37ad5512010-08-23 06:44:23 +00005399 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005400 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5401 Inits, &InitChanged))
5402 return ExprError();
5403
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005405 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005406
Douglas Gregora16548e2009-08-11 05:31:07 +00005407 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005408 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005409}
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregora16548e2009-08-11 05:31:07 +00005411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005412ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005413TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005414 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005415
Douglas Gregorebe10102009-08-20 07:17:43 +00005416 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005417 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005418 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005419 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregorebe10102009-08-20 07:17:43 +00005421 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005422 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 bool ExprChanged = false;
5424 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5425 DEnd = E->designators_end();
5426 D != DEnd; ++D) {
5427 if (D->isFieldDesignator()) {
5428 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5429 D->getDotLoc(),
5430 D->getFieldLoc()));
5431 continue;
5432 }
Mike Stump11289f42009-09-09 15:08:12 +00005433
Douglas Gregora16548e2009-08-11 05:31:07 +00005434 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005435 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005436 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005437 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005438
5439 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005440 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005441
Douglas Gregora16548e2009-08-11 05:31:07 +00005442 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5443 ArrayExprs.push_back(Index.release());
5444 continue;
5445 }
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005448 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005449 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5450 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
John McCalldadc5752010-08-24 06:29:42 +00005453 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005454 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005456
5457 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005458 End.get(),
5459 D->getLBracketLoc(),
5460 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005461
Douglas Gregora16548e2009-08-11 05:31:07 +00005462 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5463 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005464
Douglas Gregora16548e2009-08-11 05:31:07 +00005465 ArrayExprs.push_back(Start.release());
5466 ArrayExprs.push_back(End.release());
5467 }
Mike Stump11289f42009-09-09 15:08:12 +00005468
Douglas Gregora16548e2009-08-11 05:31:07 +00005469 if (!getDerived().AlwaysRebuild() &&
5470 Init.get() == E->getInit() &&
5471 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005472 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregora16548e2009-08-11 05:31:07 +00005474 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5475 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005476 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005477}
Mike Stump11289f42009-09-09 15:08:12 +00005478
Douglas Gregora16548e2009-08-11 05:31:07 +00005479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005480ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005481TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005482 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005483 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005484
Douglas Gregor3da3c062009-10-28 00:29:27 +00005485 // FIXME: Will we ever have proper type location here? Will we actually
5486 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005487 QualType T = getDerived().TransformType(E->getType());
5488 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005489 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregora16548e2009-08-11 05:31:07 +00005491 if (!getDerived().AlwaysRebuild() &&
5492 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005493 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005494
Douglas Gregora16548e2009-08-11 05:31:07 +00005495 return getDerived().RebuildImplicitValueInitExpr(T);
5496}
Mike Stump11289f42009-09-09 15:08:12 +00005497
Douglas Gregora16548e2009-08-11 05:31:07 +00005498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005500TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005501 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5502 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005504
John McCalldadc5752010-08-24 06:29:42 +00005505 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005506 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005508
Douglas Gregora16548e2009-08-11 05:31:07 +00005509 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005510 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005511 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005512 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005513
John McCallb268a282010-08-23 23:25:46 +00005514 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005515 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005516}
5517
5518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005519ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005520TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005521 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005522 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005523 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5524 &ArgumentChanged))
5525 return ExprError();
5526
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5528 move_arg(Inits),
5529 E->getRParenLoc());
5530}
Mike Stump11289f42009-09-09 15:08:12 +00005531
Douglas Gregora16548e2009-08-11 05:31:07 +00005532/// \brief Transform an address-of-label expression.
5533///
5534/// By default, the transformation of an address-of-label expression always
5535/// rebuilds the expression, so that the label identifier can be resolved to
5536/// the corresponding label statement by semantic analysis.
5537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005539TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005540 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5541 E->getLabel());
5542}
Mike Stump11289f42009-09-09 15:08:12 +00005543
5544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005545ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005546TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005547 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5549 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 if (!getDerived().AlwaysRebuild() &&
5553 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005554 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005555
5556 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005557 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 E->getRParenLoc());
5559}
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregora16548e2009-08-11 05:31:07 +00005561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005562ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005563TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005564 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005565 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005567
John McCalldadc5752010-08-24 06:29:42 +00005568 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005569 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005571
John McCalldadc5752010-08-24 06:29:42 +00005572 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005575
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 if (!getDerived().AlwaysRebuild() &&
5577 Cond.get() == E->getCond() &&
5578 LHS.get() == E->getLHS() &&
5579 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005580 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregora16548e2009-08-11 05:31:07 +00005582 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005583 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 E->getRParenLoc());
5585}
Mike Stump11289f42009-09-09 15:08:12 +00005586
Douglas Gregora16548e2009-08-11 05:31:07 +00005587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005588ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005589TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005590 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005591}
5592
5593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005595TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005596 switch (E->getOperator()) {
5597 case OO_New:
5598 case OO_Delete:
5599 case OO_Array_New:
5600 case OO_Array_Delete:
5601 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005602 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005603
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005604 case OO_Call: {
5605 // This is a call to an object's operator().
5606 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5607
5608 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005609 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005610 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005611 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005612
5613 // FIXME: Poor location information
5614 SourceLocation FakeLParenLoc
5615 = SemaRef.PP.getLocForEndOfToken(
5616 static_cast<Expr *>(Object.get())->getLocEnd());
5617
5618 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005619 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005620 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5621 Args))
5622 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005623
John McCallb268a282010-08-23 23:25:46 +00005624 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005625 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005626 E->getLocEnd());
5627 }
5628
5629#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5630 case OO_##Name:
5631#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5632#include "clang/Basic/OperatorKinds.def"
5633 case OO_Subscript:
5634 // Handled below.
5635 break;
5636
5637 case OO_Conditional:
5638 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005639 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005640
5641 case OO_None:
5642 case NUM_OVERLOADED_OPERATORS:
5643 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005645 }
5646
John McCalldadc5752010-08-24 06:29:42 +00005647 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005648 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005649 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005650
John McCalldadc5752010-08-24 06:29:42 +00005651 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005653 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005654
John McCalldadc5752010-08-24 06:29:42 +00005655 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005656 if (E->getNumArgs() == 2) {
5657 Second = getDerived().TransformExpr(E->getArg(1));
5658 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005659 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 }
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 if (!getDerived().AlwaysRebuild() &&
5663 Callee.get() == E->getCallee() &&
5664 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005665 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005666 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005667
Douglas Gregora16548e2009-08-11 05:31:07 +00005668 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5669 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005670 Callee.get(),
5671 First.get(),
5672 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005673}
Mike Stump11289f42009-09-09 15:08:12 +00005674
Douglas Gregora16548e2009-08-11 05:31:07 +00005675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005676ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005677TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5678 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005679}
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregora16548e2009-08-11 05:31:07 +00005681template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005682ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005683TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005684 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5685 if (!Type)
5686 return ExprError();
5687
John McCalldadc5752010-08-24 06:29:42 +00005688 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005689 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005690 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregora16548e2009-08-11 05:31:07 +00005693 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005694 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005696 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregora16548e2009-08-11 05:31:07 +00005698 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005699 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005700 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5701 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5702 SourceLocation FakeRParenLoc
5703 = SemaRef.PP.getLocForEndOfToken(
5704 E->getSubExpr()->getSourceRange().getEnd());
5705 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005706 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005708 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005709 FakeRAngleLoc,
5710 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005711 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005712 FakeRParenLoc);
5713}
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregora16548e2009-08-11 05:31:07 +00005715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005716ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005717TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5718 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005719}
Mike Stump11289f42009-09-09 15:08:12 +00005720
5721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005722ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005723TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5724 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005725}
5726
Douglas Gregora16548e2009-08-11 05:31:07 +00005727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005728ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005729TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005730 CXXReinterpretCastExpr *E) {
5731 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005732}
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005736TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5737 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005738}
Mike Stump11289f42009-09-09 15:08:12 +00005739
Douglas Gregora16548e2009-08-11 05:31:07 +00005740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005741ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005742TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005743 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005744 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5745 if (!Type)
5746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005747
John McCalldadc5752010-08-24 06:29:42 +00005748 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005749 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005752
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005754 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005755 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005756 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005757
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005758 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005760 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005761 E->getRParenLoc());
5762}
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005765ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005766TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005767 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005768 TypeSourceInfo *TInfo
5769 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5770 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005771 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005772
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005774 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005775 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregor9da64192010-04-26 22:37:10 +00005777 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5778 E->getLocStart(),
5779 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005780 E->getLocEnd());
5781 }
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 // We don't know whether the expression is potentially evaluated until
5784 // after we perform semantic analysis, so the expression is potentially
5785 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005786 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005787 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005788
John McCalldadc5752010-08-24 06:29:42 +00005789 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005792
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 if (!getDerived().AlwaysRebuild() &&
5794 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005795 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregor9da64192010-04-26 22:37:10 +00005797 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5798 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005799 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005800 E->getLocEnd());
5801}
5802
5803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005804ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005805TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5806 if (E->isTypeOperand()) {
5807 TypeSourceInfo *TInfo
5808 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5809 if (!TInfo)
5810 return ExprError();
5811
5812 if (!getDerived().AlwaysRebuild() &&
5813 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005814 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005815
5816 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5817 E->getLocStart(),
5818 TInfo,
5819 E->getLocEnd());
5820 }
5821
5822 // We don't know whether the expression is potentially evaluated until
5823 // after we perform semantic analysis, so the expression is potentially
5824 // potentially evaluated.
5825 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5826
5827 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5828 if (SubExpr.isInvalid())
5829 return ExprError();
5830
5831 if (!getDerived().AlwaysRebuild() &&
5832 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005833 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005834
5835 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5836 E->getLocStart(),
5837 SubExpr.get(),
5838 E->getLocEnd());
5839}
5840
5841template<typename Derived>
5842ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005843TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005844 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005845}
Mike Stump11289f42009-09-09 15:08:12 +00005846
Douglas Gregora16548e2009-08-11 05:31:07 +00005847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005848ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005849TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005850 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005851 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005852}
Mike Stump11289f42009-09-09 15:08:12 +00005853
Douglas Gregora16548e2009-08-11 05:31:07 +00005854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005856TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005857 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5858 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5859 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005860
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005861 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005862 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregorb15af892010-01-07 23:12:05 +00005864 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005865}
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregora16548e2009-08-11 05:31:07 +00005867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005868ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005869TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005870 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005872 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005873
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 if (!getDerived().AlwaysRebuild() &&
5875 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005876 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005877
John McCallb268a282010-08-23 23:25:46 +00005878 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005879}
Mike Stump11289f42009-09-09 15:08:12 +00005880
Douglas Gregora16548e2009-08-11 05:31:07 +00005881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005882ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005883TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005884 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005885 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5886 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
Chandler Carruth794da4c2010-02-08 06:42:49 +00005890 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005892 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005893
Douglas Gregor033f6752009-12-23 23:03:06 +00005894 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005895}
Mike Stump11289f42009-09-09 15:08:12 +00005896
Douglas Gregora16548e2009-08-11 05:31:07 +00005897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005898ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005899TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5900 CXXScalarValueInitExpr *E) {
5901 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5902 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005904
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005906 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005907 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregor2b88c112010-09-08 00:15:04 +00005909 return getDerived().RebuildCXXScalarValueInitExpr(T,
5910 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005911 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005912}
Mike Stump11289f42009-09-09 15:08:12 +00005913
Douglas Gregora16548e2009-08-11 05:31:07 +00005914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005916TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005918 TypeSourceInfo *AllocTypeInfo
5919 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5920 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005924 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005925 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005926 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005927
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 // Transform the placement arguments (if any).
5929 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005930 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005931 if (getDerived().TransformExprs(E->getPlacementArgs(),
5932 E->getNumPlacementArgs(), true,
5933 PlacementArgs, &ArgumentChanged))
5934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005935
Douglas Gregorebe10102009-08-20 07:17:43 +00005936 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005937 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005938 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
5939 ConstructorArgs, &ArgumentChanged))
5940 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005941
Douglas Gregord2d9da02010-02-26 00:38:10 +00005942 // Transform constructor, new operator, and delete operator.
5943 CXXConstructorDecl *Constructor = 0;
5944 if (E->getConstructor()) {
5945 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005946 getDerived().TransformDecl(E->getLocStart(),
5947 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005948 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005949 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005950 }
5951
5952 FunctionDecl *OperatorNew = 0;
5953 if (E->getOperatorNew()) {
5954 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005955 getDerived().TransformDecl(E->getLocStart(),
5956 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005957 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005958 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005959 }
5960
5961 FunctionDecl *OperatorDelete = 0;
5962 if (E->getOperatorDelete()) {
5963 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005964 getDerived().TransformDecl(E->getLocStart(),
5965 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005966 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005967 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005968 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005969
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005971 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005972 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005973 Constructor == E->getConstructor() &&
5974 OperatorNew == E->getOperatorNew() &&
5975 OperatorDelete == E->getOperatorDelete() &&
5976 !ArgumentChanged) {
5977 // Mark any declarations we need as referenced.
5978 // FIXME: instantiation-specific.
5979 if (Constructor)
5980 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5981 if (OperatorNew)
5982 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5983 if (OperatorDelete)
5984 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005985 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005986 }
Mike Stump11289f42009-09-09 15:08:12 +00005987
Douglas Gregor0744ef62010-09-07 21:49:58 +00005988 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005989 if (!ArraySize.get()) {
5990 // If no array size was specified, but the new expression was
5991 // instantiated with an array type (e.g., "new T" where T is
5992 // instantiated with "int[4]"), extract the outer bound from the
5993 // array type as our array size. We do this with constant and
5994 // dependently-sized array types.
5995 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5996 if (!ArrayT) {
5997 // Do nothing
5998 } else if (const ConstantArrayType *ConsArrayT
5999 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006000 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006001 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6002 ConsArrayT->getSize(),
6003 SemaRef.Context.getSizeType(),
6004 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006005 AllocType = ConsArrayT->getElementType();
6006 } else if (const DependentSizedArrayType *DepArrayT
6007 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6008 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006009 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006010 AllocType = DepArrayT->getElementType();
6011 }
6012 }
6013 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006014
Douglas Gregora16548e2009-08-11 05:31:07 +00006015 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6016 E->isGlobalNew(),
6017 /*FIXME:*/E->getLocStart(),
6018 move_arg(PlacementArgs),
6019 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006020 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006021 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006022 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006023 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 /*FIXME:*/E->getLocStart(),
6025 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006026 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006027}
Mike Stump11289f42009-09-09 15:08:12 +00006028
Douglas Gregora16548e2009-08-11 05:31:07 +00006029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006030ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006031TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006032 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006033 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006035
Douglas Gregord2d9da02010-02-26 00:38:10 +00006036 // Transform the delete operator, if known.
6037 FunctionDecl *OperatorDelete = 0;
6038 if (E->getOperatorDelete()) {
6039 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006040 getDerived().TransformDecl(E->getLocStart(),
6041 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006042 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006043 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006044 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006045
Douglas Gregora16548e2009-08-11 05:31:07 +00006046 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006047 Operand.get() == E->getArgument() &&
6048 OperatorDelete == E->getOperatorDelete()) {
6049 // Mark any declarations we need as referenced.
6050 // FIXME: instantiation-specific.
6051 if (OperatorDelete)
6052 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006053
6054 if (!E->getArgument()->isTypeDependent()) {
6055 QualType Destroyed = SemaRef.Context.getBaseElementType(
6056 E->getDestroyedType());
6057 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6058 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6059 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6060 SemaRef.LookupDestructor(Record));
6061 }
6062 }
6063
John McCallc3007a22010-10-26 07:05:15 +00006064 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006065 }
Mike Stump11289f42009-09-09 15:08:12 +00006066
Douglas Gregora16548e2009-08-11 05:31:07 +00006067 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6068 E->isGlobalDelete(),
6069 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006070 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006071}
Mike Stump11289f42009-09-09 15:08:12 +00006072
Douglas Gregora16548e2009-08-11 05:31:07 +00006073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006074ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006075TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006076 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006077 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006078 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006080
John McCallba7bf592010-08-24 05:47:05 +00006081 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006082 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006083 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006084 E->getOperatorLoc(),
6085 E->isArrow()? tok::arrow : tok::period,
6086 ObjectTypePtr,
6087 MayBePseudoDestructor);
6088 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006089 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006090
John McCallba7bf592010-08-24 05:47:05 +00006091 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006092 NestedNameSpecifier *Qualifier = E->getQualifier();
6093 if (Qualifier) {
6094 Qualifier
6095 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6096 E->getQualifierRange(),
6097 ObjectType);
6098 if (!Qualifier)
6099 return ExprError();
6100 }
Mike Stump11289f42009-09-09 15:08:12 +00006101
Douglas Gregor678f90d2010-02-25 01:56:36 +00006102 PseudoDestructorTypeStorage Destroyed;
6103 if (E->getDestroyedTypeInfo()) {
6104 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006105 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6106 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006107 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006108 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006109 Destroyed = DestroyedTypeInfo;
6110 } else if (ObjectType->isDependentType()) {
6111 // We aren't likely to be able to resolve the identifier down to a type
6112 // now anyway, so just retain the identifier.
6113 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6114 E->getDestroyedTypeLoc());
6115 } else {
6116 // Look for a destructor known with the given name.
6117 CXXScopeSpec SS;
6118 if (Qualifier) {
6119 SS.setScopeRep(Qualifier);
6120 SS.setRange(E->getQualifierRange());
6121 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006122
John McCallba7bf592010-08-24 05:47:05 +00006123 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006124 *E->getDestroyedTypeIdentifier(),
6125 E->getDestroyedTypeLoc(),
6126 /*Scope=*/0,
6127 SS, ObjectTypePtr,
6128 false);
6129 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006131
Douglas Gregor678f90d2010-02-25 01:56:36 +00006132 Destroyed
6133 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6134 E->getDestroyedTypeLoc());
6135 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006136
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006137 TypeSourceInfo *ScopeTypeInfo = 0;
6138 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006139 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006140 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006141 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006142 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006143
John McCallb268a282010-08-23 23:25:46 +00006144 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006145 E->getOperatorLoc(),
6146 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006147 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006148 E->getQualifierRange(),
6149 ScopeTypeInfo,
6150 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006151 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006152 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006153}
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregorad8a3362009-09-04 17:36:40 +00006155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006156ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006157TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006158 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006159 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6160
6161 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6162 Sema::LookupOrdinaryName);
6163
6164 // Transform all the decls.
6165 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6166 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006167 NamedDecl *InstD = static_cast<NamedDecl*>(
6168 getDerived().TransformDecl(Old->getNameLoc(),
6169 *I));
John McCall84d87672009-12-10 09:41:52 +00006170 if (!InstD) {
6171 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6172 // This can happen because of dependent hiding.
6173 if (isa<UsingShadowDecl>(*I))
6174 continue;
6175 else
John McCallfaf5fb42010-08-26 23:41:50 +00006176 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006177 }
John McCalle66edc12009-11-24 19:00:30 +00006178
6179 // Expand using declarations.
6180 if (isa<UsingDecl>(InstD)) {
6181 UsingDecl *UD = cast<UsingDecl>(InstD);
6182 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6183 E = UD->shadow_end(); I != E; ++I)
6184 R.addDecl(*I);
6185 continue;
6186 }
6187
6188 R.addDecl(InstD);
6189 }
6190
6191 // Resolve a kind, but don't do any further analysis. If it's
6192 // ambiguous, the callee needs to deal with it.
6193 R.resolveKind();
6194
6195 // Rebuild the nested-name qualifier, if present.
6196 CXXScopeSpec SS;
6197 NestedNameSpecifier *Qualifier = 0;
6198 if (Old->getQualifier()) {
6199 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006200 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006201 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006202 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006203
John McCalle66edc12009-11-24 19:00:30 +00006204 SS.setScopeRep(Qualifier);
6205 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006206 }
6207
Douglas Gregor9262f472010-04-27 18:19:34 +00006208 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006209 CXXRecordDecl *NamingClass
6210 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6211 Old->getNameLoc(),
6212 Old->getNamingClass()));
6213 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006214 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006215
Douglas Gregorda7be082010-04-27 16:10:10 +00006216 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006217 }
6218
6219 // If we have no template arguments, it's a normal declaration name.
6220 if (!Old->hasExplicitTemplateArgs())
6221 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6222
6223 // If we have template arguments, rebuild them, then rebuild the
6224 // templateid expression.
6225 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006226 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6227 Old->getNumTemplateArgs(),
6228 TransArgs))
6229 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006230
6231 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6232 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006233}
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregora16548e2009-08-11 05:31:07 +00006235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006237TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006238 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6239 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006241
Douglas Gregora16548e2009-08-11 05:31:07 +00006242 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006243 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006244 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006245
Mike Stump11289f42009-09-09 15:08:12 +00006246 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006247 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 T,
6249 E->getLocEnd());
6250}
Mike Stump11289f42009-09-09 15:08:12 +00006251
Douglas Gregora16548e2009-08-11 05:31:07 +00006252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006253ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006254TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6255 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6256 if (!LhsT)
6257 return ExprError();
6258
6259 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6260 if (!RhsT)
6261 return ExprError();
6262
6263 if (!getDerived().AlwaysRebuild() &&
6264 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6265 return SemaRef.Owned(E);
6266
6267 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6268 E->getLocStart(),
6269 LhsT, RhsT,
6270 E->getLocEnd());
6271}
6272
6273template<typename Derived>
6274ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006275TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006276 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006277 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006278 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006279 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006282
John McCall31f82722010-11-12 08:19:04 +00006283 // TODO: If this is a conversion-function-id, verify that the
6284 // destination type name (if present) resolves the same way after
6285 // instantiation as it did in the local scope.
6286
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006287 DeclarationNameInfo NameInfo
6288 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6289 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006291
John McCalle66edc12009-11-24 19:00:30 +00006292 if (!E->hasExplicitTemplateArgs()) {
6293 if (!getDerived().AlwaysRebuild() &&
6294 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006295 // Note: it is sufficient to compare the Name component of NameInfo:
6296 // if name has not changed, DNLoc has not changed either.
6297 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006298 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006299
John McCalle66edc12009-11-24 19:00:30 +00006300 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6301 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006302 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006303 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006304 }
John McCall6b51f282009-11-23 01:53:49 +00006305
6306 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006307 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6308 E->getNumTemplateArgs(),
6309 TransArgs))
6310 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006311
John McCalle66edc12009-11-24 19:00:30 +00006312 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6313 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006314 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006315 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006316}
6317
6318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006319ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006320TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006321 // CXXConstructExprs are always implicit, so when we have a
6322 // 1-argument construction we just transform that argument.
6323 if (E->getNumArgs() == 1 ||
6324 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6325 return getDerived().TransformExpr(E->getArg(0));
6326
Douglas Gregora16548e2009-08-11 05:31:07 +00006327 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6328
6329 QualType T = getDerived().TransformType(E->getType());
6330 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006331 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006332
6333 CXXConstructorDecl *Constructor
6334 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006335 getDerived().TransformDecl(E->getLocStart(),
6336 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006337 if (!Constructor)
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 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006341 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006342 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6343 &ArgumentChanged))
6344 return ExprError();
6345
Douglas Gregora16548e2009-08-11 05:31:07 +00006346 if (!getDerived().AlwaysRebuild() &&
6347 T == E->getType() &&
6348 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006349 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006350 // Mark the constructor as referenced.
6351 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006352 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006353 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006354 }
Mike Stump11289f42009-09-09 15:08:12 +00006355
Douglas Gregordb121ba2009-12-14 16:27:04 +00006356 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6357 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006358 move_arg(Args),
6359 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006360 E->getConstructionKind(),
6361 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006362}
Mike Stump11289f42009-09-09 15:08:12 +00006363
Douglas Gregora16548e2009-08-11 05:31:07 +00006364/// \brief Transform a C++ temporary-binding expression.
6365///
Douglas Gregor363b1512009-12-24 18:51:59 +00006366/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6367/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006369ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006370TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006371 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006372}
Mike Stump11289f42009-09-09 15:08:12 +00006373
John McCall5d413782010-12-06 08:20:24 +00006374/// \brief Transform a C++ expression that contains cleanups that should
6375/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006376///
John McCall5d413782010-12-06 08:20:24 +00006377/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006378/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006380ExprResult
John McCall5d413782010-12-06 08:20:24 +00006381TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006382 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006383}
Mike Stump11289f42009-09-09 15:08:12 +00006384
Douglas Gregora16548e2009-08-11 05:31:07 +00006385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006386ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006387TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006388 CXXTemporaryObjectExpr *E) {
6389 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6390 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006391 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006392
Douglas Gregora16548e2009-08-11 05:31:07 +00006393 CXXConstructorDecl *Constructor
6394 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006395 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006396 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006397 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006398 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006399
Douglas Gregora16548e2009-08-11 05:31:07 +00006400 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006401 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006402 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006403 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6404 &ArgumentChanged))
6405 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregora16548e2009-08-11 05:31:07 +00006407 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006408 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006409 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006410 !ArgumentChanged) {
6411 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006412 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006413 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006414 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006415
6416 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6417 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006418 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006419 E->getLocEnd());
6420}
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregora16548e2009-08-11 05:31:07 +00006422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006423ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006424TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006425 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006426 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6427 if (!T)
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 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006431 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006432 Args.reserve(E->arg_size());
6433 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6434 &ArgumentChanged))
6435 return ExprError();
6436
Douglas Gregora16548e2009-08-11 05:31:07 +00006437 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006438 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006439 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006440 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006441
Douglas Gregora16548e2009-08-11 05:31:07 +00006442 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006443 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006444 E->getLParenLoc(),
6445 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 E->getRParenLoc());
6447}
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregora16548e2009-08-11 05:31:07 +00006449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006450ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006451TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006452 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006453 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006454 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006455 Expr *OldBase;
6456 QualType BaseType;
6457 QualType ObjectType;
6458 if (!E->isImplicitAccess()) {
6459 OldBase = E->getBase();
6460 Base = getDerived().TransformExpr(OldBase);
6461 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006462 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006463
John McCall2d74de92009-12-01 22:10:20 +00006464 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006465 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006466 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006467 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006468 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006469 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006470 ObjectTy,
6471 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006472 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006473 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006474
John McCallba7bf592010-08-24 05:47:05 +00006475 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006476 BaseType = ((Expr*) Base.get())->getType();
6477 } else {
6478 OldBase = 0;
6479 BaseType = getDerived().TransformType(E->getBaseType());
6480 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6481 }
Mike Stump11289f42009-09-09 15:08:12 +00006482
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006483 // Transform the first part of the nested-name-specifier that qualifies
6484 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006485 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006486 = getDerived().TransformFirstQualifierInScope(
6487 E->getFirstQualifierFoundInScope(),
6488 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006490 NestedNameSpecifier *Qualifier = 0;
6491 if (E->getQualifier()) {
6492 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6493 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006494 ObjectType,
6495 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006496 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006497 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006498 }
Mike Stump11289f42009-09-09 15:08:12 +00006499
John McCall31f82722010-11-12 08:19:04 +00006500 // TODO: If this is a conversion-function-id, verify that the
6501 // destination type name (if present) resolves the same way after
6502 // instantiation as it did in the local scope.
6503
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006504 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006505 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006506 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006508
John McCall2d74de92009-12-01 22:10:20 +00006509 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006510 // This is a reference to a member without an explicitly-specified
6511 // template argument list. Optimize for this common case.
6512 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006513 Base.get() == OldBase &&
6514 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006515 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006516 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006517 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006518 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006519
John McCallb268a282010-08-23 23:25:46 +00006520 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006521 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006522 E->isArrow(),
6523 E->getOperatorLoc(),
6524 Qualifier,
6525 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006526 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006527 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006528 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006529 }
6530
John McCall6b51f282009-11-23 01:53:49 +00006531 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006532 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6533 E->getNumTemplateArgs(),
6534 TransArgs))
6535 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006536
John McCallb268a282010-08-23 23:25:46 +00006537 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006538 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006539 E->isArrow(),
6540 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006541 Qualifier,
6542 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006543 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006544 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006545 &TransArgs);
6546}
6547
6548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006550TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006551 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006552 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006553 QualType BaseType;
6554 if (!Old->isImplicitAccess()) {
6555 Base = getDerived().TransformExpr(Old->getBase());
6556 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006557 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006558 BaseType = ((Expr*) Base.get())->getType();
6559 } else {
6560 BaseType = getDerived().TransformType(Old->getBaseType());
6561 }
John McCall10eae182009-11-30 22:42:35 +00006562
6563 NestedNameSpecifier *Qualifier = 0;
6564 if (Old->getQualifier()) {
6565 Qualifier
6566 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006567 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006568 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006569 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006570 }
6571
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006572 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006573 Sema::LookupOrdinaryName);
6574
6575 // Transform all the decls.
6576 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6577 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006578 NamedDecl *InstD = static_cast<NamedDecl*>(
6579 getDerived().TransformDecl(Old->getMemberLoc(),
6580 *I));
John McCall84d87672009-12-10 09:41:52 +00006581 if (!InstD) {
6582 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6583 // This can happen because of dependent hiding.
6584 if (isa<UsingShadowDecl>(*I))
6585 continue;
6586 else
John McCallfaf5fb42010-08-26 23:41:50 +00006587 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006588 }
John McCall10eae182009-11-30 22:42:35 +00006589
6590 // Expand using declarations.
6591 if (isa<UsingDecl>(InstD)) {
6592 UsingDecl *UD = cast<UsingDecl>(InstD);
6593 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6594 E = UD->shadow_end(); I != E; ++I)
6595 R.addDecl(*I);
6596 continue;
6597 }
6598
6599 R.addDecl(InstD);
6600 }
6601
6602 R.resolveKind();
6603
Douglas Gregor9262f472010-04-27 18:19:34 +00006604 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006605 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006606 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006607 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006608 Old->getMemberLoc(),
6609 Old->getNamingClass()));
6610 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006611 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006612
Douglas Gregorda7be082010-04-27 16:10:10 +00006613 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006614 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006615
John McCall10eae182009-11-30 22:42:35 +00006616 TemplateArgumentListInfo TransArgs;
6617 if (Old->hasExplicitTemplateArgs()) {
6618 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6619 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006620 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6621 Old->getNumTemplateArgs(),
6622 TransArgs))
6623 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006624 }
John McCall38836f02010-01-15 08:34:02 +00006625
6626 // FIXME: to do this check properly, we will need to preserve the
6627 // first-qualifier-in-scope here, just in case we had a dependent
6628 // base (and therefore couldn't do the check) and a
6629 // nested-name-qualifier (and therefore could do the lookup).
6630 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006631
John McCallb268a282010-08-23 23:25:46 +00006632 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006633 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006634 Old->getOperatorLoc(),
6635 Old->isArrow(),
6636 Qualifier,
6637 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006638 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006639 R,
6640 (Old->hasExplicitTemplateArgs()
6641 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006642}
6643
6644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006645ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006646TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6647 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6648 if (SubExpr.isInvalid())
6649 return ExprError();
6650
6651 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006652 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006653
6654 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6655}
6656
6657template<typename Derived>
6658ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006659TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6660 llvm_unreachable("pack expansion expression in unhandled context");
6661 return ExprError();
6662}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006663
6664template<typename Derived>
6665ExprResult
6666TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6667 // If E is not value-dependent, then nothing will change when we transform it.
6668 // Note: This is an instantiation-centric view.
6669 if (!E->isValueDependent())
6670 return SemaRef.Owned(E);
6671
6672 // Note: None of the implementations of TryExpandParameterPacks can ever
6673 // produce a diagnostic when given only a single unexpanded parameter pack,
6674 // so
6675 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6676 bool ShouldExpand = false;
6677 unsigned NumExpansions = 0;
6678 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6679 &Unexpanded, 1,
6680 ShouldExpand, NumExpansions))
6681 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006682
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006683 if (!ShouldExpand)
6684 return SemaRef.Owned(E);
6685
6686 // We now know the length of the parameter pack, so build a new expression
6687 // that stores that length.
6688 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6689 E->getPackLoc(), E->getRParenLoc(),
6690 NumExpansions);
6691}
6692
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006693template<typename Derived>
6694ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006695TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006696 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006697}
6698
Mike Stump11289f42009-09-09 15:08:12 +00006699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006700ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006701TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006702 TypeSourceInfo *EncodedTypeInfo
6703 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6704 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006706
Douglas Gregora16548e2009-08-11 05:31:07 +00006707 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006708 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006709 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006710
6711 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006712 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006713 E->getRParenLoc());
6714}
Mike Stump11289f42009-09-09 15:08:12 +00006715
Douglas Gregora16548e2009-08-11 05:31:07 +00006716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006718TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006719 // Transform arguments.
6720 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006721 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006722 Args.reserve(E->getNumArgs());
6723 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6724 &ArgChanged))
6725 return ExprError();
6726
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006727 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6728 // Class message: transform the receiver type.
6729 TypeSourceInfo *ReceiverTypeInfo
6730 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6731 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006732 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006733
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006734 // If nothing changed, just retain the existing message send.
6735 if (!getDerived().AlwaysRebuild() &&
6736 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006737 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006738
6739 // Build a new class message send.
6740 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6741 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006742 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006743 E->getMethodDecl(),
6744 E->getLeftLoc(),
6745 move_arg(Args),
6746 E->getRightLoc());
6747 }
6748
6749 // Instance message: transform the receiver
6750 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6751 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006752 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006753 = getDerived().TransformExpr(E->getInstanceReceiver());
6754 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006755 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006756
6757 // If nothing changed, just retain the existing message send.
6758 if (!getDerived().AlwaysRebuild() &&
6759 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006760 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006761
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006762 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006763 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006764 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006765 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006766 E->getMethodDecl(),
6767 E->getLeftLoc(),
6768 move_arg(Args),
6769 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006770}
6771
Mike Stump11289f42009-09-09 15:08:12 +00006772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006775 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006776}
6777
Mike Stump11289f42009-09-09 15:08:12 +00006778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006780TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006781 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006782}
6783
Mike Stump11289f42009-09-09 15:08:12 +00006784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006785ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006787 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006788 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006789 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006790 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006791
6792 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006793
Douglas Gregord51d90d2010-04-26 20:11:03 +00006794 // If nothing changed, just retain the existing expression.
6795 if (!getDerived().AlwaysRebuild() &&
6796 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006797 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006798
John McCallb268a282010-08-23 23:25:46 +00006799 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006800 E->getLocation(),
6801 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006802}
6803
Mike Stump11289f42009-09-09 15:08:12 +00006804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006805ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006806TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006807 // 'super' and types never change. Property never changes. Just
6808 // retain the existing expression.
6809 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006810 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006811
Douglas Gregor9faee212010-04-26 20:47:02 +00006812 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006813 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006814 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006815 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006816
Douglas Gregor9faee212010-04-26 20:47:02 +00006817 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006818
Douglas Gregor9faee212010-04-26 20:47:02 +00006819 // If nothing changed, just retain the existing expression.
6820 if (!getDerived().AlwaysRebuild() &&
6821 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006822 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006823
John McCallb7bd14f2010-12-02 01:19:52 +00006824 if (E->isExplicitProperty())
6825 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6826 E->getExplicitProperty(),
6827 E->getLocation());
6828
6829 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6830 E->getType(),
6831 E->getImplicitPropertyGetter(),
6832 E->getImplicitPropertySetter(),
6833 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006834}
6835
Mike Stump11289f42009-09-09 15:08:12 +00006836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006837ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006838TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006839 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006840 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006841 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006842 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006843
Douglas Gregord51d90d2010-04-26 20:11:03 +00006844 // If nothing changed, just retain the existing expression.
6845 if (!getDerived().AlwaysRebuild() &&
6846 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006847 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006848
John McCallb268a282010-08-23 23:25:46 +00006849 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006850 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006851}
6852
Mike Stump11289f42009-09-09 15:08:12 +00006853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006855TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006857 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006858 SubExprs.reserve(E->getNumSubExprs());
6859 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6860 SubExprs, &ArgumentChanged))
6861 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006862
Douglas Gregora16548e2009-08-11 05:31:07 +00006863 if (!getDerived().AlwaysRebuild() &&
6864 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006865 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006866
Douglas Gregora16548e2009-08-11 05:31:07 +00006867 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6868 move_arg(SubExprs),
6869 E->getRParenLoc());
6870}
6871
Mike Stump11289f42009-09-09 15:08:12 +00006872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006874TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006875 SourceLocation CaretLoc(E->getExprLoc());
6876
6877 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6878 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6879 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6880 llvm::SmallVector<ParmVarDecl*, 4> Params;
6881 llvm::SmallVector<QualType, 4> ParamTypes;
6882
6883 // Parameter substitution.
Douglas Gregorf3010112011-01-07 16:43:16 +00006884 // FIXME: Variadic templates
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006885 const BlockDecl *BD = E->getBlockDecl();
6886 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6887 EN = BD->param_end(); P != EN; ++P) {
6888 ParmVarDecl *OldParm = (*P);
6889 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6890 QualType NewType = NewParm->getType();
6891 Params.push_back(NewParm);
6892 ParamTypes.push_back(NewParm->getType());
6893 }
6894
6895 const FunctionType *BExprFunctionType = E->getFunctionType();
6896 QualType BExprResultType = BExprFunctionType->getResultType();
6897 if (!BExprResultType.isNull()) {
6898 if (!BExprResultType->isDependentType())
6899 CurBlock->ReturnType = BExprResultType;
6900 else if (BExprResultType != SemaRef.Context.DependentTy)
6901 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6902 }
John McCall3882ace2011-01-05 12:14:39 +00006903
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006904 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6905 CurBlock->ReturnType,
6906 ParamTypes.data(),
6907 ParamTypes.size(),
6908 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006909 0,
6910 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006911 CurBlock->FunctionType = FunctionType;
John McCall3882ace2011-01-05 12:14:39 +00006912
6913 // Set the parameters on the block decl.
6914 if (!Params.empty())
6915 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6916
6917 // Transform the body
6918 StmtResult Body = getDerived().TransformStmt(E->getBody());
6919 if (Body.isInvalid())
6920 return ExprError();
6921
John McCallb268a282010-08-23 23:25:46 +00006922 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006923}
6924
Mike Stump11289f42009-09-09 15:08:12 +00006925template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006926ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006927TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006928 NestedNameSpecifier *Qualifier = 0;
6929
6930 ValueDecl *ND
6931 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6932 E->getDecl()));
6933 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006934 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006935
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006936 if (!getDerived().AlwaysRebuild() &&
6937 ND == E->getDecl()) {
6938 // Mark it referenced in the new context regardless.
6939 // FIXME: this is a bit instantiation-specific.
6940 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6941
John McCallc3007a22010-10-26 07:05:15 +00006942 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006943 }
6944
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006945 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006946 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006947 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006948}
Mike Stump11289f42009-09-09 15:08:12 +00006949
Douglas Gregora16548e2009-08-11 05:31:07 +00006950//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006951// Type reconstruction
6952//===----------------------------------------------------------------------===//
6953
Mike Stump11289f42009-09-09 15:08:12 +00006954template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006955QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6956 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006957 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006958 getDerived().getBaseEntity());
6959}
6960
Mike Stump11289f42009-09-09 15:08:12 +00006961template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006962QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6963 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006964 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006965 getDerived().getBaseEntity());
6966}
6967
Mike Stump11289f42009-09-09 15:08:12 +00006968template<typename Derived>
6969QualType
John McCall70dd5f62009-10-30 00:06:24 +00006970TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6971 bool WrittenAsLValue,
6972 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006973 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006974 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006975}
6976
6977template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006978QualType
John McCall70dd5f62009-10-30 00:06:24 +00006979TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6980 QualType ClassType,
6981 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006982 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006983 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006984}
6985
6986template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006987QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006988TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6989 ArrayType::ArraySizeModifier SizeMod,
6990 const llvm::APInt *Size,
6991 Expr *SizeExpr,
6992 unsigned IndexTypeQuals,
6993 SourceRange BracketsRange) {
6994 if (SizeExpr || !Size)
6995 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6996 IndexTypeQuals, BracketsRange,
6997 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006998
6999 QualType Types[] = {
7000 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7001 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7002 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007003 };
7004 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7005 QualType SizeType;
7006 for (unsigned I = 0; I != NumTypes; ++I)
7007 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7008 SizeType = Types[I];
7009 break;
7010 }
Mike Stump11289f42009-09-09 15:08:12 +00007011
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007012 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7013 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007014 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007015 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007016 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007017}
Mike Stump11289f42009-09-09 15:08:12 +00007018
Douglas Gregord6ff3322009-08-04 16:50:30 +00007019template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007020QualType
7021TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007022 ArrayType::ArraySizeModifier SizeMod,
7023 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007024 unsigned IndexTypeQuals,
7025 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007026 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007027 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007028}
7029
7030template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007031QualType
Mike Stump11289f42009-09-09 15:08:12 +00007032TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007033 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007034 unsigned IndexTypeQuals,
7035 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007036 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007037 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007038}
Mike Stump11289f42009-09-09 15:08:12 +00007039
Douglas Gregord6ff3322009-08-04 16:50:30 +00007040template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007041QualType
7042TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007043 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007044 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007045 unsigned IndexTypeQuals,
7046 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007047 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007048 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007049 IndexTypeQuals, BracketsRange);
7050}
7051
7052template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007053QualType
7054TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007055 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007056 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007057 unsigned IndexTypeQuals,
7058 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007059 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007060 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007061 IndexTypeQuals, BracketsRange);
7062}
7063
7064template<typename Derived>
7065QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007066 unsigned NumElements,
7067 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007068 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007069 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007070}
Mike Stump11289f42009-09-09 15:08:12 +00007071
Douglas Gregord6ff3322009-08-04 16:50:30 +00007072template<typename Derived>
7073QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7074 unsigned NumElements,
7075 SourceLocation AttributeLoc) {
7076 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7077 NumElements, true);
7078 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007079 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7080 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007081 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007082}
Mike Stump11289f42009-09-09 15:08:12 +00007083
Douglas Gregord6ff3322009-08-04 16:50:30 +00007084template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007085QualType
7086TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007087 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007088 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007089 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007090}
Mike Stump11289f42009-09-09 15:08:12 +00007091
Douglas Gregord6ff3322009-08-04 16:50:30 +00007092template<typename Derived>
7093QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007094 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007095 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007096 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007097 unsigned Quals,
7098 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007099 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007100 Quals,
7101 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007102 getDerived().getBaseEntity(),
7103 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007104}
Mike Stump11289f42009-09-09 15:08:12 +00007105
Douglas Gregord6ff3322009-08-04 16:50:30 +00007106template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007107QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7108 return SemaRef.Context.getFunctionNoProtoType(T);
7109}
7110
7111template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007112QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7113 assert(D && "no decl found");
7114 if (D->isInvalidDecl()) return QualType();
7115
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007116 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007117 TypeDecl *Ty;
7118 if (isa<UsingDecl>(D)) {
7119 UsingDecl *Using = cast<UsingDecl>(D);
7120 assert(Using->isTypeName() &&
7121 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7122
7123 // A valid resolved using typename decl points to exactly one type decl.
7124 assert(++Using->shadow_begin() == Using->shadow_end());
7125 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007126
John McCallb96ec562009-12-04 22:46:56 +00007127 } else {
7128 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7129 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7130 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7131 }
7132
7133 return SemaRef.Context.getTypeDeclType(Ty);
7134}
7135
7136template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007137QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7138 SourceLocation Loc) {
7139 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007140}
7141
7142template<typename Derived>
7143QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7144 return SemaRef.Context.getTypeOfType(Underlying);
7145}
7146
7147template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007148QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7149 SourceLocation Loc) {
7150 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007151}
7152
7153template<typename Derived>
7154QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007155 TemplateName Template,
7156 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007157 const TemplateArgumentListInfo &TemplateArgs) {
7158 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007159}
Mike Stump11289f42009-09-09 15:08:12 +00007160
Douglas Gregor1135c352009-08-06 05:28:30 +00007161template<typename Derived>
7162NestedNameSpecifier *
7163TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7164 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007165 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007166 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007167 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007168 CXXScopeSpec SS;
7169 // FIXME: The source location information is all wrong.
7170 SS.setRange(Range);
7171 SS.setScopeRep(Prefix);
7172 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007173 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007174 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007175 ObjectType,
7176 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007177 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007178}
7179
7180template<typename Derived>
7181NestedNameSpecifier *
7182TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7183 SourceRange Range,
7184 NamespaceDecl *NS) {
7185 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7186}
7187
7188template<typename Derived>
7189NestedNameSpecifier *
7190TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7191 SourceRange Range,
7192 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007193 QualType T) {
7194 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007195 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007196 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007197 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7198 T.getTypePtr());
7199 }
Mike Stump11289f42009-09-09 15:08:12 +00007200
Douglas Gregor1135c352009-08-06 05:28:30 +00007201 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7202 return 0;
7203}
Mike Stump11289f42009-09-09 15:08:12 +00007204
Douglas Gregor71dc5092009-08-06 06:41:21 +00007205template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007206TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007207TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7208 bool TemplateKW,
7209 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007210 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007211 Template);
7212}
7213
7214template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007215TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007216TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007217 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007218 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007219 QualType ObjectType,
7220 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007221 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007222 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007223 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007224 UnqualifiedId Name;
7225 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007226 Sema::TemplateTy Template;
7227 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7228 /*FIXME:*/getDerived().getBaseLocation(),
7229 SS,
7230 Name,
John McCallba7bf592010-08-24 05:47:05 +00007231 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007232 /*EnteringContext=*/false,
7233 Template);
John McCall31f82722010-11-12 08:19:04 +00007234 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007235}
Mike Stump11289f42009-09-09 15:08:12 +00007236
Douglas Gregora16548e2009-08-11 05:31:07 +00007237template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007238TemplateName
7239TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7240 OverloadedOperatorKind Operator,
7241 QualType ObjectType) {
7242 CXXScopeSpec SS;
7243 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7244 SS.setScopeRep(Qualifier);
7245 UnqualifiedId Name;
7246 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7247 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7248 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007249 Sema::TemplateTy Template;
7250 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007251 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007252 SS,
7253 Name,
John McCallba7bf592010-08-24 05:47:05 +00007254 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007255 /*EnteringContext=*/false,
7256 Template);
7257 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007258}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007259
Douglas Gregor71395fa2009-11-04 00:56:37 +00007260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007261ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007262TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7263 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007264 Expr *OrigCallee,
7265 Expr *First,
7266 Expr *Second) {
7267 Expr *Callee = OrigCallee->IgnoreParenCasts();
7268 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007269
Douglas Gregora16548e2009-08-11 05:31:07 +00007270 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007271 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007272 if (!First->getType()->isOverloadableType() &&
7273 !Second->getType()->isOverloadableType())
7274 return getSema().CreateBuiltinArraySubscriptExpr(First,
7275 Callee->getLocStart(),
7276 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007277 } else if (Op == OO_Arrow) {
7278 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007279 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7280 } else if (Second == 0 || isPostIncDec) {
7281 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007282 // The argument is not of overloadable type, so try to create a
7283 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007284 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007285 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007286
John McCallb268a282010-08-23 23:25:46 +00007287 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007288 }
7289 } else {
John McCallb268a282010-08-23 23:25:46 +00007290 if (!First->getType()->isOverloadableType() &&
7291 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007292 // Neither of the arguments is an overloadable type, so try to
7293 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007294 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007295 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007296 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007297 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007298 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007299
Douglas Gregora16548e2009-08-11 05:31:07 +00007300 return move(Result);
7301 }
7302 }
Mike Stump11289f42009-09-09 15:08:12 +00007303
7304 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007305 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007306 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007307
John McCallb268a282010-08-23 23:25:46 +00007308 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007309 assert(ULE->requiresADL());
7310
7311 // FIXME: Do we have to check
7312 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007313 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007314 } else {
John McCallb268a282010-08-23 23:25:46 +00007315 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007316 }
Mike Stump11289f42009-09-09 15:08:12 +00007317
Douglas Gregora16548e2009-08-11 05:31:07 +00007318 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007319 Expr *Args[2] = { First, Second };
7320 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007321
Douglas Gregora16548e2009-08-11 05:31:07 +00007322 // Create the overloaded operator invocation for unary operators.
7323 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007324 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007325 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007326 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007327 }
Mike Stump11289f42009-09-09 15:08:12 +00007328
Sebastian Redladba46e2009-10-29 20:17:01 +00007329 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007330 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007331 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007332 First,
7333 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007334
Douglas Gregora16548e2009-08-11 05:31:07 +00007335 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007336 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007337 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007338 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7339 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007341
Mike Stump11289f42009-09-09 15:08:12 +00007342 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007343}
Mike Stump11289f42009-09-09 15:08:12 +00007344
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007346ExprResult
John McCallb268a282010-08-23 23:25:46 +00007347TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007348 SourceLocation OperatorLoc,
7349 bool isArrow,
7350 NestedNameSpecifier *Qualifier,
7351 SourceRange QualifierRange,
7352 TypeSourceInfo *ScopeType,
7353 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007354 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007355 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007356 CXXScopeSpec SS;
7357 if (Qualifier) {
7358 SS.setRange(QualifierRange);
7359 SS.setScopeRep(Qualifier);
7360 }
7361
John McCallb268a282010-08-23 23:25:46 +00007362 QualType BaseType = Base->getType();
7363 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007364 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007365 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007366 !BaseType->getAs<PointerType>()->getPointeeType()
7367 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007368 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007369 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007370 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007371 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007372 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007373 /*FIXME?*/true);
7374 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007375
Douglas Gregor678f90d2010-02-25 01:56:36 +00007376 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007377 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7378 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7379 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7380 NameInfo.setNamedTypeInfo(DestroyedType);
7381
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007382 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007383
John McCallb268a282010-08-23 23:25:46 +00007384 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007385 OperatorLoc, isArrow,
7386 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007387 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007388 /*TemplateArgs*/ 0);
7389}
7390
Douglas Gregord6ff3322009-08-04 16:50:30 +00007391} // end namespace clang
7392
7393#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H