blob: 0624aaa7ee9fd51f74e78b5aef31228b009d3afe [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() ||
3571 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3572 Result = getDerived().RebuildFunctionProtoType(ResultType,
3573 ParamTypes.data(),
3574 ParamTypes.size(),
3575 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003576 T->getTypeQuals(),
3577 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003578 if (Result.isNull())
3579 return QualType();
3580 }
Mike Stump11289f42009-09-09 15:08:12 +00003581
John McCall550e0c22009-10-21 00:40:46 +00003582 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3583 NewTL.setLParenLoc(TL.getLParenLoc());
3584 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003585 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003586 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3587 NewTL.setArg(i, ParamDecls[i]);
3588
3589 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003590}
Mike Stump11289f42009-09-09 15:08:12 +00003591
Douglas Gregord6ff3322009-08-04 16:50:30 +00003592template<typename Derived>
3593QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003594 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003595 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003596 FunctionNoProtoType *T = TL.getTypePtr();
3597 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3598 if (ResultType.isNull())
3599 return QualType();
3600
3601 QualType Result = TL.getType();
3602 if (getDerived().AlwaysRebuild() ||
3603 ResultType != T->getResultType())
3604 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3605
3606 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3607 NewTL.setLParenLoc(TL.getLParenLoc());
3608 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003609 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003610
3611 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003612}
Mike Stump11289f42009-09-09 15:08:12 +00003613
John McCallb96ec562009-12-04 22:46:56 +00003614template<typename Derived> QualType
3615TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003616 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003617 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003618 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003619 if (!D)
3620 return QualType();
3621
3622 QualType Result = TL.getType();
3623 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3624 Result = getDerived().RebuildUnresolvedUsingType(D);
3625 if (Result.isNull())
3626 return QualType();
3627 }
3628
3629 // We might get an arbitrary type spec type back. We should at
3630 // least always get a type spec type, though.
3631 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3632 NewTL.setNameLoc(TL.getNameLoc());
3633
3634 return Result;
3635}
3636
Douglas Gregord6ff3322009-08-04 16:50:30 +00003637template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003638QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003639 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003640 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003641 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003642 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3643 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003644 if (!Typedef)
3645 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003646
John McCall550e0c22009-10-21 00:40:46 +00003647 QualType Result = TL.getType();
3648 if (getDerived().AlwaysRebuild() ||
3649 Typedef != T->getDecl()) {
3650 Result = getDerived().RebuildTypedefType(Typedef);
3651 if (Result.isNull())
3652 return QualType();
3653 }
Mike Stump11289f42009-09-09 15:08:12 +00003654
John McCall550e0c22009-10-21 00:40:46 +00003655 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3656 NewTL.setNameLoc(TL.getNameLoc());
3657
3658 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003659}
Mike Stump11289f42009-09-09 15:08:12 +00003660
Douglas Gregord6ff3322009-08-04 16:50:30 +00003661template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003662QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003663 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003664 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003665 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003666
John McCalldadc5752010-08-24 06:29:42 +00003667 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003668 if (E.isInvalid())
3669 return QualType();
3670
John McCall550e0c22009-10-21 00:40:46 +00003671 QualType Result = TL.getType();
3672 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003673 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003674 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003675 if (Result.isNull())
3676 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003677 }
John McCall550e0c22009-10-21 00:40:46 +00003678 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003679
John McCall550e0c22009-10-21 00:40:46 +00003680 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003681 NewTL.setTypeofLoc(TL.getTypeofLoc());
3682 NewTL.setLParenLoc(TL.getLParenLoc());
3683 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003684
3685 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003686}
Mike Stump11289f42009-09-09 15:08:12 +00003687
3688template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003689QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003690 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003691 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3692 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3693 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003694 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003695
John McCall550e0c22009-10-21 00:40:46 +00003696 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003697 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3698 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003699 if (Result.isNull())
3700 return QualType();
3701 }
Mike Stump11289f42009-09-09 15:08:12 +00003702
John McCall550e0c22009-10-21 00:40:46 +00003703 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003704 NewTL.setTypeofLoc(TL.getTypeofLoc());
3705 NewTL.setLParenLoc(TL.getLParenLoc());
3706 NewTL.setRParenLoc(TL.getRParenLoc());
3707 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003708
3709 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003710}
Mike Stump11289f42009-09-09 15:08:12 +00003711
3712template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003713QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003714 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003715 DecltypeType *T = TL.getTypePtr();
3716
Douglas Gregore922c772009-08-04 22:27:00 +00003717 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003718 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003719
John McCalldadc5752010-08-24 06:29:42 +00003720 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003721 if (E.isInvalid())
3722 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003723
John McCall550e0c22009-10-21 00:40:46 +00003724 QualType Result = TL.getType();
3725 if (getDerived().AlwaysRebuild() ||
3726 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003727 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003728 if (Result.isNull())
3729 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003730 }
John McCall550e0c22009-10-21 00:40:46 +00003731 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003732
John McCall550e0c22009-10-21 00:40:46 +00003733 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3734 NewTL.setNameLoc(TL.getNameLoc());
3735
3736 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003737}
3738
3739template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003740QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003741 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003742 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003743 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003744 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3745 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003746 if (!Record)
3747 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003748
John McCall550e0c22009-10-21 00:40:46 +00003749 QualType Result = TL.getType();
3750 if (getDerived().AlwaysRebuild() ||
3751 Record != T->getDecl()) {
3752 Result = getDerived().RebuildRecordType(Record);
3753 if (Result.isNull())
3754 return QualType();
3755 }
Mike Stump11289f42009-09-09 15:08:12 +00003756
John McCall550e0c22009-10-21 00:40:46 +00003757 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3758 NewTL.setNameLoc(TL.getNameLoc());
3759
3760 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003761}
Mike Stump11289f42009-09-09 15:08:12 +00003762
3763template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003764QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003765 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003766 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003767 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003768 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3769 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003770 if (!Enum)
3771 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003772
John McCall550e0c22009-10-21 00:40:46 +00003773 QualType Result = TL.getType();
3774 if (getDerived().AlwaysRebuild() ||
3775 Enum != T->getDecl()) {
3776 Result = getDerived().RebuildEnumType(Enum);
3777 if (Result.isNull())
3778 return QualType();
3779 }
Mike Stump11289f42009-09-09 15:08:12 +00003780
John McCall550e0c22009-10-21 00:40:46 +00003781 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3782 NewTL.setNameLoc(TL.getNameLoc());
3783
3784 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003785}
John McCallfcc33b02009-09-05 00:15:47 +00003786
John McCalle78aac42010-03-10 03:28:59 +00003787template<typename Derived>
3788QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3789 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003790 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003791 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3792 TL.getTypePtr()->getDecl());
3793 if (!D) return QualType();
3794
3795 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3796 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3797 return T;
3798}
3799
Douglas Gregord6ff3322009-08-04 16:50:30 +00003800template<typename Derived>
3801QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003802 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003803 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003804 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003805}
3806
Mike Stump11289f42009-09-09 15:08:12 +00003807template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003808QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003809 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003810 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003811 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003812}
3813
3814template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003815QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003816 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003817 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003818 const TemplateSpecializationType *T = TL.getTypePtr();
3819
Mike Stump11289f42009-09-09 15:08:12 +00003820 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003821 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003822 if (Template.isNull())
3823 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003824
John McCall31f82722010-11-12 08:19:04 +00003825 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3826}
3827
Douglas Gregorfe921a72010-12-20 23:36:19 +00003828namespace {
3829 /// \brief Simple iterator that traverses the template arguments in a
3830 /// container that provides a \c getArgLoc() member function.
3831 ///
3832 /// This iterator is intended to be used with the iterator form of
3833 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3834 template<typename ArgLocContainer>
3835 class TemplateArgumentLocContainerIterator {
3836 ArgLocContainer *Container;
3837 unsigned Index;
3838
3839 public:
3840 typedef TemplateArgumentLoc value_type;
3841 typedef TemplateArgumentLoc reference;
3842 typedef int difference_type;
3843 typedef std::input_iterator_tag iterator_category;
3844
3845 class pointer {
3846 TemplateArgumentLoc Arg;
3847
3848 public:
3849 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3850
3851 const TemplateArgumentLoc *operator->() const {
3852 return &Arg;
3853 }
3854 };
3855
3856
3857 TemplateArgumentLocContainerIterator() {}
3858
3859 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3860 unsigned Index)
3861 : Container(&Container), Index(Index) { }
3862
3863 TemplateArgumentLocContainerIterator &operator++() {
3864 ++Index;
3865 return *this;
3866 }
3867
3868 TemplateArgumentLocContainerIterator operator++(int) {
3869 TemplateArgumentLocContainerIterator Old(*this);
3870 ++(*this);
3871 return Old;
3872 }
3873
3874 TemplateArgumentLoc operator*() const {
3875 return Container->getArgLoc(Index);
3876 }
3877
3878 pointer operator->() const {
3879 return pointer(Container->getArgLoc(Index));
3880 }
3881
3882 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003883 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003884 return X.Container == Y.Container && X.Index == Y.Index;
3885 }
3886
3887 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003888 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003889 return !(X == Y);
3890 }
3891 };
3892}
3893
3894
John McCall31f82722010-11-12 08:19:04 +00003895template <typename Derived>
3896QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3897 TypeLocBuilder &TLB,
3898 TemplateSpecializationTypeLoc TL,
3899 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00003900 TemplateArgumentListInfo NewTemplateArgs;
3901 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3902 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003903 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3904 ArgIterator;
3905 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3906 ArgIterator(TL, TL.getNumArgs()),
3907 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003908 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003909
John McCall0ad16662009-10-29 08:12:44 +00003910 // FIXME: maybe don't rebuild if all the template arguments are the same.
3911
3912 QualType Result =
3913 getDerived().RebuildTemplateSpecializationType(Template,
3914 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003915 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003916
3917 if (!Result.isNull()) {
3918 TemplateSpecializationTypeLoc NewTL
3919 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3920 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3921 NewTL.setLAngleLoc(TL.getLAngleLoc());
3922 NewTL.setRAngleLoc(TL.getRAngleLoc());
3923 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3924 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003925 }
Mike Stump11289f42009-09-09 15:08:12 +00003926
John McCall0ad16662009-10-29 08:12:44 +00003927 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003928}
Mike Stump11289f42009-09-09 15:08:12 +00003929
3930template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003931QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003932TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003933 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003934 ElaboratedType *T = TL.getTypePtr();
3935
3936 NestedNameSpecifier *NNS = 0;
3937 // NOTE: the qualifier in an ElaboratedType is optional.
3938 if (T->getQualifier() != 0) {
3939 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003940 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003941 if (!NNS)
3942 return QualType();
3943 }
Mike Stump11289f42009-09-09 15:08:12 +00003944
John McCall31f82722010-11-12 08:19:04 +00003945 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3946 if (NamedT.isNull())
3947 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003948
John McCall550e0c22009-10-21 00:40:46 +00003949 QualType Result = TL.getType();
3950 if (getDerived().AlwaysRebuild() ||
3951 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003952 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003953 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3954 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003955 if (Result.isNull())
3956 return QualType();
3957 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003958
Abramo Bagnara6150c882010-05-11 21:36:43 +00003959 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003960 NewTL.setKeywordLoc(TL.getKeywordLoc());
3961 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003962
3963 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003964}
Mike Stump11289f42009-09-09 15:08:12 +00003965
3966template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00003967QualType TreeTransform<Derived>::TransformAttributedType(
3968 TypeLocBuilder &TLB,
3969 AttributedTypeLoc TL) {
3970 const AttributedType *oldType = TL.getTypePtr();
3971 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
3972 if (modifiedType.isNull())
3973 return QualType();
3974
3975 QualType result = TL.getType();
3976
3977 // FIXME: dependent operand expressions?
3978 if (getDerived().AlwaysRebuild() ||
3979 modifiedType != oldType->getModifiedType()) {
3980 // TODO: this is really lame; we should really be rebuilding the
3981 // equivalent type from first principles.
3982 QualType equivalentType
3983 = getDerived().TransformType(oldType->getEquivalentType());
3984 if (equivalentType.isNull())
3985 return QualType();
3986 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
3987 modifiedType,
3988 equivalentType);
3989 }
3990
3991 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
3992 newTL.setAttrNameLoc(TL.getAttrNameLoc());
3993 if (TL.hasAttrOperand())
3994 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
3995 if (TL.hasAttrExprOperand())
3996 newTL.setAttrExprOperand(TL.getAttrExprOperand());
3997 else if (TL.hasAttrEnumOperand())
3998 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
3999
4000 return result;
4001}
4002
4003template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004004QualType
4005TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4006 ParenTypeLoc TL) {
4007 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4008 if (Inner.isNull())
4009 return QualType();
4010
4011 QualType Result = TL.getType();
4012 if (getDerived().AlwaysRebuild() ||
4013 Inner != TL.getInnerLoc().getType()) {
4014 Result = getDerived().RebuildParenType(Inner);
4015 if (Result.isNull())
4016 return QualType();
4017 }
4018
4019 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4020 NewTL.setLParenLoc(TL.getLParenLoc());
4021 NewTL.setRParenLoc(TL.getRParenLoc());
4022 return Result;
4023}
4024
4025template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004026QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004027 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004028 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004029
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004031 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004032 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004033 if (!NNS)
4034 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004035
John McCallc392f372010-06-11 00:33:02 +00004036 QualType Result
4037 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4038 T->getIdentifier(),
4039 TL.getKeywordLoc(),
4040 TL.getQualifierRange(),
4041 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004042 if (Result.isNull())
4043 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004044
Abramo Bagnarad7548482010-05-19 21:37:53 +00004045 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4046 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004047 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4048
Abramo Bagnarad7548482010-05-19 21:37:53 +00004049 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4050 NewTL.setKeywordLoc(TL.getKeywordLoc());
4051 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004052 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004053 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4054 NewTL.setKeywordLoc(TL.getKeywordLoc());
4055 NewTL.setQualifierRange(TL.getQualifierRange());
4056 NewTL.setNameLoc(TL.getNameLoc());
4057 }
John McCall550e0c22009-10-21 00:40:46 +00004058 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004059}
Mike Stump11289f42009-09-09 15:08:12 +00004060
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004062QualType TreeTransform<Derived>::
4063 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004064 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00004065 DependentTemplateSpecializationType *T = TL.getTypePtr();
4066
4067 NestedNameSpecifier *NNS
4068 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004069 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004070 if (!NNS)
4071 return QualType();
4072
John McCall31f82722010-11-12 08:19:04 +00004073 return getDerived()
4074 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4075}
4076
4077template<typename Derived>
4078QualType TreeTransform<Derived>::
4079 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4080 DependentTemplateSpecializationTypeLoc TL,
4081 NestedNameSpecifier *NNS) {
4082 DependentTemplateSpecializationType *T = TL.getTypePtr();
4083
John McCallc392f372010-06-11 00:33:02 +00004084 TemplateArgumentListInfo NewTemplateArgs;
4085 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4086 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004087
4088 typedef TemplateArgumentLocContainerIterator<
4089 DependentTemplateSpecializationTypeLoc> ArgIterator;
4090 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4091 ArgIterator(TL, TL.getNumArgs()),
4092 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004093 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004094
Douglas Gregora5614c52010-09-08 23:56:00 +00004095 QualType Result
4096 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4097 NNS,
4098 TL.getQualifierRange(),
4099 T->getIdentifier(),
4100 TL.getNameLoc(),
4101 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004102 if (Result.isNull())
4103 return QualType();
4104
4105 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4106 QualType NamedT = ElabT->getNamedType();
4107
4108 // Copy information relevant to the template specialization.
4109 TemplateSpecializationTypeLoc NamedTL
4110 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4111 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4112 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4113 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4114 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4115
4116 // Copy information relevant to the elaborated type.
4117 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4118 NewTL.setKeywordLoc(TL.getKeywordLoc());
4119 NewTL.setQualifierRange(TL.getQualifierRange());
4120 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004121 TypeLoc NewTL(Result, TL.getOpaqueData());
4122 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004123 }
4124 return Result;
4125}
4126
4127template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004128QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4129 PackExpansionTypeLoc TL) {
Douglas Gregor79aaca42011-01-05 19:06:29 +00004130 llvm_unreachable("Caller must expansion pack expansion types");
Douglas Gregord2fa7662010-12-20 02:24:11 +00004131 return QualType();
4132}
4133
4134template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004135QualType
4136TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004137 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004138 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004139 TLB.pushFullCopy(TL);
4140 return TL.getType();
4141}
4142
4143template<typename Derived>
4144QualType
4145TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004146 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004147 // ObjCObjectType is never dependent.
4148 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004149 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150}
Mike Stump11289f42009-09-09 15:08:12 +00004151
4152template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004153QualType
4154TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004155 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004156 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004157 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004158 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004159}
4160
Douglas Gregord6ff3322009-08-04 16:50:30 +00004161//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004162// Statement transformation
4163//===----------------------------------------------------------------------===//
4164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004165StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004166TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004167 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004168}
4169
4170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004171StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004172TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4173 return getDerived().TransformCompoundStmt(S, false);
4174}
4175
4176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004177StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004178TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004179 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004180 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004181 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004182 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004183 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4184 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004185 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004186 if (Result.isInvalid()) {
4187 // Immediately fail if this was a DeclStmt, since it's very
4188 // likely that this will cause problems for future statements.
4189 if (isa<DeclStmt>(*B))
4190 return StmtError();
4191
4192 // Otherwise, just keep processing substatements and fail later.
4193 SubStmtInvalid = true;
4194 continue;
4195 }
Mike Stump11289f42009-09-09 15:08:12 +00004196
Douglas Gregorebe10102009-08-20 07:17:43 +00004197 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4198 Statements.push_back(Result.takeAs<Stmt>());
4199 }
Mike Stump11289f42009-09-09 15:08:12 +00004200
John McCall1ababa62010-08-27 19:56:05 +00004201 if (SubStmtInvalid)
4202 return StmtError();
4203
Douglas Gregorebe10102009-08-20 07:17:43 +00004204 if (!getDerived().AlwaysRebuild() &&
4205 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004206 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004207
4208 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4209 move_arg(Statements),
4210 S->getRBracLoc(),
4211 IsStmtExpr);
4212}
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregorebe10102009-08-20 07:17:43 +00004214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004215StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004216TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004217 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004218 {
4219 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004220 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004221
Eli Friedman06577382009-11-19 03:14:00 +00004222 // Transform the left-hand case value.
4223 LHS = getDerived().TransformExpr(S->getLHS());
4224 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004225 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004226
Eli Friedman06577382009-11-19 03:14:00 +00004227 // Transform the right-hand case value (for the GNU case-range extension).
4228 RHS = getDerived().TransformExpr(S->getRHS());
4229 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004230 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004231 }
Mike Stump11289f42009-09-09 15:08:12 +00004232
Douglas Gregorebe10102009-08-20 07:17:43 +00004233 // Build the case statement.
4234 // Case statements are always rebuilt so that they will attached to their
4235 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004236 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004237 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004238 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004239 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004240 S->getColonLoc());
4241 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004242 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004243
Douglas Gregorebe10102009-08-20 07:17:43 +00004244 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004245 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004246 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004247 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004248
Douglas Gregorebe10102009-08-20 07:17:43 +00004249 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004250 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004251}
4252
4253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004254StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004255TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004256 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004257 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004258 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004259 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004260
Douglas Gregorebe10102009-08-20 07:17:43 +00004261 // Default statements are always rebuilt
4262 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004263 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004264}
Mike Stump11289f42009-09-09 15:08:12 +00004265
Douglas Gregorebe10102009-08-20 07:17:43 +00004266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004267StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004268TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004269 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004270 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004271 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004272
Douglas Gregorebe10102009-08-20 07:17:43 +00004273 // FIXME: Pass the real colon location in.
4274 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4275 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004276 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004277}
Mike Stump11289f42009-09-09 15:08:12 +00004278
Douglas Gregorebe10102009-08-20 07:17:43 +00004279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004280StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004281TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004282 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004283 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004284 VarDecl *ConditionVar = 0;
4285 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004286 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004287 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004288 getDerived().TransformDefinition(
4289 S->getConditionVariable()->getLocation(),
4290 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004291 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004292 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004293 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004294 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004295
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004296 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004297 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004298
4299 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004300 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004301 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4302 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004303 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004304 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004305
John McCallb268a282010-08-23 23:25:46 +00004306 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004307 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004308 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004309
John McCallb268a282010-08-23 23:25:46 +00004310 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4311 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004312 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004313
Douglas Gregorebe10102009-08-20 07:17:43 +00004314 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004315 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004316 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004317 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004318
Douglas Gregorebe10102009-08-20 07:17:43 +00004319 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004320 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004321 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004322 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004323
Douglas Gregorebe10102009-08-20 07:17:43 +00004324 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004325 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004326 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004327 Then.get() == S->getThen() &&
4328 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004329 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004331 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004332 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004333 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004334}
4335
4336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004337StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004338TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004339 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004340 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004341 VarDecl *ConditionVar = 0;
4342 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004343 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004344 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004345 getDerived().TransformDefinition(
4346 S->getConditionVariable()->getLocation(),
4347 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004348 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004349 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004350 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004351 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004352
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004353 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004354 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004355 }
Mike Stump11289f42009-09-09 15:08:12 +00004356
Douglas Gregorebe10102009-08-20 07:17:43 +00004357 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004358 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004359 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004360 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004361 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004362 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004363
Douglas Gregorebe10102009-08-20 07:17:43 +00004364 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004365 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004366 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004367 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004368
Douglas Gregorebe10102009-08-20 07:17:43 +00004369 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004370 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4371 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004372}
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregorebe10102009-08-20 07:17:43 +00004374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004375StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004376TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004377 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004378 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004379 VarDecl *ConditionVar = 0;
4380 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004381 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004382 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004383 getDerived().TransformDefinition(
4384 S->getConditionVariable()->getLocation(),
4385 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004386 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004387 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004388 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004389 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004390
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004391 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004392 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004393
4394 if (S->getCond()) {
4395 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004396 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4397 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004398 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004399 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004400 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004401 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004402 }
Mike Stump11289f42009-09-09 15:08:12 +00004403
John McCallb268a282010-08-23 23:25:46 +00004404 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4405 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004406 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004407
Douglas Gregorebe10102009-08-20 07:17:43 +00004408 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004409 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004410 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004411 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004412
Douglas Gregorebe10102009-08-20 07:17:43 +00004413 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004414 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004415 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004416 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004417 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004418
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004419 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004420 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004421}
Mike Stump11289f42009-09-09 15:08:12 +00004422
Douglas Gregorebe10102009-08-20 07:17:43 +00004423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004424StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004425TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004426 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004427 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004428 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004429 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004430
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004431 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004432 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004433 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004434 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004435
Douglas Gregorebe10102009-08-20 07:17:43 +00004436 if (!getDerived().AlwaysRebuild() &&
4437 Cond.get() == S->getCond() &&
4438 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004439 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004440
John McCallb268a282010-08-23 23:25:46 +00004441 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4442 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004443 S->getRParenLoc());
4444}
Mike Stump11289f42009-09-09 15:08:12 +00004445
Douglas Gregorebe10102009-08-20 07:17:43 +00004446template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004447StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004448TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004449 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004450 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004451 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004452 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004453
Douglas Gregorebe10102009-08-20 07:17:43 +00004454 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004455 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004456 VarDecl *ConditionVar = 0;
4457 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004458 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004459 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004460 getDerived().TransformDefinition(
4461 S->getConditionVariable()->getLocation(),
4462 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004463 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004464 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004465 } else {
4466 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004467
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004468 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004469 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004470
4471 if (S->getCond()) {
4472 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004473 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4474 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004475 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004476 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004477
John McCallb268a282010-08-23 23:25:46 +00004478 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004479 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004480 }
Mike Stump11289f42009-09-09 15:08:12 +00004481
John McCallb268a282010-08-23 23:25:46 +00004482 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4483 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004484 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004485
Douglas Gregorebe10102009-08-20 07:17:43 +00004486 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004487 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004488 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004489 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004490
John McCallb268a282010-08-23 23:25:46 +00004491 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4492 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004493 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004494
Douglas Gregorebe10102009-08-20 07:17:43 +00004495 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004496 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004497 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004498 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregorebe10102009-08-20 07:17:43 +00004500 if (!getDerived().AlwaysRebuild() &&
4501 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004502 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004503 Inc.get() == S->getInc() &&
4504 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004505 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004506
Douglas Gregorebe10102009-08-20 07:17:43 +00004507 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004508 Init.get(), FullCond, ConditionVar,
4509 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004510}
4511
4512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004513StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004514TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004515 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004516 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004517 S->getLabel());
4518}
4519
4520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004521StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004522TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004523 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004524 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004525 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004526
Douglas Gregorebe10102009-08-20 07:17:43 +00004527 if (!getDerived().AlwaysRebuild() &&
4528 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004529 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004530
4531 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004532 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004533}
4534
4535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004536StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004537TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004538 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004539}
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregorebe10102009-08-20 07:17:43 +00004541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004542StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004543TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004544 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004545}
Mike Stump11289f42009-09-09 15:08:12 +00004546
Douglas Gregorebe10102009-08-20 07:17:43 +00004547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004548StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004549TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004550 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004551 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004552 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004553
Mike Stump11289f42009-09-09 15:08:12 +00004554 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004555 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004556 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004557}
Mike Stump11289f42009-09-09 15:08:12 +00004558
Douglas Gregorebe10102009-08-20 07:17:43 +00004559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004560StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004561TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004562 bool DeclChanged = false;
4563 llvm::SmallVector<Decl *, 4> Decls;
4564 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4565 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004566 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4567 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004568 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004569 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregorebe10102009-08-20 07:17:43 +00004571 if (Transformed != *D)
4572 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregorebe10102009-08-20 07:17:43 +00004574 Decls.push_back(Transformed);
4575 }
Mike Stump11289f42009-09-09 15:08:12 +00004576
Douglas Gregorebe10102009-08-20 07:17:43 +00004577 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004578 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004579
4580 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004581 S->getStartLoc(), S->getEndLoc());
4582}
Mike Stump11289f42009-09-09 15:08:12 +00004583
Douglas Gregorebe10102009-08-20 07:17:43 +00004584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004585StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004586TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004587 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004588 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004589}
4590
4591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004592StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004593TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004594
John McCall37ad5512010-08-23 06:44:23 +00004595 ASTOwningVector<Expr*> Constraints(getSema());
4596 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004597 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004598
John McCalldadc5752010-08-24 06:29:42 +00004599 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004600 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004601
4602 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004603
Anders Carlssonaaeef072010-01-24 05:50:09 +00004604 // Go through the outputs.
4605 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004606 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004607
Anders Carlssonaaeef072010-01-24 05:50:09 +00004608 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004609 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004610
Anders Carlssonaaeef072010-01-24 05:50:09 +00004611 // Transform the output expr.
4612 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004613 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004614 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004615 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004616
Anders Carlssonaaeef072010-01-24 05:50:09 +00004617 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004618
John McCallb268a282010-08-23 23:25:46 +00004619 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004620 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004621
Anders Carlssonaaeef072010-01-24 05:50:09 +00004622 // Go through the inputs.
4623 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004624 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004625
Anders Carlssonaaeef072010-01-24 05:50:09 +00004626 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004627 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004628
Anders Carlssonaaeef072010-01-24 05:50:09 +00004629 // Transform the input expr.
4630 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004631 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004632 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004633 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004634
Anders Carlssonaaeef072010-01-24 05:50:09 +00004635 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004636
John McCallb268a282010-08-23 23:25:46 +00004637 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004638 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004639
Anders Carlssonaaeef072010-01-24 05:50:09 +00004640 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004641 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004642
4643 // Go through the clobbers.
4644 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004645 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004646
4647 // No need to transform the asm string literal.
4648 AsmString = SemaRef.Owned(S->getAsmString());
4649
4650 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4651 S->isSimple(),
4652 S->isVolatile(),
4653 S->getNumOutputs(),
4654 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004655 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004656 move_arg(Constraints),
4657 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004658 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004659 move_arg(Clobbers),
4660 S->getRParenLoc(),
4661 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004662}
4663
4664
4665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004666StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004667TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004668 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004669 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004670 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004671 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004672
Douglas Gregor96c79492010-04-23 22:50:49 +00004673 // Transform the @catch statements (if present).
4674 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004675 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004676 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004677 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004678 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004679 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004680 if (Catch.get() != S->getCatchStmt(I))
4681 AnyCatchChanged = true;
4682 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004683 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004684
Douglas Gregor306de2f2010-04-22 23:59:56 +00004685 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004686 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004687 if (S->getFinallyStmt()) {
4688 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4689 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004690 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004691 }
4692
4693 // If nothing changed, just retain this statement.
4694 if (!getDerived().AlwaysRebuild() &&
4695 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004696 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004697 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004698 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004699
Douglas Gregor306de2f2010-04-22 23:59:56 +00004700 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004701 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4702 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004703}
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregorebe10102009-08-20 07:17:43 +00004705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004706StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004707TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004708 // Transform the @catch parameter, if there is one.
4709 VarDecl *Var = 0;
4710 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4711 TypeSourceInfo *TSInfo = 0;
4712 if (FromVar->getTypeSourceInfo()) {
4713 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4714 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004715 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004716 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004717
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004718 QualType T;
4719 if (TSInfo)
4720 T = TSInfo->getType();
4721 else {
4722 T = getDerived().TransformType(FromVar->getType());
4723 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004724 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004725 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004726
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004727 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4728 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004729 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004730 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004731
John McCalldadc5752010-08-24 06:29:42 +00004732 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004733 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004734 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004735
4736 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004737 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004738 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004739}
Mike Stump11289f42009-09-09 15:08:12 +00004740
Douglas Gregorebe10102009-08-20 07:17:43 +00004741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004742StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004743TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004744 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004745 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004746 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004747 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004748
Douglas Gregor306de2f2010-04-22 23:59:56 +00004749 // If nothing changed, just retain this statement.
4750 if (!getDerived().AlwaysRebuild() &&
4751 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004752 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004753
4754 // Build a new statement.
4755 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004756 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004757}
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregorebe10102009-08-20 07:17:43 +00004759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004760StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004761TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004762 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004763 if (S->getThrowExpr()) {
4764 Operand = getDerived().TransformExpr(S->getThrowExpr());
4765 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004766 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004767 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004768
Douglas Gregor2900c162010-04-22 21:44:01 +00004769 if (!getDerived().AlwaysRebuild() &&
4770 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004771 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004772
John McCallb268a282010-08-23 23:25:46 +00004773 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004774}
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregorebe10102009-08-20 07:17:43 +00004776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004777StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004778TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004779 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004780 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004781 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004782 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004783 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004784
Douglas Gregor6148de72010-04-22 22:01:21 +00004785 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004786 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004787 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004788 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004789
Douglas Gregor6148de72010-04-22 22:01:21 +00004790 // If nothing change, just retain the current statement.
4791 if (!getDerived().AlwaysRebuild() &&
4792 Object.get() == S->getSynchExpr() &&
4793 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004794 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004795
4796 // Build a new statement.
4797 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004798 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004799}
4800
4801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004802StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004803TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004804 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004805 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004806 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004807 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004808 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004809
Douglas Gregorf68a5082010-04-22 23:10:45 +00004810 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004811 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004812 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004813 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004814
Douglas Gregorf68a5082010-04-22 23:10:45 +00004815 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004816 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004817 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004818 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004819
Douglas Gregorf68a5082010-04-22 23:10:45 +00004820 // If nothing changed, just retain this statement.
4821 if (!getDerived().AlwaysRebuild() &&
4822 Element.get() == S->getElement() &&
4823 Collection.get() == S->getCollection() &&
4824 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004825 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004826
Douglas Gregorf68a5082010-04-22 23:10:45 +00004827 // Build a new statement.
4828 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4829 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004830 Element.get(),
4831 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004832 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004833 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004834}
4835
4836
4837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004838StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004839TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4840 // Transform the exception declaration, if any.
4841 VarDecl *Var = 0;
4842 if (S->getExceptionDecl()) {
4843 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004844 TypeSourceInfo *T = getDerived().TransformType(
4845 ExceptionDecl->getTypeSourceInfo());
4846 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004847 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004849 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004850 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004851 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004852 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004853 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004854 }
Mike Stump11289f42009-09-09 15:08:12 +00004855
Douglas Gregorebe10102009-08-20 07:17:43 +00004856 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004857 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004858 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004859 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregorebe10102009-08-20 07:17:43 +00004861 if (!getDerived().AlwaysRebuild() &&
4862 !Var &&
4863 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004864 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004865
4866 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4867 Var,
John McCallb268a282010-08-23 23:25:46 +00004868 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004869}
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregorebe10102009-08-20 07:17:43 +00004871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004872StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004873TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4874 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004875 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004876 = getDerived().TransformCompoundStmt(S->getTryBlock());
4877 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004878 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004879
Douglas Gregorebe10102009-08-20 07:17:43 +00004880 // Transform the handlers.
4881 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004882 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004883 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004884 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004885 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4886 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004887 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004888
Douglas Gregorebe10102009-08-20 07:17:43 +00004889 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4890 Handlers.push_back(Handler.takeAs<Stmt>());
4891 }
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregorebe10102009-08-20 07:17:43 +00004893 if (!getDerived().AlwaysRebuild() &&
4894 TryBlock.get() == S->getTryBlock() &&
4895 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004896 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004897
John McCallb268a282010-08-23 23:25:46 +00004898 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004899 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004900}
Mike Stump11289f42009-09-09 15:08:12 +00004901
Douglas Gregorebe10102009-08-20 07:17:43 +00004902//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004903// Expression transformation
4904//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004906ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004907TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004908 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004909}
Mike Stump11289f42009-09-09 15:08:12 +00004910
4911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004913TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004914 NestedNameSpecifier *Qualifier = 0;
4915 if (E->getQualifier()) {
4916 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004917 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004918 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004919 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004920 }
John McCallce546572009-12-08 09:08:17 +00004921
4922 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004923 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4924 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004925 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004926 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004927
John McCall815039a2010-08-17 21:27:17 +00004928 DeclarationNameInfo NameInfo = E->getNameInfo();
4929 if (NameInfo.getName()) {
4930 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4931 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004932 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004933 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004934
4935 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004936 Qualifier == E->getQualifier() &&
4937 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004938 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004939 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004940
4941 // Mark it referenced in the new context regardless.
4942 // FIXME: this is a bit instantiation-specific.
4943 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4944
John McCallc3007a22010-10-26 07:05:15 +00004945 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004946 }
John McCallce546572009-12-08 09:08:17 +00004947
4948 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004949 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004950 TemplateArgs = &TransArgs;
4951 TransArgs.setLAngleLoc(E->getLAngleLoc());
4952 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004953 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4954 E->getNumTemplateArgs(),
4955 TransArgs))
4956 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004957 }
4958
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004959 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004960 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004961}
Mike Stump11289f42009-09-09 15:08:12 +00004962
Douglas Gregora16548e2009-08-11 05:31:07 +00004963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004965TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004966 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004967}
Mike Stump11289f42009-09-09 15:08:12 +00004968
Douglas Gregora16548e2009-08-11 05:31:07 +00004969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004970ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004971TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004972 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004973}
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregora16548e2009-08-11 05:31:07 +00004975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004976ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004977TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004978 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004979}
Mike Stump11289f42009-09-09 15:08:12 +00004980
Douglas Gregora16548e2009-08-11 05:31:07 +00004981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004982ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004983TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004984 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004985}
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregora16548e2009-08-11 05:31:07 +00004987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004988ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004989TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004990 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004991}
4992
4993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004994ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004995TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004996 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004997 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004998 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004999
Douglas Gregora16548e2009-08-11 05:31:07 +00005000 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005001 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005002
John McCallb268a282010-08-23 23:25:46 +00005003 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005004 E->getRParen());
5005}
5006
Mike Stump11289f42009-09-09 15:08:12 +00005007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005008ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005009TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005010 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregora16548e2009-08-11 05:31:07 +00005014 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005015 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005016
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5018 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005019 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005020}
Mike Stump11289f42009-09-09 15:08:12 +00005021
Douglas Gregora16548e2009-08-11 05:31:07 +00005022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005023ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005024TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5025 // Transform the type.
5026 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5027 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005028 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005029
Douglas Gregor882211c2010-04-28 22:16:22 +00005030 // Transform all of the components into components similar to what the
5031 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005032 // FIXME: It would be slightly more efficient in the non-dependent case to
5033 // just map FieldDecls, rather than requiring the rebuilder to look for
5034 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005035 // template code that we don't care.
5036 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005037 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005038 typedef OffsetOfExpr::OffsetOfNode Node;
5039 llvm::SmallVector<Component, 4> Components;
5040 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5041 const Node &ON = E->getComponent(I);
5042 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005043 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005044 Comp.LocStart = ON.getRange().getBegin();
5045 Comp.LocEnd = ON.getRange().getEnd();
5046 switch (ON.getKind()) {
5047 case Node::Array: {
5048 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005049 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005050 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005051 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005052
Douglas Gregor882211c2010-04-28 22:16:22 +00005053 ExprChanged = ExprChanged || Index.get() != FromIndex;
5054 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005055 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005056 break;
5057 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005058
Douglas Gregor882211c2010-04-28 22:16:22 +00005059 case Node::Field:
5060 case Node::Identifier:
5061 Comp.isBrackets = false;
5062 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005063 if (!Comp.U.IdentInfo)
5064 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005065
Douglas Gregor882211c2010-04-28 22:16:22 +00005066 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005067
Douglas Gregord1702062010-04-29 00:18:15 +00005068 case Node::Base:
5069 // Will be recomputed during the rebuild.
5070 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005071 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005072
Douglas Gregor882211c2010-04-28 22:16:22 +00005073 Components.push_back(Comp);
5074 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005075
Douglas Gregor882211c2010-04-28 22:16:22 +00005076 // If nothing changed, retain the existing expression.
5077 if (!getDerived().AlwaysRebuild() &&
5078 Type == E->getTypeSourceInfo() &&
5079 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005080 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005081
Douglas Gregor882211c2010-04-28 22:16:22 +00005082 // Build a new offsetof expression.
5083 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5084 Components.data(), Components.size(),
5085 E->getRParenLoc());
5086}
5087
5088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005089ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005090TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5091 assert(getDerived().AlreadyTransformed(E->getType()) &&
5092 "opaque value expression requires transformation");
5093 return SemaRef.Owned(E);
5094}
5095
5096template<typename Derived>
5097ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005098TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005099 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005100 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005101
John McCallbcd03502009-12-07 02:54:59 +00005102 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005103 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005105
John McCall4c98fd82009-11-04 07:28:41 +00005106 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005107 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005108
John McCall4c98fd82009-11-04 07:28:41 +00005109 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005110 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 E->getSourceRange());
5112 }
Mike Stump11289f42009-09-09 15:08:12 +00005113
John McCalldadc5752010-08-24 06:29:42 +00005114 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005115 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 // C++0x [expr.sizeof]p1:
5117 // The operand is either an expression, which is an unevaluated operand
5118 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005119 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5122 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005124
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005126 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 }
Mike Stump11289f42009-09-09 15:08:12 +00005128
John McCallb268a282010-08-23 23:25:46 +00005129 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 E->isSizeOf(),
5131 E->getSourceRange());
5132}
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregora16548e2009-08-11 05:31:07 +00005134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005136TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005137 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005138 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005140
John McCalldadc5752010-08-24 06:29:42 +00005141 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005142 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
5145
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 if (!getDerived().AlwaysRebuild() &&
5147 LHS.get() == E->getLHS() &&
5148 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005149 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005150
John McCallb268a282010-08-23 23:25:46 +00005151 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005152 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005153 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005154 E->getRBracketLoc());
5155}
Mike Stump11289f42009-09-09 15:08:12 +00005156
5157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005159TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005160 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005161 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005163 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005164
5165 // Transform arguments.
5166 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005167 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005168 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5169 &ArgChanged))
5170 return ExprError();
5171
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 if (!getDerived().AlwaysRebuild() &&
5173 Callee.get() == E->getCallee() &&
5174 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005175 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005178 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005179 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005180 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005182 E->getRParenLoc());
5183}
Mike Stump11289f42009-09-09 15:08:12 +00005184
5185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005186ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005187TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005188 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005189 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005190 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005191
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005192 NestedNameSpecifier *Qualifier = 0;
5193 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005194 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005195 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005196 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005197 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005198 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005199 }
Mike Stump11289f42009-09-09 15:08:12 +00005200
Eli Friedman2cfcef62009-12-04 06:40:45 +00005201 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005202 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5203 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005206
John McCall16df1e52010-03-30 21:47:33 +00005207 NamedDecl *FoundDecl = E->getFoundDecl();
5208 if (FoundDecl == E->getMemberDecl()) {
5209 FoundDecl = Member;
5210 } else {
5211 FoundDecl = cast_or_null<NamedDecl>(
5212 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5213 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005214 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005215 }
5216
Douglas Gregora16548e2009-08-11 05:31:07 +00005217 if (!getDerived().AlwaysRebuild() &&
5218 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005219 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005220 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005221 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005222 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005223
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005224 // Mark it referenced in the new context regardless.
5225 // FIXME: this is a bit instantiation-specific.
5226 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005227 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005228 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005229
John McCall6b51f282009-11-23 01:53:49 +00005230 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005231 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005232 TransArgs.setLAngleLoc(E->getLAngleLoc());
5233 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005234 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5235 E->getNumTemplateArgs(),
5236 TransArgs))
5237 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005238 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005239
Douglas Gregora16548e2009-08-11 05:31:07 +00005240 // FIXME: Bogus source location for the operator
5241 SourceLocation FakeOperatorLoc
5242 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5243
John McCall38836f02010-01-15 08:34:02 +00005244 // FIXME: to do this check properly, we will need to preserve the
5245 // first-qualifier-in-scope here, just in case we had a dependent
5246 // base (and therefore couldn't do the check) and a
5247 // nested-name-qualifier (and therefore could do the lookup).
5248 NamedDecl *FirstQualifierInScope = 0;
5249
John McCallb268a282010-08-23 23:25:46 +00005250 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005251 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005252 Qualifier,
5253 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005254 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005255 Member,
John McCall16df1e52010-03-30 21:47:33 +00005256 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005257 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005258 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005259 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005260}
Mike Stump11289f42009-09-09 15:08:12 +00005261
Douglas Gregora16548e2009-08-11 05:31:07 +00005262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005263ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005264TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005265 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005266 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005267 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005268
John McCalldadc5752010-08-24 06:29:42 +00005269 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005270 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregora16548e2009-08-11 05:31:07 +00005273 if (!getDerived().AlwaysRebuild() &&
5274 LHS.get() == E->getLHS() &&
5275 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005276 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregora16548e2009-08-11 05:31:07 +00005278 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005279 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005280}
5281
Mike Stump11289f42009-09-09 15:08:12 +00005282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005283ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005284TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005285 CompoundAssignOperator *E) {
5286 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005287}
Mike Stump11289f42009-09-09 15:08:12 +00005288
Douglas Gregora16548e2009-08-11 05:31:07 +00005289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005291TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005292 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005293 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005295
John McCalldadc5752010-08-24 06:29:42 +00005296 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005297 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005298 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005299
John McCalldadc5752010-08-24 06:29:42 +00005300 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005303
Douglas Gregora16548e2009-08-11 05:31:07 +00005304 if (!getDerived().AlwaysRebuild() &&
5305 Cond.get() == E->getCond() &&
5306 LHS.get() == E->getLHS() &&
5307 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005308 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005309
John McCallb268a282010-08-23 23:25:46 +00005310 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005311 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005312 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005313 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005314 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005315}
Mike Stump11289f42009-09-09 15:08:12 +00005316
5317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005319TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005320 // Implicit casts are eliminated during transformation, since they
5321 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005322 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005323}
Mike Stump11289f42009-09-09 15:08:12 +00005324
Douglas Gregora16548e2009-08-11 05:31:07 +00005325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005326ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005327TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005328 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5329 if (!Type)
5330 return ExprError();
5331
John McCalldadc5752010-08-24 06:29:42 +00005332 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005333 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005334 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005335 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005336
Douglas Gregora16548e2009-08-11 05:31:07 +00005337 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005338 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005339 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005340 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005341
John McCall97513962010-01-15 18:39:57 +00005342 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005343 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005344 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005345 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005346}
Mike Stump11289f42009-09-09 15:08:12 +00005347
Douglas Gregora16548e2009-08-11 05:31:07 +00005348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005349ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005350TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005351 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5352 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5353 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005355
John McCalldadc5752010-08-24 06:29:42 +00005356 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005357 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005358 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005359
Douglas Gregora16548e2009-08-11 05:31:07 +00005360 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005361 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005362 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005363 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005364
John McCall5d7aa7f2010-01-19 22:33:45 +00005365 // Note: the expression type doesn't necessarily match the
5366 // type-as-written, but that's okay, because it should always be
5367 // derivable from the initializer.
5368
John McCalle15bbff2010-01-18 19:35:47 +00005369 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005370 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005371 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005372}
Mike Stump11289f42009-09-09 15:08:12 +00005373
Douglas Gregora16548e2009-08-11 05:31:07 +00005374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005376TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005377 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005378 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005380
Douglas Gregora16548e2009-08-11 05:31:07 +00005381 if (!getDerived().AlwaysRebuild() &&
5382 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005383 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005384
Douglas Gregora16548e2009-08-11 05:31:07 +00005385 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005386 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005388 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005389 E->getAccessorLoc(),
5390 E->getAccessor());
5391}
Mike Stump11289f42009-09-09 15:08:12 +00005392
Douglas Gregora16548e2009-08-11 05:31:07 +00005393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005395TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005397
John McCall37ad5512010-08-23 06:44:23 +00005398 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005399 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5400 Inits, &InitChanged))
5401 return ExprError();
5402
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005404 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005405
Douglas Gregora16548e2009-08-11 05:31:07 +00005406 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005407 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005408}
Mike Stump11289f42009-09-09 15:08:12 +00005409
Douglas Gregora16548e2009-08-11 05:31:07 +00005410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005411ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005412TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005413 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005414
Douglas Gregorebe10102009-08-20 07:17:43 +00005415 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005416 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005417 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregorebe10102009-08-20 07:17:43 +00005420 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005421 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005422 bool ExprChanged = false;
5423 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5424 DEnd = E->designators_end();
5425 D != DEnd; ++D) {
5426 if (D->isFieldDesignator()) {
5427 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5428 D->getDotLoc(),
5429 D->getFieldLoc()));
5430 continue;
5431 }
Mike Stump11289f42009-09-09 15:08:12 +00005432
Douglas Gregora16548e2009-08-11 05:31:07 +00005433 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005434 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005437
5438 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005439 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005440
Douglas Gregora16548e2009-08-11 05:31:07 +00005441 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5442 ArrayExprs.push_back(Index.release());
5443 continue;
5444 }
Mike Stump11289f42009-09-09 15:08:12 +00005445
Douglas Gregora16548e2009-08-11 05:31:07 +00005446 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005447 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005448 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5449 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005450 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005451
John McCalldadc5752010-08-24 06:29:42 +00005452 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005453 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005454 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005455
5456 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 End.get(),
5458 D->getLBracketLoc(),
5459 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005460
Douglas Gregora16548e2009-08-11 05:31:07 +00005461 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5462 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregora16548e2009-08-11 05:31:07 +00005464 ArrayExprs.push_back(Start.release());
5465 ArrayExprs.push_back(End.release());
5466 }
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregora16548e2009-08-11 05:31:07 +00005468 if (!getDerived().AlwaysRebuild() &&
5469 Init.get() == E->getInit() &&
5470 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005471 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005472
Douglas Gregora16548e2009-08-11 05:31:07 +00005473 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5474 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005475 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005476}
Mike Stump11289f42009-09-09 15:08:12 +00005477
Douglas Gregora16548e2009-08-11 05:31:07 +00005478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005479ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005480TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005481 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005482 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005483
Douglas Gregor3da3c062009-10-28 00:29:27 +00005484 // FIXME: Will we ever have proper type location here? Will we actually
5485 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005486 QualType T = getDerived().TransformType(E->getType());
5487 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005489
Douglas Gregora16548e2009-08-11 05:31:07 +00005490 if (!getDerived().AlwaysRebuild() &&
5491 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005492 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregora16548e2009-08-11 05:31:07 +00005494 return getDerived().RebuildImplicitValueInitExpr(T);
5495}
Mike Stump11289f42009-09-09 15:08:12 +00005496
Douglas Gregora16548e2009-08-11 05:31:07 +00005497template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005498ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005499TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005500 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5501 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005502 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005503
John McCalldadc5752010-08-24 06:29:42 +00005504 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005505 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005506 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005507
Douglas Gregora16548e2009-08-11 05:31:07 +00005508 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005509 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005510 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005511 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005512
John McCallb268a282010-08-23 23:25:46 +00005513 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005514 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005515}
5516
5517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005518ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005519TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005520 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005521 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005522 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5523 &ArgumentChanged))
5524 return ExprError();
5525
Douglas Gregora16548e2009-08-11 05:31:07 +00005526 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5527 move_arg(Inits),
5528 E->getRParenLoc());
5529}
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531/// \brief Transform an address-of-label expression.
5532///
5533/// By default, the transformation of an address-of-label expression always
5534/// rebuilds the expression, so that the label identifier can be resolved to
5535/// the corresponding label statement by semantic analysis.
5536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005538TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5540 E->getLabel());
5541}
Mike Stump11289f42009-09-09 15:08:12 +00005542
5543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005544ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005545TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005546 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005547 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5548 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005550
Douglas Gregora16548e2009-08-11 05:31:07 +00005551 if (!getDerived().AlwaysRebuild() &&
5552 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005553 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005554
5555 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005556 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005557 E->getRParenLoc());
5558}
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregora16548e2009-08-11 05:31:07 +00005560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005561ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005562TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005563 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005566
John McCalldadc5752010-08-24 06:29:42 +00005567 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005570
John McCalldadc5752010-08-24 06:29:42 +00005571 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005572 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005574
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 if (!getDerived().AlwaysRebuild() &&
5576 Cond.get() == E->getCond() &&
5577 LHS.get() == E->getLHS() &&
5578 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005579 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005582 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 E->getRParenLoc());
5584}
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregora16548e2009-08-11 05:31:07 +00005586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005587ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005588TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005589 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005590}
5591
5592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005593ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005594TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005595 switch (E->getOperator()) {
5596 case OO_New:
5597 case OO_Delete:
5598 case OO_Array_New:
5599 case OO_Array_Delete:
5600 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005601 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005602
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005603 case OO_Call: {
5604 // This is a call to an object's operator().
5605 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5606
5607 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005608 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005609 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005610 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005611
5612 // FIXME: Poor location information
5613 SourceLocation FakeLParenLoc
5614 = SemaRef.PP.getLocForEndOfToken(
5615 static_cast<Expr *>(Object.get())->getLocEnd());
5616
5617 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005618 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005619 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5620 Args))
5621 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005622
John McCallb268a282010-08-23 23:25:46 +00005623 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005624 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005625 E->getLocEnd());
5626 }
5627
5628#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5629 case OO_##Name:
5630#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5631#include "clang/Basic/OperatorKinds.def"
5632 case OO_Subscript:
5633 // Handled below.
5634 break;
5635
5636 case OO_Conditional:
5637 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005638 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005639
5640 case OO_None:
5641 case NUM_OVERLOADED_OPERATORS:
5642 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005643 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005644 }
5645
John McCalldadc5752010-08-24 06:29:42 +00005646 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005647 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
John McCalldadc5752010-08-24 06:29:42 +00005650 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005651 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005652 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005653
John McCalldadc5752010-08-24 06:29:42 +00005654 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 if (E->getNumArgs() == 2) {
5656 Second = getDerived().TransformExpr(E->getArg(1));
5657 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005658 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 }
Mike Stump11289f42009-09-09 15:08:12 +00005660
Douglas Gregora16548e2009-08-11 05:31:07 +00005661 if (!getDerived().AlwaysRebuild() &&
5662 Callee.get() == E->getCallee() &&
5663 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005664 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005665 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005666
Douglas Gregora16548e2009-08-11 05:31:07 +00005667 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5668 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005669 Callee.get(),
5670 First.get(),
5671 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005672}
Mike Stump11289f42009-09-09 15:08:12 +00005673
Douglas Gregora16548e2009-08-11 05:31:07 +00005674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005676TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5677 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005678}
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregora16548e2009-08-11 05:31:07 +00005680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005682TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005683 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5684 if (!Type)
5685 return ExprError();
5686
John McCalldadc5752010-08-24 06:29:42 +00005687 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005688 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005690 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005691
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005693 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005694 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005695 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005698 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5700 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5701 SourceLocation FakeRParenLoc
5702 = SemaRef.PP.getLocForEndOfToken(
5703 E->getSubExpr()->getSourceRange().getEnd());
5704 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005705 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005707 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 FakeRAngleLoc,
5709 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005710 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 FakeRParenLoc);
5712}
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregora16548e2009-08-11 05:31:07 +00005714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005715ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005716TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5717 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005718}
Mike Stump11289f42009-09-09 15:08:12 +00005719
5720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005722TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5723 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005724}
5725
Douglas Gregora16548e2009-08-11 05:31:07 +00005726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005727ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005728TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005729 CXXReinterpretCastExpr *E) {
5730 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005731}
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005735TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5736 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005737}
Mike Stump11289f42009-09-09 15:08:12 +00005738
Douglas Gregora16548e2009-08-11 05:31:07 +00005739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005740ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005741TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005742 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005743 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5744 if (!Type)
5745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005746
John McCalldadc5752010-08-24 06:29:42 +00005747 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005748 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005751
Douglas Gregora16548e2009-08-11 05:31:07 +00005752 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005753 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005755 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005756
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005757 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005758 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005759 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 E->getRParenLoc());
5761}
Mike Stump11289f42009-09-09 15:08:12 +00005762
Douglas Gregora16548e2009-08-11 05:31:07 +00005763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005764ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005765TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005766 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005767 TypeSourceInfo *TInfo
5768 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5769 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005771
Douglas Gregora16548e2009-08-11 05:31:07 +00005772 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005773 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005774 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005775
Douglas Gregor9da64192010-04-26 22:37:10 +00005776 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5777 E->getLocStart(),
5778 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 E->getLocEnd());
5780 }
Mike Stump11289f42009-09-09 15:08:12 +00005781
Douglas Gregora16548e2009-08-11 05:31:07 +00005782 // We don't know whether the expression is potentially evaluated until
5783 // after we perform semantic analysis, so the expression is potentially
5784 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005785 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005786 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005787
John McCalldadc5752010-08-24 06:29:42 +00005788 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 if (!getDerived().AlwaysRebuild() &&
5793 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005794 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregor9da64192010-04-26 22:37:10 +00005796 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5797 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005798 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005799 E->getLocEnd());
5800}
5801
5802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005803ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005804TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5805 if (E->isTypeOperand()) {
5806 TypeSourceInfo *TInfo
5807 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5808 if (!TInfo)
5809 return ExprError();
5810
5811 if (!getDerived().AlwaysRebuild() &&
5812 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005813 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005814
5815 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5816 E->getLocStart(),
5817 TInfo,
5818 E->getLocEnd());
5819 }
5820
5821 // We don't know whether the expression is potentially evaluated until
5822 // after we perform semantic analysis, so the expression is potentially
5823 // potentially evaluated.
5824 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5825
5826 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5827 if (SubExpr.isInvalid())
5828 return ExprError();
5829
5830 if (!getDerived().AlwaysRebuild() &&
5831 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005832 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005833
5834 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5835 E->getLocStart(),
5836 SubExpr.get(),
5837 E->getLocEnd());
5838}
5839
5840template<typename Derived>
5841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005842TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005843 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005844}
Mike Stump11289f42009-09-09 15:08:12 +00005845
Douglas Gregora16548e2009-08-11 05:31:07 +00005846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005847ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005848TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005849 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005850 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005851}
Mike Stump11289f42009-09-09 15:08:12 +00005852
Douglas Gregora16548e2009-08-11 05:31:07 +00005853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005855TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005856 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5857 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5858 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005860 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005861 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005862
Douglas Gregorb15af892010-01-07 23:12:05 +00005863 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005864}
Mike Stump11289f42009-09-09 15:08:12 +00005865
Douglas Gregora16548e2009-08-11 05:31:07 +00005866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005867ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005868TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005869 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005870 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005872
Douglas Gregora16548e2009-08-11 05:31:07 +00005873 if (!getDerived().AlwaysRebuild() &&
5874 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005875 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005876
John McCallb268a282010-08-23 23:25:46 +00005877 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005878}
Mike Stump11289f42009-09-09 15:08:12 +00005879
Douglas Gregora16548e2009-08-11 05:31:07 +00005880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005881ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005882TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005883 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005884 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5885 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005887 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005888
Chandler Carruth794da4c2010-02-08 06:42:49 +00005889 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005890 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005891 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005892
Douglas Gregor033f6752009-12-23 23:03:06 +00005893 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005894}
Mike Stump11289f42009-09-09 15:08:12 +00005895
Douglas Gregora16548e2009-08-11 05:31:07 +00005896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005897ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005898TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5899 CXXScalarValueInitExpr *E) {
5900 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5901 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005903
Douglas Gregora16548e2009-08-11 05:31:07 +00005904 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005905 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005906 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005907
Douglas Gregor2b88c112010-09-08 00:15:04 +00005908 return getDerived().RebuildCXXScalarValueInitExpr(T,
5909 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005910 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005911}
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregora16548e2009-08-11 05:31:07 +00005913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005915TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005917 TypeSourceInfo *AllocTypeInfo
5918 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5919 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005920 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005923 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005924 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005926
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 // Transform the placement arguments (if any).
5928 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005929 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005930 if (getDerived().TransformExprs(E->getPlacementArgs(),
5931 E->getNumPlacementArgs(), true,
5932 PlacementArgs, &ArgumentChanged))
5933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005934
Douglas Gregorebe10102009-08-20 07:17:43 +00005935 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005936 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005937 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
5938 ConstructorArgs, &ArgumentChanged))
5939 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregord2d9da02010-02-26 00:38:10 +00005941 // Transform constructor, new operator, and delete operator.
5942 CXXConstructorDecl *Constructor = 0;
5943 if (E->getConstructor()) {
5944 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005945 getDerived().TransformDecl(E->getLocStart(),
5946 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005947 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005948 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005949 }
5950
5951 FunctionDecl *OperatorNew = 0;
5952 if (E->getOperatorNew()) {
5953 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005954 getDerived().TransformDecl(E->getLocStart(),
5955 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005956 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005957 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005958 }
5959
5960 FunctionDecl *OperatorDelete = 0;
5961 if (E->getOperatorDelete()) {
5962 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005963 getDerived().TransformDecl(E->getLocStart(),
5964 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005965 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005966 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005967 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005968
Douglas Gregora16548e2009-08-11 05:31:07 +00005969 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005970 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005971 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005972 Constructor == E->getConstructor() &&
5973 OperatorNew == E->getOperatorNew() &&
5974 OperatorDelete == E->getOperatorDelete() &&
5975 !ArgumentChanged) {
5976 // Mark any declarations we need as referenced.
5977 // FIXME: instantiation-specific.
5978 if (Constructor)
5979 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5980 if (OperatorNew)
5981 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5982 if (OperatorDelete)
5983 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005984 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005985 }
Mike Stump11289f42009-09-09 15:08:12 +00005986
Douglas Gregor0744ef62010-09-07 21:49:58 +00005987 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005988 if (!ArraySize.get()) {
5989 // If no array size was specified, but the new expression was
5990 // instantiated with an array type (e.g., "new T" where T is
5991 // instantiated with "int[4]"), extract the outer bound from the
5992 // array type as our array size. We do this with constant and
5993 // dependently-sized array types.
5994 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5995 if (!ArrayT) {
5996 // Do nothing
5997 } else if (const ConstantArrayType *ConsArrayT
5998 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005999 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006000 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6001 ConsArrayT->getSize(),
6002 SemaRef.Context.getSizeType(),
6003 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006004 AllocType = ConsArrayT->getElementType();
6005 } else if (const DependentSizedArrayType *DepArrayT
6006 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6007 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006008 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006009 AllocType = DepArrayT->getElementType();
6010 }
6011 }
6012 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006013
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6015 E->isGlobalNew(),
6016 /*FIXME:*/E->getLocStart(),
6017 move_arg(PlacementArgs),
6018 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006019 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006020 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006021 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006022 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 /*FIXME:*/E->getLocStart(),
6024 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006025 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006026}
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006030TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006031 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006033 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregord2d9da02010-02-26 00:38:10 +00006035 // Transform the delete operator, if known.
6036 FunctionDecl *OperatorDelete = 0;
6037 if (E->getOperatorDelete()) {
6038 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006039 getDerived().TransformDecl(E->getLocStart(),
6040 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006041 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006043 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006044
Douglas Gregora16548e2009-08-11 05:31:07 +00006045 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006046 Operand.get() == E->getArgument() &&
6047 OperatorDelete == E->getOperatorDelete()) {
6048 // Mark any declarations we need as referenced.
6049 // FIXME: instantiation-specific.
6050 if (OperatorDelete)
6051 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006052
6053 if (!E->getArgument()->isTypeDependent()) {
6054 QualType Destroyed = SemaRef.Context.getBaseElementType(
6055 E->getDestroyedType());
6056 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6057 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6058 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6059 SemaRef.LookupDestructor(Record));
6060 }
6061 }
6062
John McCallc3007a22010-10-26 07:05:15 +00006063 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006064 }
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregora16548e2009-08-11 05:31:07 +00006066 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6067 E->isGlobalDelete(),
6068 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006069 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006070}
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregora16548e2009-08-11 05:31:07 +00006072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006073ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006074TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006075 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006076 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006077 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006079
John McCallba7bf592010-08-24 05:47:05 +00006080 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006081 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006082 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006083 E->getOperatorLoc(),
6084 E->isArrow()? tok::arrow : tok::period,
6085 ObjectTypePtr,
6086 MayBePseudoDestructor);
6087 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006088 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006089
John McCallba7bf592010-08-24 05:47:05 +00006090 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006091 NestedNameSpecifier *Qualifier = E->getQualifier();
6092 if (Qualifier) {
6093 Qualifier
6094 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6095 E->getQualifierRange(),
6096 ObjectType);
6097 if (!Qualifier)
6098 return ExprError();
6099 }
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregor678f90d2010-02-25 01:56:36 +00006101 PseudoDestructorTypeStorage Destroyed;
6102 if (E->getDestroyedTypeInfo()) {
6103 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006104 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6105 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006106 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006107 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006108 Destroyed = DestroyedTypeInfo;
6109 } else if (ObjectType->isDependentType()) {
6110 // We aren't likely to be able to resolve the identifier down to a type
6111 // now anyway, so just retain the identifier.
6112 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6113 E->getDestroyedTypeLoc());
6114 } else {
6115 // Look for a destructor known with the given name.
6116 CXXScopeSpec SS;
6117 if (Qualifier) {
6118 SS.setScopeRep(Qualifier);
6119 SS.setRange(E->getQualifierRange());
6120 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006121
John McCallba7bf592010-08-24 05:47:05 +00006122 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006123 *E->getDestroyedTypeIdentifier(),
6124 E->getDestroyedTypeLoc(),
6125 /*Scope=*/0,
6126 SS, ObjectTypePtr,
6127 false);
6128 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006129 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006130
Douglas Gregor678f90d2010-02-25 01:56:36 +00006131 Destroyed
6132 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6133 E->getDestroyedTypeLoc());
6134 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006135
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006136 TypeSourceInfo *ScopeTypeInfo = 0;
6137 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006138 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006139 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006140 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006141 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006142
John McCallb268a282010-08-23 23:25:46 +00006143 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006144 E->getOperatorLoc(),
6145 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006146 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006147 E->getQualifierRange(),
6148 ScopeTypeInfo,
6149 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006150 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006151 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006152}
Mike Stump11289f42009-09-09 15:08:12 +00006153
Douglas Gregorad8a3362009-09-04 17:36:40 +00006154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006155ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006156TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006157 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006158 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6159
6160 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6161 Sema::LookupOrdinaryName);
6162
6163 // Transform all the decls.
6164 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6165 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006166 NamedDecl *InstD = static_cast<NamedDecl*>(
6167 getDerived().TransformDecl(Old->getNameLoc(),
6168 *I));
John McCall84d87672009-12-10 09:41:52 +00006169 if (!InstD) {
6170 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6171 // This can happen because of dependent hiding.
6172 if (isa<UsingShadowDecl>(*I))
6173 continue;
6174 else
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006176 }
John McCalle66edc12009-11-24 19:00:30 +00006177
6178 // Expand using declarations.
6179 if (isa<UsingDecl>(InstD)) {
6180 UsingDecl *UD = cast<UsingDecl>(InstD);
6181 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6182 E = UD->shadow_end(); I != E; ++I)
6183 R.addDecl(*I);
6184 continue;
6185 }
6186
6187 R.addDecl(InstD);
6188 }
6189
6190 // Resolve a kind, but don't do any further analysis. If it's
6191 // ambiguous, the callee needs to deal with it.
6192 R.resolveKind();
6193
6194 // Rebuild the nested-name qualifier, if present.
6195 CXXScopeSpec SS;
6196 NestedNameSpecifier *Qualifier = 0;
6197 if (Old->getQualifier()) {
6198 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006199 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006200 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006201 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006202
John McCalle66edc12009-11-24 19:00:30 +00006203 SS.setScopeRep(Qualifier);
6204 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006205 }
6206
Douglas Gregor9262f472010-04-27 18:19:34 +00006207 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006208 CXXRecordDecl *NamingClass
6209 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6210 Old->getNameLoc(),
6211 Old->getNamingClass()));
6212 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006214
Douglas Gregorda7be082010-04-27 16:10:10 +00006215 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006216 }
6217
6218 // If we have no template arguments, it's a normal declaration name.
6219 if (!Old->hasExplicitTemplateArgs())
6220 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6221
6222 // If we have template arguments, rebuild them, then rebuild the
6223 // templateid expression.
6224 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006225 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6226 Old->getNumTemplateArgs(),
6227 TransArgs))
6228 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006229
6230 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6231 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006232}
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregora16548e2009-08-11 05:31:07 +00006234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006235ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006236TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006237 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6238 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006239 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006240
Douglas Gregora16548e2009-08-11 05:31:07 +00006241 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006242 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006243 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006244
Mike Stump11289f42009-09-09 15:08:12 +00006245 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006246 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006247 T,
6248 E->getLocEnd());
6249}
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregora16548e2009-08-11 05:31:07 +00006251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006252ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006253TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6254 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6255 if (!LhsT)
6256 return ExprError();
6257
6258 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6259 if (!RhsT)
6260 return ExprError();
6261
6262 if (!getDerived().AlwaysRebuild() &&
6263 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6264 return SemaRef.Owned(E);
6265
6266 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6267 E->getLocStart(),
6268 LhsT, RhsT,
6269 E->getLocEnd());
6270}
6271
6272template<typename Derived>
6273ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006274TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006275 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006277 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006278 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006281
John McCall31f82722010-11-12 08:19:04 +00006282 // TODO: If this is a conversion-function-id, verify that the
6283 // destination type name (if present) resolves the same way after
6284 // instantiation as it did in the local scope.
6285
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006286 DeclarationNameInfo NameInfo
6287 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6288 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006289 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006290
John McCalle66edc12009-11-24 19:00:30 +00006291 if (!E->hasExplicitTemplateArgs()) {
6292 if (!getDerived().AlwaysRebuild() &&
6293 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006294 // Note: it is sufficient to compare the Name component of NameInfo:
6295 // if name has not changed, DNLoc has not changed either.
6296 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006297 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006298
John McCalle66edc12009-11-24 19:00:30 +00006299 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6300 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006301 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006302 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006303 }
John McCall6b51f282009-11-23 01:53:49 +00006304
6305 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006306 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6307 E->getNumTemplateArgs(),
6308 TransArgs))
6309 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006310
John McCalle66edc12009-11-24 19:00:30 +00006311 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6312 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006313 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006314 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006315}
6316
6317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006319TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006320 // CXXConstructExprs are always implicit, so when we have a
6321 // 1-argument construction we just transform that argument.
6322 if (E->getNumArgs() == 1 ||
6323 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6324 return getDerived().TransformExpr(E->getArg(0));
6325
Douglas Gregora16548e2009-08-11 05:31:07 +00006326 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6327
6328 QualType T = getDerived().TransformType(E->getType());
6329 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006330 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006331
6332 CXXConstructorDecl *Constructor
6333 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006334 getDerived().TransformDecl(E->getLocStart(),
6335 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006336 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006337 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006338
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006340 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006341 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6342 &ArgumentChanged))
6343 return ExprError();
6344
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 if (!getDerived().AlwaysRebuild() &&
6346 T == E->getType() &&
6347 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006348 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006349 // Mark the constructor as referenced.
6350 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006351 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006352 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006353 }
Mike Stump11289f42009-09-09 15:08:12 +00006354
Douglas Gregordb121ba2009-12-14 16:27:04 +00006355 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6356 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006357 move_arg(Args),
6358 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006359 E->getConstructionKind(),
6360 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006361}
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregora16548e2009-08-11 05:31:07 +00006363/// \brief Transform a C++ temporary-binding expression.
6364///
Douglas Gregor363b1512009-12-24 18:51:59 +00006365/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6366/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006369TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006370 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006371}
Mike Stump11289f42009-09-09 15:08:12 +00006372
John McCall5d413782010-12-06 08:20:24 +00006373/// \brief Transform a C++ expression that contains cleanups that should
6374/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006375///
John McCall5d413782010-12-06 08:20:24 +00006376/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006377/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006379ExprResult
John McCall5d413782010-12-06 08:20:24 +00006380TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006381 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006382}
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregora16548e2009-08-11 05:31:07 +00006384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006385ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006386TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006387 CXXTemporaryObjectExpr *E) {
6388 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6389 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006390 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006391
Douglas Gregora16548e2009-08-11 05:31:07 +00006392 CXXConstructorDecl *Constructor
6393 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006394 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006395 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006396 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006398
Douglas Gregora16548e2009-08-11 05:31:07 +00006399 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006400 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006402 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6403 &ArgumentChanged))
6404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006405
Douglas Gregora16548e2009-08-11 05:31:07 +00006406 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006407 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006408 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006409 !ArgumentChanged) {
6410 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006411 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006412 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006413 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006414
6415 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6416 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006417 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006418 E->getLocEnd());
6419}
Mike Stump11289f42009-09-09 15:08:12 +00006420
Douglas Gregora16548e2009-08-11 05:31:07 +00006421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006422ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006423TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006424 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006425 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6426 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006427 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006428
Douglas Gregora16548e2009-08-11 05:31:07 +00006429 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006430 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006431 Args.reserve(E->arg_size());
6432 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6433 &ArgumentChanged))
6434 return ExprError();
6435
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006437 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006439 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006440
Douglas Gregora16548e2009-08-11 05:31:07 +00006441 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006442 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006443 E->getLParenLoc(),
6444 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006445 E->getRParenLoc());
6446}
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregora16548e2009-08-11 05:31:07 +00006448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006449ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006450TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006451 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006452 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006453 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006454 Expr *OldBase;
6455 QualType BaseType;
6456 QualType ObjectType;
6457 if (!E->isImplicitAccess()) {
6458 OldBase = E->getBase();
6459 Base = getDerived().TransformExpr(OldBase);
6460 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006462
John McCall2d74de92009-12-01 22:10:20 +00006463 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006464 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006465 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006466 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006467 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006468 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006469 ObjectTy,
6470 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006471 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006472 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006473
John McCallba7bf592010-08-24 05:47:05 +00006474 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006475 BaseType = ((Expr*) Base.get())->getType();
6476 } else {
6477 OldBase = 0;
6478 BaseType = getDerived().TransformType(E->getBaseType());
6479 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6480 }
Mike Stump11289f42009-09-09 15:08:12 +00006481
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006482 // Transform the first part of the nested-name-specifier that qualifies
6483 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006484 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006485 = getDerived().TransformFirstQualifierInScope(
6486 E->getFirstQualifierFoundInScope(),
6487 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006488
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006489 NestedNameSpecifier *Qualifier = 0;
6490 if (E->getQualifier()) {
6491 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6492 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006493 ObjectType,
6494 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006495 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006496 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006497 }
Mike Stump11289f42009-09-09 15:08:12 +00006498
John McCall31f82722010-11-12 08:19:04 +00006499 // TODO: If this is a conversion-function-id, verify that the
6500 // destination type name (if present) resolves the same way after
6501 // instantiation as it did in the local scope.
6502
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006503 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006504 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006505 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006506 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006507
John McCall2d74de92009-12-01 22:10:20 +00006508 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006509 // This is a reference to a member without an explicitly-specified
6510 // template argument list. Optimize for this common case.
6511 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006512 Base.get() == OldBase &&
6513 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006514 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006515 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006516 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006517 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006518
John McCallb268a282010-08-23 23:25:46 +00006519 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006520 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006521 E->isArrow(),
6522 E->getOperatorLoc(),
6523 Qualifier,
6524 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006525 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006526 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006527 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006528 }
6529
John McCall6b51f282009-11-23 01:53:49 +00006530 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006531 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6532 E->getNumTemplateArgs(),
6533 TransArgs))
6534 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006535
John McCallb268a282010-08-23 23:25:46 +00006536 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006537 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006538 E->isArrow(),
6539 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006540 Qualifier,
6541 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006542 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006543 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006544 &TransArgs);
6545}
6546
6547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006548ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006549TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006550 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006551 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006552 QualType BaseType;
6553 if (!Old->isImplicitAccess()) {
6554 Base = getDerived().TransformExpr(Old->getBase());
6555 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006556 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006557 BaseType = ((Expr*) Base.get())->getType();
6558 } else {
6559 BaseType = getDerived().TransformType(Old->getBaseType());
6560 }
John McCall10eae182009-11-30 22:42:35 +00006561
6562 NestedNameSpecifier *Qualifier = 0;
6563 if (Old->getQualifier()) {
6564 Qualifier
6565 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006566 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006567 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006568 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006569 }
6570
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006571 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006572 Sema::LookupOrdinaryName);
6573
6574 // Transform all the decls.
6575 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6576 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006577 NamedDecl *InstD = static_cast<NamedDecl*>(
6578 getDerived().TransformDecl(Old->getMemberLoc(),
6579 *I));
John McCall84d87672009-12-10 09:41:52 +00006580 if (!InstD) {
6581 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6582 // This can happen because of dependent hiding.
6583 if (isa<UsingShadowDecl>(*I))
6584 continue;
6585 else
John McCallfaf5fb42010-08-26 23:41:50 +00006586 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006587 }
John McCall10eae182009-11-30 22:42:35 +00006588
6589 // Expand using declarations.
6590 if (isa<UsingDecl>(InstD)) {
6591 UsingDecl *UD = cast<UsingDecl>(InstD);
6592 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6593 E = UD->shadow_end(); I != E; ++I)
6594 R.addDecl(*I);
6595 continue;
6596 }
6597
6598 R.addDecl(InstD);
6599 }
6600
6601 R.resolveKind();
6602
Douglas Gregor9262f472010-04-27 18:19:34 +00006603 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006604 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006605 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006606 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006607 Old->getMemberLoc(),
6608 Old->getNamingClass()));
6609 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006610 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006611
Douglas Gregorda7be082010-04-27 16:10:10 +00006612 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006613 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006614
John McCall10eae182009-11-30 22:42:35 +00006615 TemplateArgumentListInfo TransArgs;
6616 if (Old->hasExplicitTemplateArgs()) {
6617 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6618 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006619 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6620 Old->getNumTemplateArgs(),
6621 TransArgs))
6622 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006623 }
John McCall38836f02010-01-15 08:34:02 +00006624
6625 // FIXME: to do this check properly, we will need to preserve the
6626 // first-qualifier-in-scope here, just in case we had a dependent
6627 // base (and therefore couldn't do the check) and a
6628 // nested-name-qualifier (and therefore could do the lookup).
6629 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006630
John McCallb268a282010-08-23 23:25:46 +00006631 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006632 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006633 Old->getOperatorLoc(),
6634 Old->isArrow(),
6635 Qualifier,
6636 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006637 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006638 R,
6639 (Old->hasExplicitTemplateArgs()
6640 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006641}
6642
6643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006644ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006645TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6646 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6647 if (SubExpr.isInvalid())
6648 return ExprError();
6649
6650 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006651 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006652
6653 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6654}
6655
6656template<typename Derived>
6657ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006658TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6659 llvm_unreachable("pack expansion expression in unhandled context");
6660 return ExprError();
6661}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006662
6663template<typename Derived>
6664ExprResult
6665TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6666 // If E is not value-dependent, then nothing will change when we transform it.
6667 // Note: This is an instantiation-centric view.
6668 if (!E->isValueDependent())
6669 return SemaRef.Owned(E);
6670
6671 // Note: None of the implementations of TryExpandParameterPacks can ever
6672 // produce a diagnostic when given only a single unexpanded parameter pack,
6673 // so
6674 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6675 bool ShouldExpand = false;
6676 unsigned NumExpansions = 0;
6677 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6678 &Unexpanded, 1,
6679 ShouldExpand, NumExpansions))
6680 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006681
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006682 if (!ShouldExpand)
6683 return SemaRef.Owned(E);
6684
6685 // We now know the length of the parameter pack, so build a new expression
6686 // that stores that length.
6687 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6688 E->getPackLoc(), E->getRParenLoc(),
6689 NumExpansions);
6690}
6691
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006692template<typename Derived>
6693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006694TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006695 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006696}
6697
Mike Stump11289f42009-09-09 15:08:12 +00006698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006700TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006701 TypeSourceInfo *EncodedTypeInfo
6702 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6703 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006705
Douglas Gregora16548e2009-08-11 05:31:07 +00006706 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006707 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006708 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006709
6710 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006711 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006712 E->getRParenLoc());
6713}
Mike Stump11289f42009-09-09 15:08:12 +00006714
Douglas Gregora16548e2009-08-11 05:31:07 +00006715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006716ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006717TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006718 // Transform arguments.
6719 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006720 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006721 Args.reserve(E->getNumArgs());
6722 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6723 &ArgChanged))
6724 return ExprError();
6725
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006726 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6727 // Class message: transform the receiver type.
6728 TypeSourceInfo *ReceiverTypeInfo
6729 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6730 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006731 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006732
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006733 // If nothing changed, just retain the existing message send.
6734 if (!getDerived().AlwaysRebuild() &&
6735 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006736 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006737
6738 // Build a new class message send.
6739 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6740 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006741 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006742 E->getMethodDecl(),
6743 E->getLeftLoc(),
6744 move_arg(Args),
6745 E->getRightLoc());
6746 }
6747
6748 // Instance message: transform the receiver
6749 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6750 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006751 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006752 = getDerived().TransformExpr(E->getInstanceReceiver());
6753 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006754 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006755
6756 // If nothing changed, just retain the existing message send.
6757 if (!getDerived().AlwaysRebuild() &&
6758 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006759 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006760
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006761 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006762 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006763 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006764 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006765 E->getMethodDecl(),
6766 E->getLeftLoc(),
6767 move_arg(Args),
6768 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006769}
6770
Mike Stump11289f42009-09-09 15:08:12 +00006771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006772ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006773TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006774 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006775}
6776
Mike Stump11289f42009-09-09 15:08:12 +00006777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006779TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006780 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006781}
6782
Mike Stump11289f42009-09-09 15:08:12 +00006783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006785TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006786 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006787 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006788 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006789 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006790
6791 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006792
Douglas Gregord51d90d2010-04-26 20:11:03 +00006793 // If nothing changed, just retain the existing expression.
6794 if (!getDerived().AlwaysRebuild() &&
6795 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006796 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006797
John McCallb268a282010-08-23 23:25:46 +00006798 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006799 E->getLocation(),
6800 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006801}
6802
Mike Stump11289f42009-09-09 15:08:12 +00006803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006805TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006806 // 'super' and types never change. Property never changes. Just
6807 // retain the existing expression.
6808 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006809 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006810
Douglas Gregor9faee212010-04-26 20:47:02 +00006811 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006812 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006813 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006814 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006815
Douglas Gregor9faee212010-04-26 20:47:02 +00006816 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006817
Douglas Gregor9faee212010-04-26 20:47:02 +00006818 // If nothing changed, just retain the existing expression.
6819 if (!getDerived().AlwaysRebuild() &&
6820 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006821 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006822
John McCallb7bd14f2010-12-02 01:19:52 +00006823 if (E->isExplicitProperty())
6824 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6825 E->getExplicitProperty(),
6826 E->getLocation());
6827
6828 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6829 E->getType(),
6830 E->getImplicitPropertyGetter(),
6831 E->getImplicitPropertySetter(),
6832 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006833}
6834
Mike Stump11289f42009-09-09 15:08:12 +00006835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006837TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006838 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006839 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006840 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006842
Douglas Gregord51d90d2010-04-26 20:11:03 +00006843 // If nothing changed, just retain the existing expression.
6844 if (!getDerived().AlwaysRebuild() &&
6845 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006846 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006847
John McCallb268a282010-08-23 23:25:46 +00006848 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006849 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006850}
6851
Mike Stump11289f42009-09-09 15:08:12 +00006852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006854TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006855 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006856 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006857 SubExprs.reserve(E->getNumSubExprs());
6858 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6859 SubExprs, &ArgumentChanged))
6860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006861
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 if (!getDerived().AlwaysRebuild() &&
6863 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006864 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006865
Douglas Gregora16548e2009-08-11 05:31:07 +00006866 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6867 move_arg(SubExprs),
6868 E->getRParenLoc());
6869}
6870
Mike Stump11289f42009-09-09 15:08:12 +00006871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006873TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006874 SourceLocation CaretLoc(E->getExprLoc());
6875
6876 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6877 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6878 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6879 llvm::SmallVector<ParmVarDecl*, 4> Params;
6880 llvm::SmallVector<QualType, 4> ParamTypes;
6881
6882 // Parameter substitution.
Douglas Gregorf3010112011-01-07 16:43:16 +00006883 // FIXME: Variadic templates
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006884 const BlockDecl *BD = E->getBlockDecl();
6885 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6886 EN = BD->param_end(); P != EN; ++P) {
6887 ParmVarDecl *OldParm = (*P);
6888 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6889 QualType NewType = NewParm->getType();
6890 Params.push_back(NewParm);
6891 ParamTypes.push_back(NewParm->getType());
6892 }
6893
6894 const FunctionType *BExprFunctionType = E->getFunctionType();
6895 QualType BExprResultType = BExprFunctionType->getResultType();
6896 if (!BExprResultType.isNull()) {
6897 if (!BExprResultType->isDependentType())
6898 CurBlock->ReturnType = BExprResultType;
6899 else if (BExprResultType != SemaRef.Context.DependentTy)
6900 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6901 }
John McCall3882ace2011-01-05 12:14:39 +00006902
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006903 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6904 CurBlock->ReturnType,
6905 ParamTypes.data(),
6906 ParamTypes.size(),
6907 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006908 0,
6909 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006910 CurBlock->FunctionType = FunctionType;
John McCall3882ace2011-01-05 12:14:39 +00006911
6912 // Set the parameters on the block decl.
6913 if (!Params.empty())
6914 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6915
6916 // Transform the body
6917 StmtResult Body = getDerived().TransformStmt(E->getBody());
6918 if (Body.isInvalid())
6919 return ExprError();
6920
John McCallb268a282010-08-23 23:25:46 +00006921 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006922}
6923
Mike Stump11289f42009-09-09 15:08:12 +00006924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006926TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006927 NestedNameSpecifier *Qualifier = 0;
6928
6929 ValueDecl *ND
6930 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6931 E->getDecl()));
6932 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006933 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006934
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006935 if (!getDerived().AlwaysRebuild() &&
6936 ND == E->getDecl()) {
6937 // Mark it referenced in the new context regardless.
6938 // FIXME: this is a bit instantiation-specific.
6939 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6940
John McCallc3007a22010-10-26 07:05:15 +00006941 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006942 }
6943
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006944 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006945 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006946 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006947}
Mike Stump11289f42009-09-09 15:08:12 +00006948
Douglas Gregora16548e2009-08-11 05:31:07 +00006949//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006950// Type reconstruction
6951//===----------------------------------------------------------------------===//
6952
Mike Stump11289f42009-09-09 15:08:12 +00006953template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006954QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6955 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006956 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006957 getDerived().getBaseEntity());
6958}
6959
Mike Stump11289f42009-09-09 15:08:12 +00006960template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006961QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6962 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006963 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006964 getDerived().getBaseEntity());
6965}
6966
Mike Stump11289f42009-09-09 15:08:12 +00006967template<typename Derived>
6968QualType
John McCall70dd5f62009-10-30 00:06:24 +00006969TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6970 bool WrittenAsLValue,
6971 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006972 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006973 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006974}
6975
6976template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006977QualType
John McCall70dd5f62009-10-30 00:06:24 +00006978TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6979 QualType ClassType,
6980 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006981 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006982 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006983}
6984
6985template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006986QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006987TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6988 ArrayType::ArraySizeModifier SizeMod,
6989 const llvm::APInt *Size,
6990 Expr *SizeExpr,
6991 unsigned IndexTypeQuals,
6992 SourceRange BracketsRange) {
6993 if (SizeExpr || !Size)
6994 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6995 IndexTypeQuals, BracketsRange,
6996 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006997
6998 QualType Types[] = {
6999 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7000 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7001 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007002 };
7003 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7004 QualType SizeType;
7005 for (unsigned I = 0; I != NumTypes; ++I)
7006 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7007 SizeType = Types[I];
7008 break;
7009 }
Mike Stump11289f42009-09-09 15:08:12 +00007010
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007011 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7012 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007013 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007014 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007015 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007016}
Mike Stump11289f42009-09-09 15:08:12 +00007017
Douglas Gregord6ff3322009-08-04 16:50:30 +00007018template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007019QualType
7020TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007021 ArrayType::ArraySizeModifier SizeMod,
7022 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007023 unsigned IndexTypeQuals,
7024 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007025 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007026 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007027}
7028
7029template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007030QualType
Mike Stump11289f42009-09-09 15:08:12 +00007031TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007032 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007033 unsigned IndexTypeQuals,
7034 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007035 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007036 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007037}
Mike Stump11289f42009-09-09 15:08:12 +00007038
Douglas Gregord6ff3322009-08-04 16:50:30 +00007039template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007040QualType
7041TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007042 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007043 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007044 unsigned IndexTypeQuals,
7045 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007046 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007047 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007048 IndexTypeQuals, BracketsRange);
7049}
7050
7051template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007052QualType
7053TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007054 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007055 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007056 unsigned IndexTypeQuals,
7057 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007058 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007059 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007060 IndexTypeQuals, BracketsRange);
7061}
7062
7063template<typename Derived>
7064QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007065 unsigned NumElements,
7066 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007067 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007068 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007069}
Mike Stump11289f42009-09-09 15:08:12 +00007070
Douglas Gregord6ff3322009-08-04 16:50:30 +00007071template<typename Derived>
7072QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7073 unsigned NumElements,
7074 SourceLocation AttributeLoc) {
7075 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7076 NumElements, true);
7077 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007078 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7079 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007080 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007081}
Mike Stump11289f42009-09-09 15:08:12 +00007082
Douglas Gregord6ff3322009-08-04 16:50:30 +00007083template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007084QualType
7085TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007086 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007087 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007088 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007089}
Mike Stump11289f42009-09-09 15:08:12 +00007090
Douglas Gregord6ff3322009-08-04 16:50:30 +00007091template<typename Derived>
7092QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007093 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007094 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007095 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007096 unsigned Quals,
7097 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007098 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007099 Quals,
7100 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007101 getDerived().getBaseEntity(),
7102 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007103}
Mike Stump11289f42009-09-09 15:08:12 +00007104
Douglas Gregord6ff3322009-08-04 16:50:30 +00007105template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007106QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7107 return SemaRef.Context.getFunctionNoProtoType(T);
7108}
7109
7110template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007111QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7112 assert(D && "no decl found");
7113 if (D->isInvalidDecl()) return QualType();
7114
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007115 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007116 TypeDecl *Ty;
7117 if (isa<UsingDecl>(D)) {
7118 UsingDecl *Using = cast<UsingDecl>(D);
7119 assert(Using->isTypeName() &&
7120 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7121
7122 // A valid resolved using typename decl points to exactly one type decl.
7123 assert(++Using->shadow_begin() == Using->shadow_end());
7124 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007125
John McCallb96ec562009-12-04 22:46:56 +00007126 } else {
7127 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7128 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7129 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7130 }
7131
7132 return SemaRef.Context.getTypeDeclType(Ty);
7133}
7134
7135template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007136QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7137 SourceLocation Loc) {
7138 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007139}
7140
7141template<typename Derived>
7142QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7143 return SemaRef.Context.getTypeOfType(Underlying);
7144}
7145
7146template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007147QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7148 SourceLocation Loc) {
7149 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007150}
7151
7152template<typename Derived>
7153QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007154 TemplateName Template,
7155 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007156 const TemplateArgumentListInfo &TemplateArgs) {
7157 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007158}
Mike Stump11289f42009-09-09 15:08:12 +00007159
Douglas Gregor1135c352009-08-06 05:28:30 +00007160template<typename Derived>
7161NestedNameSpecifier *
7162TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7163 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007164 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007165 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007166 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007167 CXXScopeSpec SS;
7168 // FIXME: The source location information is all wrong.
7169 SS.setRange(Range);
7170 SS.setScopeRep(Prefix);
7171 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007172 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007173 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007174 ObjectType,
7175 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007176 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007177}
7178
7179template<typename Derived>
7180NestedNameSpecifier *
7181TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7182 SourceRange Range,
7183 NamespaceDecl *NS) {
7184 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7185}
7186
7187template<typename Derived>
7188NestedNameSpecifier *
7189TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7190 SourceRange Range,
7191 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007192 QualType T) {
7193 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007194 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007195 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007196 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7197 T.getTypePtr());
7198 }
Mike Stump11289f42009-09-09 15:08:12 +00007199
Douglas Gregor1135c352009-08-06 05:28:30 +00007200 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7201 return 0;
7202}
Mike Stump11289f42009-09-09 15:08:12 +00007203
Douglas Gregor71dc5092009-08-06 06:41:21 +00007204template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007205TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007206TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7207 bool TemplateKW,
7208 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007209 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007210 Template);
7211}
7212
7213template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007214TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007215TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007216 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007217 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007218 QualType ObjectType,
7219 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007220 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007221 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007222 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007223 UnqualifiedId Name;
7224 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007225 Sema::TemplateTy Template;
7226 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7227 /*FIXME:*/getDerived().getBaseLocation(),
7228 SS,
7229 Name,
John McCallba7bf592010-08-24 05:47:05 +00007230 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007231 /*EnteringContext=*/false,
7232 Template);
John McCall31f82722010-11-12 08:19:04 +00007233 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007234}
Mike Stump11289f42009-09-09 15:08:12 +00007235
Douglas Gregora16548e2009-08-11 05:31:07 +00007236template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007237TemplateName
7238TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7239 OverloadedOperatorKind Operator,
7240 QualType ObjectType) {
7241 CXXScopeSpec SS;
7242 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7243 SS.setScopeRep(Qualifier);
7244 UnqualifiedId Name;
7245 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7246 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7247 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007248 Sema::TemplateTy Template;
7249 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007250 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007251 SS,
7252 Name,
John McCallba7bf592010-08-24 05:47:05 +00007253 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007254 /*EnteringContext=*/false,
7255 Template);
7256 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007257}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007258
Douglas Gregor71395fa2009-11-04 00:56:37 +00007259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007260ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007261TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7262 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007263 Expr *OrigCallee,
7264 Expr *First,
7265 Expr *Second) {
7266 Expr *Callee = OrigCallee->IgnoreParenCasts();
7267 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007268
Douglas Gregora16548e2009-08-11 05:31:07 +00007269 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007270 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007271 if (!First->getType()->isOverloadableType() &&
7272 !Second->getType()->isOverloadableType())
7273 return getSema().CreateBuiltinArraySubscriptExpr(First,
7274 Callee->getLocStart(),
7275 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007276 } else if (Op == OO_Arrow) {
7277 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007278 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7279 } else if (Second == 0 || isPostIncDec) {
7280 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007281 // The argument is not of overloadable type, so try to create a
7282 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007283 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007284 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007285
John McCallb268a282010-08-23 23:25:46 +00007286 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007287 }
7288 } else {
John McCallb268a282010-08-23 23:25:46 +00007289 if (!First->getType()->isOverloadableType() &&
7290 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007291 // Neither of the arguments is an overloadable type, so try to
7292 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007293 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007294 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007295 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007296 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007298
Douglas Gregora16548e2009-08-11 05:31:07 +00007299 return move(Result);
7300 }
7301 }
Mike Stump11289f42009-09-09 15:08:12 +00007302
7303 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007304 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007305 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007306
John McCallb268a282010-08-23 23:25:46 +00007307 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007308 assert(ULE->requiresADL());
7309
7310 // FIXME: Do we have to check
7311 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007312 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007313 } else {
John McCallb268a282010-08-23 23:25:46 +00007314 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007315 }
Mike Stump11289f42009-09-09 15:08:12 +00007316
Douglas Gregora16548e2009-08-11 05:31:07 +00007317 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007318 Expr *Args[2] = { First, Second };
7319 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007320
Douglas Gregora16548e2009-08-11 05:31:07 +00007321 // Create the overloaded operator invocation for unary operators.
7322 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007323 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007324 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007325 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007326 }
Mike Stump11289f42009-09-09 15:08:12 +00007327
Sebastian Redladba46e2009-10-29 20:17:01 +00007328 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007329 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007330 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007331 First,
7332 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007333
Douglas Gregora16548e2009-08-11 05:31:07 +00007334 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007335 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007336 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007337 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7338 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007340
Mike Stump11289f42009-09-09 15:08:12 +00007341 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007342}
Mike Stump11289f42009-09-09 15:08:12 +00007343
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007345ExprResult
John McCallb268a282010-08-23 23:25:46 +00007346TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007347 SourceLocation OperatorLoc,
7348 bool isArrow,
7349 NestedNameSpecifier *Qualifier,
7350 SourceRange QualifierRange,
7351 TypeSourceInfo *ScopeType,
7352 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007353 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007354 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007355 CXXScopeSpec SS;
7356 if (Qualifier) {
7357 SS.setRange(QualifierRange);
7358 SS.setScopeRep(Qualifier);
7359 }
7360
John McCallb268a282010-08-23 23:25:46 +00007361 QualType BaseType = Base->getType();
7362 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007363 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007364 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007365 !BaseType->getAs<PointerType>()->getPointeeType()
7366 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007367 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007368 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007369 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007370 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007371 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007372 /*FIXME?*/true);
7373 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007374
Douglas Gregor678f90d2010-02-25 01:56:36 +00007375 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007376 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7377 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7378 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7379 NameInfo.setNamedTypeInfo(DestroyedType);
7380
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007381 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007382
John McCallb268a282010-08-23 23:25:46 +00007383 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007384 OperatorLoc, isArrow,
7385 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007386 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007387 /*TemplateArgs*/ 0);
7388}
7389
Douglas Gregord6ff3322009-08-04 16:50:30 +00007390} // end namespace clang
7391
7392#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H