blob: 65a7580436537017b3fbaa7aacecb9dc853e1d22 [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 Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000028#include "clang/Sema/Ownership.h"
29#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000030#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000031#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000032#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000036using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000037
Douglas Gregord6ff3322009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump11289f42009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump11289f42009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000093
94public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000097
Douglas Gregord6ff3322009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000104 }
105
John McCalldadc5752010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000119
Douglas Gregord6ff3322009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump11289f42009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregora16548e2009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000141
Douglas Gregora16548e2009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregora16548e2009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Douglas Gregora16548e2009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump11289f42009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregord196a582009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000182
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCall550e0c22009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000192 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000193
John McCall550e0c22009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 ///
John McCall550e0c22009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000203
204 /// \brief Transform the given type-with-location into a new
205 /// type, collecting location information in the given builder
206 /// as necessary.
207 ///
John McCall31f82722010-11-12 08:19:04 +0000208 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000209
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000210 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000211 ///
Mike Stump11289f42009-09-09 15:08:12 +0000212 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000213 /// appropriate TransformXXXStmt function to transform a specific kind of
214 /// statement or the TransformExpr() function to transform an expression.
215 /// Subclasses may override this function to transform statements using some
216 /// other mechanism.
217 ///
218 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000219 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000220
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000221 /// \brief Transform the given expression.
222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 /// By default, this routine transforms an expression by delegating to the
224 /// appropriate TransformXXXExpr function to build a new expression.
225 /// Subclasses may override this function to transform expressions using some
226 /// other mechanism.
227 ///
228 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000229 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000230
Douglas Gregord6ff3322009-08-04 16:50:30 +0000231 /// \brief Transform the given declaration, which is referenced from a type
232 /// or expression.
233 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000234 /// By default, acts as the identity function on declarations. Subclasses
235 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000236 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000237
238 /// \brief Transform the definition of the given declaration.
239 ///
Mike Stump11289f42009-09-09 15:08:12 +0000240 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000241 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000242 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
243 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000244 }
Mike Stump11289f42009-09-09 15:08:12 +0000245
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000249 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000257 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000258
Douglas Gregord6ff3322009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregorf816bd72009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000275 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000276 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000277
Douglas Gregord6ff3322009-08-04 16:50:30 +0000278 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000279 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000280 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000281 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000282 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000283 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000284 QualType ObjectType = QualType(),
285 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000286
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump11289f42009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
Douglas Gregor62e06f22010-12-20 17:31:10 +0000298 /// \brief Transform the given set of template arguments.
299 ///
300 /// By default, this operation transforms all of the template arguments
301 /// in the input set using \c TransformTemplateArgument(), and appends
302 /// the transformed arguments to the output list.
303 ///
304 /// \param Inputs The set of template arguments to be transformed.
305 ///
306 /// \param NumInputs The number of template arguments in \p Inputs.
307 ///
308 /// \param Outputs The set of transformed template arguments output by this
309 /// routine.
310 ///
311 /// Returns true if an error occurred.
312 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
313 unsigned NumInputs,
314 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000315
316 /// \brief Transform the given set of template arguments.
317 ///
318 /// By default, this operation transforms all of the template arguments
319 /// in the input set using \c TransformTemplateArgument(), and appends
320 /// the transformed arguments to the output list.
321 ///
322 /// \param Inputs The set of template arguments to be transformed. The
323 /// \c getArgLoc() function will be invoked on each argument indexed, while
324 /// the number of arguments is determined via \c getNumArgs().
325 ///
326 /// \param Outputs The set of transformed template arguments output by this
327 /// routine.
328 ///
329 /// Returns true if an error occurred.
330 template<typename InputsType>
331 bool TransformTemplateArgumentsFromArgLoc(const InputsType &Inputs,
332 TemplateArgumentListInfo &Outputs);
333
John McCall0ad16662009-10-29 08:12:44 +0000334 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
335 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
336 TemplateArgumentLoc &ArgLoc);
337
John McCallbcd03502009-12-07 02:54:59 +0000338 /// \brief Fakes up a TypeSourceInfo for a type.
339 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
340 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000341 getDerived().getBaseLocation());
342 }
Mike Stump11289f42009-09-09 15:08:12 +0000343
John McCall550e0c22009-10-21 00:40:46 +0000344#define ABSTRACT_TYPELOC(CLASS, PARENT)
345#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000346 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000347#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000348
John McCall31f82722010-11-12 08:19:04 +0000349 QualType
350 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
351 TemplateSpecializationTypeLoc TL,
352 TemplateName Template);
353
354 QualType
355 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
356 DependentTemplateSpecializationTypeLoc TL,
357 NestedNameSpecifier *Prefix);
358
John McCall58f10c32010-03-11 09:03:00 +0000359 /// \brief Transforms the parameters of a function type into the
360 /// given vectors.
361 ///
362 /// The result vectors should be kept in sync; null entries in the
363 /// variables vector are acceptable.
364 ///
365 /// Return true on error.
366 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
367 llvm::SmallVectorImpl<QualType> &PTypes,
368 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
369
370 /// \brief Transforms a single function-type parameter. Return null
371 /// on error.
372 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
373
John McCall31f82722010-11-12 08:19:04 +0000374 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000375
John McCalldadc5752010-08-24 06:29:42 +0000376 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
377 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000378
Douglas Gregorebe10102009-08-20 07:17:43 +0000379#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000380 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000381#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000382 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000383#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000384#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000385
Douglas Gregord6ff3322009-08-04 16:50:30 +0000386 /// \brief Build a new pointer type given its pointee type.
387 ///
388 /// By default, performs semantic analysis when building the pointer type.
389 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000390 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000391
392 /// \brief Build a new block pointer type given its pointee type.
393 ///
Mike Stump11289f42009-09-09 15:08:12 +0000394 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000395 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000396 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397
John McCall70dd5f62009-10-30 00:06:24 +0000398 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 ///
John McCall70dd5f62009-10-30 00:06:24 +0000400 /// By default, performs semantic analysis when building the
401 /// reference type. Subclasses may override this routine to provide
402 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000403 ///
John McCall70dd5f62009-10-30 00:06:24 +0000404 /// \param LValue whether the type was written with an lvalue sigil
405 /// or an rvalue sigil.
406 QualType RebuildReferenceType(QualType ReferentType,
407 bool LValue,
408 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000409
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 /// \brief Build a new member pointer type given the pointee type and the
411 /// class type it refers into.
412 ///
413 /// By default, performs semantic analysis when building the member pointer
414 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000415 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
416 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000417
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// \brief Build a new array type given the element type, size
419 /// modifier, size of the array (if known), size expression, and index type
420 /// qualifiers.
421 ///
422 /// By default, performs semantic analysis when building the array type.
423 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000424 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 QualType RebuildArrayType(QualType ElementType,
426 ArrayType::ArraySizeModifier SizeMod,
427 const llvm::APInt *Size,
428 Expr *SizeExpr,
429 unsigned IndexTypeQuals,
430 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000431
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432 /// \brief Build a new constant array type given the element type, size
433 /// modifier, (known) size of the array, and index type qualifiers.
434 ///
435 /// By default, performs semantic analysis when building the array type.
436 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000437 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000438 ArrayType::ArraySizeModifier SizeMod,
439 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000440 unsigned IndexTypeQuals,
441 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000442
Douglas Gregord6ff3322009-08-04 16:50:30 +0000443 /// \brief Build a new incomplete array type given the element type, size
444 /// modifier, and index type qualifiers.
445 ///
446 /// By default, performs semantic analysis when building the array type.
447 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000448 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000449 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000450 unsigned IndexTypeQuals,
451 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000452
Mike Stump11289f42009-09-09 15:08:12 +0000453 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000454 /// size modifier, size expression, and index type qualifiers.
455 ///
456 /// By default, performs semantic analysis when building the array type.
457 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000458 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000459 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000460 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000461 unsigned IndexTypeQuals,
462 SourceRange BracketsRange);
463
Mike Stump11289f42009-09-09 15:08:12 +0000464 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000465 /// size modifier, size expression, and index type qualifiers.
466 ///
467 /// By default, performs semantic analysis when building the array type.
468 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000471 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 unsigned IndexTypeQuals,
473 SourceRange BracketsRange);
474
475 /// \brief Build a new vector type given the element type and
476 /// number of elements.
477 ///
478 /// By default, performs semantic analysis when building the vector type.
479 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000480 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000481 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000482
Douglas Gregord6ff3322009-08-04 16:50:30 +0000483 /// \brief Build a new extended vector type given the element type and
484 /// number of elements.
485 ///
486 /// By default, performs semantic analysis when building the vector type.
487 /// Subclasses may override this routine to provide different behavior.
488 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
489 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000490
491 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492 /// given the element type and number of elements.
493 ///
494 /// By default, performs semantic analysis when building the vector type.
495 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000496 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000497 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000499
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500 /// \brief Build a new function type.
501 ///
502 /// By default, performs semantic analysis when building the function type.
503 /// Subclasses may override this routine to provide different behavior.
504 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000505 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000507 bool Variadic, unsigned Quals,
508 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000509
John McCall550e0c22009-10-21 00:40:46 +0000510 /// \brief Build a new unprototyped function type.
511 QualType RebuildFunctionNoProtoType(QualType ResultType);
512
John McCallb96ec562009-12-04 22:46:56 +0000513 /// \brief Rebuild an unresolved typename type, given the decl that
514 /// the UnresolvedUsingTypenameDecl was transformed to.
515 QualType RebuildUnresolvedUsingType(Decl *D);
516
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// \brief Build a new typedef type.
518 QualType RebuildTypedefType(TypedefDecl *Typedef) {
519 return SemaRef.Context.getTypeDeclType(Typedef);
520 }
521
522 /// \brief Build a new class/struct/union type.
523 QualType RebuildRecordType(RecordDecl *Record) {
524 return SemaRef.Context.getTypeDeclType(Record);
525 }
526
527 /// \brief Build a new Enum type.
528 QualType RebuildEnumType(EnumDecl *Enum) {
529 return SemaRef.Context.getTypeDeclType(Enum);
530 }
John McCallfcc33b02009-09-05 00:15:47 +0000531
Mike Stump11289f42009-09-09 15:08:12 +0000532 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533 ///
534 /// By default, performs semantic analysis when building the typeof type.
535 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000536 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537
Mike Stump11289f42009-09-09 15:08:12 +0000538 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000539 ///
540 /// By default, builds a new TypeOfType with the given underlying type.
541 QualType RebuildTypeOfType(QualType Underlying);
542
Mike Stump11289f42009-09-09 15:08:12 +0000543 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544 ///
545 /// By default, performs semantic analysis when building the decltype type.
546 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000547 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000548
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 /// \brief Build a new template specialization type.
550 ///
551 /// By default, performs semantic analysis when building the template
552 /// specialization type. Subclasses may override this routine to provide
553 /// different behavior.
554 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000555 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000556 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000557
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000558 /// \brief Build a new parenthesized type.
559 ///
560 /// By default, builds a new ParenType type from the inner type.
561 /// Subclasses may override this routine to provide different behavior.
562 QualType RebuildParenType(QualType InnerType) {
563 return SemaRef.Context.getParenType(InnerType);
564 }
565
Douglas Gregord6ff3322009-08-04 16:50:30 +0000566 /// \brief Build a new qualified name type.
567 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000568 /// By default, builds a new ElaboratedType type from the keyword,
569 /// the nested-name-specifier and the named type.
570 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000571 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
572 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000573 NestedNameSpecifier *NNS, QualType Named) {
574 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000575 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000576
577 /// \brief Build a new typename type that refers to a template-id.
578 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000579 /// By default, builds a new DependentNameType type from the
580 /// nested-name-specifier and the given type. Subclasses may override
581 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000582 QualType RebuildDependentTemplateSpecializationType(
583 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000584 NestedNameSpecifier *Qualifier,
585 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000586 const IdentifierInfo *Name,
587 SourceLocation NameLoc,
588 const TemplateArgumentListInfo &Args) {
589 // Rebuild the template name.
590 // TODO: avoid TemplateName abstraction
591 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000592 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000593 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000594
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000595 if (InstName.isNull())
596 return QualType();
597
John McCallc392f372010-06-11 00:33:02 +0000598 // If it's still dependent, make a dependent specialization.
599 if (InstName.getAsDependentTemplateName())
600 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000601 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000602
603 // Otherwise, make an elaborated type wrapping a non-dependent
604 // specialization.
605 QualType T =
606 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
607 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000608
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000609 // NOTE: NNS is already recorded in template specialization type T.
610 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000611 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000612
613 /// \brief Build a new typename type that refers to an identifier.
614 ///
615 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000616 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000617 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000618 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000619 NestedNameSpecifier *NNS,
620 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000621 SourceLocation KeywordLoc,
622 SourceRange NNSRange,
623 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000624 CXXScopeSpec SS;
625 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000626 SS.setRange(NNSRange);
627
Douglas Gregore677daf2010-03-31 22:19:08 +0000628 if (NNS->isDependent()) {
629 // If the name is still dependent, just build a new dependent name type.
630 if (!SemaRef.computeDeclContext(SS))
631 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
632 }
633
Abramo Bagnara6150c882010-05-11 21:36:43 +0000634 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000635 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
636 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000637
638 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
639
Abramo Bagnarad7548482010-05-19 21:37:53 +0000640 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000641 // into a non-dependent elaborated-type-specifier. Find the tag we're
642 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000643 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000644 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
645 if (!DC)
646 return QualType();
647
John McCallbf8c5192010-05-27 06:40:31 +0000648 if (SemaRef.RequireCompleteDeclContext(SS, DC))
649 return QualType();
650
Douglas Gregore677daf2010-03-31 22:19:08 +0000651 TagDecl *Tag = 0;
652 SemaRef.LookupQualifiedName(Result, DC);
653 switch (Result.getResultKind()) {
654 case LookupResult::NotFound:
655 case LookupResult::NotFoundInCurrentInstantiation:
656 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000657
Douglas Gregore677daf2010-03-31 22:19:08 +0000658 case LookupResult::Found:
659 Tag = Result.getAsSingle<TagDecl>();
660 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000661
Douglas Gregore677daf2010-03-31 22:19:08 +0000662 case LookupResult::FoundOverloaded:
663 case LookupResult::FoundUnresolvedValue:
664 llvm_unreachable("Tag lookup cannot find non-tags");
665 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000666
Douglas Gregore677daf2010-03-31 22:19:08 +0000667 case LookupResult::Ambiguous:
668 // Let the LookupResult structure handle ambiguities.
669 return QualType();
670 }
671
672 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000673 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000674 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000675 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000676 return QualType();
677 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000678
Abramo Bagnarad7548482010-05-19 21:37:53 +0000679 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
680 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000681 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
682 return QualType();
683 }
684
685 // Build the elaborated-type-specifier type.
686 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000687 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000688 }
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregor1135c352009-08-06 05:28:30 +0000690 /// \brief Build a new nested-name-specifier given the prefix and an
691 /// identifier that names the next step in the nested-name-specifier.
692 ///
693 /// By default, performs semantic analysis when building the new
694 /// nested-name-specifier. Subclasses may override this routine to provide
695 /// different behavior.
696 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
697 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000698 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000699 QualType ObjectType,
700 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000701
702 /// \brief Build a new nested-name-specifier given the prefix and the
703 /// namespace named in the next step in the nested-name-specifier.
704 ///
705 /// By default, performs semantic analysis when building the new
706 /// nested-name-specifier. Subclasses may override this routine to provide
707 /// different behavior.
708 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
709 SourceRange Range,
710 NamespaceDecl *NS);
711
712 /// \brief Build a new nested-name-specifier given the prefix and the
713 /// type named in the next step in the nested-name-specifier.
714 ///
715 /// By default, performs semantic analysis when building the new
716 /// nested-name-specifier. Subclasses may override this routine to provide
717 /// different behavior.
718 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
719 SourceRange Range,
720 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000721 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000722
723 /// \brief Build a new template name given a nested name specifier, a flag
724 /// indicating whether the "template" keyword was provided, and the template
725 /// that the template name refers to.
726 ///
727 /// By default, builds the new template name directly. Subclasses may override
728 /// this routine to provide different behavior.
729 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
730 bool TemplateKW,
731 TemplateDecl *Template);
732
Douglas Gregor71dc5092009-08-06 06:41:21 +0000733 /// \brief Build a new template name given a nested name specifier and the
734 /// name that is referred to as a template.
735 ///
736 /// By default, performs semantic analysis to determine whether the name can
737 /// be resolved to a specific template, then builds the appropriate kind of
738 /// template name. Subclasses may override this routine to provide different
739 /// behavior.
740 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000741 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000742 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000743 QualType ObjectType,
744 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000745
Douglas Gregor71395fa2009-11-04 00:56:37 +0000746 /// \brief Build a new template name given a nested name specifier and the
747 /// overloaded operator name that is referred to as a template.
748 ///
749 /// By default, performs semantic analysis to determine whether the name can
750 /// be resolved to a specific template, then builds the appropriate kind of
751 /// template name. Subclasses may override this routine to provide different
752 /// behavior.
753 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
754 OverloadedOperatorKind Operator,
755 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000756
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 /// \brief Build a new compound statement.
758 ///
759 /// By default, performs semantic analysis to build the new statement.
760 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000761 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 MultiStmtArg Statements,
763 SourceLocation RBraceLoc,
764 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000765 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 IsStmtExpr);
767 }
768
769 /// \brief Build a new case statement.
770 ///
771 /// By default, performs semantic analysis to build the new statement.
772 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000773 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000774 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000776 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000777 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000778 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000779 ColonLoc);
780 }
Mike Stump11289f42009-09-09 15:08:12 +0000781
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 /// \brief Attach the body to a new case statement.
783 ///
784 /// By default, performs semantic analysis to build the new statement.
785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000786 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000787 getSema().ActOnCaseStmtBody(S, Body);
788 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 }
Mike Stump11289f42009-09-09 15:08:12 +0000790
Douglas Gregorebe10102009-08-20 07:17:43 +0000791 /// \brief Build a new default statement.
792 ///
793 /// By default, performs semantic analysis to build the new statement.
794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000795 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000796 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000797 Stmt *SubStmt) {
798 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000799 /*CurScope=*/0);
800 }
Mike Stump11289f42009-09-09 15:08:12 +0000801
Douglas Gregorebe10102009-08-20 07:17:43 +0000802 /// \brief Build a new label statement.
803 ///
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000806 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 IdentifierInfo *Id,
808 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000809 Stmt *SubStmt, bool HasUnusedAttr) {
810 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
811 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000812 }
Mike Stump11289f42009-09-09 15:08:12 +0000813
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 /// \brief Build a new "if" statement.
815 ///
816 /// By default, performs semantic analysis to build the new statement.
817 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000818 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000819 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000820 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000821 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000822 }
Mike Stump11289f42009-09-09 15:08:12 +0000823
Douglas Gregorebe10102009-08-20 07:17:43 +0000824 /// \brief Start building a new switch statement.
825 ///
826 /// By default, performs semantic analysis to build the new statement.
827 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000828 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000829 Expr *Cond, VarDecl *CondVar) {
830 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000831 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 }
Mike Stump11289f42009-09-09 15:08:12 +0000833
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 /// \brief Attach the body to the switch statement.
835 ///
836 /// By default, performs semantic analysis to build the new statement.
837 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000838 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000839 Stmt *Switch, Stmt *Body) {
840 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000841 }
842
843 /// \brief Build a new while statement.
844 ///
845 /// By default, performs semantic analysis to build the new statement.
846 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000847 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000848 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000849 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000850 Stmt *Body) {
851 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 }
Mike Stump11289f42009-09-09 15:08:12 +0000853
Douglas Gregorebe10102009-08-20 07:17:43 +0000854 /// \brief Build a new do-while statement.
855 ///
856 /// By default, performs semantic analysis to build the new statement.
857 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000858 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000859 SourceLocation WhileLoc,
860 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000861 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000863 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
864 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 }
866
867 /// \brief Build a new for statement.
868 ///
869 /// By default, performs semantic analysis to build the new statement.
870 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000871 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000872 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000873 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000874 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000875 SourceLocation RParenLoc, Stmt *Body) {
876 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000877 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000878 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000879 }
Mike Stump11289f42009-09-09 15:08:12 +0000880
Douglas Gregorebe10102009-08-20 07:17:43 +0000881 /// \brief Build a new goto statement.
882 ///
883 /// By default, performs semantic analysis to build the new statement.
884 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000885 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000886 SourceLocation LabelLoc,
887 LabelStmt *Label) {
888 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
889 }
890
891 /// \brief Build a new indirect goto statement.
892 ///
893 /// By default, performs semantic analysis to build the new statement.
894 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000895 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000896 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000897 Expr *Target) {
898 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000899 }
Mike Stump11289f42009-09-09 15:08:12 +0000900
Douglas Gregorebe10102009-08-20 07:17:43 +0000901 /// \brief Build a new return statement.
902 ///
903 /// By default, performs semantic analysis to build the new statement.
904 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000905 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000906 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000907
John McCallb268a282010-08-23 23:25:46 +0000908 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000909 }
Mike Stump11289f42009-09-09 15:08:12 +0000910
Douglas Gregorebe10102009-08-20 07:17:43 +0000911 /// \brief Build a new declaration statement.
912 ///
913 /// By default, performs semantic analysis to build the new statement.
914 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000915 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000916 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000917 SourceLocation EndLoc) {
918 return getSema().Owned(
919 new (getSema().Context) DeclStmt(
920 DeclGroupRef::Create(getSema().Context,
921 Decls, NumDecls),
922 StartLoc, EndLoc));
923 }
Mike Stump11289f42009-09-09 15:08:12 +0000924
Anders Carlssonaaeef072010-01-24 05:50:09 +0000925 /// \brief Build a new inline asm 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 RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000930 bool IsSimple,
931 bool IsVolatile,
932 unsigned NumOutputs,
933 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000934 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000935 MultiExprArg Constraints,
936 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000937 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000938 MultiExprArg Clobbers,
939 SourceLocation RParenLoc,
940 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000941 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000942 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000943 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000944 RParenLoc, MSAsm);
945 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000946
947 /// \brief Build a new Objective-C @try statement.
948 ///
949 /// By default, performs semantic analysis to build the new statement.
950 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000951 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000952 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000953 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000954 Stmt *Finally) {
955 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
956 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000957 }
958
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000959 /// \brief Rebuild an Objective-C exception declaration.
960 ///
961 /// By default, performs semantic analysis to build the new declaration.
962 /// Subclasses may override this routine to provide different behavior.
963 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
964 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000965 return getSema().BuildObjCExceptionDecl(TInfo, T,
966 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000967 ExceptionDecl->getLocation());
968 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000969
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000970 /// \brief Build a new Objective-C @catch statement.
971 ///
972 /// By default, performs semantic analysis to build the new statement.
973 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000974 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000975 SourceLocation RParenLoc,
976 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000977 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000978 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000979 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000980 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000981
Douglas Gregor306de2f2010-04-22 23:59:56 +0000982 /// \brief Build a new Objective-C @finally statement.
983 ///
984 /// By default, performs semantic analysis to build the new statement.
985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000986 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000987 Stmt *Body) {
988 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000989 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000990
Douglas Gregor6148de72010-04-22 22:01:21 +0000991 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000995 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000996 Expr *Operand) {
997 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000998 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000999
Douglas Gregor6148de72010-04-22 22:01:21 +00001000 /// \brief Build a new Objective-C @synchronized statement.
1001 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001004 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001005 Expr *Object,
1006 Stmt *Body) {
1007 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1008 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001009 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001010
1011 /// \brief Build a new Objective-C fast enumeration statement.
1012 ///
1013 /// By default, performs semantic analysis to build the new statement.
1014 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001015 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001016 SourceLocation LParenLoc,
1017 Stmt *Element,
1018 Expr *Collection,
1019 SourceLocation RParenLoc,
1020 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001021 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001022 Element,
1023 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001024 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001025 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001026 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001027
Douglas Gregorebe10102009-08-20 07:17:43 +00001028 /// \brief Build a new C++ exception declaration.
1029 ///
1030 /// By default, performs semantic analysis to build the new decaration.
1031 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001032 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001033 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001034 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001035 SourceLocation Loc) {
1036 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001037 }
1038
1039 /// \brief Build a new C++ catch statement.
1040 ///
1041 /// By default, performs semantic analysis to build the new statement.
1042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001043 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001044 VarDecl *ExceptionDecl,
1045 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001046 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1047 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001048 }
Mike Stump11289f42009-09-09 15:08:12 +00001049
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 /// \brief Build a new C++ try statement.
1051 ///
1052 /// By default, performs semantic analysis to build the new statement.
1053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001054 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001055 Stmt *TryBlock,
1056 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001057 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001058 }
Mike Stump11289f42009-09-09 15:08:12 +00001059
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 /// \brief Build a new expression that references a declaration.
1061 ///
1062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001064 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001065 LookupResult &R,
1066 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001067 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1068 }
1069
1070
1071 /// \brief Build a new expression that references a declaration.
1072 ///
1073 /// By default, performs semantic analysis to build the new expression.
1074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001075 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001076 SourceRange QualifierRange,
1077 ValueDecl *VD,
1078 const DeclarationNameInfo &NameInfo,
1079 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001080 CXXScopeSpec SS;
1081 SS.setScopeRep(Qualifier);
1082 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001083
1084 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001085
1086 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 }
Mike Stump11289f42009-09-09 15:08:12 +00001088
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001090 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 /// By default, performs semantic analysis to build the new expression.
1092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001093 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001095 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 }
1097
Douglas Gregorad8a3362009-09-04 17:36:40 +00001098 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001099 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001102 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001103 SourceLocation OperatorLoc,
1104 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001105 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001106 SourceRange QualifierRange,
1107 TypeSourceInfo *ScopeType,
1108 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001109 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001110 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001111
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001113 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001114 /// By default, performs semantic analysis to build the new expression.
1115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001116 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001117 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001118 Expr *SubExpr) {
1119 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 }
Mike Stump11289f42009-09-09 15:08:12 +00001121
Douglas Gregor882211c2010-04-28 22:16:22 +00001122 /// \brief Build a new builtin offsetof expression.
1123 ///
1124 /// By default, performs semantic analysis to build the new expression.
1125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001126 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001127 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001128 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001129 unsigned NumComponents,
1130 SourceLocation RParenLoc) {
1131 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1132 NumComponents, RParenLoc);
1133 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001134
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001139 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001140 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001141 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001142 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001143 }
1144
Mike Stump11289f42009-09-09 15:08:12 +00001145 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001147 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001148 /// By default, performs semantic analysis to build the new expression.
1149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001150 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001151 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001152 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001153 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001154 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001155 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001156
Douglas Gregora16548e2009-08-11 05:31:07 +00001157 return move(Result);
1158 }
Mike Stump11289f42009-09-09 15:08:12 +00001159
Douglas Gregora16548e2009-08-11 05:31:07 +00001160 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001161 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001162 /// By default, performs semantic analysis to build the new expression.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001165 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001166 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001167 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001168 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1169 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 RBracketLoc);
1171 }
1172
1173 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001174 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001175 /// By default, performs semantic analysis to build the new expression.
1176 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001177 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001178 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001179 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001180 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001181 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001182 }
1183
1184 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001185 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001188 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001189 bool isArrow,
1190 NestedNameSpecifier *Qualifier,
1191 SourceRange QualifierRange,
1192 const DeclarationNameInfo &MemberNameInfo,
1193 ValueDecl *Member,
1194 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001195 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001196 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001197 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001198 // We have a reference to an unnamed field. This is always the
1199 // base of an anonymous struct/union member access, i.e. the
1200 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001201 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001202 assert(Member->getType()->isRecordType() &&
1203 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001204
John McCallb268a282010-08-23 23:25:46 +00001205 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001206 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001207 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001208
John McCall7decc9e2010-11-18 06:31:45 +00001209 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001210 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001211 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001212 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001213 cast<FieldDecl>(Member)->getType(),
1214 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001215 return getSema().Owned(ME);
1216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001218 CXXScopeSpec SS;
1219 if (Qualifier) {
1220 SS.setRange(QualifierRange);
1221 SS.setScopeRep(Qualifier);
1222 }
1223
John McCallb268a282010-08-23 23:25:46 +00001224 getSema().DefaultFunctionArrayConversion(Base);
1225 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001226
John McCall16df1e52010-03-30 21:47:33 +00001227 // FIXME: this involves duplicating earlier analysis in a lot of
1228 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001229 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001230 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001231 R.resolveKind();
1232
John McCallb268a282010-08-23 23:25:46 +00001233 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001234 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001235 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 }
Mike Stump11289f42009-09-09 15:08:12 +00001237
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001239 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 /// By default, performs semantic analysis to build the new expression.
1241 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001242 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001243 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001244 Expr *LHS, Expr *RHS) {
1245 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 }
1247
1248 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001249 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001252 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001254 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001256 Expr *RHS) {
1257 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1258 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 }
1260
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001262 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 /// By default, performs semantic analysis to build the new expression.
1264 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001265 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001266 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001267 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001269 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001270 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 }
Mike Stump11289f42009-09-09 15:08:12 +00001272
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001274 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001278 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001280 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001281 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001282 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 }
Mike Stump11289f42009-09-09 15:08:12 +00001284
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001286 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001289 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 SourceLocation OpLoc,
1291 SourceLocation AccessorLoc,
1292 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001293
John McCall10eae182009-11-30 22:42:35 +00001294 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001295 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001296 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001297 OpLoc, /*IsArrow*/ false,
1298 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001299 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001300 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 }
Mike Stump11289f42009-09-09 15:08:12 +00001302
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001304 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 /// By default, performs semantic analysis to build the new expression.
1306 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001307 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001309 SourceLocation RBraceLoc,
1310 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001311 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001312 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1313 if (Result.isInvalid() || ResultTy->isDependentType())
1314 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001315
Douglas Gregord3d93062009-11-09 17:16:50 +00001316 // Patch in the result type we were given, which may have been computed
1317 // when the initial InitListExpr was built.
1318 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1319 ILE->setType(ResultTy);
1320 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 }
Mike Stump11289f42009-09-09 15:08:12 +00001322
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001324 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001327 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 MultiExprArg ArrayExprs,
1329 SourceLocation EqualOrColonLoc,
1330 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001331 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001332 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001334 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001337
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 ArrayExprs.release();
1339 return move(Result);
1340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001343 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 /// By default, builds the implicit value initialization without performing
1345 /// any semantic analysis. Subclasses may override this routine to provide
1346 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001347 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1349 }
Mike Stump11289f42009-09-09 15:08:12 +00001350
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001352 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001355 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001356 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001357 SourceLocation RParenLoc) {
1358 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001359 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001360 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 }
1362
1363 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001364 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 /// By default, performs semantic analysis to build the new expression.
1366 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001367 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 MultiExprArg SubExprs,
1369 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001370 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001371 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 }
Mike Stump11289f42009-09-09 15:08:12 +00001373
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001375 ///
1376 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// rather than attempting to map the label statement itself.
1378 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001379 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 SourceLocation LabelLoc,
1381 LabelStmt *Label) {
1382 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1383 }
Mike Stump11289f42009-09-09 15:08:12 +00001384
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// \brief Build a new GNU statement 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 RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001390 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001392 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 }
Mike Stump11289f42009-09-09 15:08:12 +00001394
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// \brief Build a new __builtin_choose_expr expression.
1396 ///
1397 /// By default, performs semantic analysis to build the new expression.
1398 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001399 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001400 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 SourceLocation RParenLoc) {
1402 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001403 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 RParenLoc);
1405 }
Mike Stump11289f42009-09-09 15:08:12 +00001406
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 /// \brief Build a new overloaded operator call expression.
1408 ///
1409 /// By default, performs semantic analysis to build the new expression.
1410 /// The semantic analysis provides the behavior of template instantiation,
1411 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001412 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 /// argument-dependent lookup, etc. Subclasses may override this routine to
1414 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001415 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001417 Expr *Callee,
1418 Expr *First,
1419 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001420
1421 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 /// reinterpret_cast.
1423 ///
1424 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001425 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001427 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 Stmt::StmtClass Class,
1429 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001430 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 SourceLocation RAngleLoc,
1432 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001433 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 SourceLocation RParenLoc) {
1435 switch (Class) {
1436 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001437 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001438 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001439 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001440
1441 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001442 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001443 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001444 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001445
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001447 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001448 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001449 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001451
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001453 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001454 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001455 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001456
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 default:
1458 assert(false && "Invalid C++ named cast");
1459 break;
1460 }
Mike Stump11289f42009-09-09 15:08:12 +00001461
John McCallfaf5fb42010-08-26 23:41:50 +00001462 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 }
Mike Stump11289f42009-09-09 15:08:12 +00001464
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 /// \brief Build a new C++ static_cast expression.
1466 ///
1467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001469 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001471 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 SourceLocation RAngleLoc,
1473 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001474 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001476 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001477 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001478 SourceRange(LAngleLoc, RAngleLoc),
1479 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 }
1481
1482 /// \brief Build a new C++ dynamic_cast expression.
1483 ///
1484 /// By default, performs semantic analysis to build the new expression.
1485 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001486 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001488 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 SourceLocation RAngleLoc,
1490 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001491 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001493 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001494 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001495 SourceRange(LAngleLoc, RAngleLoc),
1496 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 }
1498
1499 /// \brief Build a new C++ reinterpret_cast expression.
1500 ///
1501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001503 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001505 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 SourceLocation RAngleLoc,
1507 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001508 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001510 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001511 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001512 SourceRange(LAngleLoc, RAngleLoc),
1513 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 }
1515
1516 /// \brief Build a new C++ const_cast expression.
1517 ///
1518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001520 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001522 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 SourceLocation RAngleLoc,
1524 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001525 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001527 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001528 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001529 SourceRange(LAngleLoc, RAngleLoc),
1530 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 }
Mike Stump11289f42009-09-09 15:08:12 +00001532
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 /// \brief Build a new C++ functional-style cast expression.
1534 ///
1535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001537 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1538 SourceLocation LParenLoc,
1539 Expr *Sub,
1540 SourceLocation RParenLoc) {
1541 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001542 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 RParenLoc);
1544 }
Mike Stump11289f42009-09-09 15:08:12 +00001545
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// \brief Build a new C++ typeid(type) expression.
1547 ///
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001550 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001551 SourceLocation TypeidLoc,
1552 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001554 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001555 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 }
Mike Stump11289f42009-09-09 15:08:12 +00001557
Francois Pichet9f4f2072010-09-08 12:20:18 +00001558
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 /// \brief Build a new C++ typeid(expr) expression.
1560 ///
1561 /// By default, performs semantic analysis to build the new expression.
1562 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001563 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001564 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001565 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001567 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001568 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001569 }
1570
Francois Pichet9f4f2072010-09-08 12:20:18 +00001571 /// \brief Build a new C++ __uuidof(type) expression.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
1575 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1576 SourceLocation TypeidLoc,
1577 TypeSourceInfo *Operand,
1578 SourceLocation RParenLoc) {
1579 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1580 RParenLoc);
1581 }
1582
1583 /// \brief Build a new C++ __uuidof(expr) expression.
1584 ///
1585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
1587 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1588 SourceLocation TypeidLoc,
1589 Expr *Operand,
1590 SourceLocation RParenLoc) {
1591 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1592 RParenLoc);
1593 }
1594
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// \brief Build a new C++ "this" expression.
1596 ///
1597 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001598 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001600 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001601 QualType ThisType,
1602 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001604 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1605 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 }
1607
1608 /// \brief Build a new C++ throw expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001612 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001613 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 }
1615
1616 /// \brief Build a new C++ default-argument expression.
1617 ///
1618 /// By default, builds a new default-argument expression, which does not
1619 /// require any semantic analysis. Subclasses may override this routine to
1620 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001621 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001622 ParmVarDecl *Param) {
1623 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1624 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 }
1626
1627 /// \brief Build a new C++ zero-initialization expression.
1628 ///
1629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001631 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1632 SourceLocation LParenLoc,
1633 SourceLocation RParenLoc) {
1634 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001635 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001636 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 }
Mike Stump11289f42009-09-09 15:08:12 +00001638
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 /// \brief Build a new C++ "new" expression.
1640 ///
1641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001643 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001644 bool UseGlobal,
1645 SourceLocation PlacementLParen,
1646 MultiExprArg PlacementArgs,
1647 SourceLocation PlacementRParen,
1648 SourceRange TypeIdParens,
1649 QualType AllocatedType,
1650 TypeSourceInfo *AllocatedTypeInfo,
1651 Expr *ArraySize,
1652 SourceLocation ConstructorLParen,
1653 MultiExprArg ConstructorArgs,
1654 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001655 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 PlacementLParen,
1657 move(PlacementArgs),
1658 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001659 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001660 AllocatedType,
1661 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001662 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 ConstructorLParen,
1664 move(ConstructorArgs),
1665 ConstructorRParen);
1666 }
Mike Stump11289f42009-09-09 15:08:12 +00001667
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 /// \brief Build a new C++ "delete" expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001672 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 bool IsGlobalDelete,
1674 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001675 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001677 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 }
Mike Stump11289f42009-09-09 15:08:12 +00001679
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 /// \brief Build a new unary type trait expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001685 SourceLocation StartLoc,
1686 TypeSourceInfo *T,
1687 SourceLocation RParenLoc) {
1688 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 }
1690
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001691 /// \brief Build a new binary type trait expression.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
1695 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1696 SourceLocation StartLoc,
1697 TypeSourceInfo *LhsT,
1698 TypeSourceInfo *RhsT,
1699 SourceLocation RParenLoc) {
1700 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1701 }
1702
Mike Stump11289f42009-09-09 15:08:12 +00001703 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 /// expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001708 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001710 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001711 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 CXXScopeSpec SS;
1713 SS.setRange(QualifierRange);
1714 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001715
1716 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001717 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001718 *TemplateArgs);
1719
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001720 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 }
1722
1723 /// \brief Build a new template-id expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001727 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001728 LookupResult &R,
1729 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001730 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001731 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 }
1733
1734 /// \brief Build a new object-construction expression.
1735 ///
1736 /// By default, performs semantic analysis to build the new expression.
1737 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001738 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001739 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 CXXConstructorDecl *Constructor,
1741 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001742 MultiExprArg Args,
1743 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001744 CXXConstructExpr::ConstructionKind ConstructKind,
1745 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001746 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001747 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001748 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001749 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001750
Douglas Gregordb121ba2009-12-14 16:27:04 +00001751 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001752 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001753 RequiresZeroInit, ConstructKind,
1754 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 }
1756
1757 /// \brief Build a new object-construction expression.
1758 ///
1759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001761 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1762 SourceLocation LParenLoc,
1763 MultiExprArg Args,
1764 SourceLocation RParenLoc) {
1765 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 LParenLoc,
1767 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 RParenLoc);
1769 }
1770
1771 /// \brief Build a new object-construction expression.
1772 ///
1773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001775 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1776 SourceLocation LParenLoc,
1777 MultiExprArg Args,
1778 SourceLocation RParenLoc) {
1779 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 LParenLoc,
1781 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 RParenLoc);
1783 }
Mike Stump11289f42009-09-09 15:08:12 +00001784
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 /// \brief Build a new member reference expression.
1786 ///
1787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001789 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001790 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 bool IsArrow,
1792 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001793 NestedNameSpecifier *Qualifier,
1794 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001795 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001796 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001797 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001799 SS.setRange(QualifierRange);
1800 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001801
John McCallb268a282010-08-23 23:25:46 +00001802 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001803 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001804 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001805 MemberNameInfo,
1806 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 }
1808
John McCall10eae182009-11-30 22:42:35 +00001809 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001810 ///
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001813 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001814 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001815 SourceLocation OperatorLoc,
1816 bool IsArrow,
1817 NestedNameSpecifier *Qualifier,
1818 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001819 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001820 LookupResult &R,
1821 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001822 CXXScopeSpec SS;
1823 SS.setRange(QualifierRange);
1824 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001825
John McCallb268a282010-08-23 23:25:46 +00001826 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001827 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001828 SS, FirstQualifierInScope,
1829 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001830 }
Mike Stump11289f42009-09-09 15:08:12 +00001831
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001832 /// \brief Build a new noexcept expression.
1833 ///
1834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
1836 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1837 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1838 }
1839
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// \brief Build a new Objective-C @encode expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001844 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001845 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001847 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001849 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001850
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001851 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001853 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001854 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001855 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001856 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001857 MultiExprArg Args,
1858 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001859 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1860 ReceiverTypeInfo->getType(),
1861 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001862 Sel, Method, LBracLoc, SelectorLoc,
1863 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001864 }
1865
1866 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001867 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001868 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001869 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001870 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001872 MultiExprArg Args,
1873 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001874 return SemaRef.BuildInstanceMessage(Receiver,
1875 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001876 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001877 Sel, Method, LBracLoc, SelectorLoc,
1878 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001879 }
1880
Douglas Gregord51d90d2010-04-26 20:11:03 +00001881 /// \brief Build a new Objective-C ivar reference expression.
1882 ///
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001885 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001886 SourceLocation IvarLoc,
1887 bool IsArrow, bool IsFreeIvar) {
1888 // FIXME: We lose track of the IsFreeIvar bit.
1889 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001890 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001891 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1892 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001893 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001894 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001895 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001896 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001897 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001898 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001899
Douglas Gregord51d90d2010-04-26 20:11:03 +00001900 if (Result.get())
1901 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001902
John McCallb268a282010-08-23 23:25:46 +00001903 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001904 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001905 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001906 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001907 /*TemplateArgs=*/0);
1908 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001909
1910 /// \brief Build a new Objective-C property reference expression.
1911 ///
1912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001914 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001915 ObjCPropertyDecl *Property,
1916 SourceLocation PropertyLoc) {
1917 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001918 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001919 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1920 Sema::LookupMemberName);
1921 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001922 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001923 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001924 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001925 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001926 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001927
Douglas Gregor9faee212010-04-26 20:47:02 +00001928 if (Result.get())
1929 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001930
John McCallb268a282010-08-23 23:25:46 +00001931 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001932 /*FIXME:*/PropertyLoc, IsArrow,
1933 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001934 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001935 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001936 /*TemplateArgs=*/0);
1937 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001938
John McCallb7bd14f2010-12-02 01:19:52 +00001939 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001940 ///
1941 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00001942 /// Subclasses may override this routine to provide different behavior.
1943 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1944 ObjCMethodDecl *Getter,
1945 ObjCMethodDecl *Setter,
1946 SourceLocation PropertyLoc) {
1947 // Since these expressions can only be value-dependent, we do not
1948 // need to perform semantic analysis again.
1949 return Owned(
1950 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
1951 VK_LValue, OK_ObjCProperty,
1952 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001953 }
1954
Douglas Gregord51d90d2010-04-26 20:11:03 +00001955 /// \brief Build a new Objective-C "isa" expression.
1956 ///
1957 /// By default, performs semantic analysis to build the new expression.
1958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001959 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001960 bool IsArrow) {
1961 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001962 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001963 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1964 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001965 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001966 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001967 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001968 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001969 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001970
Douglas Gregord51d90d2010-04-26 20:11:03 +00001971 if (Result.get())
1972 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001973
John McCallb268a282010-08-23 23:25:46 +00001974 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001975 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001976 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001977 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001978 /*TemplateArgs=*/0);
1979 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001980
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 /// \brief Build a new shuffle vector expression.
1982 ///
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001985 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001986 MultiExprArg SubExprs,
1987 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001989 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1991 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1992 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1993 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001994
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 // Build a reference to the __builtin_shufflevector builtin
1996 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001997 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00001999 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002001
2002 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 unsigned NumSubExprs = SubExprs.size();
2004 Expr **Subs = (Expr **)SubExprs.release();
2005 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2006 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002007 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002008 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002010 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002011
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002013 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002018 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 }
John McCall31f82722010-11-12 08:19:04 +00002020
2021private:
2022 QualType TransformTypeInObjectScope(QualType T,
2023 QualType ObjectType,
2024 NamedDecl *FirstQualifierInScope,
2025 NestedNameSpecifier *Prefix);
2026
2027 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2028 QualType ObjectType,
2029 NamedDecl *FirstQualifierInScope,
2030 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002031};
Douglas Gregora16548e2009-08-11 05:31:07 +00002032
Douglas Gregorebe10102009-08-20 07:17:43 +00002033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002034StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002035 if (!S)
2036 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002037
Douglas Gregorebe10102009-08-20 07:17:43 +00002038 switch (S->getStmtClass()) {
2039 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregorebe10102009-08-20 07:17:43 +00002041 // Transform individual statement nodes
2042#define STMT(Node, Parent) \
2043 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2044#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002045#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002046
Douglas Gregorebe10102009-08-20 07:17:43 +00002047 // Transform expressions by calling TransformExpr.
2048#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002049#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002050#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002051#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002052 {
John McCalldadc5752010-08-24 06:29:42 +00002053 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002054 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002055 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002056
John McCallb268a282010-08-23 23:25:46 +00002057 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002058 }
Mike Stump11289f42009-09-09 15:08:12 +00002059 }
2060
John McCallc3007a22010-10-26 07:05:15 +00002061 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002062}
Mike Stump11289f42009-09-09 15:08:12 +00002063
2064
Douglas Gregore922c772009-08-04 22:27:00 +00002065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002066ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 if (!E)
2068 return SemaRef.Owned(E);
2069
2070 switch (E->getStmtClass()) {
2071 case Stmt::NoStmtClass: break;
2072#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002073#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002074#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002075 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002076#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002077 }
2078
John McCallc3007a22010-10-26 07:05:15 +00002079 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002080}
2081
2082template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002083NestedNameSpecifier *
2084TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002085 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002086 QualType ObjectType,
2087 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002088 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002089
Douglas Gregorebe10102009-08-20 07:17:43 +00002090 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002091 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002092 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002093 ObjectType,
2094 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002095 if (!Prefix)
2096 return 0;
2097 }
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregor1135c352009-08-06 05:28:30 +00002099 switch (NNS->getKind()) {
2100 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002101 if (Prefix) {
2102 // The object type and qualifier-in-scope really apply to the
2103 // leftmost entity.
2104 ObjectType = QualType();
2105 FirstQualifierInScope = 0;
2106 }
2107
Mike Stump11289f42009-09-09 15:08:12 +00002108 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002109 "Identifier nested-name-specifier with no prefix or object type");
2110 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2111 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002112 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002113
2114 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002115 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002116 ObjectType,
2117 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002118
Douglas Gregor1135c352009-08-06 05:28:30 +00002119 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002120 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002121 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002122 getDerived().TransformDecl(Range.getBegin(),
2123 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002124 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002125 Prefix == NNS->getPrefix() &&
2126 NS == NNS->getAsNamespace())
2127 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002128
Douglas Gregor1135c352009-08-06 05:28:30 +00002129 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2130 }
Mike Stump11289f42009-09-09 15:08:12 +00002131
Douglas Gregor1135c352009-08-06 05:28:30 +00002132 case NestedNameSpecifier::Global:
2133 // There is no meaningful transformation that one could perform on the
2134 // global scope.
2135 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002136
Douglas Gregor1135c352009-08-06 05:28:30 +00002137 case NestedNameSpecifier::TypeSpecWithTemplate:
2138 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002139 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002140 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2141 ObjectType,
2142 FirstQualifierInScope,
2143 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002144 if (T.isNull())
2145 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002146
Douglas Gregor1135c352009-08-06 05:28:30 +00002147 if (!getDerived().AlwaysRebuild() &&
2148 Prefix == NNS->getPrefix() &&
2149 T == QualType(NNS->getAsType(), 0))
2150 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002151
2152 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2153 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002154 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002155 }
2156 }
Mike Stump11289f42009-09-09 15:08:12 +00002157
Douglas Gregor1135c352009-08-06 05:28:30 +00002158 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002159 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002160}
2161
2162template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002163DeclarationNameInfo
2164TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002165::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002166 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002167 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002168 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002169
2170 switch (Name.getNameKind()) {
2171 case DeclarationName::Identifier:
2172 case DeclarationName::ObjCZeroArgSelector:
2173 case DeclarationName::ObjCOneArgSelector:
2174 case DeclarationName::ObjCMultiArgSelector:
2175 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002176 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002177 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002178 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002179
Douglas Gregorf816bd72009-09-03 22:13:48 +00002180 case DeclarationName::CXXConstructorName:
2181 case DeclarationName::CXXDestructorName:
2182 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002183 TypeSourceInfo *NewTInfo;
2184 CanQualType NewCanTy;
2185 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002186 NewTInfo = getDerived().TransformType(OldTInfo);
2187 if (!NewTInfo)
2188 return DeclarationNameInfo();
2189 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002190 }
2191 else {
2192 NewTInfo = 0;
2193 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002194 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002195 if (NewT.isNull())
2196 return DeclarationNameInfo();
2197 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002200 DeclarationName NewName
2201 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2202 NewCanTy);
2203 DeclarationNameInfo NewNameInfo(NameInfo);
2204 NewNameInfo.setName(NewName);
2205 NewNameInfo.setNamedTypeInfo(NewTInfo);
2206 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002207 }
Mike Stump11289f42009-09-09 15:08:12 +00002208 }
2209
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002210 assert(0 && "Unknown name kind.");
2211 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002212}
2213
2214template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002215TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002216TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002217 QualType ObjectType,
2218 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002219 SourceLocation Loc = getDerived().getBaseLocation();
2220
Douglas Gregor71dc5092009-08-06 06:41:21 +00002221 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002222 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002223 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002224 /*FIXME*/ SourceRange(Loc),
2225 ObjectType,
2226 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002227 if (!NNS)
2228 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002229
Douglas Gregor71dc5092009-08-06 06:41:21 +00002230 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002231 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002232 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002233 if (!TransTemplate)
2234 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002235
Douglas Gregor71dc5092009-08-06 06:41:21 +00002236 if (!getDerived().AlwaysRebuild() &&
2237 NNS == QTN->getQualifier() &&
2238 TransTemplate == Template)
2239 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002240
Douglas Gregor71dc5092009-08-06 06:41:21 +00002241 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2242 TransTemplate);
2243 }
Mike Stump11289f42009-09-09 15:08:12 +00002244
John McCalle66edc12009-11-24 19:00:30 +00002245 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002246 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002247 }
Mike Stump11289f42009-09-09 15:08:12 +00002248
Douglas Gregor71dc5092009-08-06 06:41:21 +00002249 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002250 NestedNameSpecifier *NNS = DTN->getQualifier();
2251 if (NNS) {
2252 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2253 /*FIXME:*/SourceRange(Loc),
2254 ObjectType,
2255 FirstQualifierInScope);
2256 if (!NNS) return TemplateName();
2257
2258 // These apply to the scope specifier, not the template.
2259 ObjectType = QualType();
2260 FirstQualifierInScope = 0;
2261 }
Mike Stump11289f42009-09-09 15:08:12 +00002262
Douglas Gregor71dc5092009-08-06 06:41:21 +00002263 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002264 NNS == DTN->getQualifier() &&
2265 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002266 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002267
Douglas Gregora5614c52010-09-08 23:56:00 +00002268 if (DTN->isIdentifier()) {
2269 // FIXME: Bad range
2270 SourceRange QualifierRange(getDerived().getBaseLocation());
2271 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2272 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002273 ObjectType,
2274 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002275 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002276
2277 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002278 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002279 }
Mike Stump11289f42009-09-09 15:08:12 +00002280
Douglas Gregor71dc5092009-08-06 06:41:21 +00002281 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002282 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002283 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002284 if (!TransTemplate)
2285 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002286
Douglas Gregor71dc5092009-08-06 06:41:21 +00002287 if (!getDerived().AlwaysRebuild() &&
2288 TransTemplate == Template)
2289 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002290
Douglas Gregor71dc5092009-08-06 06:41:21 +00002291 return TemplateName(TransTemplate);
2292 }
Mike Stump11289f42009-09-09 15:08:12 +00002293
John McCalle66edc12009-11-24 19:00:30 +00002294 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002295 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002296 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002297}
2298
2299template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002300void TreeTransform<Derived>::InventTemplateArgumentLoc(
2301 const TemplateArgument &Arg,
2302 TemplateArgumentLoc &Output) {
2303 SourceLocation Loc = getDerived().getBaseLocation();
2304 switch (Arg.getKind()) {
2305 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002306 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002307 break;
2308
2309 case TemplateArgument::Type:
2310 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002311 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002312
John McCall0ad16662009-10-29 08:12:44 +00002313 break;
2314
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002315 case TemplateArgument::Template:
2316 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2317 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002318
John McCall0ad16662009-10-29 08:12:44 +00002319 case TemplateArgument::Expression:
2320 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2321 break;
2322
2323 case TemplateArgument::Declaration:
2324 case TemplateArgument::Integral:
2325 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002326 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002327 break;
2328 }
2329}
2330
2331template<typename Derived>
2332bool TreeTransform<Derived>::TransformTemplateArgument(
2333 const TemplateArgumentLoc &Input,
2334 TemplateArgumentLoc &Output) {
2335 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002336 switch (Arg.getKind()) {
2337 case TemplateArgument::Null:
2338 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002339 Output = Input;
2340 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002341
Douglas Gregore922c772009-08-04 22:27:00 +00002342 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002343 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002344 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002345 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002346
2347 DI = getDerived().TransformType(DI);
2348 if (!DI) return true;
2349
2350 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2351 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002352 }
Mike Stump11289f42009-09-09 15:08:12 +00002353
Douglas Gregore922c772009-08-04 22:27:00 +00002354 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002355 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002356 DeclarationName Name;
2357 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2358 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002359 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002360 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002361 if (!D) return true;
2362
John McCall0d07eb32009-10-29 18:45:58 +00002363 Expr *SourceExpr = Input.getSourceDeclExpression();
2364 if (SourceExpr) {
2365 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002366 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002367 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002368 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002369 }
2370
2371 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002372 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002373 }
Mike Stump11289f42009-09-09 15:08:12 +00002374
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002375 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002376 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002377 TemplateName Template
2378 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2379 if (Template.isNull())
2380 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002381
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002382 Output = TemplateArgumentLoc(TemplateArgument(Template),
2383 Input.getTemplateQualifierRange(),
2384 Input.getTemplateNameLoc());
2385 return false;
2386 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002387
Douglas Gregore922c772009-08-04 22:27:00 +00002388 case TemplateArgument::Expression: {
2389 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002390 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002391 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002392
John McCall0ad16662009-10-29 08:12:44 +00002393 Expr *InputExpr = Input.getSourceExpression();
2394 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2395
John McCalldadc5752010-08-24 06:29:42 +00002396 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002397 = getDerived().TransformExpr(InputExpr);
2398 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002399 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002400 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002401 }
Mike Stump11289f42009-09-09 15:08:12 +00002402
Douglas Gregore922c772009-08-04 22:27:00 +00002403 case TemplateArgument::Pack: {
2404 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2405 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002406 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002407 AEnd = Arg.pack_end();
2408 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002409
John McCall0ad16662009-10-29 08:12:44 +00002410 // FIXME: preserve source information here when we start
2411 // caring about parameter packs.
2412
John McCall0d07eb32009-10-29 18:45:58 +00002413 TemplateArgumentLoc InputArg;
2414 TemplateArgumentLoc OutputArg;
2415 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2416 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002417 return true;
2418
John McCall0d07eb32009-10-29 18:45:58 +00002419 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002420 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002421
2422 TemplateArgument *TransformedArgsPtr
2423 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2424 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2425 TransformedArgsPtr);
2426 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2427 TransformedArgs.size()),
2428 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002429 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002430 }
2431 }
Mike Stump11289f42009-09-09 15:08:12 +00002432
Douglas Gregore922c772009-08-04 22:27:00 +00002433 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002434 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002435}
2436
Douglas Gregor62e06f22010-12-20 17:31:10 +00002437template<typename Derived>
2438bool TreeTransform<Derived>::TransformTemplateArguments(
2439 const TemplateArgumentLoc *Inputs,
2440 unsigned NumInputs,
2441 TemplateArgumentListInfo &Outputs) {
2442 for (unsigned I = 0; I != NumInputs; ++I) {
2443 TemplateArgumentLoc Out;
2444 if (getDerived().TransformTemplateArgument(Inputs[I], Out))
2445 return true;
2446
2447 Outputs.addArgument(Out);
2448 }
2449
2450 return false;
2451}
2452
Douglas Gregor42cafa82010-12-20 17:42:22 +00002453template<typename Derived>
2454template<typename InputsType>
2455bool TreeTransform<Derived>::TransformTemplateArgumentsFromArgLoc(
2456 const InputsType &Inputs,
2457 TemplateArgumentListInfo &Outputs) {
2458 for (unsigned I = 0, N = Inputs.getNumArgs(); I != N; ++I) {
2459 TemplateArgumentLoc Out;
2460 if (getDerived().TransformTemplateArgument(Inputs.getArgLoc(I), Out))
2461 return true;
2462
2463 Outputs.addArgument(Out);
2464 }
2465
2466 return false;
2467
2468}
2469
Douglas Gregord6ff3322009-08-04 16:50:30 +00002470//===----------------------------------------------------------------------===//
2471// Type transformation
2472//===----------------------------------------------------------------------===//
2473
2474template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002475QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002476 if (getDerived().AlreadyTransformed(T))
2477 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002478
John McCall550e0c22009-10-21 00:40:46 +00002479 // Temporary workaround. All of these transformations should
2480 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002481 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002482 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002483
John McCall31f82722010-11-12 08:19:04 +00002484 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002485
John McCall550e0c22009-10-21 00:40:46 +00002486 if (!NewDI)
2487 return QualType();
2488
2489 return NewDI->getType();
2490}
2491
2492template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002493TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002494 if (getDerived().AlreadyTransformed(DI->getType()))
2495 return DI;
2496
2497 TypeLocBuilder TLB;
2498
2499 TypeLoc TL = DI->getTypeLoc();
2500 TLB.reserve(TL.getFullDataSize());
2501
John McCall31f82722010-11-12 08:19:04 +00002502 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002503 if (Result.isNull())
2504 return 0;
2505
John McCallbcd03502009-12-07 02:54:59 +00002506 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002507}
2508
2509template<typename Derived>
2510QualType
John McCall31f82722010-11-12 08:19:04 +00002511TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002512 switch (T.getTypeLocClass()) {
2513#define ABSTRACT_TYPELOC(CLASS, PARENT)
2514#define TYPELOC(CLASS, PARENT) \
2515 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002516 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002517#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002518 }
Mike Stump11289f42009-09-09 15:08:12 +00002519
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002520 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002521 return QualType();
2522}
2523
2524/// FIXME: By default, this routine adds type qualifiers only to types
2525/// that can have qualifiers, and silently suppresses those qualifiers
2526/// that are not permitted (e.g., qualifiers on reference or function
2527/// types). This is the right thing for template instantiation, but
2528/// probably not for other clients.
2529template<typename Derived>
2530QualType
2531TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002532 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002533 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002534
John McCall31f82722010-11-12 08:19:04 +00002535 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002536 if (Result.isNull())
2537 return QualType();
2538
2539 // Silently suppress qualifiers if the result type can't be qualified.
2540 // FIXME: this is the right thing for template instantiation, but
2541 // probably not for other clients.
2542 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002543 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002544
John McCallcb0f89a2010-06-05 06:41:15 +00002545 if (!Quals.empty()) {
2546 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2547 TLB.push<QualifiedTypeLoc>(Result);
2548 // No location information to preserve.
2549 }
John McCall550e0c22009-10-21 00:40:46 +00002550
2551 return Result;
2552}
2553
John McCall31f82722010-11-12 08:19:04 +00002554/// \brief Transforms a type that was written in a scope specifier,
2555/// given an object type, the results of unqualified lookup, and
2556/// an already-instantiated prefix.
2557///
2558/// The object type is provided iff the scope specifier qualifies the
2559/// member of a dependent member-access expression. The prefix is
2560/// provided iff the the scope specifier in which this appears has a
2561/// prefix.
2562///
2563/// This is private to TreeTransform.
2564template<typename Derived>
2565QualType
2566TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2567 QualType ObjectType,
2568 NamedDecl *UnqualLookup,
2569 NestedNameSpecifier *Prefix) {
2570 if (getDerived().AlreadyTransformed(T))
2571 return T;
2572
2573 TypeSourceInfo *TSI =
2574 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2575
2576 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2577 UnqualLookup, Prefix);
2578 if (!TSI) return QualType();
2579 return TSI->getType();
2580}
2581
2582template<typename Derived>
2583TypeSourceInfo *
2584TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2585 QualType ObjectType,
2586 NamedDecl *UnqualLookup,
2587 NestedNameSpecifier *Prefix) {
2588 // TODO: in some cases, we might be some verification to do here.
2589 if (ObjectType.isNull())
2590 return getDerived().TransformType(TSI);
2591
2592 QualType T = TSI->getType();
2593 if (getDerived().AlreadyTransformed(T))
2594 return TSI;
2595
2596 TypeLocBuilder TLB;
2597 QualType Result;
2598
2599 if (isa<TemplateSpecializationType>(T)) {
2600 TemplateSpecializationTypeLoc TL
2601 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2602
2603 TemplateName Template =
2604 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2605 ObjectType, UnqualLookup);
2606 if (Template.isNull()) return 0;
2607
2608 Result = getDerived()
2609 .TransformTemplateSpecializationType(TLB, TL, Template);
2610 } else if (isa<DependentTemplateSpecializationType>(T)) {
2611 DependentTemplateSpecializationTypeLoc TL
2612 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2613
2614 Result = getDerived()
2615 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2616 } else {
2617 // Nothing special needs to be done for these.
2618 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2619 }
2620
2621 if (Result.isNull()) return 0;
2622 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2623}
2624
John McCall550e0c22009-10-21 00:40:46 +00002625template <class TyLoc> static inline
2626QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2627 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2628 NewT.setNameLoc(T.getNameLoc());
2629 return T.getType();
2630}
2631
John McCall550e0c22009-10-21 00:40:46 +00002632template<typename Derived>
2633QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002634 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002635 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2636 NewT.setBuiltinLoc(T.getBuiltinLoc());
2637 if (T.needsExtraLocalData())
2638 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2639 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002640}
Mike Stump11289f42009-09-09 15:08:12 +00002641
Douglas Gregord6ff3322009-08-04 16:50:30 +00002642template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002643QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002644 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002645 // FIXME: recurse?
2646 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002647}
Mike Stump11289f42009-09-09 15:08:12 +00002648
Douglas Gregord6ff3322009-08-04 16:50:30 +00002649template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002650QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002651 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002652 QualType PointeeType
2653 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002654 if (PointeeType.isNull())
2655 return QualType();
2656
2657 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002658 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002659 // A dependent pointer type 'T *' has is being transformed such
2660 // that an Objective-C class type is being replaced for 'T'. The
2661 // resulting pointer type is an ObjCObjectPointerType, not a
2662 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002663 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002664
John McCall8b07ec22010-05-15 11:32:37 +00002665 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2666 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002667 return Result;
2668 }
John McCall31f82722010-11-12 08:19:04 +00002669
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002670 if (getDerived().AlwaysRebuild() ||
2671 PointeeType != TL.getPointeeLoc().getType()) {
2672 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2673 if (Result.isNull())
2674 return QualType();
2675 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002676
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002677 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2678 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002679 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002680}
Mike Stump11289f42009-09-09 15:08:12 +00002681
2682template<typename Derived>
2683QualType
John McCall550e0c22009-10-21 00:40:46 +00002684TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002685 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002686 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002687 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2688 if (PointeeType.isNull())
2689 return QualType();
2690
2691 QualType Result = TL.getType();
2692 if (getDerived().AlwaysRebuild() ||
2693 PointeeType != TL.getPointeeLoc().getType()) {
2694 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002695 TL.getSigilLoc());
2696 if (Result.isNull())
2697 return QualType();
2698 }
2699
Douglas Gregor049211a2010-04-22 16:50:51 +00002700 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002701 NewT.setSigilLoc(TL.getSigilLoc());
2702 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002703}
2704
John McCall70dd5f62009-10-30 00:06:24 +00002705/// Transforms a reference type. Note that somewhat paradoxically we
2706/// don't care whether the type itself is an l-value type or an r-value
2707/// type; we only care if the type was *written* as an l-value type
2708/// or an r-value type.
2709template<typename Derived>
2710QualType
2711TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002712 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002713 const ReferenceType *T = TL.getTypePtr();
2714
2715 // Note that this works with the pointee-as-written.
2716 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2717 if (PointeeType.isNull())
2718 return QualType();
2719
2720 QualType Result = TL.getType();
2721 if (getDerived().AlwaysRebuild() ||
2722 PointeeType != T->getPointeeTypeAsWritten()) {
2723 Result = getDerived().RebuildReferenceType(PointeeType,
2724 T->isSpelledAsLValue(),
2725 TL.getSigilLoc());
2726 if (Result.isNull())
2727 return QualType();
2728 }
2729
2730 // r-value references can be rebuilt as l-value references.
2731 ReferenceTypeLoc NewTL;
2732 if (isa<LValueReferenceType>(Result))
2733 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2734 else
2735 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2736 NewTL.setSigilLoc(TL.getSigilLoc());
2737
2738 return Result;
2739}
2740
Mike Stump11289f42009-09-09 15:08:12 +00002741template<typename Derived>
2742QualType
John McCall550e0c22009-10-21 00:40:46 +00002743TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002744 LValueReferenceTypeLoc TL) {
2745 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002746}
2747
Mike Stump11289f42009-09-09 15:08:12 +00002748template<typename Derived>
2749QualType
John McCall550e0c22009-10-21 00:40:46 +00002750TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002751 RValueReferenceTypeLoc TL) {
2752 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002753}
Mike Stump11289f42009-09-09 15:08:12 +00002754
Douglas Gregord6ff3322009-08-04 16:50:30 +00002755template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002756QualType
John McCall550e0c22009-10-21 00:40:46 +00002757TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002758 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002759 MemberPointerType *T = TL.getTypePtr();
2760
2761 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002762 if (PointeeType.isNull())
2763 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002764
John McCall550e0c22009-10-21 00:40:46 +00002765 // TODO: preserve source information for this.
2766 QualType ClassType
2767 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768 if (ClassType.isNull())
2769 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 QualType Result = TL.getType();
2772 if (getDerived().AlwaysRebuild() ||
2773 PointeeType != T->getPointeeType() ||
2774 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002775 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2776 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002777 if (Result.isNull())
2778 return QualType();
2779 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002780
John McCall550e0c22009-10-21 00:40:46 +00002781 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2782 NewTL.setSigilLoc(TL.getSigilLoc());
2783
2784 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002785}
2786
Mike Stump11289f42009-09-09 15:08:12 +00002787template<typename Derived>
2788QualType
John McCall550e0c22009-10-21 00:40:46 +00002789TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002790 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002791 ConstantArrayType *T = TL.getTypePtr();
2792 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002793 if (ElementType.isNull())
2794 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002795
John McCall550e0c22009-10-21 00:40:46 +00002796 QualType Result = TL.getType();
2797 if (getDerived().AlwaysRebuild() ||
2798 ElementType != T->getElementType()) {
2799 Result = getDerived().RebuildConstantArrayType(ElementType,
2800 T->getSizeModifier(),
2801 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002802 T->getIndexTypeCVRQualifiers(),
2803 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002804 if (Result.isNull())
2805 return QualType();
2806 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002807
John McCall550e0c22009-10-21 00:40:46 +00002808 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2809 NewTL.setLBracketLoc(TL.getLBracketLoc());
2810 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002811
John McCall550e0c22009-10-21 00:40:46 +00002812 Expr *Size = TL.getSizeExpr();
2813 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002814 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002815 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2816 }
2817 NewTL.setSizeExpr(Size);
2818
2819 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002820}
Mike Stump11289f42009-09-09 15:08:12 +00002821
Douglas Gregord6ff3322009-08-04 16:50:30 +00002822template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002823QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002824 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002825 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002826 IncompleteArrayType *T = TL.getTypePtr();
2827 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002828 if (ElementType.isNull())
2829 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002830
John McCall550e0c22009-10-21 00:40:46 +00002831 QualType Result = TL.getType();
2832 if (getDerived().AlwaysRebuild() ||
2833 ElementType != T->getElementType()) {
2834 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002835 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002836 T->getIndexTypeCVRQualifiers(),
2837 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002838 if (Result.isNull())
2839 return QualType();
2840 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002841
John McCall550e0c22009-10-21 00:40:46 +00002842 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2843 NewTL.setLBracketLoc(TL.getLBracketLoc());
2844 NewTL.setRBracketLoc(TL.getRBracketLoc());
2845 NewTL.setSizeExpr(0);
2846
2847 return Result;
2848}
2849
2850template<typename Derived>
2851QualType
2852TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002853 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002854 VariableArrayType *T = TL.getTypePtr();
2855 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2856 if (ElementType.isNull())
2857 return QualType();
2858
2859 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002860 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002861
John McCalldadc5752010-08-24 06:29:42 +00002862 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002863 = getDerived().TransformExpr(T->getSizeExpr());
2864 if (SizeResult.isInvalid())
2865 return QualType();
2866
John McCallb268a282010-08-23 23:25:46 +00002867 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002868
2869 QualType Result = TL.getType();
2870 if (getDerived().AlwaysRebuild() ||
2871 ElementType != T->getElementType() ||
2872 Size != T->getSizeExpr()) {
2873 Result = getDerived().RebuildVariableArrayType(ElementType,
2874 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002875 Size,
John McCall550e0c22009-10-21 00:40:46 +00002876 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002877 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002878 if (Result.isNull())
2879 return QualType();
2880 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002881
John McCall550e0c22009-10-21 00:40:46 +00002882 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2883 NewTL.setLBracketLoc(TL.getLBracketLoc());
2884 NewTL.setRBracketLoc(TL.getRBracketLoc());
2885 NewTL.setSizeExpr(Size);
2886
2887 return Result;
2888}
2889
2890template<typename Derived>
2891QualType
2892TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002893 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002894 DependentSizedArrayType *T = TL.getTypePtr();
2895 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2896 if (ElementType.isNull())
2897 return QualType();
2898
2899 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002900 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002901
John McCalldadc5752010-08-24 06:29:42 +00002902 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002903 = getDerived().TransformExpr(T->getSizeExpr());
2904 if (SizeResult.isInvalid())
2905 return QualType();
2906
2907 Expr *Size = static_cast<Expr*>(SizeResult.get());
2908
2909 QualType Result = TL.getType();
2910 if (getDerived().AlwaysRebuild() ||
2911 ElementType != T->getElementType() ||
2912 Size != T->getSizeExpr()) {
2913 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2914 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002915 Size,
John McCall550e0c22009-10-21 00:40:46 +00002916 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002917 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002918 if (Result.isNull())
2919 return QualType();
2920 }
2921 else SizeResult.take();
2922
2923 // We might have any sort of array type now, but fortunately they
2924 // all have the same location layout.
2925 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2926 NewTL.setLBracketLoc(TL.getLBracketLoc());
2927 NewTL.setRBracketLoc(TL.getRBracketLoc());
2928 NewTL.setSizeExpr(Size);
2929
2930 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002931}
Mike Stump11289f42009-09-09 15:08:12 +00002932
2933template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002934QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002935 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002936 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002937 DependentSizedExtVectorType *T = TL.getTypePtr();
2938
2939 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940 QualType ElementType = getDerived().TransformType(T->getElementType());
2941 if (ElementType.isNull())
2942 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002943
Douglas Gregore922c772009-08-04 22:27:00 +00002944 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002945 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002946
John McCalldadc5752010-08-24 06:29:42 +00002947 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002948 if (Size.isInvalid())
2949 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002950
John McCall550e0c22009-10-21 00:40:46 +00002951 QualType Result = TL.getType();
2952 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002953 ElementType != T->getElementType() ||
2954 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002955 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002956 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002957 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002958 if (Result.isNull())
2959 return QualType();
2960 }
John McCall550e0c22009-10-21 00:40:46 +00002961
2962 // Result might be dependent or not.
2963 if (isa<DependentSizedExtVectorType>(Result)) {
2964 DependentSizedExtVectorTypeLoc NewTL
2965 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2966 NewTL.setNameLoc(TL.getNameLoc());
2967 } else {
2968 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2969 NewTL.setNameLoc(TL.getNameLoc());
2970 }
2971
2972 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002973}
Mike Stump11289f42009-09-09 15:08:12 +00002974
2975template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002976QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002977 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002978 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002979 QualType ElementType = getDerived().TransformType(T->getElementType());
2980 if (ElementType.isNull())
2981 return QualType();
2982
John McCall550e0c22009-10-21 00:40:46 +00002983 QualType Result = TL.getType();
2984 if (getDerived().AlwaysRebuild() ||
2985 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002986 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00002987 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00002988 if (Result.isNull())
2989 return QualType();
2990 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002991
John McCall550e0c22009-10-21 00:40:46 +00002992 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2993 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002994
John McCall550e0c22009-10-21 00:40:46 +00002995 return Result;
2996}
2997
2998template<typename Derived>
2999QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003000 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003001 VectorType *T = TL.getTypePtr();
3002 QualType ElementType = getDerived().TransformType(T->getElementType());
3003 if (ElementType.isNull())
3004 return QualType();
3005
3006 QualType Result = TL.getType();
3007 if (getDerived().AlwaysRebuild() ||
3008 ElementType != T->getElementType()) {
3009 Result = getDerived().RebuildExtVectorType(ElementType,
3010 T->getNumElements(),
3011 /*FIXME*/ SourceLocation());
3012 if (Result.isNull())
3013 return QualType();
3014 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003015
John McCall550e0c22009-10-21 00:40:46 +00003016 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3017 NewTL.setNameLoc(TL.getNameLoc());
3018
3019 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003020}
Mike Stump11289f42009-09-09 15:08:12 +00003021
3022template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003023ParmVarDecl *
3024TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3025 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3026 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3027 if (!NewDI)
3028 return 0;
3029
3030 if (NewDI == OldDI)
3031 return OldParm;
3032 else
3033 return ParmVarDecl::Create(SemaRef.Context,
3034 OldParm->getDeclContext(),
3035 OldParm->getLocation(),
3036 OldParm->getIdentifier(),
3037 NewDI->getType(),
3038 NewDI,
3039 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003040 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003041 /* DefArg */ NULL);
3042}
3043
3044template<typename Derived>
3045bool TreeTransform<Derived>::
3046 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3047 llvm::SmallVectorImpl<QualType> &PTypes,
3048 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3049 FunctionProtoType *T = TL.getTypePtr();
3050
3051 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3052 ParmVarDecl *OldParm = TL.getArg(i);
3053
3054 QualType NewType;
3055 ParmVarDecl *NewParm;
3056
3057 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00003058 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3059 if (!NewParm)
3060 return true;
3061 NewType = NewParm->getType();
3062
3063 // Deal with the possibility that we don't have a parameter
3064 // declaration for this parameter.
3065 } else {
3066 NewParm = 0;
3067
3068 QualType OldType = T->getArgType(i);
3069 NewType = getDerived().TransformType(OldType);
3070 if (NewType.isNull())
3071 return true;
3072 }
3073
3074 PTypes.push_back(NewType);
3075 PVars.push_back(NewParm);
3076 }
3077
3078 return false;
3079}
3080
3081template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003082QualType
John McCall550e0c22009-10-21 00:40:46 +00003083TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003084 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003085 // Transform the parameters and return type.
3086 //
3087 // We instantiate in source order, with the return type first followed by
3088 // the parameters, because users tend to expect this (even if they shouldn't
3089 // rely on it!).
3090 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003091 // When the function has a trailing return type, we instantiate the
3092 // parameters before the return type, since the return type can then refer
3093 // to the parameters themselves (via decltype, sizeof, etc.).
3094 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003095 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003096 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003097 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003098
Douglas Gregor7fb25412010-10-01 18:44:50 +00003099 QualType ResultType;
3100
3101 if (TL.getTrailingReturn()) {
3102 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3103 return QualType();
3104
3105 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3106 if (ResultType.isNull())
3107 return QualType();
3108 }
3109 else {
3110 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3111 if (ResultType.isNull())
3112 return QualType();
3113
3114 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3115 return QualType();
3116 }
3117
John McCall550e0c22009-10-21 00:40:46 +00003118 QualType Result = TL.getType();
3119 if (getDerived().AlwaysRebuild() ||
3120 ResultType != T->getResultType() ||
3121 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3122 Result = getDerived().RebuildFunctionProtoType(ResultType,
3123 ParamTypes.data(),
3124 ParamTypes.size(),
3125 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003126 T->getTypeQuals(),
3127 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003128 if (Result.isNull())
3129 return QualType();
3130 }
Mike Stump11289f42009-09-09 15:08:12 +00003131
John McCall550e0c22009-10-21 00:40:46 +00003132 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3133 NewTL.setLParenLoc(TL.getLParenLoc());
3134 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003135 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003136 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3137 NewTL.setArg(i, ParamDecls[i]);
3138
3139 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140}
Mike Stump11289f42009-09-09 15:08:12 +00003141
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142template<typename Derived>
3143QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003144 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003145 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003146 FunctionNoProtoType *T = TL.getTypePtr();
3147 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3148 if (ResultType.isNull())
3149 return QualType();
3150
3151 QualType Result = TL.getType();
3152 if (getDerived().AlwaysRebuild() ||
3153 ResultType != T->getResultType())
3154 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3155
3156 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3157 NewTL.setLParenLoc(TL.getLParenLoc());
3158 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003159 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003160
3161 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003162}
Mike Stump11289f42009-09-09 15:08:12 +00003163
John McCallb96ec562009-12-04 22:46:56 +00003164template<typename Derived> QualType
3165TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003166 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003167 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003168 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003169 if (!D)
3170 return QualType();
3171
3172 QualType Result = TL.getType();
3173 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3174 Result = getDerived().RebuildUnresolvedUsingType(D);
3175 if (Result.isNull())
3176 return QualType();
3177 }
3178
3179 // We might get an arbitrary type spec type back. We should at
3180 // least always get a type spec type, though.
3181 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3182 NewTL.setNameLoc(TL.getNameLoc());
3183
3184 return Result;
3185}
3186
Douglas Gregord6ff3322009-08-04 16:50:30 +00003187template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003188QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003189 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003190 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003191 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003192 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3193 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003194 if (!Typedef)
3195 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003196
John McCall550e0c22009-10-21 00:40:46 +00003197 QualType Result = TL.getType();
3198 if (getDerived().AlwaysRebuild() ||
3199 Typedef != T->getDecl()) {
3200 Result = getDerived().RebuildTypedefType(Typedef);
3201 if (Result.isNull())
3202 return QualType();
3203 }
Mike Stump11289f42009-09-09 15:08:12 +00003204
John McCall550e0c22009-10-21 00:40:46 +00003205 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3206 NewTL.setNameLoc(TL.getNameLoc());
3207
3208 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003209}
Mike Stump11289f42009-09-09 15:08:12 +00003210
Douglas Gregord6ff3322009-08-04 16:50:30 +00003211template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003212QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003213 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003214 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003215 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003216
John McCalldadc5752010-08-24 06:29:42 +00003217 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003218 if (E.isInvalid())
3219 return QualType();
3220
John McCall550e0c22009-10-21 00:40:46 +00003221 QualType Result = TL.getType();
3222 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003223 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003224 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003225 if (Result.isNull())
3226 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003227 }
John McCall550e0c22009-10-21 00:40:46 +00003228 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003229
John McCall550e0c22009-10-21 00:40:46 +00003230 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003231 NewTL.setTypeofLoc(TL.getTypeofLoc());
3232 NewTL.setLParenLoc(TL.getLParenLoc());
3233 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003234
3235 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003236}
Mike Stump11289f42009-09-09 15:08:12 +00003237
3238template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003239QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003240 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003241 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3242 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3243 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003244 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003245
John McCall550e0c22009-10-21 00:40:46 +00003246 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003247 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3248 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003249 if (Result.isNull())
3250 return QualType();
3251 }
Mike Stump11289f42009-09-09 15:08:12 +00003252
John McCall550e0c22009-10-21 00:40:46 +00003253 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003254 NewTL.setTypeofLoc(TL.getTypeofLoc());
3255 NewTL.setLParenLoc(TL.getLParenLoc());
3256 NewTL.setRParenLoc(TL.getRParenLoc());
3257 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003258
3259 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003260}
Mike Stump11289f42009-09-09 15:08:12 +00003261
3262template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003263QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003264 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003265 DecltypeType *T = TL.getTypePtr();
3266
Douglas Gregore922c772009-08-04 22:27:00 +00003267 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003268 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003269
John McCalldadc5752010-08-24 06:29:42 +00003270 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003271 if (E.isInvalid())
3272 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003273
John McCall550e0c22009-10-21 00:40:46 +00003274 QualType Result = TL.getType();
3275 if (getDerived().AlwaysRebuild() ||
3276 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003277 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003278 if (Result.isNull())
3279 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003280 }
John McCall550e0c22009-10-21 00:40:46 +00003281 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003282
John McCall550e0c22009-10-21 00:40:46 +00003283 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3284 NewTL.setNameLoc(TL.getNameLoc());
3285
3286 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003287}
3288
3289template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003290QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003291 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003292 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003294 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3295 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296 if (!Record)
3297 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003298
John McCall550e0c22009-10-21 00:40:46 +00003299 QualType Result = TL.getType();
3300 if (getDerived().AlwaysRebuild() ||
3301 Record != T->getDecl()) {
3302 Result = getDerived().RebuildRecordType(Record);
3303 if (Result.isNull())
3304 return QualType();
3305 }
Mike Stump11289f42009-09-09 15:08:12 +00003306
John McCall550e0c22009-10-21 00:40:46 +00003307 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3308 NewTL.setNameLoc(TL.getNameLoc());
3309
3310 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003311}
Mike Stump11289f42009-09-09 15:08:12 +00003312
3313template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003314QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003315 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003316 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003318 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3319 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320 if (!Enum)
3321 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003322
John McCall550e0c22009-10-21 00:40:46 +00003323 QualType Result = TL.getType();
3324 if (getDerived().AlwaysRebuild() ||
3325 Enum != T->getDecl()) {
3326 Result = getDerived().RebuildEnumType(Enum);
3327 if (Result.isNull())
3328 return QualType();
3329 }
Mike Stump11289f42009-09-09 15:08:12 +00003330
John McCall550e0c22009-10-21 00:40:46 +00003331 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3332 NewTL.setNameLoc(TL.getNameLoc());
3333
3334 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003335}
John McCallfcc33b02009-09-05 00:15:47 +00003336
John McCalle78aac42010-03-10 03:28:59 +00003337template<typename Derived>
3338QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3339 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003340 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003341 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3342 TL.getTypePtr()->getDecl());
3343 if (!D) return QualType();
3344
3345 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3346 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3347 return T;
3348}
3349
Mike Stump11289f42009-09-09 15:08:12 +00003350
Douglas Gregord6ff3322009-08-04 16:50:30 +00003351template<typename Derived>
3352QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003353 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003354 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003355 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003356}
3357
Mike Stump11289f42009-09-09 15:08:12 +00003358template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003359QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003360 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003361 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003362 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003363}
3364
3365template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003366QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003367 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003368 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003369 const TemplateSpecializationType *T = TL.getTypePtr();
3370
Mike Stump11289f42009-09-09 15:08:12 +00003371 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003372 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003373 if (Template.isNull())
3374 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003375
John McCall31f82722010-11-12 08:19:04 +00003376 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3377}
3378
3379template <typename Derived>
3380QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3381 TypeLocBuilder &TLB,
3382 TemplateSpecializationTypeLoc TL,
3383 TemplateName Template) {
3384 const TemplateSpecializationType *T = TL.getTypePtr();
3385
John McCall6b51f282009-11-23 01:53:49 +00003386 TemplateArgumentListInfo NewTemplateArgs;
3387 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3388 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor42cafa82010-12-20 17:42:22 +00003389 if (getDerived().TransformTemplateArgumentsFromArgLoc(TL, NewTemplateArgs))
3390 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003391
John McCall0ad16662009-10-29 08:12:44 +00003392 // FIXME: maybe don't rebuild if all the template arguments are the same.
3393
3394 QualType Result =
3395 getDerived().RebuildTemplateSpecializationType(Template,
3396 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003397 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003398
3399 if (!Result.isNull()) {
3400 TemplateSpecializationTypeLoc NewTL
3401 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3402 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3403 NewTL.setLAngleLoc(TL.getLAngleLoc());
3404 NewTL.setRAngleLoc(TL.getRAngleLoc());
3405 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3406 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003407 }
Mike Stump11289f42009-09-09 15:08:12 +00003408
John McCall0ad16662009-10-29 08:12:44 +00003409 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003410}
Mike Stump11289f42009-09-09 15:08:12 +00003411
3412template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003413QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003414TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003415 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003416 ElaboratedType *T = TL.getTypePtr();
3417
3418 NestedNameSpecifier *NNS = 0;
3419 // NOTE: the qualifier in an ElaboratedType is optional.
3420 if (T->getQualifier() != 0) {
3421 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003422 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003423 if (!NNS)
3424 return QualType();
3425 }
Mike Stump11289f42009-09-09 15:08:12 +00003426
John McCall31f82722010-11-12 08:19:04 +00003427 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3428 if (NamedT.isNull())
3429 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003430
John McCall550e0c22009-10-21 00:40:46 +00003431 QualType Result = TL.getType();
3432 if (getDerived().AlwaysRebuild() ||
3433 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003434 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003435 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3436 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003437 if (Result.isNull())
3438 return QualType();
3439 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003440
Abramo Bagnara6150c882010-05-11 21:36:43 +00003441 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003442 NewTL.setKeywordLoc(TL.getKeywordLoc());
3443 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003444
3445 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003446}
Mike Stump11289f42009-09-09 15:08:12 +00003447
3448template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00003449QualType
3450TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3451 ParenTypeLoc TL) {
3452 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3453 if (Inner.isNull())
3454 return QualType();
3455
3456 QualType Result = TL.getType();
3457 if (getDerived().AlwaysRebuild() ||
3458 Inner != TL.getInnerLoc().getType()) {
3459 Result = getDerived().RebuildParenType(Inner);
3460 if (Result.isNull())
3461 return QualType();
3462 }
3463
3464 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3465 NewTL.setLParenLoc(TL.getLParenLoc());
3466 NewTL.setRParenLoc(TL.getRParenLoc());
3467 return Result;
3468}
3469
3470template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003471QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003472 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003473 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003474
Douglas Gregord6ff3322009-08-04 16:50:30 +00003475 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003476 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003477 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003478 if (!NNS)
3479 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003480
John McCallc392f372010-06-11 00:33:02 +00003481 QualType Result
3482 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3483 T->getIdentifier(),
3484 TL.getKeywordLoc(),
3485 TL.getQualifierRange(),
3486 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003487 if (Result.isNull())
3488 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003489
Abramo Bagnarad7548482010-05-19 21:37:53 +00003490 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3491 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003492 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3493
Abramo Bagnarad7548482010-05-19 21:37:53 +00003494 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3495 NewTL.setKeywordLoc(TL.getKeywordLoc());
3496 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003497 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003498 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3499 NewTL.setKeywordLoc(TL.getKeywordLoc());
3500 NewTL.setQualifierRange(TL.getQualifierRange());
3501 NewTL.setNameLoc(TL.getNameLoc());
3502 }
John McCall550e0c22009-10-21 00:40:46 +00003503 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003504}
Mike Stump11289f42009-09-09 15:08:12 +00003505
Douglas Gregord6ff3322009-08-04 16:50:30 +00003506template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003507QualType TreeTransform<Derived>::
3508 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003509 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003510 DependentTemplateSpecializationType *T = TL.getTypePtr();
3511
3512 NestedNameSpecifier *NNS
3513 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003514 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003515 if (!NNS)
3516 return QualType();
3517
John McCall31f82722010-11-12 08:19:04 +00003518 return getDerived()
3519 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3520}
3521
3522template<typename Derived>
3523QualType TreeTransform<Derived>::
3524 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3525 DependentTemplateSpecializationTypeLoc TL,
3526 NestedNameSpecifier *NNS) {
3527 DependentTemplateSpecializationType *T = TL.getTypePtr();
3528
John McCallc392f372010-06-11 00:33:02 +00003529 TemplateArgumentListInfo NewTemplateArgs;
3530 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3531 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor42cafa82010-12-20 17:42:22 +00003532 if (getDerived().TransformTemplateArgumentsFromArgLoc(TL, NewTemplateArgs))
3533 return QualType();
John McCallc392f372010-06-11 00:33:02 +00003534
Douglas Gregora5614c52010-09-08 23:56:00 +00003535 QualType Result
3536 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3537 NNS,
3538 TL.getQualifierRange(),
3539 T->getIdentifier(),
3540 TL.getNameLoc(),
3541 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003542 if (Result.isNull())
3543 return QualType();
3544
3545 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3546 QualType NamedT = ElabT->getNamedType();
3547
3548 // Copy information relevant to the template specialization.
3549 TemplateSpecializationTypeLoc NamedTL
3550 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3551 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3552 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3553 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3554 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3555
3556 // Copy information relevant to the elaborated type.
3557 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3558 NewTL.setKeywordLoc(TL.getKeywordLoc());
3559 NewTL.setQualifierRange(TL.getQualifierRange());
3560 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003561 TypeLoc NewTL(Result, TL.getOpaqueData());
3562 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003563 }
3564 return Result;
3565}
3566
3567template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00003568QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3569 PackExpansionTypeLoc TL) {
3570 // FIXME: Implement!
3571 getSema().Diag(TL.getEllipsisLoc(),
3572 diag::err_pack_expansion_instantiation_unsupported);
3573 return QualType();
3574}
3575
3576template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003577QualType
3578TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003579 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003580 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003581 TLB.pushFullCopy(TL);
3582 return TL.getType();
3583}
3584
3585template<typename Derived>
3586QualType
3587TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003588 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003589 // ObjCObjectType is never dependent.
3590 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003591 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003592}
Mike Stump11289f42009-09-09 15:08:12 +00003593
3594template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003595QualType
3596TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003597 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003598 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003599 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003600 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003601}
3602
Douglas Gregord6ff3322009-08-04 16:50:30 +00003603//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003604// Statement transformation
3605//===----------------------------------------------------------------------===//
3606template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003607StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003608TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003609 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003610}
3611
3612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003613StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003614TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3615 return getDerived().TransformCompoundStmt(S, false);
3616}
3617
3618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003619StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003620TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003621 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003622 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003623 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003624 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003625 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3626 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003627 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003628 if (Result.isInvalid()) {
3629 // Immediately fail if this was a DeclStmt, since it's very
3630 // likely that this will cause problems for future statements.
3631 if (isa<DeclStmt>(*B))
3632 return StmtError();
3633
3634 // Otherwise, just keep processing substatements and fail later.
3635 SubStmtInvalid = true;
3636 continue;
3637 }
Mike Stump11289f42009-09-09 15:08:12 +00003638
Douglas Gregorebe10102009-08-20 07:17:43 +00003639 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3640 Statements.push_back(Result.takeAs<Stmt>());
3641 }
Mike Stump11289f42009-09-09 15:08:12 +00003642
John McCall1ababa62010-08-27 19:56:05 +00003643 if (SubStmtInvalid)
3644 return StmtError();
3645
Douglas Gregorebe10102009-08-20 07:17:43 +00003646 if (!getDerived().AlwaysRebuild() &&
3647 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003648 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003649
3650 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3651 move_arg(Statements),
3652 S->getRBracLoc(),
3653 IsStmtExpr);
3654}
Mike Stump11289f42009-09-09 15:08:12 +00003655
Douglas Gregorebe10102009-08-20 07:17:43 +00003656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003657StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003658TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003659 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003660 {
3661 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003662 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003663
Eli Friedman06577382009-11-19 03:14:00 +00003664 // Transform the left-hand case value.
3665 LHS = getDerived().TransformExpr(S->getLHS());
3666 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003667 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003668
Eli Friedman06577382009-11-19 03:14:00 +00003669 // Transform the right-hand case value (for the GNU case-range extension).
3670 RHS = getDerived().TransformExpr(S->getRHS());
3671 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003672 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003673 }
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregorebe10102009-08-20 07:17:43 +00003675 // Build the case statement.
3676 // Case statements are always rebuilt so that they will attached to their
3677 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003678 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003679 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003680 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003681 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003682 S->getColonLoc());
3683 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003684 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003685
Douglas Gregorebe10102009-08-20 07:17:43 +00003686 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003687 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003688 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003689 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003690
Douglas Gregorebe10102009-08-20 07:17:43 +00003691 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003692 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003693}
3694
3695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003696StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003697TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003698 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003699 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003700 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003701 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003702
Douglas Gregorebe10102009-08-20 07:17:43 +00003703 // Default statements are always rebuilt
3704 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003705 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003706}
Mike Stump11289f42009-09-09 15:08:12 +00003707
Douglas Gregorebe10102009-08-20 07:17:43 +00003708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003709StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003710TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003711 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003712 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003713 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003714
Douglas Gregorebe10102009-08-20 07:17:43 +00003715 // FIXME: Pass the real colon location in.
3716 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3717 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003718 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003719}
Mike Stump11289f42009-09-09 15:08:12 +00003720
Douglas Gregorebe10102009-08-20 07:17:43 +00003721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003722StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003723TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003724 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003725 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003726 VarDecl *ConditionVar = 0;
3727 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003728 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003729 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003730 getDerived().TransformDefinition(
3731 S->getConditionVariable()->getLocation(),
3732 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003733 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003734 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003735 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003736 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003737
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003738 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003739 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003740
3741 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003742 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003743 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003744 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003745 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003746 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003747 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003748
John McCallb268a282010-08-23 23:25:46 +00003749 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003750 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003751 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003752
John McCallb268a282010-08-23 23:25:46 +00003753 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3754 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003755 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003756
Douglas Gregorebe10102009-08-20 07:17:43 +00003757 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003758 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003759 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003760 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003761
Douglas Gregorebe10102009-08-20 07:17:43 +00003762 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003763 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003764 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003765 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003766
Douglas Gregorebe10102009-08-20 07:17:43 +00003767 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003768 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003769 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 Then.get() == S->getThen() &&
3771 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003772 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003773
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003774 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00003775 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00003776 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003777}
3778
3779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003780StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003781TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003783 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003784 VarDecl *ConditionVar = 0;
3785 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003786 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003787 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003788 getDerived().TransformDefinition(
3789 S->getConditionVariable()->getLocation(),
3790 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003791 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003792 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003793 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003794 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003795
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003796 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003797 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003798 }
Mike Stump11289f42009-09-09 15:08:12 +00003799
Douglas Gregorebe10102009-08-20 07:17:43 +00003800 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003801 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003802 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003803 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003804 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003805 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003806
Douglas Gregorebe10102009-08-20 07:17:43 +00003807 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003808 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003809 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003810 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003811
Douglas Gregorebe10102009-08-20 07:17:43 +00003812 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003813 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3814 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003815}
Mike Stump11289f42009-09-09 15:08:12 +00003816
Douglas Gregorebe10102009-08-20 07:17:43 +00003817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003818StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003819TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003820 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003821 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003822 VarDecl *ConditionVar = 0;
3823 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003824 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003825 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003826 getDerived().TransformDefinition(
3827 S->getConditionVariable()->getLocation(),
3828 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003829 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003830 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003831 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003832 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003833
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003834 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003835 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003836
3837 if (S->getCond()) {
3838 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003839 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003840 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003841 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003842 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003843 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003844 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003845 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003846 }
Mike Stump11289f42009-09-09 15:08:12 +00003847
John McCallb268a282010-08-23 23:25:46 +00003848 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3849 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003850 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003851
Douglas Gregorebe10102009-08-20 07:17:43 +00003852 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003853 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003854 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003855 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003856
Douglas Gregorebe10102009-08-20 07:17:43 +00003857 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003858 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003859 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003860 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003861 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003862
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003863 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003864 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003865}
Mike Stump11289f42009-09-09 15:08:12 +00003866
Douglas Gregorebe10102009-08-20 07:17:43 +00003867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003868StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003869TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003870 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003871 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003872 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003873 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003874
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003875 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003876 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003877 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003878 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003879
Douglas Gregorebe10102009-08-20 07:17:43 +00003880 if (!getDerived().AlwaysRebuild() &&
3881 Cond.get() == S->getCond() &&
3882 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003883 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003884
John McCallb268a282010-08-23 23:25:46 +00003885 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3886 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003887 S->getRParenLoc());
3888}
Mike Stump11289f42009-09-09 15:08:12 +00003889
Douglas Gregorebe10102009-08-20 07:17:43 +00003890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003891StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003892TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003893 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003894 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003895 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003896 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregorebe10102009-08-20 07:17:43 +00003898 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003899 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003900 VarDecl *ConditionVar = 0;
3901 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003902 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003903 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003904 getDerived().TransformDefinition(
3905 S->getConditionVariable()->getLocation(),
3906 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003907 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003908 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003909 } else {
3910 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003911
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003912 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003913 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003914
3915 if (S->getCond()) {
3916 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003917 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003918 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003919 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003920 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003921 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003922
John McCallb268a282010-08-23 23:25:46 +00003923 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003924 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003925 }
Mike Stump11289f42009-09-09 15:08:12 +00003926
John McCallb268a282010-08-23 23:25:46 +00003927 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3928 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003929 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003930
Douglas Gregorebe10102009-08-20 07:17:43 +00003931 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003932 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003933 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003934 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003935
John McCallb268a282010-08-23 23:25:46 +00003936 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3937 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003938 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003939
Douglas Gregorebe10102009-08-20 07:17:43 +00003940 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003941 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003942 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003943 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregorebe10102009-08-20 07:17:43 +00003945 if (!getDerived().AlwaysRebuild() &&
3946 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003947 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003948 Inc.get() == S->getInc() &&
3949 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003950 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregorebe10102009-08-20 07:17:43 +00003952 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003953 Init.get(), FullCond, ConditionVar,
3954 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003955}
3956
3957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003958StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003959TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003960 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003961 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003962 S->getLabel());
3963}
3964
3965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003966StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003967TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003968 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003969 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003970 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003971
Douglas Gregorebe10102009-08-20 07:17:43 +00003972 if (!getDerived().AlwaysRebuild() &&
3973 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003974 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003975
3976 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003977 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003978}
3979
3980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003981StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003982TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003983 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003984}
Mike Stump11289f42009-09-09 15:08:12 +00003985
Douglas Gregorebe10102009-08-20 07:17:43 +00003986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003987StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003988TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003989 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003990}
Mike Stump11289f42009-09-09 15:08:12 +00003991
Douglas Gregorebe10102009-08-20 07:17:43 +00003992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003993StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003994TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003995 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003996 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003997 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003998
Mike Stump11289f42009-09-09 15:08:12 +00003999 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004000 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004001 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004002}
Mike Stump11289f42009-09-09 15:08:12 +00004003
Douglas Gregorebe10102009-08-20 07:17:43 +00004004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004005StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004006TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004007 bool DeclChanged = false;
4008 llvm::SmallVector<Decl *, 4> Decls;
4009 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4010 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004011 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4012 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004013 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004014 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004015
Douglas Gregorebe10102009-08-20 07:17:43 +00004016 if (Transformed != *D)
4017 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004018
Douglas Gregorebe10102009-08-20 07:17:43 +00004019 Decls.push_back(Transformed);
4020 }
Mike Stump11289f42009-09-09 15:08:12 +00004021
Douglas Gregorebe10102009-08-20 07:17:43 +00004022 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004023 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004024
4025 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004026 S->getStartLoc(), S->getEndLoc());
4027}
Mike Stump11289f42009-09-09 15:08:12 +00004028
Douglas Gregorebe10102009-08-20 07:17:43 +00004029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004030StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004031TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004032 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004033 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004034}
4035
4036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004037StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004038TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004039
John McCall37ad5512010-08-23 06:44:23 +00004040 ASTOwningVector<Expr*> Constraints(getSema());
4041 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004042 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004043
John McCalldadc5752010-08-24 06:29:42 +00004044 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004045 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004046
4047 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004048
Anders Carlssonaaeef072010-01-24 05:50:09 +00004049 // Go through the outputs.
4050 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004051 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004052
Anders Carlssonaaeef072010-01-24 05:50:09 +00004053 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004054 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004055
Anders Carlssonaaeef072010-01-24 05:50:09 +00004056 // Transform the output expr.
4057 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004058 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004059 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004060 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004061
Anders Carlssonaaeef072010-01-24 05:50:09 +00004062 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004063
John McCallb268a282010-08-23 23:25:46 +00004064 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004065 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004066
Anders Carlssonaaeef072010-01-24 05:50:09 +00004067 // Go through the inputs.
4068 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004069 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004070
Anders Carlssonaaeef072010-01-24 05:50:09 +00004071 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004072 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004073
Anders Carlssonaaeef072010-01-24 05:50:09 +00004074 // Transform the input expr.
4075 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004076 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004077 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004078 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004079
Anders Carlssonaaeef072010-01-24 05:50:09 +00004080 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004081
John McCallb268a282010-08-23 23:25:46 +00004082 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004083 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004084
Anders Carlssonaaeef072010-01-24 05:50:09 +00004085 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004086 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004087
4088 // Go through the clobbers.
4089 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004090 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004091
4092 // No need to transform the asm string literal.
4093 AsmString = SemaRef.Owned(S->getAsmString());
4094
4095 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4096 S->isSimple(),
4097 S->isVolatile(),
4098 S->getNumOutputs(),
4099 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004100 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004101 move_arg(Constraints),
4102 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004103 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004104 move_arg(Clobbers),
4105 S->getRParenLoc(),
4106 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004107}
4108
4109
4110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004111StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004112TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004113 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004114 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004115 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004116 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004117
Douglas Gregor96c79492010-04-23 22:50:49 +00004118 // Transform the @catch statements (if present).
4119 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004120 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004121 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004122 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004123 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004124 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004125 if (Catch.get() != S->getCatchStmt(I))
4126 AnyCatchChanged = true;
4127 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004128 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004129
Douglas Gregor306de2f2010-04-22 23:59:56 +00004130 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004131 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004132 if (S->getFinallyStmt()) {
4133 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4134 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004135 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004136 }
4137
4138 // If nothing changed, just retain this statement.
4139 if (!getDerived().AlwaysRebuild() &&
4140 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004141 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004142 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004143 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004144
Douglas Gregor306de2f2010-04-22 23:59:56 +00004145 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004146 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4147 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004148}
Mike Stump11289f42009-09-09 15:08:12 +00004149
Douglas Gregorebe10102009-08-20 07:17:43 +00004150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004151StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004152TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004153 // Transform the @catch parameter, if there is one.
4154 VarDecl *Var = 0;
4155 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4156 TypeSourceInfo *TSInfo = 0;
4157 if (FromVar->getTypeSourceInfo()) {
4158 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4159 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004160 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004161 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004162
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004163 QualType T;
4164 if (TSInfo)
4165 T = TSInfo->getType();
4166 else {
4167 T = getDerived().TransformType(FromVar->getType());
4168 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004169 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004171
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004172 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4173 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004174 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004175 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004176
John McCalldadc5752010-08-24 06:29:42 +00004177 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004178 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004179 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004180
4181 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004182 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004183 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004184}
Mike Stump11289f42009-09-09 15:08:12 +00004185
Douglas Gregorebe10102009-08-20 07:17:43 +00004186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004187StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004188TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004189 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004190 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004191 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004192 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004193
Douglas Gregor306de2f2010-04-22 23:59:56 +00004194 // If nothing changed, just retain this statement.
4195 if (!getDerived().AlwaysRebuild() &&
4196 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004197 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004198
4199 // Build a new statement.
4200 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004201 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004202}
Mike Stump11289f42009-09-09 15:08:12 +00004203
Douglas Gregorebe10102009-08-20 07:17:43 +00004204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004205StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004206TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004207 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004208 if (S->getThrowExpr()) {
4209 Operand = getDerived().TransformExpr(S->getThrowExpr());
4210 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004211 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004212 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004213
Douglas Gregor2900c162010-04-22 21:44:01 +00004214 if (!getDerived().AlwaysRebuild() &&
4215 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004216 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004217
John McCallb268a282010-08-23 23:25:46 +00004218 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004219}
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregorebe10102009-08-20 07:17:43 +00004221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004222StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004223TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004224 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004225 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004226 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004227 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004228 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004229
Douglas Gregor6148de72010-04-22 22:01:21 +00004230 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004231 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004232 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004233 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004234
Douglas Gregor6148de72010-04-22 22:01:21 +00004235 // If nothing change, just retain the current statement.
4236 if (!getDerived().AlwaysRebuild() &&
4237 Object.get() == S->getSynchExpr() &&
4238 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004239 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004240
4241 // Build a new statement.
4242 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004243 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004244}
4245
4246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004247StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004248TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004249 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004250 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004251 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004252 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004253 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004254
Douglas Gregorf68a5082010-04-22 23:10:45 +00004255 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004256 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004257 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004258 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004259
Douglas Gregorf68a5082010-04-22 23:10:45 +00004260 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004261 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004262 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004263 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004264
Douglas Gregorf68a5082010-04-22 23:10:45 +00004265 // If nothing changed, just retain this statement.
4266 if (!getDerived().AlwaysRebuild() &&
4267 Element.get() == S->getElement() &&
4268 Collection.get() == S->getCollection() &&
4269 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004270 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004271
Douglas Gregorf68a5082010-04-22 23:10:45 +00004272 // Build a new statement.
4273 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4274 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004275 Element.get(),
4276 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004277 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004278 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004279}
4280
4281
4282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004283StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004284TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4285 // Transform the exception declaration, if any.
4286 VarDecl *Var = 0;
4287 if (S->getExceptionDecl()) {
4288 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004289 TypeSourceInfo *T = getDerived().TransformType(
4290 ExceptionDecl->getTypeSourceInfo());
4291 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004292 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004294 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004295 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004296 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004297 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004298 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004299 }
Mike Stump11289f42009-09-09 15:08:12 +00004300
Douglas Gregorebe10102009-08-20 07:17:43 +00004301 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004302 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004303 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004304 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004305
Douglas Gregorebe10102009-08-20 07:17:43 +00004306 if (!getDerived().AlwaysRebuild() &&
4307 !Var &&
4308 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004309 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004310
4311 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4312 Var,
John McCallb268a282010-08-23 23:25:46 +00004313 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004314}
Mike Stump11289f42009-09-09 15:08:12 +00004315
Douglas Gregorebe10102009-08-20 07:17:43 +00004316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004317StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004318TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4319 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004320 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004321 = getDerived().TransformCompoundStmt(S->getTryBlock());
4322 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004323 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregorebe10102009-08-20 07:17:43 +00004325 // Transform the handlers.
4326 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004327 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004328 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004329 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004330 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4331 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004332 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004333
Douglas Gregorebe10102009-08-20 07:17:43 +00004334 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4335 Handlers.push_back(Handler.takeAs<Stmt>());
4336 }
Mike Stump11289f42009-09-09 15:08:12 +00004337
Douglas Gregorebe10102009-08-20 07:17:43 +00004338 if (!getDerived().AlwaysRebuild() &&
4339 TryBlock.get() == S->getTryBlock() &&
4340 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004341 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004342
John McCallb268a282010-08-23 23:25:46 +00004343 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004344 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004345}
Mike Stump11289f42009-09-09 15:08:12 +00004346
Douglas Gregorebe10102009-08-20 07:17:43 +00004347//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004348// Expression transformation
4349//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004352TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004353 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004354}
Mike Stump11289f42009-09-09 15:08:12 +00004355
4356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004357ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004358TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004359 NestedNameSpecifier *Qualifier = 0;
4360 if (E->getQualifier()) {
4361 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004362 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004363 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004364 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004365 }
John McCallce546572009-12-08 09:08:17 +00004366
4367 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004368 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4369 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004370 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004371 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004372
John McCall815039a2010-08-17 21:27:17 +00004373 DeclarationNameInfo NameInfo = E->getNameInfo();
4374 if (NameInfo.getName()) {
4375 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4376 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004377 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004378 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004379
4380 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004381 Qualifier == E->getQualifier() &&
4382 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004383 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004384 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004385
4386 // Mark it referenced in the new context regardless.
4387 // FIXME: this is a bit instantiation-specific.
4388 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4389
John McCallc3007a22010-10-26 07:05:15 +00004390 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004391 }
John McCallce546572009-12-08 09:08:17 +00004392
4393 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004394 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004395 TemplateArgs = &TransArgs;
4396 TransArgs.setLAngleLoc(E->getLAngleLoc());
4397 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004398 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4399 E->getNumTemplateArgs(),
4400 TransArgs))
4401 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004402 }
4403
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004404 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004405 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004406}
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004410TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004411 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004412}
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregora16548e2009-08-11 05:31:07 +00004414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004416TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004417 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004418}
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregora16548e2009-08-11 05:31:07 +00004420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004422TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004423 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004424}
Mike Stump11289f42009-09-09 15:08:12 +00004425
Douglas Gregora16548e2009-08-11 05:31:07 +00004426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004428TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004429 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004430}
Mike Stump11289f42009-09-09 15:08:12 +00004431
Douglas Gregora16548e2009-08-11 05:31:07 +00004432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004434TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004435 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004436}
4437
4438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004440TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004441 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004444
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004446 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004447
John McCallb268a282010-08-23 23:25:46 +00004448 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004449 E->getRParen());
4450}
4451
Mike Stump11289f42009-09-09 15:08:12 +00004452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004453ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004454TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004455 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004458
Douglas Gregora16548e2009-08-11 05:31:07 +00004459 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004460 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004461
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4463 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004464 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004465}
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004468ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004469TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4470 // Transform the type.
4471 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4472 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004473 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004474
Douglas Gregor882211c2010-04-28 22:16:22 +00004475 // Transform all of the components into components similar to what the
4476 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004477 // FIXME: It would be slightly more efficient in the non-dependent case to
4478 // just map FieldDecls, rather than requiring the rebuilder to look for
4479 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004480 // template code that we don't care.
4481 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004482 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004483 typedef OffsetOfExpr::OffsetOfNode Node;
4484 llvm::SmallVector<Component, 4> Components;
4485 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4486 const Node &ON = E->getComponent(I);
4487 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004488 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004489 Comp.LocStart = ON.getRange().getBegin();
4490 Comp.LocEnd = ON.getRange().getEnd();
4491 switch (ON.getKind()) {
4492 case Node::Array: {
4493 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004494 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004495 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004496 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004497
Douglas Gregor882211c2010-04-28 22:16:22 +00004498 ExprChanged = ExprChanged || Index.get() != FromIndex;
4499 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004500 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004501 break;
4502 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004503
Douglas Gregor882211c2010-04-28 22:16:22 +00004504 case Node::Field:
4505 case Node::Identifier:
4506 Comp.isBrackets = false;
4507 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004508 if (!Comp.U.IdentInfo)
4509 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004510
Douglas Gregor882211c2010-04-28 22:16:22 +00004511 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004512
Douglas Gregord1702062010-04-29 00:18:15 +00004513 case Node::Base:
4514 // Will be recomputed during the rebuild.
4515 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004516 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004517
Douglas Gregor882211c2010-04-28 22:16:22 +00004518 Components.push_back(Comp);
4519 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004520
Douglas Gregor882211c2010-04-28 22:16:22 +00004521 // If nothing changed, retain the existing expression.
4522 if (!getDerived().AlwaysRebuild() &&
4523 Type == E->getTypeSourceInfo() &&
4524 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004525 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004526
Douglas Gregor882211c2010-04-28 22:16:22 +00004527 // Build a new offsetof expression.
4528 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4529 Components.data(), Components.size(),
4530 E->getRParenLoc());
4531}
4532
4533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004534ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004535TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4536 assert(getDerived().AlreadyTransformed(E->getType()) &&
4537 "opaque value expression requires transformation");
4538 return SemaRef.Owned(E);
4539}
4540
4541template<typename Derived>
4542ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004543TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004545 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004546
John McCallbcd03502009-12-07 02:54:59 +00004547 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004548 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004550
John McCall4c98fd82009-11-04 07:28:41 +00004551 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004552 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004553
John McCall4c98fd82009-11-04 07:28:41 +00004554 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004555 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004556 E->getSourceRange());
4557 }
Mike Stump11289f42009-09-09 15:08:12 +00004558
John McCalldadc5752010-08-24 06:29:42 +00004559 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004560 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 // C++0x [expr.sizeof]p1:
4562 // The operand is either an expression, which is an unevaluated operand
4563 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004564 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4567 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004571 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 }
Mike Stump11289f42009-09-09 15:08:12 +00004573
John McCallb268a282010-08-23 23:25:46 +00004574 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004575 E->isSizeOf(),
4576 E->getSourceRange());
4577}
Mike Stump11289f42009-09-09 15:08:12 +00004578
Douglas Gregora16548e2009-08-11 05:31:07 +00004579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004580ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004581TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004582 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004583 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004585
John McCalldadc5752010-08-24 06:29:42 +00004586 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004589
4590
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 if (!getDerived().AlwaysRebuild() &&
4592 LHS.get() == E->getLHS() &&
4593 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004594 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004595
John McCallb268a282010-08-23 23:25:46 +00004596 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004598 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004599 E->getRBracketLoc());
4600}
Mike Stump11289f42009-09-09 15:08:12 +00004601
4602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004603ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004604TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004605 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004606 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004608 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004609
4610 // Transform arguments.
4611 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004612 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004613 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004614 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004616 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004617
Mike Stump11289f42009-09-09 15:08:12 +00004618 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004619 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 }
Mike Stump11289f42009-09-09 15:08:12 +00004621
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 if (!getDerived().AlwaysRebuild() &&
4623 Callee.get() == E->getCallee() &&
4624 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004625 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004628 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004629 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004630 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004632 E->getRParenLoc());
4633}
Mike Stump11289f42009-09-09 15:08:12 +00004634
4635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004636ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004637TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004638 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004640 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004641
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004642 NestedNameSpecifier *Qualifier = 0;
4643 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004644 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004645 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004646 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004647 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004648 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004649 }
Mike Stump11289f42009-09-09 15:08:12 +00004650
Eli Friedman2cfcef62009-12-04 06:40:45 +00004651 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004652 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4653 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004654 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004656
John McCall16df1e52010-03-30 21:47:33 +00004657 NamedDecl *FoundDecl = E->getFoundDecl();
4658 if (FoundDecl == E->getMemberDecl()) {
4659 FoundDecl = Member;
4660 } else {
4661 FoundDecl = cast_or_null<NamedDecl>(
4662 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4663 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004664 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004665 }
4666
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 if (!getDerived().AlwaysRebuild() &&
4668 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004669 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004670 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004671 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004672 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004673
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004674 // Mark it referenced in the new context regardless.
4675 // FIXME: this is a bit instantiation-specific.
4676 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004677 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004678 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004679
John McCall6b51f282009-11-23 01:53:49 +00004680 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004681 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004682 TransArgs.setLAngleLoc(E->getLAngleLoc());
4683 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004684 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4685 E->getNumTemplateArgs(),
4686 TransArgs))
4687 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004688 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 // FIXME: Bogus source location for the operator
4691 SourceLocation FakeOperatorLoc
4692 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4693
John McCall38836f02010-01-15 08:34:02 +00004694 // FIXME: to do this check properly, we will need to preserve the
4695 // first-qualifier-in-scope here, just in case we had a dependent
4696 // base (and therefore couldn't do the check) and a
4697 // nested-name-qualifier (and therefore could do the lookup).
4698 NamedDecl *FirstQualifierInScope = 0;
4699
John McCallb268a282010-08-23 23:25:46 +00004700 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004702 Qualifier,
4703 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004704 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004705 Member,
John McCall16df1e52010-03-30 21:47:33 +00004706 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004707 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004708 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004709 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004710}
Mike Stump11289f42009-09-09 15:08:12 +00004711
Douglas Gregora16548e2009-08-11 05:31:07 +00004712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004714TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004715 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004718
John McCalldadc5752010-08-24 06:29:42 +00004719 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004720 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004722
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 if (!getDerived().AlwaysRebuild() &&
4724 LHS.get() == E->getLHS() &&
4725 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004726 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004729 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004730}
4731
Mike Stump11289f42009-09-09 15:08:12 +00004732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004733ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004734TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004735 CompoundAssignOperator *E) {
4736 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004737}
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregora16548e2009-08-11 05:31:07 +00004739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004741TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004742 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004744 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004745
John McCalldadc5752010-08-24 06:29:42 +00004746 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004749
John McCalldadc5752010-08-24 06:29:42 +00004750 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 if (!getDerived().AlwaysRebuild() &&
4755 Cond.get() == E->getCond() &&
4756 LHS.get() == E->getLHS() &&
4757 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004758 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004759
John McCallb268a282010-08-23 23:25:46 +00004760 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004761 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004762 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004763 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004764 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004765}
Mike Stump11289f42009-09-09 15:08:12 +00004766
4767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004768ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004769TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004770 // Implicit casts are eliminated during transformation, since they
4771 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004772 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004773}
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004777TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004778 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4779 if (!Type)
4780 return ExprError();
4781
John McCalldadc5752010-08-24 06:29:42 +00004782 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004783 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004788 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004789 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004790 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004791
John McCall97513962010-01-15 18:39:57 +00004792 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004793 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004795 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004796}
Mike Stump11289f42009-09-09 15:08:12 +00004797
Douglas Gregora16548e2009-08-11 05:31:07 +00004798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004799ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004800TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004801 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4802 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4803 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004805
John McCalldadc5752010-08-24 06:29:42 +00004806 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004809
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004811 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004813 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004814
John McCall5d7aa7f2010-01-19 22:33:45 +00004815 // Note: the expression type doesn't necessarily match the
4816 // type-as-written, but that's okay, because it should always be
4817 // derivable from the initializer.
4818
John McCalle15bbff2010-01-18 19:35:47 +00004819 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004821 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004822}
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregora16548e2009-08-11 05:31:07 +00004824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004826TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004827 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004828 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004829 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004830
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 if (!getDerived().AlwaysRebuild() &&
4832 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004833 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004834
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004836 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004838 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004839 E->getAccessorLoc(),
4840 E->getAccessor());
4841}
Mike Stump11289f42009-09-09 15:08:12 +00004842
Douglas Gregora16548e2009-08-11 05:31:07 +00004843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004844ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004845TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004846 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004847
John McCall37ad5512010-08-23 06:44:23 +00004848 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004849 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004850 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004851 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004855 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004856 }
Mike Stump11289f42009-09-09 15:08:12 +00004857
Douglas Gregora16548e2009-08-11 05:31:07 +00004858 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004859 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004862 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004863}
Mike Stump11289f42009-09-09 15:08:12 +00004864
Douglas Gregora16548e2009-08-11 05:31:07 +00004865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004867TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004868 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004869
Douglas Gregorebe10102009-08-20 07:17:43 +00004870 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004871 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004872 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregorebe10102009-08-20 07:17:43 +00004875 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004876 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 bool ExprChanged = false;
4878 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4879 DEnd = E->designators_end();
4880 D != DEnd; ++D) {
4881 if (D->isFieldDesignator()) {
4882 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4883 D->getDotLoc(),
4884 D->getFieldLoc()));
4885 continue;
4886 }
Mike Stump11289f42009-09-09 15:08:12 +00004887
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004889 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004890 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004892
4893 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4897 ArrayExprs.push_back(Index.release());
4898 continue;
4899 }
Mike Stump11289f42009-09-09 15:08:12 +00004900
Douglas Gregora16548e2009-08-11 05:31:07 +00004901 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004902 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4904 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004905 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004906
John McCalldadc5752010-08-24 06:29:42 +00004907 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004908 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004910
4911 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004912 End.get(),
4913 D->getLBracketLoc(),
4914 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004915
Douglas Gregora16548e2009-08-11 05:31:07 +00004916 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4917 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004918
Douglas Gregora16548e2009-08-11 05:31:07 +00004919 ArrayExprs.push_back(Start.release());
4920 ArrayExprs.push_back(End.release());
4921 }
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregora16548e2009-08-11 05:31:07 +00004923 if (!getDerived().AlwaysRebuild() &&
4924 Init.get() == E->getInit() &&
4925 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004926 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4929 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004930 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004931}
Mike Stump11289f42009-09-09 15:08:12 +00004932
Douglas Gregora16548e2009-08-11 05:31:07 +00004933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004934ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004935TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004936 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004937 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004938
Douglas Gregor3da3c062009-10-28 00:29:27 +00004939 // FIXME: Will we ever have proper type location here? Will we actually
4940 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004941 QualType T = getDerived().TransformType(E->getType());
4942 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004943 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregora16548e2009-08-11 05:31:07 +00004945 if (!getDerived().AlwaysRebuild() &&
4946 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004947 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004948
Douglas Gregora16548e2009-08-11 05:31:07 +00004949 return getDerived().RebuildImplicitValueInitExpr(T);
4950}
Mike Stump11289f42009-09-09 15:08:12 +00004951
Douglas Gregora16548e2009-08-11 05:31:07 +00004952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004953ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004954TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004955 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4956 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004958
John McCalldadc5752010-08-24 06:29:42 +00004959 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004960 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004961 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004962
Douglas Gregora16548e2009-08-11 05:31:07 +00004963 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004964 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004965 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004966 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004967
John McCallb268a282010-08-23 23:25:46 +00004968 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004969 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004970}
4971
4972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004973ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004974TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004975 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004976 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004977 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004978 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004979 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004983 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 }
Mike Stump11289f42009-09-09 15:08:12 +00004985
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4987 move_arg(Inits),
4988 E->getRParenLoc());
4989}
Mike Stump11289f42009-09-09 15:08:12 +00004990
Douglas Gregora16548e2009-08-11 05:31:07 +00004991/// \brief Transform an address-of-label expression.
4992///
4993/// By default, the transformation of an address-of-label expression always
4994/// rebuilds the expression, so that the label identifier can be resolved to
4995/// the corresponding label statement by semantic analysis.
4996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004997ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004998TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5000 E->getLabel());
5001}
Mike Stump11289f42009-09-09 15:08:12 +00005002
5003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005004ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005005TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005006 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005007 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5008 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 if (!getDerived().AlwaysRebuild() &&
5012 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005013 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005014
5015 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005016 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 E->getRParenLoc());
5018}
Mike Stump11289f42009-09-09 15:08:12 +00005019
Douglas Gregora16548e2009-08-11 05:31:07 +00005020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005021ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005022TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005023 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005025 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005026
John McCalldadc5752010-08-24 06:29:42 +00005027 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005029 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005030
John McCalldadc5752010-08-24 06:29:42 +00005031 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005033 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005034
Douglas Gregora16548e2009-08-11 05:31:07 +00005035 if (!getDerived().AlwaysRebuild() &&
5036 Cond.get() == E->getCond() &&
5037 LHS.get() == E->getLHS() &&
5038 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005039 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005040
Douglas Gregora16548e2009-08-11 05:31:07 +00005041 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005042 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 E->getRParenLoc());
5044}
Mike Stump11289f42009-09-09 15:08:12 +00005045
Douglas Gregora16548e2009-08-11 05:31:07 +00005046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005047ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005048TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005049 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005050}
5051
5052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005053ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005054TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005055 switch (E->getOperator()) {
5056 case OO_New:
5057 case OO_Delete:
5058 case OO_Array_New:
5059 case OO_Array_Delete:
5060 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005061 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005062
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005063 case OO_Call: {
5064 // This is a call to an object's operator().
5065 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5066
5067 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005068 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005069 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005070 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005071
5072 // FIXME: Poor location information
5073 SourceLocation FakeLParenLoc
5074 = SemaRef.PP.getLocForEndOfToken(
5075 static_cast<Expr *>(Object.get())->getLocEnd());
5076
5077 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005078 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005079 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00005080 if (getDerived().DropCallArgument(E->getArg(I)))
5081 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005082
John McCalldadc5752010-08-24 06:29:42 +00005083 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005084 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005085 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005086
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005087 Args.push_back(Arg.release());
5088 }
5089
John McCallb268a282010-08-23 23:25:46 +00005090 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005091 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005092 E->getLocEnd());
5093 }
5094
5095#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5096 case OO_##Name:
5097#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5098#include "clang/Basic/OperatorKinds.def"
5099 case OO_Subscript:
5100 // Handled below.
5101 break;
5102
5103 case OO_Conditional:
5104 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005105 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005106
5107 case OO_None:
5108 case NUM_OVERLOADED_OPERATORS:
5109 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005110 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005111 }
5112
John McCalldadc5752010-08-24 06:29:42 +00005113 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005114 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005115 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005116
John McCalldadc5752010-08-24 06:29:42 +00005117 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005119 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005120
John McCalldadc5752010-08-24 06:29:42 +00005121 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 if (E->getNumArgs() == 2) {
5123 Second = getDerived().TransformExpr(E->getArg(1));
5124 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005125 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 }
Mike Stump11289f42009-09-09 15:08:12 +00005127
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 if (!getDerived().AlwaysRebuild() &&
5129 Callee.get() == E->getCallee() &&
5130 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005131 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005132 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregora16548e2009-08-11 05:31:07 +00005134 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5135 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005136 Callee.get(),
5137 First.get(),
5138 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005139}
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregora16548e2009-08-11 05:31:07 +00005141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005143TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5144 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005145}
Mike Stump11289f42009-09-09 15:08:12 +00005146
Douglas Gregora16548e2009-08-11 05:31:07 +00005147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005149TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005150 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5151 if (!Type)
5152 return ExprError();
5153
John McCalldadc5752010-08-24 06:29:42 +00005154 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005155 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005157 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005158
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005160 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005162 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005165 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005166 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5167 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5168 SourceLocation FakeRParenLoc
5169 = SemaRef.PP.getLocForEndOfToken(
5170 E->getSubExpr()->getSourceRange().getEnd());
5171 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005172 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005174 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005175 FakeRAngleLoc,
5176 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005177 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005178 FakeRParenLoc);
5179}
Mike Stump11289f42009-09-09 15:08:12 +00005180
Douglas Gregora16548e2009-08-11 05:31:07 +00005181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005183TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5184 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005185}
Mike Stump11289f42009-09-09 15:08:12 +00005186
5187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005188ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005189TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5190 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005191}
5192
Douglas Gregora16548e2009-08-11 05:31:07 +00005193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005194ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005195TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005196 CXXReinterpretCastExpr *E) {
5197 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005198}
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregora16548e2009-08-11 05:31:07 +00005200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005202TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5203 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005204}
Mike Stump11289f42009-09-09 15:08:12 +00005205
Douglas Gregora16548e2009-08-11 05:31:07 +00005206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005207ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005208TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005209 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005210 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5211 if (!Type)
5212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005213
John McCalldadc5752010-08-24 06:29:42 +00005214 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005215 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005216 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005217 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005220 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005221 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005222 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005224 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005225 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005226 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005227 E->getRParenLoc());
5228}
Mike Stump11289f42009-09-09 15:08:12 +00005229
Douglas Gregora16548e2009-08-11 05:31:07 +00005230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005232TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005233 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005234 TypeSourceInfo *TInfo
5235 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5236 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005238
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005240 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005241 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregor9da64192010-04-26 22:37:10 +00005243 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5244 E->getLocStart(),
5245 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 E->getLocEnd());
5247 }
Mike Stump11289f42009-09-09 15:08:12 +00005248
Douglas Gregora16548e2009-08-11 05:31:07 +00005249 // We don't know whether the expression is potentially evaluated until
5250 // after we perform semantic analysis, so the expression is potentially
5251 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005252 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005253 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005254
John McCalldadc5752010-08-24 06:29:42 +00005255 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005257 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 if (!getDerived().AlwaysRebuild() &&
5260 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005261 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregor9da64192010-04-26 22:37:10 +00005263 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5264 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005265 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005266 E->getLocEnd());
5267}
5268
5269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005270ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005271TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5272 if (E->isTypeOperand()) {
5273 TypeSourceInfo *TInfo
5274 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5275 if (!TInfo)
5276 return ExprError();
5277
5278 if (!getDerived().AlwaysRebuild() &&
5279 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005280 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005281
5282 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5283 E->getLocStart(),
5284 TInfo,
5285 E->getLocEnd());
5286 }
5287
5288 // We don't know whether the expression is potentially evaluated until
5289 // after we perform semantic analysis, so the expression is potentially
5290 // potentially evaluated.
5291 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5292
5293 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5294 if (SubExpr.isInvalid())
5295 return ExprError();
5296
5297 if (!getDerived().AlwaysRebuild() &&
5298 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005299 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005300
5301 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5302 E->getLocStart(),
5303 SubExpr.get(),
5304 E->getLocEnd());
5305}
5306
5307template<typename Derived>
5308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005309TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005310 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005311}
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregora16548e2009-08-11 05:31:07 +00005313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005314ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005315TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005316 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005317 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005318}
Mike Stump11289f42009-09-09 15:08:12 +00005319
Douglas Gregora16548e2009-08-11 05:31:07 +00005320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005322TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005323 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5324 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5325 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005326
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005327 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005328 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005329
Douglas Gregorb15af892010-01-07 23:12:05 +00005330 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005331}
Mike Stump11289f42009-09-09 15:08:12 +00005332
Douglas Gregora16548e2009-08-11 05:31:07 +00005333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005334ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005335TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005336 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005337 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005339
Douglas Gregora16548e2009-08-11 05:31:07 +00005340 if (!getDerived().AlwaysRebuild() &&
5341 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005342 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005343
John McCallb268a282010-08-23 23:25:46 +00005344 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005345}
Mike Stump11289f42009-09-09 15:08:12 +00005346
Douglas Gregora16548e2009-08-11 05:31:07 +00005347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005349TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005350 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005351 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5352 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005353 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005355
Chandler Carruth794da4c2010-02-08 06:42:49 +00005356 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005357 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005358 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005359
Douglas Gregor033f6752009-12-23 23:03:06 +00005360 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005361}
Mike Stump11289f42009-09-09 15:08:12 +00005362
Douglas Gregora16548e2009-08-11 05:31:07 +00005363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005364ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005365TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5366 CXXScalarValueInitExpr *E) {
5367 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5368 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005369 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005370
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005372 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005373 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005374
Douglas Gregor2b88c112010-09-08 00:15:04 +00005375 return getDerived().RebuildCXXScalarValueInitExpr(T,
5376 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005377 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005378}
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregora16548e2009-08-11 05:31:07 +00005380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005382TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005383 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005384 TypeSourceInfo *AllocTypeInfo
5385 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5386 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005387 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005388
Douglas Gregora16548e2009-08-11 05:31:07 +00005389 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005390 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005391 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005392 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005393
Douglas Gregora16548e2009-08-11 05:31:07 +00005394 // Transform the placement arguments (if any).
5395 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005396 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005398 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5399 ArgumentChanged = true;
5400 break;
5401 }
5402
John McCalldadc5752010-08-24 06:29:42 +00005403 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005405 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005406
Douglas Gregora16548e2009-08-11 05:31:07 +00005407 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5408 PlacementArgs.push_back(Arg.take());
5409 }
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregorebe10102009-08-20 07:17:43 +00005411 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005412 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005413 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005414 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5415 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005416 break;
John McCall09d13692010-10-05 22:36:42 +00005417 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005418
John McCalldadc5752010-08-24 06:29:42 +00005419 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005420 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5424 ConstructorArgs.push_back(Arg.take());
5425 }
Mike Stump11289f42009-09-09 15:08:12 +00005426
Douglas Gregord2d9da02010-02-26 00:38:10 +00005427 // Transform constructor, new operator, and delete operator.
5428 CXXConstructorDecl *Constructor = 0;
5429 if (E->getConstructor()) {
5430 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005431 getDerived().TransformDecl(E->getLocStart(),
5432 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005433 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005435 }
5436
5437 FunctionDecl *OperatorNew = 0;
5438 if (E->getOperatorNew()) {
5439 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005440 getDerived().TransformDecl(E->getLocStart(),
5441 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005442 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005444 }
5445
5446 FunctionDecl *OperatorDelete = 0;
5447 if (E->getOperatorDelete()) {
5448 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005449 getDerived().TransformDecl(E->getLocStart(),
5450 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005451 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005452 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005453 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005454
Douglas Gregora16548e2009-08-11 05:31:07 +00005455 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005456 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005458 Constructor == E->getConstructor() &&
5459 OperatorNew == E->getOperatorNew() &&
5460 OperatorDelete == E->getOperatorDelete() &&
5461 !ArgumentChanged) {
5462 // Mark any declarations we need as referenced.
5463 // FIXME: instantiation-specific.
5464 if (Constructor)
5465 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5466 if (OperatorNew)
5467 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5468 if (OperatorDelete)
5469 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005470 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005471 }
Mike Stump11289f42009-09-09 15:08:12 +00005472
Douglas Gregor0744ef62010-09-07 21:49:58 +00005473 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005474 if (!ArraySize.get()) {
5475 // If no array size was specified, but the new expression was
5476 // instantiated with an array type (e.g., "new T" where T is
5477 // instantiated with "int[4]"), extract the outer bound from the
5478 // array type as our array size. We do this with constant and
5479 // dependently-sized array types.
5480 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5481 if (!ArrayT) {
5482 // Do nothing
5483 } else if (const ConstantArrayType *ConsArrayT
5484 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005485 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005486 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5487 ConsArrayT->getSize(),
5488 SemaRef.Context.getSizeType(),
5489 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005490 AllocType = ConsArrayT->getElementType();
5491 } else if (const DependentSizedArrayType *DepArrayT
5492 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5493 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005494 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005495 AllocType = DepArrayT->getElementType();
5496 }
5497 }
5498 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005499
Douglas Gregora16548e2009-08-11 05:31:07 +00005500 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5501 E->isGlobalNew(),
5502 /*FIXME:*/E->getLocStart(),
5503 move_arg(PlacementArgs),
5504 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005505 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005506 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005507 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005508 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005509 /*FIXME:*/E->getLocStart(),
5510 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005511 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005512}
Mike Stump11289f42009-09-09 15:08:12 +00005513
Douglas Gregora16548e2009-08-11 05:31:07 +00005514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005516TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005517 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005519 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005520
Douglas Gregord2d9da02010-02-26 00:38:10 +00005521 // Transform the delete operator, if known.
5522 FunctionDecl *OperatorDelete = 0;
5523 if (E->getOperatorDelete()) {
5524 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005525 getDerived().TransformDecl(E->getLocStart(),
5526 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005527 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005528 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005529 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005532 Operand.get() == E->getArgument() &&
5533 OperatorDelete == E->getOperatorDelete()) {
5534 // Mark any declarations we need as referenced.
5535 // FIXME: instantiation-specific.
5536 if (OperatorDelete)
5537 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005538
5539 if (!E->getArgument()->isTypeDependent()) {
5540 QualType Destroyed = SemaRef.Context.getBaseElementType(
5541 E->getDestroyedType());
5542 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5543 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5544 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5545 SemaRef.LookupDestructor(Record));
5546 }
5547 }
5548
John McCallc3007a22010-10-26 07:05:15 +00005549 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005550 }
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5553 E->isGlobalDelete(),
5554 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005555 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005556}
Mike Stump11289f42009-09-09 15:08:12 +00005557
Douglas Gregora16548e2009-08-11 05:31:07 +00005558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005559ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005560TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005561 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005562 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005563 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005565
John McCallba7bf592010-08-24 05:47:05 +00005566 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005567 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005568 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005569 E->getOperatorLoc(),
5570 E->isArrow()? tok::arrow : tok::period,
5571 ObjectTypePtr,
5572 MayBePseudoDestructor);
5573 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005575
John McCallba7bf592010-08-24 05:47:05 +00005576 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005577 NestedNameSpecifier *Qualifier = E->getQualifier();
5578 if (Qualifier) {
5579 Qualifier
5580 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5581 E->getQualifierRange(),
5582 ObjectType);
5583 if (!Qualifier)
5584 return ExprError();
5585 }
Mike Stump11289f42009-09-09 15:08:12 +00005586
Douglas Gregor678f90d2010-02-25 01:56:36 +00005587 PseudoDestructorTypeStorage Destroyed;
5588 if (E->getDestroyedTypeInfo()) {
5589 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005590 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5591 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005592 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005593 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005594 Destroyed = DestroyedTypeInfo;
5595 } else if (ObjectType->isDependentType()) {
5596 // We aren't likely to be able to resolve the identifier down to a type
5597 // now anyway, so just retain the identifier.
5598 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5599 E->getDestroyedTypeLoc());
5600 } else {
5601 // Look for a destructor known with the given name.
5602 CXXScopeSpec SS;
5603 if (Qualifier) {
5604 SS.setScopeRep(Qualifier);
5605 SS.setRange(E->getQualifierRange());
5606 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005607
John McCallba7bf592010-08-24 05:47:05 +00005608 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005609 *E->getDestroyedTypeIdentifier(),
5610 E->getDestroyedTypeLoc(),
5611 /*Scope=*/0,
5612 SS, ObjectTypePtr,
5613 false);
5614 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005616
Douglas Gregor678f90d2010-02-25 01:56:36 +00005617 Destroyed
5618 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5619 E->getDestroyedTypeLoc());
5620 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005621
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005622 TypeSourceInfo *ScopeTypeInfo = 0;
5623 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005624 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005625 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005626 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005627 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005628
John McCallb268a282010-08-23 23:25:46 +00005629 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005630 E->getOperatorLoc(),
5631 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005632 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005633 E->getQualifierRange(),
5634 ScopeTypeInfo,
5635 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005636 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005637 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005638}
Mike Stump11289f42009-09-09 15:08:12 +00005639
Douglas Gregorad8a3362009-09-04 17:36:40 +00005640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005641ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005642TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005643 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005644 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5645
5646 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5647 Sema::LookupOrdinaryName);
5648
5649 // Transform all the decls.
5650 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5651 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005652 NamedDecl *InstD = static_cast<NamedDecl*>(
5653 getDerived().TransformDecl(Old->getNameLoc(),
5654 *I));
John McCall84d87672009-12-10 09:41:52 +00005655 if (!InstD) {
5656 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5657 // This can happen because of dependent hiding.
5658 if (isa<UsingShadowDecl>(*I))
5659 continue;
5660 else
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005662 }
John McCalle66edc12009-11-24 19:00:30 +00005663
5664 // Expand using declarations.
5665 if (isa<UsingDecl>(InstD)) {
5666 UsingDecl *UD = cast<UsingDecl>(InstD);
5667 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5668 E = UD->shadow_end(); I != E; ++I)
5669 R.addDecl(*I);
5670 continue;
5671 }
5672
5673 R.addDecl(InstD);
5674 }
5675
5676 // Resolve a kind, but don't do any further analysis. If it's
5677 // ambiguous, the callee needs to deal with it.
5678 R.resolveKind();
5679
5680 // Rebuild the nested-name qualifier, if present.
5681 CXXScopeSpec SS;
5682 NestedNameSpecifier *Qualifier = 0;
5683 if (Old->getQualifier()) {
5684 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005685 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005686 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005687 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005688
John McCalle66edc12009-11-24 19:00:30 +00005689 SS.setScopeRep(Qualifier);
5690 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005691 }
5692
Douglas Gregor9262f472010-04-27 18:19:34 +00005693 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005694 CXXRecordDecl *NamingClass
5695 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5696 Old->getNameLoc(),
5697 Old->getNamingClass()));
5698 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005699 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005700
Douglas Gregorda7be082010-04-27 16:10:10 +00005701 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005702 }
5703
5704 // If we have no template arguments, it's a normal declaration name.
5705 if (!Old->hasExplicitTemplateArgs())
5706 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5707
5708 // If we have template arguments, rebuild them, then rebuild the
5709 // templateid expression.
5710 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005711 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
5712 Old->getNumTemplateArgs(),
5713 TransArgs))
5714 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005715
5716 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5717 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005718}
Mike Stump11289f42009-09-09 15:08:12 +00005719
Douglas Gregora16548e2009-08-11 05:31:07 +00005720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005722TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005723 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5724 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005726
Douglas Gregora16548e2009-08-11 05:31:07 +00005727 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005728 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005729 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005730
Mike Stump11289f42009-09-09 15:08:12 +00005731 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 T,
5734 E->getLocEnd());
5735}
Mike Stump11289f42009-09-09 15:08:12 +00005736
Douglas Gregora16548e2009-08-11 05:31:07 +00005737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005738ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00005739TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
5740 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
5741 if (!LhsT)
5742 return ExprError();
5743
5744 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
5745 if (!RhsT)
5746 return ExprError();
5747
5748 if (!getDerived().AlwaysRebuild() &&
5749 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
5750 return SemaRef.Owned(E);
5751
5752 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
5753 E->getLocStart(),
5754 LhsT, RhsT,
5755 E->getLocEnd());
5756}
5757
5758template<typename Derived>
5759ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005760TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005761 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005762 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005763 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005764 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005765 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005767
John McCall31f82722010-11-12 08:19:04 +00005768 // TODO: If this is a conversion-function-id, verify that the
5769 // destination type name (if present) resolves the same way after
5770 // instantiation as it did in the local scope.
5771
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005772 DeclarationNameInfo NameInfo
5773 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5774 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005776
John McCalle66edc12009-11-24 19:00:30 +00005777 if (!E->hasExplicitTemplateArgs()) {
5778 if (!getDerived().AlwaysRebuild() &&
5779 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005780 // Note: it is sufficient to compare the Name component of NameInfo:
5781 // if name has not changed, DNLoc has not changed either.
5782 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005783 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005784
John McCalle66edc12009-11-24 19:00:30 +00005785 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5786 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005787 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005788 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005789 }
John McCall6b51f282009-11-23 01:53:49 +00005790
5791 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005792 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5793 E->getNumTemplateArgs(),
5794 TransArgs))
5795 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005796
John McCalle66edc12009-11-24 19:00:30 +00005797 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5798 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005799 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005800 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005801}
5802
5803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005806 // CXXConstructExprs are always implicit, so when we have a
5807 // 1-argument construction we just transform that argument.
5808 if (E->getNumArgs() == 1 ||
5809 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5810 return getDerived().TransformExpr(E->getArg(0));
5811
Douglas Gregora16548e2009-08-11 05:31:07 +00005812 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5813
5814 QualType T = getDerived().TransformType(E->getType());
5815 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005816 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005817
5818 CXXConstructorDecl *Constructor
5819 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005820 getDerived().TransformDecl(E->getLocStart(),
5821 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005822 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005823 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005824
Douglas Gregora16548e2009-08-11 05:31:07 +00005825 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005826 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005827 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 ArgEnd = E->arg_end();
5829 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005830 if (getDerived().DropCallArgument(*Arg)) {
5831 ArgumentChanged = true;
5832 break;
5833 }
5834
John McCalldadc5752010-08-24 06:29:42 +00005835 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005836 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005838
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005840 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 }
5842
5843 if (!getDerived().AlwaysRebuild() &&
5844 T == E->getType() &&
5845 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005846 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005847 // Mark the constructor as referenced.
5848 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005849 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005850 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005851 }
Mike Stump11289f42009-09-09 15:08:12 +00005852
Douglas Gregordb121ba2009-12-14 16:27:04 +00005853 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5854 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005855 move_arg(Args),
5856 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005857 E->getConstructionKind(),
5858 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005859}
Mike Stump11289f42009-09-09 15:08:12 +00005860
Douglas Gregora16548e2009-08-11 05:31:07 +00005861/// \brief Transform a C++ temporary-binding expression.
5862///
Douglas Gregor363b1512009-12-24 18:51:59 +00005863/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5864/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005867TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005868 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005869}
Mike Stump11289f42009-09-09 15:08:12 +00005870
John McCall5d413782010-12-06 08:20:24 +00005871/// \brief Transform a C++ expression that contains cleanups that should
5872/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00005873///
John McCall5d413782010-12-06 08:20:24 +00005874/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00005875/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005877ExprResult
John McCall5d413782010-12-06 08:20:24 +00005878TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005879 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005880}
Mike Stump11289f42009-09-09 15:08:12 +00005881
Douglas Gregora16548e2009-08-11 05:31:07 +00005882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005883ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005884TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005885 CXXTemporaryObjectExpr *E) {
5886 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5887 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
Douglas Gregora16548e2009-08-11 05:31:07 +00005890 CXXConstructorDecl *Constructor
5891 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005892 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005893 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005894 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005895 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005896
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005898 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005900 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 ArgEnd = E->arg_end();
5902 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005903 if (getDerived().DropCallArgument(*Arg)) {
5904 ArgumentChanged = true;
5905 break;
5906 }
5907
John McCalldadc5752010-08-24 06:29:42 +00005908 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005909 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005910 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005911
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5913 Args.push_back((Expr *)TransArg.release());
5914 }
Mike Stump11289f42009-09-09 15:08:12 +00005915
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005917 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005918 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005919 !ArgumentChanged) {
5920 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005921 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005922 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005923 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005924
5925 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5926 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 E->getLocEnd());
5929}
Mike Stump11289f42009-09-09 15:08:12 +00005930
Douglas Gregora16548e2009-08-11 05:31:07 +00005931template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005932ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005933TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005934 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005935 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5936 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregora16548e2009-08-11 05:31:07 +00005939 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005940 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005941 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5942 ArgEnd = E->arg_end();
5943 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005944 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005945 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005946 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005947
Douglas Gregora16548e2009-08-11 05:31:07 +00005948 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005949 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005950 }
Mike Stump11289f42009-09-09 15:08:12 +00005951
Douglas Gregora16548e2009-08-11 05:31:07 +00005952 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005953 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005954 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005955 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005956
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005958 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005959 E->getLParenLoc(),
5960 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005961 E->getRParenLoc());
5962}
Mike Stump11289f42009-09-09 15:08:12 +00005963
Douglas Gregora16548e2009-08-11 05:31:07 +00005964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005965ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005966TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005967 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005968 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005969 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005970 Expr *OldBase;
5971 QualType BaseType;
5972 QualType ObjectType;
5973 if (!E->isImplicitAccess()) {
5974 OldBase = E->getBase();
5975 Base = getDerived().TransformExpr(OldBase);
5976 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005978
John McCall2d74de92009-12-01 22:10:20 +00005979 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005980 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005981 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005982 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005983 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005984 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005985 ObjectTy,
5986 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005987 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005989
John McCallba7bf592010-08-24 05:47:05 +00005990 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005991 BaseType = ((Expr*) Base.get())->getType();
5992 } else {
5993 OldBase = 0;
5994 BaseType = getDerived().TransformType(E->getBaseType());
5995 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5996 }
Mike Stump11289f42009-09-09 15:08:12 +00005997
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005998 // Transform the first part of the nested-name-specifier that qualifies
5999 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006000 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006001 = getDerived().TransformFirstQualifierInScope(
6002 E->getFirstQualifierFoundInScope(),
6003 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006004
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006005 NestedNameSpecifier *Qualifier = 0;
6006 if (E->getQualifier()) {
6007 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6008 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006009 ObjectType,
6010 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006011 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006013 }
Mike Stump11289f42009-09-09 15:08:12 +00006014
John McCall31f82722010-11-12 08:19:04 +00006015 // TODO: If this is a conversion-function-id, verify that the
6016 // destination type name (if present) resolves the same way after
6017 // instantiation as it did in the local scope.
6018
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006019 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006020 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006021 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006023
John McCall2d74de92009-12-01 22:10:20 +00006024 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006025 // This is a reference to a member without an explicitly-specified
6026 // template argument list. Optimize for this common case.
6027 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006028 Base.get() == OldBase &&
6029 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006030 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006031 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006032 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006033 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006034
John McCallb268a282010-08-23 23:25:46 +00006035 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006036 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006037 E->isArrow(),
6038 E->getOperatorLoc(),
6039 Qualifier,
6040 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006041 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006042 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006043 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006044 }
6045
John McCall6b51f282009-11-23 01:53:49 +00006046 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006047 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6048 E->getNumTemplateArgs(),
6049 TransArgs))
6050 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006051
John McCallb268a282010-08-23 23:25:46 +00006052 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006053 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006054 E->isArrow(),
6055 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006056 Qualifier,
6057 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006058 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006059 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006060 &TransArgs);
6061}
6062
6063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006064ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006065TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006066 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006067 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006068 QualType BaseType;
6069 if (!Old->isImplicitAccess()) {
6070 Base = getDerived().TransformExpr(Old->getBase());
6071 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006073 BaseType = ((Expr*) Base.get())->getType();
6074 } else {
6075 BaseType = getDerived().TransformType(Old->getBaseType());
6076 }
John McCall10eae182009-11-30 22:42:35 +00006077
6078 NestedNameSpecifier *Qualifier = 0;
6079 if (Old->getQualifier()) {
6080 Qualifier
6081 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006082 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006083 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006084 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006085 }
6086
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006087 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006088 Sema::LookupOrdinaryName);
6089
6090 // Transform all the decls.
6091 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6092 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006093 NamedDecl *InstD = static_cast<NamedDecl*>(
6094 getDerived().TransformDecl(Old->getMemberLoc(),
6095 *I));
John McCall84d87672009-12-10 09:41:52 +00006096 if (!InstD) {
6097 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6098 // This can happen because of dependent hiding.
6099 if (isa<UsingShadowDecl>(*I))
6100 continue;
6101 else
John McCallfaf5fb42010-08-26 23:41:50 +00006102 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006103 }
John McCall10eae182009-11-30 22:42:35 +00006104
6105 // Expand using declarations.
6106 if (isa<UsingDecl>(InstD)) {
6107 UsingDecl *UD = cast<UsingDecl>(InstD);
6108 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6109 E = UD->shadow_end(); I != E; ++I)
6110 R.addDecl(*I);
6111 continue;
6112 }
6113
6114 R.addDecl(InstD);
6115 }
6116
6117 R.resolveKind();
6118
Douglas Gregor9262f472010-04-27 18:19:34 +00006119 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006120 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006121 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006122 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006123 Old->getMemberLoc(),
6124 Old->getNamingClass()));
6125 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006126 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006127
Douglas Gregorda7be082010-04-27 16:10:10 +00006128 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006129 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006130
John McCall10eae182009-11-30 22:42:35 +00006131 TemplateArgumentListInfo TransArgs;
6132 if (Old->hasExplicitTemplateArgs()) {
6133 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6134 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006135 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6136 Old->getNumTemplateArgs(),
6137 TransArgs))
6138 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006139 }
John McCall38836f02010-01-15 08:34:02 +00006140
6141 // FIXME: to do this check properly, we will need to preserve the
6142 // first-qualifier-in-scope here, just in case we had a dependent
6143 // base (and therefore couldn't do the check) and a
6144 // nested-name-qualifier (and therefore could do the lookup).
6145 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006146
John McCallb268a282010-08-23 23:25:46 +00006147 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006148 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006149 Old->getOperatorLoc(),
6150 Old->isArrow(),
6151 Qualifier,
6152 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006153 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006154 R,
6155 (Old->hasExplicitTemplateArgs()
6156 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006157}
6158
6159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006160ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006161TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6162 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6163 if (SubExpr.isInvalid())
6164 return ExprError();
6165
6166 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006167 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006168
6169 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6170}
6171
6172template<typename Derived>
6173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006174TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006175 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006176}
6177
Mike Stump11289f42009-09-09 15:08:12 +00006178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006180TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006181 TypeSourceInfo *EncodedTypeInfo
6182 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6183 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006184 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006185
Douglas Gregora16548e2009-08-11 05:31:07 +00006186 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006187 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006188 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006189
6190 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006191 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006192 E->getRParenLoc());
6193}
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregora16548e2009-08-11 05:31:07 +00006195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006196ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006197TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006198 // Transform arguments.
6199 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006200 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006201 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006202 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006203 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006204 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006205
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006206 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006207 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006208 }
6209
6210 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6211 // Class message: transform the receiver type.
6212 TypeSourceInfo *ReceiverTypeInfo
6213 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6214 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006215 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006216
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006217 // If nothing changed, just retain the existing message send.
6218 if (!getDerived().AlwaysRebuild() &&
6219 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006220 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006221
6222 // Build a new class message send.
6223 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6224 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006225 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006226 E->getMethodDecl(),
6227 E->getLeftLoc(),
6228 move_arg(Args),
6229 E->getRightLoc());
6230 }
6231
6232 // Instance message: transform the receiver
6233 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6234 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006235 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006236 = getDerived().TransformExpr(E->getInstanceReceiver());
6237 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006238 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006239
6240 // If nothing changed, just retain the existing message send.
6241 if (!getDerived().AlwaysRebuild() &&
6242 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006243 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006244
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006245 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006246 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006247 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006248 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006249 E->getMethodDecl(),
6250 E->getLeftLoc(),
6251 move_arg(Args),
6252 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006253}
6254
Mike Stump11289f42009-09-09 15:08:12 +00006255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006257TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006258 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006259}
6260
Mike Stump11289f42009-09-09 15:08:12 +00006261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006262ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006263TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006264 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006265}
6266
Mike Stump11289f42009-09-09 15:08:12 +00006267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006269TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006270 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006271 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006272 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006273 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006274
6275 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006276
Douglas Gregord51d90d2010-04-26 20:11:03 +00006277 // If nothing changed, just retain the existing expression.
6278 if (!getDerived().AlwaysRebuild() &&
6279 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006280 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006281
John McCallb268a282010-08-23 23:25:46 +00006282 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006283 E->getLocation(),
6284 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006285}
6286
Mike Stump11289f42009-09-09 15:08:12 +00006287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006289TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006290 // 'super' and types never change. Property never changes. Just
6291 // retain the existing expression.
6292 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006293 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006294
Douglas Gregor9faee212010-04-26 20:47:02 +00006295 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006296 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006297 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006298 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006299
Douglas Gregor9faee212010-04-26 20:47:02 +00006300 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006301
Douglas Gregor9faee212010-04-26 20:47:02 +00006302 // If nothing changed, just retain the existing expression.
6303 if (!getDerived().AlwaysRebuild() &&
6304 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006306
John McCallb7bd14f2010-12-02 01:19:52 +00006307 if (E->isExplicitProperty())
6308 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6309 E->getExplicitProperty(),
6310 E->getLocation());
6311
6312 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6313 E->getType(),
6314 E->getImplicitPropertyGetter(),
6315 E->getImplicitPropertySetter(),
6316 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006317}
6318
Mike Stump11289f42009-09-09 15:08:12 +00006319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006320ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006321TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006322 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006323 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006324 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006325 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006326
Douglas Gregord51d90d2010-04-26 20:11:03 +00006327 // If nothing changed, just retain the existing expression.
6328 if (!getDerived().AlwaysRebuild() &&
6329 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006330 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006331
John McCallb268a282010-08-23 23:25:46 +00006332 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006333 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006334}
6335
Mike Stump11289f42009-09-09 15:08:12 +00006336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006337ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006338TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006340 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006341 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006342 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006343 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006345
Douglas Gregora16548e2009-08-11 05:31:07 +00006346 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006347 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006348 }
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 if (!getDerived().AlwaysRebuild() &&
6351 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006352 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006353
Douglas Gregora16548e2009-08-11 05:31:07 +00006354 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6355 move_arg(SubExprs),
6356 E->getRParenLoc());
6357}
6358
Mike Stump11289f42009-09-09 15:08:12 +00006359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006360ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006361TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006362 SourceLocation CaretLoc(E->getExprLoc());
6363
6364 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6365 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6366 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6367 llvm::SmallVector<ParmVarDecl*, 4> Params;
6368 llvm::SmallVector<QualType, 4> ParamTypes;
6369
6370 // Parameter substitution.
6371 const BlockDecl *BD = E->getBlockDecl();
6372 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6373 EN = BD->param_end(); P != EN; ++P) {
6374 ParmVarDecl *OldParm = (*P);
6375 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6376 QualType NewType = NewParm->getType();
6377 Params.push_back(NewParm);
6378 ParamTypes.push_back(NewParm->getType());
6379 }
6380
6381 const FunctionType *BExprFunctionType = E->getFunctionType();
6382 QualType BExprResultType = BExprFunctionType->getResultType();
6383 if (!BExprResultType.isNull()) {
6384 if (!BExprResultType->isDependentType())
6385 CurBlock->ReturnType = BExprResultType;
6386 else if (BExprResultType != SemaRef.Context.DependentTy)
6387 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6388 }
6389
6390 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006391 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006392 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006393 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006394 // Set the parameters on the block decl.
6395 if (!Params.empty())
6396 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6397
6398 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6399 CurBlock->ReturnType,
6400 ParamTypes.data(),
6401 ParamTypes.size(),
6402 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006403 0,
6404 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006405
6406 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006407 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006408}
6409
Mike Stump11289f42009-09-09 15:08:12 +00006410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006411ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006412TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006413 NestedNameSpecifier *Qualifier = 0;
6414
6415 ValueDecl *ND
6416 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6417 E->getDecl()));
6418 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006419 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006420
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006421 if (!getDerived().AlwaysRebuild() &&
6422 ND == E->getDecl()) {
6423 // Mark it referenced in the new context regardless.
6424 // FIXME: this is a bit instantiation-specific.
6425 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6426
John McCallc3007a22010-10-26 07:05:15 +00006427 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006428 }
6429
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006430 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006431 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006432 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006433}
Mike Stump11289f42009-09-09 15:08:12 +00006434
Douglas Gregora16548e2009-08-11 05:31:07 +00006435//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006436// Type reconstruction
6437//===----------------------------------------------------------------------===//
6438
Mike Stump11289f42009-09-09 15:08:12 +00006439template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006440QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6441 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006442 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006443 getDerived().getBaseEntity());
6444}
6445
Mike Stump11289f42009-09-09 15:08:12 +00006446template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006447QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6448 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006449 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006450 getDerived().getBaseEntity());
6451}
6452
Mike Stump11289f42009-09-09 15:08:12 +00006453template<typename Derived>
6454QualType
John McCall70dd5f62009-10-30 00:06:24 +00006455TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6456 bool WrittenAsLValue,
6457 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006458 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006459 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006460}
6461
6462template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006463QualType
John McCall70dd5f62009-10-30 00:06:24 +00006464TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6465 QualType ClassType,
6466 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006467 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006468 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006469}
6470
6471template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006472QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006473TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6474 ArrayType::ArraySizeModifier SizeMod,
6475 const llvm::APInt *Size,
6476 Expr *SizeExpr,
6477 unsigned IndexTypeQuals,
6478 SourceRange BracketsRange) {
6479 if (SizeExpr || !Size)
6480 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6481 IndexTypeQuals, BracketsRange,
6482 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006483
6484 QualType Types[] = {
6485 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6486 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6487 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006488 };
6489 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6490 QualType SizeType;
6491 for (unsigned I = 0; I != NumTypes; ++I)
6492 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6493 SizeType = Types[I];
6494 break;
6495 }
Mike Stump11289f42009-09-09 15:08:12 +00006496
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006497 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6498 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006499 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006500 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006501 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006502}
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregord6ff3322009-08-04 16:50:30 +00006504template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006505QualType
6506TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006507 ArrayType::ArraySizeModifier SizeMod,
6508 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006509 unsigned IndexTypeQuals,
6510 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006511 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006512 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006513}
6514
6515template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006516QualType
Mike Stump11289f42009-09-09 15:08:12 +00006517TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006518 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006519 unsigned IndexTypeQuals,
6520 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006521 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006522 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006523}
Mike Stump11289f42009-09-09 15:08:12 +00006524
Douglas Gregord6ff3322009-08-04 16:50:30 +00006525template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006526QualType
6527TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006528 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006529 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006530 unsigned IndexTypeQuals,
6531 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006532 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006533 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006534 IndexTypeQuals, BracketsRange);
6535}
6536
6537template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006538QualType
6539TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006540 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006541 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006542 unsigned IndexTypeQuals,
6543 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006544 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006545 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006546 IndexTypeQuals, BracketsRange);
6547}
6548
6549template<typename Derived>
6550QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006551 unsigned NumElements,
6552 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006553 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006554 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006555}
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregord6ff3322009-08-04 16:50:30 +00006557template<typename Derived>
6558QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6559 unsigned NumElements,
6560 SourceLocation AttributeLoc) {
6561 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6562 NumElements, true);
6563 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006564 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6565 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006566 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006567}
Mike Stump11289f42009-09-09 15:08:12 +00006568
Douglas Gregord6ff3322009-08-04 16:50:30 +00006569template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006570QualType
6571TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006572 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006573 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006574 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006575}
Mike Stump11289f42009-09-09 15:08:12 +00006576
Douglas Gregord6ff3322009-08-04 16:50:30 +00006577template<typename Derived>
6578QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006579 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006580 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006581 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006582 unsigned Quals,
6583 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006584 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006585 Quals,
6586 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006587 getDerived().getBaseEntity(),
6588 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006589}
Mike Stump11289f42009-09-09 15:08:12 +00006590
Douglas Gregord6ff3322009-08-04 16:50:30 +00006591template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006592QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6593 return SemaRef.Context.getFunctionNoProtoType(T);
6594}
6595
6596template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006597QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6598 assert(D && "no decl found");
6599 if (D->isInvalidDecl()) return QualType();
6600
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006601 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006602 TypeDecl *Ty;
6603 if (isa<UsingDecl>(D)) {
6604 UsingDecl *Using = cast<UsingDecl>(D);
6605 assert(Using->isTypeName() &&
6606 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6607
6608 // A valid resolved using typename decl points to exactly one type decl.
6609 assert(++Using->shadow_begin() == Using->shadow_end());
6610 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006611
John McCallb96ec562009-12-04 22:46:56 +00006612 } else {
6613 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6614 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6615 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6616 }
6617
6618 return SemaRef.Context.getTypeDeclType(Ty);
6619}
6620
6621template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006622QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6623 SourceLocation Loc) {
6624 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006625}
6626
6627template<typename Derived>
6628QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6629 return SemaRef.Context.getTypeOfType(Underlying);
6630}
6631
6632template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006633QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6634 SourceLocation Loc) {
6635 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006636}
6637
6638template<typename Derived>
6639QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006640 TemplateName Template,
6641 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006642 const TemplateArgumentListInfo &TemplateArgs) {
6643 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006644}
Mike Stump11289f42009-09-09 15:08:12 +00006645
Douglas Gregor1135c352009-08-06 05:28:30 +00006646template<typename Derived>
6647NestedNameSpecifier *
6648TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6649 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006650 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006651 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006652 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006653 CXXScopeSpec SS;
6654 // FIXME: The source location information is all wrong.
6655 SS.setRange(Range);
6656 SS.setScopeRep(Prefix);
6657 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006658 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006659 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006660 ObjectType,
6661 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006662 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006663}
6664
6665template<typename Derived>
6666NestedNameSpecifier *
6667TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6668 SourceRange Range,
6669 NamespaceDecl *NS) {
6670 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6671}
6672
6673template<typename Derived>
6674NestedNameSpecifier *
6675TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6676 SourceRange Range,
6677 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006678 QualType T) {
6679 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006680 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006681 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006682 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6683 T.getTypePtr());
6684 }
Mike Stump11289f42009-09-09 15:08:12 +00006685
Douglas Gregor1135c352009-08-06 05:28:30 +00006686 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6687 return 0;
6688}
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregor71dc5092009-08-06 06:41:21 +00006690template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006691TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006692TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6693 bool TemplateKW,
6694 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006695 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006696 Template);
6697}
6698
6699template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006700TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006701TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006702 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006703 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00006704 QualType ObjectType,
6705 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006706 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006707 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006708 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006709 UnqualifiedId Name;
6710 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006711 Sema::TemplateTy Template;
6712 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6713 /*FIXME:*/getDerived().getBaseLocation(),
6714 SS,
6715 Name,
John McCallba7bf592010-08-24 05:47:05 +00006716 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006717 /*EnteringContext=*/false,
6718 Template);
John McCall31f82722010-11-12 08:19:04 +00006719 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006720}
Mike Stump11289f42009-09-09 15:08:12 +00006721
Douglas Gregora16548e2009-08-11 05:31:07 +00006722template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006723TemplateName
6724TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6725 OverloadedOperatorKind Operator,
6726 QualType ObjectType) {
6727 CXXScopeSpec SS;
6728 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6729 SS.setScopeRep(Qualifier);
6730 UnqualifiedId Name;
6731 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6732 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6733 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006734 Sema::TemplateTy Template;
6735 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006736 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006737 SS,
6738 Name,
John McCallba7bf592010-08-24 05:47:05 +00006739 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006740 /*EnteringContext=*/false,
6741 Template);
6742 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006743}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006744
Douglas Gregor71395fa2009-11-04 00:56:37 +00006745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006746ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006747TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6748 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006749 Expr *OrigCallee,
6750 Expr *First,
6751 Expr *Second) {
6752 Expr *Callee = OrigCallee->IgnoreParenCasts();
6753 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006754
Douglas Gregora16548e2009-08-11 05:31:07 +00006755 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006756 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006757 if (!First->getType()->isOverloadableType() &&
6758 !Second->getType()->isOverloadableType())
6759 return getSema().CreateBuiltinArraySubscriptExpr(First,
6760 Callee->getLocStart(),
6761 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006762 } else if (Op == OO_Arrow) {
6763 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006764 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6765 } else if (Second == 0 || isPostIncDec) {
6766 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006767 // The argument is not of overloadable type, so try to create a
6768 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006769 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006770 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006771
John McCallb268a282010-08-23 23:25:46 +00006772 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006773 }
6774 } else {
John McCallb268a282010-08-23 23:25:46 +00006775 if (!First->getType()->isOverloadableType() &&
6776 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006777 // Neither of the arguments is an overloadable type, so try to
6778 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006779 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006780 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006781 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006782 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006783 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006784
Douglas Gregora16548e2009-08-11 05:31:07 +00006785 return move(Result);
6786 }
6787 }
Mike Stump11289f42009-09-09 15:08:12 +00006788
6789 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006790 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006791 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006792
John McCallb268a282010-08-23 23:25:46 +00006793 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006794 assert(ULE->requiresADL());
6795
6796 // FIXME: Do we have to check
6797 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006798 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006799 } else {
John McCallb268a282010-08-23 23:25:46 +00006800 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006801 }
Mike Stump11289f42009-09-09 15:08:12 +00006802
Douglas Gregora16548e2009-08-11 05:31:07 +00006803 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006804 Expr *Args[2] = { First, Second };
6805 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006806
Douglas Gregora16548e2009-08-11 05:31:07 +00006807 // Create the overloaded operator invocation for unary operators.
6808 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006809 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006810 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006811 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006812 }
Mike Stump11289f42009-09-09 15:08:12 +00006813
Sebastian Redladba46e2009-10-29 20:17:01 +00006814 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006815 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006816 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006817 First,
6818 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006819
Douglas Gregora16548e2009-08-11 05:31:07 +00006820 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006821 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006822 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006823 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6824 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006826
Mike Stump11289f42009-09-09 15:08:12 +00006827 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006828}
Mike Stump11289f42009-09-09 15:08:12 +00006829
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006831ExprResult
John McCallb268a282010-08-23 23:25:46 +00006832TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006833 SourceLocation OperatorLoc,
6834 bool isArrow,
6835 NestedNameSpecifier *Qualifier,
6836 SourceRange QualifierRange,
6837 TypeSourceInfo *ScopeType,
6838 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006839 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006840 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006841 CXXScopeSpec SS;
6842 if (Qualifier) {
6843 SS.setRange(QualifierRange);
6844 SS.setScopeRep(Qualifier);
6845 }
6846
John McCallb268a282010-08-23 23:25:46 +00006847 QualType BaseType = Base->getType();
6848 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006849 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006850 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006851 !BaseType->getAs<PointerType>()->getPointeeType()
6852 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006853 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006854 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006855 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006856 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006857 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006858 /*FIXME?*/true);
6859 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006860
Douglas Gregor678f90d2010-02-25 01:56:36 +00006861 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006862 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6863 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6864 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6865 NameInfo.setNamedTypeInfo(DestroyedType);
6866
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006867 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006868
John McCallb268a282010-08-23 23:25:46 +00006869 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006870 OperatorLoc, isArrow,
6871 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006872 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006873 /*TemplateArgs*/ 0);
6874}
6875
Douglas Gregord6ff3322009-08-04 16:50:30 +00006876} // end namespace clang
6877
6878#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H