blob: c0bafc7cb0cfc2ad5978706a01e0d04f36809684 [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
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCallbcd03502009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump11289f42009-09-09 15:08:12 +0000307
John McCall550e0c22009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000311#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000312
John McCall31f82722010-11-12 08:19:04 +0000313 QualType
314 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
315 TemplateSpecializationTypeLoc TL,
316 TemplateName Template);
317
318 QualType
319 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
320 DependentTemplateSpecializationTypeLoc TL,
321 NestedNameSpecifier *Prefix);
322
John McCall58f10c32010-03-11 09:03:00 +0000323 /// \brief Transforms the parameters of a function type into the
324 /// given vectors.
325 ///
326 /// The result vectors should be kept in sync; null entries in the
327 /// variables vector are acceptable.
328 ///
329 /// Return true on error.
330 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
331 llvm::SmallVectorImpl<QualType> &PTypes,
332 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
333
334 /// \brief Transforms a single function-type parameter. Return null
335 /// on error.
336 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
337
John McCall31f82722010-11-12 08:19:04 +0000338 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000339
John McCalldadc5752010-08-24 06:29:42 +0000340 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
341 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000344 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000346 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000424 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000435 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000445 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000461 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000473
John McCall550e0c22009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCallb96ec562009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCallfcc33b02009-09-05 00:15:47 +0000495
Mike Stump11289f42009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000500 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501
Mike Stump11289f42009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump11289f42009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000511 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000521
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000527 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
528 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000529 NestedNameSpecifier *NNS, QualType Named) {
530 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000531 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000532
533 /// \brief Build a new typename type that refers to a template-id.
534 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000535 /// By default, builds a new DependentNameType type from the
536 /// nested-name-specifier and the given type. Subclasses may override
537 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000538 QualType RebuildDependentTemplateSpecializationType(
539 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000540 NestedNameSpecifier *Qualifier,
541 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000542 const IdentifierInfo *Name,
543 SourceLocation NameLoc,
544 const TemplateArgumentListInfo &Args) {
545 // Rebuild the template name.
546 // TODO: avoid TemplateName abstraction
547 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000548 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000549 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000550
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000551 if (InstName.isNull())
552 return QualType();
553
John McCallc392f372010-06-11 00:33:02 +0000554 // If it's still dependent, make a dependent specialization.
555 if (InstName.getAsDependentTemplateName())
556 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000557 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000558
559 // Otherwise, make an elaborated type wrapping a non-dependent
560 // specialization.
561 QualType T =
562 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
563 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000564
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000565 // NOTE: NNS is already recorded in template specialization type T.
566 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000567 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568
569 /// \brief Build a new typename type that refers to an identifier.
570 ///
571 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000573 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000575 NestedNameSpecifier *NNS,
576 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000577 SourceLocation KeywordLoc,
578 SourceRange NNSRange,
579 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000580 CXXScopeSpec SS;
581 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000582 SS.setRange(NNSRange);
583
Douglas Gregore677daf2010-03-31 22:19:08 +0000584 if (NNS->isDependent()) {
585 // If the name is still dependent, just build a new dependent name type.
586 if (!SemaRef.computeDeclContext(SS))
587 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
588 }
589
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000591 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
592 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000593
594 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
595
Abramo Bagnarad7548482010-05-19 21:37:53 +0000596 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000597 // into a non-dependent elaborated-type-specifier. Find the tag we're
598 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000599 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000600 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
601 if (!DC)
602 return QualType();
603
John McCallbf8c5192010-05-27 06:40:31 +0000604 if (SemaRef.RequireCompleteDeclContext(SS, DC))
605 return QualType();
606
Douglas Gregore677daf2010-03-31 22:19:08 +0000607 TagDecl *Tag = 0;
608 SemaRef.LookupQualifiedName(Result, DC);
609 switch (Result.getResultKind()) {
610 case LookupResult::NotFound:
611 case LookupResult::NotFoundInCurrentInstantiation:
612 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000613
Douglas Gregore677daf2010-03-31 22:19:08 +0000614 case LookupResult::Found:
615 Tag = Result.getAsSingle<TagDecl>();
616 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000617
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 case LookupResult::FoundOverloaded:
619 case LookupResult::FoundUnresolvedValue:
620 llvm_unreachable("Tag lookup cannot find non-tags");
621 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000622
Douglas Gregore677daf2010-03-31 22:19:08 +0000623 case LookupResult::Ambiguous:
624 // Let the LookupResult structure handle ambiguities.
625 return QualType();
626 }
627
628 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000629 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000630 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000631 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000632 return QualType();
633 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000634
Abramo Bagnarad7548482010-05-19 21:37:53 +0000635 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
636 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000637 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
638 return QualType();
639 }
640
641 // Build the elaborated-type-specifier type.
642 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000643 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000644 }
Mike Stump11289f42009-09-09 15:08:12 +0000645
Douglas Gregor1135c352009-08-06 05:28:30 +0000646 /// \brief Build a new nested-name-specifier given the prefix and an
647 /// identifier that names the next step in the nested-name-specifier.
648 ///
649 /// By default, performs semantic analysis when building the new
650 /// nested-name-specifier. Subclasses may override this routine to provide
651 /// different behavior.
652 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
653 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000654 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000655 QualType ObjectType,
656 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// namespace named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 NamespaceDecl *NS);
667
668 /// \brief Build a new nested-name-specifier given the prefix and the
669 /// type named in the next step in the nested-name-specifier.
670 ///
671 /// By default, performs semantic analysis when building the new
672 /// nested-name-specifier. Subclasses may override this routine to provide
673 /// different behavior.
674 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
675 SourceRange Range,
676 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000677 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000678
679 /// \brief Build a new template name given a nested name specifier, a flag
680 /// indicating whether the "template" keyword was provided, and the template
681 /// that the template name refers to.
682 ///
683 /// By default, builds the new template name directly. Subclasses may override
684 /// this routine to provide different behavior.
685 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
686 bool TemplateKW,
687 TemplateDecl *Template);
688
Douglas Gregor71dc5092009-08-06 06:41:21 +0000689 /// \brief Build a new template name given a nested name specifier and the
690 /// name that is referred to as a template.
691 ///
692 /// By default, performs semantic analysis to determine whether the name can
693 /// be resolved to a specific template, then builds the appropriate kind of
694 /// template name. Subclasses may override this routine to provide different
695 /// behavior.
696 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000697 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000698 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000699 QualType ObjectType,
700 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregor71395fa2009-11-04 00:56:37 +0000702 /// \brief Build a new template name given a nested name specifier and the
703 /// overloaded operator name that is referred to as a template.
704 ///
705 /// By default, performs semantic analysis to determine whether the name can
706 /// be resolved to a specific template, then builds the appropriate kind of
707 /// template name. Subclasses may override this routine to provide different
708 /// behavior.
709 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
710 OverloadedOperatorKind Operator,
711 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000712
Douglas Gregorebe10102009-08-20 07:17:43 +0000713 /// \brief Build a new compound statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000717 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000718 MultiStmtArg Statements,
719 SourceLocation RBraceLoc,
720 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000721 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000722 IsStmtExpr);
723 }
724
725 /// \brief Build a new case statement.
726 ///
727 /// By default, performs semantic analysis to build the new statement.
728 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000729 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000730 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000732 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000734 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 ColonLoc);
736 }
Mike Stump11289f42009-09-09 15:08:12 +0000737
Douglas Gregorebe10102009-08-20 07:17:43 +0000738 /// \brief Attach the body to a new case statement.
739 ///
740 /// By default, performs semantic analysis to build the new statement.
741 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000742 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000743 getSema().ActOnCaseStmtBody(S, Body);
744 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 }
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 /// \brief Build a new default statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000751 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000753 Stmt *SubStmt) {
754 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /*CurScope=*/0);
756 }
Mike Stump11289f42009-09-09 15:08:12 +0000757
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 /// \brief Build a new label statement.
759 ///
760 /// By default, performs semantic analysis to build the new statement.
761 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000762 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 IdentifierInfo *Id,
764 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000765 Stmt *SubStmt, bool HasUnusedAttr) {
766 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
767 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 }
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 /// \brief Build a new "if" statement.
771 ///
772 /// By default, performs semantic analysis to build the new statement.
773 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000774 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000775 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000776 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000777 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 }
Mike Stump11289f42009-09-09 15:08:12 +0000779
Douglas Gregorebe10102009-08-20 07:17:43 +0000780 /// \brief Start building a new switch statement.
781 ///
782 /// By default, performs semantic analysis to build the new statement.
783 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000784 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000785 Expr *Cond, VarDecl *CondVar) {
786 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000787 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000788 }
Mike Stump11289f42009-09-09 15:08:12 +0000789
Douglas Gregorebe10102009-08-20 07:17:43 +0000790 /// \brief Attach the body to the switch statement.
791 ///
792 /// By default, performs semantic analysis to build the new statement.
793 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000794 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000795 Stmt *Switch, Stmt *Body) {
796 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 }
798
799 /// \brief Build a new while statement.
800 ///
801 /// By default, performs semantic analysis to build the new statement.
802 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000803 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000804 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000805 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000806 Stmt *Body) {
807 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 }
Mike Stump11289f42009-09-09 15:08:12 +0000809
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 /// \brief Build a new do-while statement.
811 ///
812 /// By default, performs semantic analysis to build the new statement.
813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000814 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000815 SourceLocation WhileLoc,
816 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000817 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000819 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
820 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000821 }
822
823 /// \brief Build a new for statement.
824 ///
825 /// By default, performs semantic analysis to build the new statement.
826 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000827 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000828 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000829 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000830 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000831 SourceLocation RParenLoc, Stmt *Body) {
832 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000833 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000834 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000835 }
Mike Stump11289f42009-09-09 15:08:12 +0000836
Douglas Gregorebe10102009-08-20 07:17:43 +0000837 /// \brief Build a new goto statement.
838 ///
839 /// By default, performs semantic analysis to build the new statement.
840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000841 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000842 SourceLocation LabelLoc,
843 LabelStmt *Label) {
844 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
845 }
846
847 /// \brief Build a new indirect goto statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000851 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000853 Expr *Target) {
854 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000855 }
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 /// \brief Build a new return statement.
858 ///
859 /// By default, performs semantic analysis to build the new statement.
860 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000861 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000862 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000863
John McCallb268a282010-08-23 23:25:46 +0000864 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 }
Mike Stump11289f42009-09-09 15:08:12 +0000866
Douglas Gregorebe10102009-08-20 07:17:43 +0000867 /// \brief Build a new declaration 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 RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000872 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000873 SourceLocation EndLoc) {
874 return getSema().Owned(
875 new (getSema().Context) DeclStmt(
876 DeclGroupRef::Create(getSema().Context,
877 Decls, NumDecls),
878 StartLoc, EndLoc));
879 }
Mike Stump11289f42009-09-09 15:08:12 +0000880
Anders Carlssonaaeef072010-01-24 05:50:09 +0000881 /// \brief Build a new inline asm 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 RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000886 bool IsSimple,
887 bool IsVolatile,
888 unsigned NumOutputs,
889 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000890 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000891 MultiExprArg Constraints,
892 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000893 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000894 MultiExprArg Clobbers,
895 SourceLocation RParenLoc,
896 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000897 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000898 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000899 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000900 RParenLoc, MSAsm);
901 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000902
903 /// \brief Build a new Objective-C @try statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000907 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000908 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000909 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000910 Stmt *Finally) {
911 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
912 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000913 }
914
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000915 /// \brief Rebuild an Objective-C exception declaration.
916 ///
917 /// By default, performs semantic analysis to build the new declaration.
918 /// Subclasses may override this routine to provide different behavior.
919 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
920 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000921 return getSema().BuildObjCExceptionDecl(TInfo, T,
922 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 ExceptionDecl->getLocation());
924 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000925
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000926 /// \brief Build a new Objective-C @catch statement.
927 ///
928 /// By default, performs semantic analysis to build the new statement.
929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000930 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000931 SourceLocation RParenLoc,
932 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000933 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000934 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000935 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000936 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000937
Douglas Gregor306de2f2010-04-22 23:59:56 +0000938 /// \brief Build a new Objective-C @finally statement.
939 ///
940 /// By default, performs semantic analysis to build the new statement.
941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000942 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000943 Stmt *Body) {
944 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000945 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000946
Douglas Gregor6148de72010-04-22 22:01:21 +0000947 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000948 ///
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 RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000952 Expr *Operand) {
953 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000954 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000955
Douglas Gregor6148de72010-04-22 22:01:21 +0000956 /// \brief Build a new Objective-C @synchronized statement.
957 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000958 /// By default, performs semantic analysis to build the new statement.
959 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000960 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000961 Expr *Object,
962 Stmt *Body) {
963 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
964 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000965 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000966
967 /// \brief Build a new Objective-C fast enumeration statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000971 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000972 SourceLocation LParenLoc,
973 Stmt *Element,
974 Expr *Collection,
975 SourceLocation RParenLoc,
976 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000977 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Element,
979 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000980 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000981 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000982 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000983
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 /// \brief Build a new C++ exception declaration.
985 ///
986 /// By default, performs semantic analysis to build the new decaration.
987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000988 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +0000989 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000990 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000991 SourceLocation Loc) {
992 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
994
995 /// \brief Build a new C++ catch statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001000 VarDecl *ExceptionDecl,
1001 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001002 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1003 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new C++ try statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001010 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001011 Stmt *TryBlock,
1012 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001013 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001014 }
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 /// \brief Build a new expression that references a declaration.
1017 ///
1018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001020 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001021 LookupResult &R,
1022 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001023 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1024 }
1025
1026
1027 /// \brief Build a new expression that references a declaration.
1028 ///
1029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001031 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001032 SourceRange QualifierRange,
1033 ValueDecl *VD,
1034 const DeclarationNameInfo &NameInfo,
1035 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001036 CXXScopeSpec SS;
1037 SS.setScopeRep(Qualifier);
1038 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001039
1040 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001041
1042 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 }
Mike Stump11289f42009-09-09 15:08:12 +00001044
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001046 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 /// By default, performs semantic analysis to build the new expression.
1048 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001049 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001051 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 }
1053
Douglas Gregorad8a3362009-09-04 17:36:40 +00001054 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001055 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001056 /// By default, performs semantic analysis to build the new expression.
1057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001058 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001059 SourceLocation OperatorLoc,
1060 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001061 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001062 SourceRange QualifierRange,
1063 TypeSourceInfo *ScopeType,
1064 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001065 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001066 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001072 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001073 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001074 Expr *SubExpr) {
1075 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 }
Mike Stump11289f42009-09-09 15:08:12 +00001077
Douglas Gregor882211c2010-04-28 22:16:22 +00001078 /// \brief Build a new builtin offsetof expression.
1079 ///
1080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001082 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001083 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001084 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001085 unsigned NumComponents,
1086 SourceLocation RParenLoc) {
1087 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1088 NumComponents, RParenLoc);
1089 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001092 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 /// By default, performs semantic analysis to build the new expression.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001095 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001096 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001098 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 }
1100
Mike Stump11289f42009-09-09 15:08:12 +00001101 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// By default, performs semantic analysis to build the new expression.
1105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001106 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001108 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001109 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 return move(Result);
1114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001117 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 /// By default, performs semantic analysis to build the new expression.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001122 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001124 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1125 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 RBracketLoc);
1127 }
1128
1129 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001130 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001131 /// By default, performs semantic analysis to build the new expression.
1132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001133 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001136 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001137 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 }
1139
1140 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001141 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// By default, performs semantic analysis to build the new expression.
1143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001144 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001145 bool isArrow,
1146 NestedNameSpecifier *Qualifier,
1147 SourceRange QualifierRange,
1148 const DeclarationNameInfo &MemberNameInfo,
1149 ValueDecl *Member,
1150 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001151 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001152 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001153 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001154 // We have a reference to an unnamed field. This is always the
1155 // base of an anonymous struct/union member access, i.e. the
1156 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001157 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001158 assert(Member->getType()->isRecordType() &&
1159 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001160
John McCallb268a282010-08-23 23:25:46 +00001161 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001162 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001163 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001164
John McCall7decc9e2010-11-18 06:31:45 +00001165 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001166 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001167 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001168 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001169 cast<FieldDecl>(Member)->getType(),
1170 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001171 return getSema().Owned(ME);
1172 }
Mike Stump11289f42009-09-09 15:08:12 +00001173
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001174 CXXScopeSpec SS;
1175 if (Qualifier) {
1176 SS.setRange(QualifierRange);
1177 SS.setScopeRep(Qualifier);
1178 }
1179
John McCallb268a282010-08-23 23:25:46 +00001180 getSema().DefaultFunctionArrayConversion(Base);
1181 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001182
John McCall16df1e52010-03-30 21:47:33 +00001183 // FIXME: this involves duplicating earlier analysis in a lot of
1184 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001185 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001186 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001187 R.resolveKind();
1188
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001190 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001191 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001195 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001198 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001199 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001200 Expr *LHS, Expr *RHS) {
1201 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 }
1203
1204 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001205 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// By default, performs semantic analysis to build the new expression.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001210 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001212 Expr *RHS) {
1213 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1214 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 }
1216
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001218 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 /// By default, performs semantic analysis to build the new expression.
1220 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001221 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001222 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001224 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001225 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001226 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 }
Mike Stump11289f42009-09-09 15:08:12 +00001228
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001230 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001233 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001234 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001236 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001237 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 }
Mike Stump11289f42009-09-09 15:08:12 +00001240
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001242 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 /// By default, performs semantic analysis to build the new expression.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 SourceLocation OpLoc,
1247 SourceLocation AccessorLoc,
1248 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001249
John McCall10eae182009-11-30 22:42:35 +00001250 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001251 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001252 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001253 OpLoc, /*IsArrow*/ false,
1254 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001255 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001256 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001265 SourceLocation RBraceLoc,
1266 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001267 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001268 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1269 if (Result.isInvalid() || ResultTy->isDependentType())
1270 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001271
Douglas Gregord3d93062009-11-09 17:16:50 +00001272 // Patch in the result type we were given, which may have been computed
1273 // when the initial InitListExpr was built.
1274 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1275 ILE->setType(ResultTy);
1276 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 }
Mike Stump11289f42009-09-09 15:08:12 +00001278
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001280 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// By default, performs semantic analysis to build the new expression.
1282 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001283 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 MultiExprArg ArrayExprs,
1285 SourceLocation EqualOrColonLoc,
1286 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001287 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001288 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001290 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001293
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 ArrayExprs.release();
1295 return move(Result);
1296 }
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001299 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// By default, builds the implicit value initialization without performing
1301 /// any semantic analysis. Subclasses may override this routine to provide
1302 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001303 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1305 }
Mike Stump11289f42009-09-09 15:08:12 +00001306
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001308 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001311 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001312 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001313 SourceLocation RParenLoc) {
1314 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001315 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001316 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
1318
1319 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 MultiExprArg SubExprs,
1325 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001326 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001327 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
1332 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// rather than attempting to map the label statement itself.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation LabelLoc,
1337 LabelStmt *Label) {
1338 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001342 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001346 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001348 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 }
Mike Stump11289f42009-09-09 15:08:12 +00001350
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// \brief Build a new __builtin_choose_expr expression.
1352 ///
1353 /// 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 RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001356 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 SourceLocation RParenLoc) {
1358 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001359 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 RParenLoc);
1361 }
Mike Stump11289f42009-09-09 15:08:12 +00001362
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 /// \brief Build a new overloaded operator call expression.
1364 ///
1365 /// By default, performs semantic analysis to build the new expression.
1366 /// The semantic analysis provides the behavior of template instantiation,
1367 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001368 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 /// argument-dependent lookup, etc. Subclasses may override this routine to
1370 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001371 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001373 Expr *Callee,
1374 Expr *First,
1375 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001376
1377 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 /// reinterpret_cast.
1379 ///
1380 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001381 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001383 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 Stmt::StmtClass Class,
1385 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001386 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 SourceLocation RAngleLoc,
1388 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001389 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 SourceLocation RParenLoc) {
1391 switch (Class) {
1392 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001393 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001394 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001395 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001396
1397 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001398 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001399 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001400 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001401
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001403 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001404 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001405 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001407
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001409 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001410 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001411 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001412
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 default:
1414 assert(false && "Invalid C++ named cast");
1415 break;
1416 }
Mike Stump11289f42009-09-09 15:08:12 +00001417
John McCallfaf5fb42010-08-26 23:41:50 +00001418 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 }
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 /// \brief Build a new C++ static_cast expression.
1422 ///
1423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001425 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001427 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 SourceLocation RAngleLoc,
1429 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001430 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001432 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001433 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001434 SourceRange(LAngleLoc, RAngleLoc),
1435 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 }
1437
1438 /// \brief Build a new C++ dynamic_cast expression.
1439 ///
1440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001442 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001444 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation RAngleLoc,
1446 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001447 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001449 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001450 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001451 SourceRange(LAngleLoc, RAngleLoc),
1452 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 }
1454
1455 /// \brief Build a new C++ reinterpret_cast expression.
1456 ///
1457 /// By default, performs semantic analysis to build the new expression.
1458 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001459 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001461 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation RAngleLoc,
1463 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001464 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001466 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001467 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001468 SourceRange(LAngleLoc, RAngleLoc),
1469 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
1471
1472 /// \brief Build a new C++ const_cast expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001476 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001478 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceLocation RAngleLoc,
1480 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001481 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001483 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001484 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001485 SourceRange(LAngleLoc, RAngleLoc),
1486 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 }
Mike Stump11289f42009-09-09 15:08:12 +00001488
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// \brief Build a new C++ functional-style cast expression.
1490 ///
1491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001493 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1494 SourceLocation LParenLoc,
1495 Expr *Sub,
1496 SourceLocation RParenLoc) {
1497 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001498 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 RParenLoc);
1500 }
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// \brief Build a new C++ typeid(type) expression.
1503 ///
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001506 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001507 SourceLocation TypeidLoc,
1508 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001510 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001511 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 }
Mike Stump11289f42009-09-09 15:08:12 +00001513
Francois Pichet9f4f2072010-09-08 12:20:18 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new C++ typeid(expr) expression.
1516 ///
1517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001519 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001520 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001521 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001523 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001524 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001525 }
1526
Francois Pichet9f4f2072010-09-08 12:20:18 +00001527 /// \brief Build a new C++ __uuidof(type) expression.
1528 ///
1529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
1531 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1532 SourceLocation TypeidLoc,
1533 TypeSourceInfo *Operand,
1534 SourceLocation RParenLoc) {
1535 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1536 RParenLoc);
1537 }
1538
1539 /// \brief Build a new C++ __uuidof(expr) expression.
1540 ///
1541 /// By default, performs semantic analysis to build the new expression.
1542 /// Subclasses may override this routine to provide different behavior.
1543 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1544 SourceLocation TypeidLoc,
1545 Expr *Operand,
1546 SourceLocation RParenLoc) {
1547 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1548 RParenLoc);
1549 }
1550
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// \brief Build a new C++ "this" expression.
1552 ///
1553 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001554 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001556 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001557 QualType ThisType,
1558 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001560 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1561 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 }
1563
1564 /// \brief Build a new C++ throw expression.
1565 ///
1566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001568 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001569 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 }
1571
1572 /// \brief Build a new C++ default-argument expression.
1573 ///
1574 /// By default, builds a new default-argument expression, which does not
1575 /// require any semantic analysis. Subclasses may override this routine to
1576 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001577 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001578 ParmVarDecl *Param) {
1579 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1580 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 }
1582
1583 /// \brief Build a new C++ zero-initialization expression.
1584 ///
1585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001587 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1588 SourceLocation LParenLoc,
1589 SourceLocation RParenLoc) {
1590 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001591 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001592 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 }
Mike Stump11289f42009-09-09 15:08:12 +00001594
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// \brief Build a new C++ "new" expression.
1596 ///
1597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001599 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001600 bool UseGlobal,
1601 SourceLocation PlacementLParen,
1602 MultiExprArg PlacementArgs,
1603 SourceLocation PlacementRParen,
1604 SourceRange TypeIdParens,
1605 QualType AllocatedType,
1606 TypeSourceInfo *AllocatedTypeInfo,
1607 Expr *ArraySize,
1608 SourceLocation ConstructorLParen,
1609 MultiExprArg ConstructorArgs,
1610 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001611 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 PlacementLParen,
1613 move(PlacementArgs),
1614 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001615 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001616 AllocatedType,
1617 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001618 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 ConstructorLParen,
1620 move(ConstructorArgs),
1621 ConstructorRParen);
1622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new C++ "delete" expression.
1625 ///
1626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001628 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 bool IsGlobalDelete,
1630 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001631 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001633 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 }
Mike Stump11289f42009-09-09 15:08:12 +00001635
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// \brief Build a new unary type trait expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001640 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001641 SourceLocation StartLoc,
1642 TypeSourceInfo *T,
1643 SourceLocation RParenLoc) {
1644 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 }
1646
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001647 /// \brief Build a new binary type trait expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
1651 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1652 SourceLocation StartLoc,
1653 TypeSourceInfo *LhsT,
1654 TypeSourceInfo *RhsT,
1655 SourceLocation RParenLoc) {
1656 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1657 }
1658
Mike Stump11289f42009-09-09 15:08:12 +00001659 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 /// expression.
1661 ///
1662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001664 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001666 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001667 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 CXXScopeSpec SS;
1669 SS.setRange(QualifierRange);
1670 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001671
1672 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001673 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001674 *TemplateArgs);
1675
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001676 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 }
1678
1679 /// \brief Build a new template-id expression.
1680 ///
1681 /// By default, performs semantic analysis to build the new expression.
1682 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001683 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001684 LookupResult &R,
1685 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001686 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001687 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 }
1689
1690 /// \brief Build a new object-construction expression.
1691 ///
1692 /// By default, performs semantic analysis to build the new expression.
1693 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001694 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001695 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 CXXConstructorDecl *Constructor,
1697 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001698 MultiExprArg Args,
1699 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001700 CXXConstructExpr::ConstructionKind ConstructKind,
1701 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001702 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001703 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001704 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001705 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001706
Douglas Gregordb121ba2009-12-14 16:27:04 +00001707 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001708 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001709 RequiresZeroInit, ConstructKind,
1710 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 }
1712
1713 /// \brief Build a new object-construction expression.
1714 ///
1715 /// By default, performs semantic analysis to build the new expression.
1716 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001717 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1718 SourceLocation LParenLoc,
1719 MultiExprArg Args,
1720 SourceLocation RParenLoc) {
1721 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 LParenLoc,
1723 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 RParenLoc);
1725 }
1726
1727 /// \brief Build a new object-construction expression.
1728 ///
1729 /// By default, performs semantic analysis to build the new expression.
1730 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001731 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1732 SourceLocation LParenLoc,
1733 MultiExprArg Args,
1734 SourceLocation RParenLoc) {
1735 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 LParenLoc,
1737 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 RParenLoc);
1739 }
Mike Stump11289f42009-09-09 15:08:12 +00001740
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// \brief Build a new member reference expression.
1742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001745 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001746 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 bool IsArrow,
1748 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001749 NestedNameSpecifier *Qualifier,
1750 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001751 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001752 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001753 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001755 SS.setRange(QualifierRange);
1756 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001757
John McCallb268a282010-08-23 23:25:46 +00001758 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001759 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001760 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001761 MemberNameInfo,
1762 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 }
1764
John McCall10eae182009-11-30 22:42:35 +00001765 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001766 ///
1767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001769 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001770 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001771 SourceLocation OperatorLoc,
1772 bool IsArrow,
1773 NestedNameSpecifier *Qualifier,
1774 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001775 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001776 LookupResult &R,
1777 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001778 CXXScopeSpec SS;
1779 SS.setRange(QualifierRange);
1780 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001781
John McCallb268a282010-08-23 23:25:46 +00001782 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001783 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001784 SS, FirstQualifierInScope,
1785 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001786 }
Mike Stump11289f42009-09-09 15:08:12 +00001787
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001788 /// \brief Build a new noexcept expression.
1789 ///
1790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
1792 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1793 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1794 }
1795
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 /// \brief Build a new Objective-C @encode expression.
1797 ///
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001800 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001801 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001803 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001805 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001806
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001807 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001808 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001809 Selector Sel,
1810 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001811 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001812 MultiExprArg Args,
1813 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001814 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1815 ReceiverTypeInfo->getType(),
1816 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001817 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001818 move(Args));
1819 }
1820
1821 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001822 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001823 Selector Sel,
1824 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001825 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001826 MultiExprArg Args,
1827 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001828 return SemaRef.BuildInstanceMessage(Receiver,
1829 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001830 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001831 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001832 move(Args));
1833 }
1834
Douglas Gregord51d90d2010-04-26 20:11:03 +00001835 /// \brief Build a new Objective-C ivar reference expression.
1836 ///
1837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001840 SourceLocation IvarLoc,
1841 bool IsArrow, bool IsFreeIvar) {
1842 // FIXME: We lose track of the IsFreeIvar bit.
1843 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001844 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001845 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1846 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001847 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001848 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001849 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001850 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001851 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001852 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001853
Douglas Gregord51d90d2010-04-26 20:11:03 +00001854 if (Result.get())
1855 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001856
John McCallb268a282010-08-23 23:25:46 +00001857 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001858 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001859 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001860 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001861 /*TemplateArgs=*/0);
1862 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001863
1864 /// \brief Build a new Objective-C property reference expression.
1865 ///
1866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001868 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001869 ObjCPropertyDecl *Property,
1870 SourceLocation PropertyLoc) {
1871 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001872 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001873 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1874 Sema::LookupMemberName);
1875 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001876 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001877 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001878 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001879 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001880 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001881
Douglas Gregor9faee212010-04-26 20:47:02 +00001882 if (Result.get())
1883 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001884
John McCallb268a282010-08-23 23:25:46 +00001885 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001886 /*FIXME:*/PropertyLoc, IsArrow,
1887 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001888 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001889 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001890 /*TemplateArgs=*/0);
1891 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001892
John McCallb7bd14f2010-12-02 01:19:52 +00001893 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001894 ///
1895 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00001896 /// Subclasses may override this routine to provide different behavior.
1897 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1898 ObjCMethodDecl *Getter,
1899 ObjCMethodDecl *Setter,
1900 SourceLocation PropertyLoc) {
1901 // Since these expressions can only be value-dependent, we do not
1902 // need to perform semantic analysis again.
1903 return Owned(
1904 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
1905 VK_LValue, OK_ObjCProperty,
1906 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001907 }
1908
Douglas Gregord51d90d2010-04-26 20:11:03 +00001909 /// \brief Build a new Objective-C "isa" expression.
1910 ///
1911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001913 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001914 bool IsArrow) {
1915 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001916 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001917 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1918 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001920 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001921 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001922 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001923 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001924
Douglas Gregord51d90d2010-04-26 20:11:03 +00001925 if (Result.get())
1926 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001927
John McCallb268a282010-08-23 23:25:46 +00001928 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001929 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001930 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001931 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001932 /*TemplateArgs=*/0);
1933 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001934
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 /// \brief Build a new shuffle vector expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001939 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001940 MultiExprArg SubExprs,
1941 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001943 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1945 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1946 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1947 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001948
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 // Build a reference to the __builtin_shufflevector builtin
1950 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001951 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00001953 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001955
1956 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 unsigned NumSubExprs = SubExprs.size();
1958 Expr **Subs = (Expr **)SubExprs.release();
1959 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1960 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001961 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00001962 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001964 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001967 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001969 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001972 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 }
John McCall31f82722010-11-12 08:19:04 +00001974
1975private:
1976 QualType TransformTypeInObjectScope(QualType T,
1977 QualType ObjectType,
1978 NamedDecl *FirstQualifierInScope,
1979 NestedNameSpecifier *Prefix);
1980
1981 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
1982 QualType ObjectType,
1983 NamedDecl *FirstQualifierInScope,
1984 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001985};
Douglas Gregora16548e2009-08-11 05:31:07 +00001986
Douglas Gregorebe10102009-08-20 07:17:43 +00001987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001988StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001989 if (!S)
1990 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001991
Douglas Gregorebe10102009-08-20 07:17:43 +00001992 switch (S->getStmtClass()) {
1993 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001994
Douglas Gregorebe10102009-08-20 07:17:43 +00001995 // Transform individual statement nodes
1996#define STMT(Node, Parent) \
1997 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1998#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001999#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002000
Douglas Gregorebe10102009-08-20 07:17:43 +00002001 // Transform expressions by calling TransformExpr.
2002#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002003#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002004#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002005#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002006 {
John McCalldadc5752010-08-24 06:29:42 +00002007 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002008 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002009 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002010
John McCallb268a282010-08-23 23:25:46 +00002011 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002012 }
Mike Stump11289f42009-09-09 15:08:12 +00002013 }
2014
John McCallc3007a22010-10-26 07:05:15 +00002015 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002016}
Mike Stump11289f42009-09-09 15:08:12 +00002017
2018
Douglas Gregore922c772009-08-04 22:27:00 +00002019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002020ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 if (!E)
2022 return SemaRef.Owned(E);
2023
2024 switch (E->getStmtClass()) {
2025 case Stmt::NoStmtClass: break;
2026#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002027#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002028#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002029 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002030#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002031 }
2032
John McCallc3007a22010-10-26 07:05:15 +00002033 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002034}
2035
2036template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002037NestedNameSpecifier *
2038TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002039 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002040 QualType ObjectType,
2041 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002042 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002043
Douglas Gregorebe10102009-08-20 07:17:43 +00002044 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002045 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002046 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002047 ObjectType,
2048 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 if (!Prefix)
2050 return 0;
2051 }
Mike Stump11289f42009-09-09 15:08:12 +00002052
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 switch (NNS->getKind()) {
2054 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002055 if (Prefix) {
2056 // The object type and qualifier-in-scope really apply to the
2057 // leftmost entity.
2058 ObjectType = QualType();
2059 FirstQualifierInScope = 0;
2060 }
2061
Mike Stump11289f42009-09-09 15:08:12 +00002062 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002063 "Identifier nested-name-specifier with no prefix or object type");
2064 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2065 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002066 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002067
2068 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002069 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002070 ObjectType,
2071 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002072
Douglas Gregor1135c352009-08-06 05:28:30 +00002073 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002074 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002075 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002076 getDerived().TransformDecl(Range.getBegin(),
2077 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002078 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002079 Prefix == NNS->getPrefix() &&
2080 NS == NNS->getAsNamespace())
2081 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002082
Douglas Gregor1135c352009-08-06 05:28:30 +00002083 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2084 }
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregor1135c352009-08-06 05:28:30 +00002086 case NestedNameSpecifier::Global:
2087 // There is no meaningful transformation that one could perform on the
2088 // global scope.
2089 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002090
Douglas Gregor1135c352009-08-06 05:28:30 +00002091 case NestedNameSpecifier::TypeSpecWithTemplate:
2092 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002093 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002094 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2095 ObjectType,
2096 FirstQualifierInScope,
2097 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002098 if (T.isNull())
2099 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002100
Douglas Gregor1135c352009-08-06 05:28:30 +00002101 if (!getDerived().AlwaysRebuild() &&
2102 Prefix == NNS->getPrefix() &&
2103 T == QualType(NNS->getAsType(), 0))
2104 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002105
2106 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2107 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002108 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002109 }
2110 }
Mike Stump11289f42009-09-09 15:08:12 +00002111
Douglas Gregor1135c352009-08-06 05:28:30 +00002112 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002113 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002114}
2115
2116template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002117DeclarationNameInfo
2118TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002119::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002120 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002121 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002122 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002123
2124 switch (Name.getNameKind()) {
2125 case DeclarationName::Identifier:
2126 case DeclarationName::ObjCZeroArgSelector:
2127 case DeclarationName::ObjCOneArgSelector:
2128 case DeclarationName::ObjCMultiArgSelector:
2129 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002130 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002131 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002132 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002133
Douglas Gregorf816bd72009-09-03 22:13:48 +00002134 case DeclarationName::CXXConstructorName:
2135 case DeclarationName::CXXDestructorName:
2136 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002137 TypeSourceInfo *NewTInfo;
2138 CanQualType NewCanTy;
2139 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002140 NewTInfo = getDerived().TransformType(OldTInfo);
2141 if (!NewTInfo)
2142 return DeclarationNameInfo();
2143 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002144 }
2145 else {
2146 NewTInfo = 0;
2147 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002148 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002149 if (NewT.isNull())
2150 return DeclarationNameInfo();
2151 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2152 }
Mike Stump11289f42009-09-09 15:08:12 +00002153
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002154 DeclarationName NewName
2155 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2156 NewCanTy);
2157 DeclarationNameInfo NewNameInfo(NameInfo);
2158 NewNameInfo.setName(NewName);
2159 NewNameInfo.setNamedTypeInfo(NewTInfo);
2160 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002161 }
Mike Stump11289f42009-09-09 15:08:12 +00002162 }
2163
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002164 assert(0 && "Unknown name kind.");
2165 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002166}
2167
2168template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002169TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002170TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002171 QualType ObjectType,
2172 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002173 SourceLocation Loc = getDerived().getBaseLocation();
2174
Douglas Gregor71dc5092009-08-06 06:41:21 +00002175 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002176 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002178 /*FIXME*/ SourceRange(Loc),
2179 ObjectType,
2180 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002181 if (!NNS)
2182 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002185 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002186 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187 if (!TransTemplate)
2188 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002189
Douglas Gregor71dc5092009-08-06 06:41:21 +00002190 if (!getDerived().AlwaysRebuild() &&
2191 NNS == QTN->getQualifier() &&
2192 TransTemplate == Template)
2193 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002194
Douglas Gregor71dc5092009-08-06 06:41:21 +00002195 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2196 TransTemplate);
2197 }
Mike Stump11289f42009-09-09 15:08:12 +00002198
John McCalle66edc12009-11-24 19:00:30 +00002199 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002200 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002201 }
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregor71dc5092009-08-06 06:41:21 +00002203 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002204 NestedNameSpecifier *NNS = DTN->getQualifier();
2205 if (NNS) {
2206 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2207 /*FIXME:*/SourceRange(Loc),
2208 ObjectType,
2209 FirstQualifierInScope);
2210 if (!NNS) return TemplateName();
2211
2212 // These apply to the scope specifier, not the template.
2213 ObjectType = QualType();
2214 FirstQualifierInScope = 0;
2215 }
Mike Stump11289f42009-09-09 15:08:12 +00002216
Douglas Gregor71dc5092009-08-06 06:41:21 +00002217 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002218 NNS == DTN->getQualifier() &&
2219 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002220 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002221
Douglas Gregora5614c52010-09-08 23:56:00 +00002222 if (DTN->isIdentifier()) {
2223 // FIXME: Bad range
2224 SourceRange QualifierRange(getDerived().getBaseLocation());
2225 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2226 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002227 ObjectType,
2228 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002229 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002230
2231 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002232 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregor71dc5092009-08-06 06:41:21 +00002235 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002236 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002237 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002238 if (!TransTemplate)
2239 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002240
Douglas Gregor71dc5092009-08-06 06:41:21 +00002241 if (!getDerived().AlwaysRebuild() &&
2242 TransTemplate == Template)
2243 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002244
Douglas Gregor71dc5092009-08-06 06:41:21 +00002245 return TemplateName(TransTemplate);
2246 }
Mike Stump11289f42009-09-09 15:08:12 +00002247
John McCalle66edc12009-11-24 19:00:30 +00002248 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002249 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002250 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002251}
2252
2253template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002254void TreeTransform<Derived>::InventTemplateArgumentLoc(
2255 const TemplateArgument &Arg,
2256 TemplateArgumentLoc &Output) {
2257 SourceLocation Loc = getDerived().getBaseLocation();
2258 switch (Arg.getKind()) {
2259 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002260 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002261 break;
2262
2263 case TemplateArgument::Type:
2264 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002265 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002266
John McCall0ad16662009-10-29 08:12:44 +00002267 break;
2268
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002269 case TemplateArgument::Template:
2270 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2271 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002272
John McCall0ad16662009-10-29 08:12:44 +00002273 case TemplateArgument::Expression:
2274 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2275 break;
2276
2277 case TemplateArgument::Declaration:
2278 case TemplateArgument::Integral:
2279 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002280 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002281 break;
2282 }
2283}
2284
2285template<typename Derived>
2286bool TreeTransform<Derived>::TransformTemplateArgument(
2287 const TemplateArgumentLoc &Input,
2288 TemplateArgumentLoc &Output) {
2289 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002290 switch (Arg.getKind()) {
2291 case TemplateArgument::Null:
2292 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002293 Output = Input;
2294 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002295
Douglas Gregore922c772009-08-04 22:27:00 +00002296 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002297 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002298 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002299 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002300
2301 DI = getDerived().TransformType(DI);
2302 if (!DI) return true;
2303
2304 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2305 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002306 }
Mike Stump11289f42009-09-09 15:08:12 +00002307
Douglas Gregore922c772009-08-04 22:27:00 +00002308 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002309 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002310 DeclarationName Name;
2311 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2312 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002313 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002314 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002315 if (!D) return true;
2316
John McCall0d07eb32009-10-29 18:45:58 +00002317 Expr *SourceExpr = Input.getSourceDeclExpression();
2318 if (SourceExpr) {
2319 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002320 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002321 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002322 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002323 }
2324
2325 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002326 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002327 }
Mike Stump11289f42009-09-09 15:08:12 +00002328
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002329 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002330 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002331 TemplateName Template
2332 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2333 if (Template.isNull())
2334 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002335
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002336 Output = TemplateArgumentLoc(TemplateArgument(Template),
2337 Input.getTemplateQualifierRange(),
2338 Input.getTemplateNameLoc());
2339 return false;
2340 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002341
Douglas Gregore922c772009-08-04 22:27:00 +00002342 case TemplateArgument::Expression: {
2343 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002344 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002345 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002346
John McCall0ad16662009-10-29 08:12:44 +00002347 Expr *InputExpr = Input.getSourceExpression();
2348 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2349
John McCalldadc5752010-08-24 06:29:42 +00002350 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002351 = getDerived().TransformExpr(InputExpr);
2352 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002353 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002354 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002355 }
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregore922c772009-08-04 22:27:00 +00002357 case TemplateArgument::Pack: {
2358 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2359 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002360 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002361 AEnd = Arg.pack_end();
2362 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002363
John McCall0ad16662009-10-29 08:12:44 +00002364 // FIXME: preserve source information here when we start
2365 // caring about parameter packs.
2366
John McCall0d07eb32009-10-29 18:45:58 +00002367 TemplateArgumentLoc InputArg;
2368 TemplateArgumentLoc OutputArg;
2369 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2370 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002371 return true;
2372
John McCall0d07eb32009-10-29 18:45:58 +00002373 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002374 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002375
2376 TemplateArgument *TransformedArgsPtr
2377 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2378 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2379 TransformedArgsPtr);
2380 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2381 TransformedArgs.size()),
2382 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002383 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002384 }
2385 }
Mike Stump11289f42009-09-09 15:08:12 +00002386
Douglas Gregore922c772009-08-04 22:27:00 +00002387 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002388 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002389}
2390
Douglas Gregord6ff3322009-08-04 16:50:30 +00002391//===----------------------------------------------------------------------===//
2392// Type transformation
2393//===----------------------------------------------------------------------===//
2394
2395template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002396QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002397 if (getDerived().AlreadyTransformed(T))
2398 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002399
John McCall550e0c22009-10-21 00:40:46 +00002400 // Temporary workaround. All of these transformations should
2401 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002402 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002403 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002404
John McCall31f82722010-11-12 08:19:04 +00002405 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002406
John McCall550e0c22009-10-21 00:40:46 +00002407 if (!NewDI)
2408 return QualType();
2409
2410 return NewDI->getType();
2411}
2412
2413template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002414TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002415 if (getDerived().AlreadyTransformed(DI->getType()))
2416 return DI;
2417
2418 TypeLocBuilder TLB;
2419
2420 TypeLoc TL = DI->getTypeLoc();
2421 TLB.reserve(TL.getFullDataSize());
2422
John McCall31f82722010-11-12 08:19:04 +00002423 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002424 if (Result.isNull())
2425 return 0;
2426
John McCallbcd03502009-12-07 02:54:59 +00002427 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002428}
2429
2430template<typename Derived>
2431QualType
John McCall31f82722010-11-12 08:19:04 +00002432TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002433 switch (T.getTypeLocClass()) {
2434#define ABSTRACT_TYPELOC(CLASS, PARENT)
2435#define TYPELOC(CLASS, PARENT) \
2436 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002437 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002438#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002439 }
Mike Stump11289f42009-09-09 15:08:12 +00002440
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002441 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002442 return QualType();
2443}
2444
2445/// FIXME: By default, this routine adds type qualifiers only to types
2446/// that can have qualifiers, and silently suppresses those qualifiers
2447/// that are not permitted (e.g., qualifiers on reference or function
2448/// types). This is the right thing for template instantiation, but
2449/// probably not for other clients.
2450template<typename Derived>
2451QualType
2452TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002453 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002454 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002455
John McCall31f82722010-11-12 08:19:04 +00002456 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002457 if (Result.isNull())
2458 return QualType();
2459
2460 // Silently suppress qualifiers if the result type can't be qualified.
2461 // FIXME: this is the right thing for template instantiation, but
2462 // probably not for other clients.
2463 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002464 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002465
John McCallcb0f89a2010-06-05 06:41:15 +00002466 if (!Quals.empty()) {
2467 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2468 TLB.push<QualifiedTypeLoc>(Result);
2469 // No location information to preserve.
2470 }
John McCall550e0c22009-10-21 00:40:46 +00002471
2472 return Result;
2473}
2474
John McCall31f82722010-11-12 08:19:04 +00002475/// \brief Transforms a type that was written in a scope specifier,
2476/// given an object type, the results of unqualified lookup, and
2477/// an already-instantiated prefix.
2478///
2479/// The object type is provided iff the scope specifier qualifies the
2480/// member of a dependent member-access expression. The prefix is
2481/// provided iff the the scope specifier in which this appears has a
2482/// prefix.
2483///
2484/// This is private to TreeTransform.
2485template<typename Derived>
2486QualType
2487TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2488 QualType ObjectType,
2489 NamedDecl *UnqualLookup,
2490 NestedNameSpecifier *Prefix) {
2491 if (getDerived().AlreadyTransformed(T))
2492 return T;
2493
2494 TypeSourceInfo *TSI =
2495 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2496
2497 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2498 UnqualLookup, Prefix);
2499 if (!TSI) return QualType();
2500 return TSI->getType();
2501}
2502
2503template<typename Derived>
2504TypeSourceInfo *
2505TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2506 QualType ObjectType,
2507 NamedDecl *UnqualLookup,
2508 NestedNameSpecifier *Prefix) {
2509 // TODO: in some cases, we might be some verification to do here.
2510 if (ObjectType.isNull())
2511 return getDerived().TransformType(TSI);
2512
2513 QualType T = TSI->getType();
2514 if (getDerived().AlreadyTransformed(T))
2515 return TSI;
2516
2517 TypeLocBuilder TLB;
2518 QualType Result;
2519
2520 if (isa<TemplateSpecializationType>(T)) {
2521 TemplateSpecializationTypeLoc TL
2522 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2523
2524 TemplateName Template =
2525 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2526 ObjectType, UnqualLookup);
2527 if (Template.isNull()) return 0;
2528
2529 Result = getDerived()
2530 .TransformTemplateSpecializationType(TLB, TL, Template);
2531 } else if (isa<DependentTemplateSpecializationType>(T)) {
2532 DependentTemplateSpecializationTypeLoc TL
2533 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2534
2535 Result = getDerived()
2536 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2537 } else {
2538 // Nothing special needs to be done for these.
2539 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2540 }
2541
2542 if (Result.isNull()) return 0;
2543 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2544}
2545
John McCall550e0c22009-10-21 00:40:46 +00002546template <class TyLoc> static inline
2547QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2548 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2549 NewT.setNameLoc(T.getNameLoc());
2550 return T.getType();
2551}
2552
John McCall550e0c22009-10-21 00:40:46 +00002553template<typename Derived>
2554QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002555 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002556 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2557 NewT.setBuiltinLoc(T.getBuiltinLoc());
2558 if (T.needsExtraLocalData())
2559 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2560 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002561}
Mike Stump11289f42009-09-09 15:08:12 +00002562
Douglas Gregord6ff3322009-08-04 16:50:30 +00002563template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002564QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002565 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002566 // FIXME: recurse?
2567 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002568}
Mike Stump11289f42009-09-09 15:08:12 +00002569
Douglas Gregord6ff3322009-08-04 16:50:30 +00002570template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002571QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002572 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002573 QualType PointeeType
2574 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002575 if (PointeeType.isNull())
2576 return QualType();
2577
2578 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002579 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002580 // A dependent pointer type 'T *' has is being transformed such
2581 // that an Objective-C class type is being replaced for 'T'. The
2582 // resulting pointer type is an ObjCObjectPointerType, not a
2583 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002584 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002585
John McCall8b07ec22010-05-15 11:32:37 +00002586 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2587 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002588 return Result;
2589 }
John McCall31f82722010-11-12 08:19:04 +00002590
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002591 if (getDerived().AlwaysRebuild() ||
2592 PointeeType != TL.getPointeeLoc().getType()) {
2593 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2594 if (Result.isNull())
2595 return QualType();
2596 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002597
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002598 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2599 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002600 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002601}
Mike Stump11289f42009-09-09 15:08:12 +00002602
2603template<typename Derived>
2604QualType
John McCall550e0c22009-10-21 00:40:46 +00002605TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002606 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002607 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002608 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2609 if (PointeeType.isNull())
2610 return QualType();
2611
2612 QualType Result = TL.getType();
2613 if (getDerived().AlwaysRebuild() ||
2614 PointeeType != TL.getPointeeLoc().getType()) {
2615 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002616 TL.getSigilLoc());
2617 if (Result.isNull())
2618 return QualType();
2619 }
2620
Douglas Gregor049211a2010-04-22 16:50:51 +00002621 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002622 NewT.setSigilLoc(TL.getSigilLoc());
2623 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002624}
2625
John McCall70dd5f62009-10-30 00:06:24 +00002626/// Transforms a reference type. Note that somewhat paradoxically we
2627/// don't care whether the type itself is an l-value type or an r-value
2628/// type; we only care if the type was *written* as an l-value type
2629/// or an r-value type.
2630template<typename Derived>
2631QualType
2632TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002633 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002634 const ReferenceType *T = TL.getTypePtr();
2635
2636 // Note that this works with the pointee-as-written.
2637 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2638 if (PointeeType.isNull())
2639 return QualType();
2640
2641 QualType Result = TL.getType();
2642 if (getDerived().AlwaysRebuild() ||
2643 PointeeType != T->getPointeeTypeAsWritten()) {
2644 Result = getDerived().RebuildReferenceType(PointeeType,
2645 T->isSpelledAsLValue(),
2646 TL.getSigilLoc());
2647 if (Result.isNull())
2648 return QualType();
2649 }
2650
2651 // r-value references can be rebuilt as l-value references.
2652 ReferenceTypeLoc NewTL;
2653 if (isa<LValueReferenceType>(Result))
2654 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2655 else
2656 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2657 NewTL.setSigilLoc(TL.getSigilLoc());
2658
2659 return Result;
2660}
2661
Mike Stump11289f42009-09-09 15:08:12 +00002662template<typename Derived>
2663QualType
John McCall550e0c22009-10-21 00:40:46 +00002664TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002665 LValueReferenceTypeLoc TL) {
2666 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002667}
2668
Mike Stump11289f42009-09-09 15:08:12 +00002669template<typename Derived>
2670QualType
John McCall550e0c22009-10-21 00:40:46 +00002671TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002672 RValueReferenceTypeLoc TL) {
2673 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002674}
Mike Stump11289f42009-09-09 15:08:12 +00002675
Douglas Gregord6ff3322009-08-04 16:50:30 +00002676template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002677QualType
John McCall550e0c22009-10-21 00:40:46 +00002678TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002679 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002680 MemberPointerType *T = TL.getTypePtr();
2681
2682 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002683 if (PointeeType.isNull())
2684 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002685
John McCall550e0c22009-10-21 00:40:46 +00002686 // TODO: preserve source information for this.
2687 QualType ClassType
2688 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002689 if (ClassType.isNull())
2690 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002691
John McCall550e0c22009-10-21 00:40:46 +00002692 QualType Result = TL.getType();
2693 if (getDerived().AlwaysRebuild() ||
2694 PointeeType != T->getPointeeType() ||
2695 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002696 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2697 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002698 if (Result.isNull())
2699 return QualType();
2700 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002701
John McCall550e0c22009-10-21 00:40:46 +00002702 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2703 NewTL.setSigilLoc(TL.getSigilLoc());
2704
2705 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002706}
2707
Mike Stump11289f42009-09-09 15:08:12 +00002708template<typename Derived>
2709QualType
John McCall550e0c22009-10-21 00:40:46 +00002710TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002711 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002712 ConstantArrayType *T = TL.getTypePtr();
2713 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002714 if (ElementType.isNull())
2715 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002716
John McCall550e0c22009-10-21 00:40:46 +00002717 QualType Result = TL.getType();
2718 if (getDerived().AlwaysRebuild() ||
2719 ElementType != T->getElementType()) {
2720 Result = getDerived().RebuildConstantArrayType(ElementType,
2721 T->getSizeModifier(),
2722 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002723 T->getIndexTypeCVRQualifiers(),
2724 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002725 if (Result.isNull())
2726 return QualType();
2727 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002728
John McCall550e0c22009-10-21 00:40:46 +00002729 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2730 NewTL.setLBracketLoc(TL.getLBracketLoc());
2731 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002732
John McCall550e0c22009-10-21 00:40:46 +00002733 Expr *Size = TL.getSizeExpr();
2734 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002735 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002736 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2737 }
2738 NewTL.setSizeExpr(Size);
2739
2740 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002741}
Mike Stump11289f42009-09-09 15:08:12 +00002742
Douglas Gregord6ff3322009-08-04 16:50:30 +00002743template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002744QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002745 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002746 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002747 IncompleteArrayType *T = TL.getTypePtr();
2748 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749 if (ElementType.isNull())
2750 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002751
John McCall550e0c22009-10-21 00:40:46 +00002752 QualType Result = TL.getType();
2753 if (getDerived().AlwaysRebuild() ||
2754 ElementType != T->getElementType()) {
2755 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002756 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002757 T->getIndexTypeCVRQualifiers(),
2758 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002759 if (Result.isNull())
2760 return QualType();
2761 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002762
John McCall550e0c22009-10-21 00:40:46 +00002763 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2764 NewTL.setLBracketLoc(TL.getLBracketLoc());
2765 NewTL.setRBracketLoc(TL.getRBracketLoc());
2766 NewTL.setSizeExpr(0);
2767
2768 return Result;
2769}
2770
2771template<typename Derived>
2772QualType
2773TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002774 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002775 VariableArrayType *T = TL.getTypePtr();
2776 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2777 if (ElementType.isNull())
2778 return QualType();
2779
2780 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002781 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002782
John McCalldadc5752010-08-24 06:29:42 +00002783 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002784 = getDerived().TransformExpr(T->getSizeExpr());
2785 if (SizeResult.isInvalid())
2786 return QualType();
2787
John McCallb268a282010-08-23 23:25:46 +00002788 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002789
2790 QualType Result = TL.getType();
2791 if (getDerived().AlwaysRebuild() ||
2792 ElementType != T->getElementType() ||
2793 Size != T->getSizeExpr()) {
2794 Result = getDerived().RebuildVariableArrayType(ElementType,
2795 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002796 Size,
John McCall550e0c22009-10-21 00:40:46 +00002797 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002798 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002799 if (Result.isNull())
2800 return QualType();
2801 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002802
John McCall550e0c22009-10-21 00:40:46 +00002803 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2804 NewTL.setLBracketLoc(TL.getLBracketLoc());
2805 NewTL.setRBracketLoc(TL.getRBracketLoc());
2806 NewTL.setSizeExpr(Size);
2807
2808 return Result;
2809}
2810
2811template<typename Derived>
2812QualType
2813TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002814 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002815 DependentSizedArrayType *T = TL.getTypePtr();
2816 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2817 if (ElementType.isNull())
2818 return QualType();
2819
2820 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002821 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002822
John McCalldadc5752010-08-24 06:29:42 +00002823 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002824 = getDerived().TransformExpr(T->getSizeExpr());
2825 if (SizeResult.isInvalid())
2826 return QualType();
2827
2828 Expr *Size = static_cast<Expr*>(SizeResult.get());
2829
2830 QualType Result = TL.getType();
2831 if (getDerived().AlwaysRebuild() ||
2832 ElementType != T->getElementType() ||
2833 Size != T->getSizeExpr()) {
2834 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2835 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002836 Size,
John McCall550e0c22009-10-21 00:40:46 +00002837 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002838 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002839 if (Result.isNull())
2840 return QualType();
2841 }
2842 else SizeResult.take();
2843
2844 // We might have any sort of array type now, but fortunately they
2845 // all have the same location layout.
2846 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2847 NewTL.setLBracketLoc(TL.getLBracketLoc());
2848 NewTL.setRBracketLoc(TL.getRBracketLoc());
2849 NewTL.setSizeExpr(Size);
2850
2851 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002852}
Mike Stump11289f42009-09-09 15:08:12 +00002853
2854template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002855QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002856 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002857 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002858 DependentSizedExtVectorType *T = TL.getTypePtr();
2859
2860 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002861 QualType ElementType = getDerived().TransformType(T->getElementType());
2862 if (ElementType.isNull())
2863 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002864
Douglas Gregore922c772009-08-04 22:27:00 +00002865 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002866 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002867
John McCalldadc5752010-08-24 06:29:42 +00002868 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002869 if (Size.isInvalid())
2870 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002871
John McCall550e0c22009-10-21 00:40:46 +00002872 QualType Result = TL.getType();
2873 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002874 ElementType != T->getElementType() ||
2875 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002876 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002877 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002878 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002879 if (Result.isNull())
2880 return QualType();
2881 }
John McCall550e0c22009-10-21 00:40:46 +00002882
2883 // Result might be dependent or not.
2884 if (isa<DependentSizedExtVectorType>(Result)) {
2885 DependentSizedExtVectorTypeLoc NewTL
2886 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2887 NewTL.setNameLoc(TL.getNameLoc());
2888 } else {
2889 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2890 NewTL.setNameLoc(TL.getNameLoc());
2891 }
2892
2893 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002894}
Mike Stump11289f42009-09-09 15:08:12 +00002895
2896template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002897QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002898 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002899 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002900 QualType ElementType = getDerived().TransformType(T->getElementType());
2901 if (ElementType.isNull())
2902 return QualType();
2903
John McCall550e0c22009-10-21 00:40:46 +00002904 QualType Result = TL.getType();
2905 if (getDerived().AlwaysRebuild() ||
2906 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002907 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00002908 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00002909 if (Result.isNull())
2910 return QualType();
2911 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002912
John McCall550e0c22009-10-21 00:40:46 +00002913 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2914 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002915
John McCall550e0c22009-10-21 00:40:46 +00002916 return Result;
2917}
2918
2919template<typename Derived>
2920QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002921 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002922 VectorType *T = TL.getTypePtr();
2923 QualType ElementType = getDerived().TransformType(T->getElementType());
2924 if (ElementType.isNull())
2925 return QualType();
2926
2927 QualType Result = TL.getType();
2928 if (getDerived().AlwaysRebuild() ||
2929 ElementType != T->getElementType()) {
2930 Result = getDerived().RebuildExtVectorType(ElementType,
2931 T->getNumElements(),
2932 /*FIXME*/ SourceLocation());
2933 if (Result.isNull())
2934 return QualType();
2935 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002936
John McCall550e0c22009-10-21 00:40:46 +00002937 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2938 NewTL.setNameLoc(TL.getNameLoc());
2939
2940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941}
Mike Stump11289f42009-09-09 15:08:12 +00002942
2943template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002944ParmVarDecl *
2945TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2946 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2947 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2948 if (!NewDI)
2949 return 0;
2950
2951 if (NewDI == OldDI)
2952 return OldParm;
2953 else
2954 return ParmVarDecl::Create(SemaRef.Context,
2955 OldParm->getDeclContext(),
2956 OldParm->getLocation(),
2957 OldParm->getIdentifier(),
2958 NewDI->getType(),
2959 NewDI,
2960 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002961 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002962 /* DefArg */ NULL);
2963}
2964
2965template<typename Derived>
2966bool TreeTransform<Derived>::
2967 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2968 llvm::SmallVectorImpl<QualType> &PTypes,
2969 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2970 FunctionProtoType *T = TL.getTypePtr();
2971
2972 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2973 ParmVarDecl *OldParm = TL.getArg(i);
2974
2975 QualType NewType;
2976 ParmVarDecl *NewParm;
2977
2978 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002979 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2980 if (!NewParm)
2981 return true;
2982 NewType = NewParm->getType();
2983
2984 // Deal with the possibility that we don't have a parameter
2985 // declaration for this parameter.
2986 } else {
2987 NewParm = 0;
2988
2989 QualType OldType = T->getArgType(i);
2990 NewType = getDerived().TransformType(OldType);
2991 if (NewType.isNull())
2992 return true;
2993 }
2994
2995 PTypes.push_back(NewType);
2996 PVars.push_back(NewParm);
2997 }
2998
2999 return false;
3000}
3001
3002template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003003QualType
John McCall550e0c22009-10-21 00:40:46 +00003004TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003005 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003006 // Transform the parameters and return type.
3007 //
3008 // We instantiate in source order, with the return type first followed by
3009 // the parameters, because users tend to expect this (even if they shouldn't
3010 // rely on it!).
3011 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003012 // When the function has a trailing return type, we instantiate the
3013 // parameters before the return type, since the return type can then refer
3014 // to the parameters themselves (via decltype, sizeof, etc.).
3015 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003016 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003017 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003018 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003019
Douglas Gregor7fb25412010-10-01 18:44:50 +00003020 QualType ResultType;
3021
3022 if (TL.getTrailingReturn()) {
3023 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3024 return QualType();
3025
3026 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3027 if (ResultType.isNull())
3028 return QualType();
3029 }
3030 else {
3031 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3032 if (ResultType.isNull())
3033 return QualType();
3034
3035 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3036 return QualType();
3037 }
3038
John McCall550e0c22009-10-21 00:40:46 +00003039 QualType Result = TL.getType();
3040 if (getDerived().AlwaysRebuild() ||
3041 ResultType != T->getResultType() ||
3042 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3043 Result = getDerived().RebuildFunctionProtoType(ResultType,
3044 ParamTypes.data(),
3045 ParamTypes.size(),
3046 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003047 T->getTypeQuals(),
3048 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003049 if (Result.isNull())
3050 return QualType();
3051 }
Mike Stump11289f42009-09-09 15:08:12 +00003052
John McCall550e0c22009-10-21 00:40:46 +00003053 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3054 NewTL.setLParenLoc(TL.getLParenLoc());
3055 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003056 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003057 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3058 NewTL.setArg(i, ParamDecls[i]);
3059
3060 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003061}
Mike Stump11289f42009-09-09 15:08:12 +00003062
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063template<typename Derived>
3064QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003065 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003066 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003067 FunctionNoProtoType *T = TL.getTypePtr();
3068 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3069 if (ResultType.isNull())
3070 return QualType();
3071
3072 QualType Result = TL.getType();
3073 if (getDerived().AlwaysRebuild() ||
3074 ResultType != T->getResultType())
3075 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3076
3077 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3078 NewTL.setLParenLoc(TL.getLParenLoc());
3079 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003080 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003081
3082 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003083}
Mike Stump11289f42009-09-09 15:08:12 +00003084
John McCallb96ec562009-12-04 22:46:56 +00003085template<typename Derived> QualType
3086TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003087 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003088 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003089 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003090 if (!D)
3091 return QualType();
3092
3093 QualType Result = TL.getType();
3094 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3095 Result = getDerived().RebuildUnresolvedUsingType(D);
3096 if (Result.isNull())
3097 return QualType();
3098 }
3099
3100 // We might get an arbitrary type spec type back. We should at
3101 // least always get a type spec type, though.
3102 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3103 NewTL.setNameLoc(TL.getNameLoc());
3104
3105 return Result;
3106}
3107
Douglas Gregord6ff3322009-08-04 16:50:30 +00003108template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003109QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003110 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003111 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003112 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003113 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3114 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003115 if (!Typedef)
3116 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003117
John McCall550e0c22009-10-21 00:40:46 +00003118 QualType Result = TL.getType();
3119 if (getDerived().AlwaysRebuild() ||
3120 Typedef != T->getDecl()) {
3121 Result = getDerived().RebuildTypedefType(Typedef);
3122 if (Result.isNull())
3123 return QualType();
3124 }
Mike Stump11289f42009-09-09 15:08:12 +00003125
John McCall550e0c22009-10-21 00:40:46 +00003126 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3127 NewTL.setNameLoc(TL.getNameLoc());
3128
3129 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003130}
Mike Stump11289f42009-09-09 15:08:12 +00003131
Douglas Gregord6ff3322009-08-04 16:50:30 +00003132template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003133QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003134 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003135 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003136 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003137
John McCalldadc5752010-08-24 06:29:42 +00003138 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003139 if (E.isInvalid())
3140 return QualType();
3141
John McCall550e0c22009-10-21 00:40:46 +00003142 QualType Result = TL.getType();
3143 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003144 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003145 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003146 if (Result.isNull())
3147 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003148 }
John McCall550e0c22009-10-21 00:40:46 +00003149 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003150
John McCall550e0c22009-10-21 00:40:46 +00003151 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003152 NewTL.setTypeofLoc(TL.getTypeofLoc());
3153 NewTL.setLParenLoc(TL.getLParenLoc());
3154 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003155
3156 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003157}
Mike Stump11289f42009-09-09 15:08:12 +00003158
3159template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003160QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003161 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003162 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3163 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3164 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003165 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003166
John McCall550e0c22009-10-21 00:40:46 +00003167 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003168 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3169 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003170 if (Result.isNull())
3171 return QualType();
3172 }
Mike Stump11289f42009-09-09 15:08:12 +00003173
John McCall550e0c22009-10-21 00:40:46 +00003174 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003175 NewTL.setTypeofLoc(TL.getTypeofLoc());
3176 NewTL.setLParenLoc(TL.getLParenLoc());
3177 NewTL.setRParenLoc(TL.getRParenLoc());
3178 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003179
3180 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003181}
Mike Stump11289f42009-09-09 15:08:12 +00003182
3183template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003184QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003185 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003186 DecltypeType *T = TL.getTypePtr();
3187
Douglas Gregore922c772009-08-04 22:27:00 +00003188 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003189 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003190
John McCalldadc5752010-08-24 06:29:42 +00003191 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003192 if (E.isInvalid())
3193 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003194
John McCall550e0c22009-10-21 00:40:46 +00003195 QualType Result = TL.getType();
3196 if (getDerived().AlwaysRebuild() ||
3197 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003198 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003199 if (Result.isNull())
3200 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003201 }
John McCall550e0c22009-10-21 00:40:46 +00003202 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003203
John McCall550e0c22009-10-21 00:40:46 +00003204 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3205 NewTL.setNameLoc(TL.getNameLoc());
3206
3207 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003208}
3209
3210template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003211QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003212 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003213 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003214 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003215 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3216 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003217 if (!Record)
3218 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003219
John McCall550e0c22009-10-21 00:40:46 +00003220 QualType Result = TL.getType();
3221 if (getDerived().AlwaysRebuild() ||
3222 Record != T->getDecl()) {
3223 Result = getDerived().RebuildRecordType(Record);
3224 if (Result.isNull())
3225 return QualType();
3226 }
Mike Stump11289f42009-09-09 15:08:12 +00003227
John McCall550e0c22009-10-21 00:40:46 +00003228 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3229 NewTL.setNameLoc(TL.getNameLoc());
3230
3231 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003232}
Mike Stump11289f42009-09-09 15:08:12 +00003233
3234template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003235QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003236 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003237 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003238 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003239 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3240 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003241 if (!Enum)
3242 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003243
John McCall550e0c22009-10-21 00:40:46 +00003244 QualType Result = TL.getType();
3245 if (getDerived().AlwaysRebuild() ||
3246 Enum != T->getDecl()) {
3247 Result = getDerived().RebuildEnumType(Enum);
3248 if (Result.isNull())
3249 return QualType();
3250 }
Mike Stump11289f42009-09-09 15:08:12 +00003251
John McCall550e0c22009-10-21 00:40:46 +00003252 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3253 NewTL.setNameLoc(TL.getNameLoc());
3254
3255 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003256}
John McCallfcc33b02009-09-05 00:15:47 +00003257
John McCalle78aac42010-03-10 03:28:59 +00003258template<typename Derived>
3259QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3260 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003261 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003262 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3263 TL.getTypePtr()->getDecl());
3264 if (!D) return QualType();
3265
3266 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3267 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3268 return T;
3269}
3270
Mike Stump11289f42009-09-09 15:08:12 +00003271
Douglas Gregord6ff3322009-08-04 16:50:30 +00003272template<typename Derived>
3273QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003274 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003275 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003276 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003277}
3278
Mike Stump11289f42009-09-09 15:08:12 +00003279template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003280QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003281 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003282 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003283 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003284}
3285
3286template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003287QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003288 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003289 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003290 const TemplateSpecializationType *T = TL.getTypePtr();
3291
Mike Stump11289f42009-09-09 15:08:12 +00003292 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003293 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003294 if (Template.isNull())
3295 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003296
John McCall31f82722010-11-12 08:19:04 +00003297 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3298}
3299
3300template <typename Derived>
3301QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3302 TypeLocBuilder &TLB,
3303 TemplateSpecializationTypeLoc TL,
3304 TemplateName Template) {
3305 const TemplateSpecializationType *T = TL.getTypePtr();
3306
John McCall6b51f282009-11-23 01:53:49 +00003307 TemplateArgumentListInfo NewTemplateArgs;
3308 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3309 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3310
3311 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3312 TemplateArgumentLoc Loc;
3313 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003314 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003315 NewTemplateArgs.addArgument(Loc);
3316 }
Mike Stump11289f42009-09-09 15:08:12 +00003317
John McCall0ad16662009-10-29 08:12:44 +00003318 // FIXME: maybe don't rebuild if all the template arguments are the same.
3319
3320 QualType Result =
3321 getDerived().RebuildTemplateSpecializationType(Template,
3322 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003323 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003324
3325 if (!Result.isNull()) {
3326 TemplateSpecializationTypeLoc NewTL
3327 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3328 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3329 NewTL.setLAngleLoc(TL.getLAngleLoc());
3330 NewTL.setRAngleLoc(TL.getRAngleLoc());
3331 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3332 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003333 }
Mike Stump11289f42009-09-09 15:08:12 +00003334
John McCall0ad16662009-10-29 08:12:44 +00003335 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003336}
Mike Stump11289f42009-09-09 15:08:12 +00003337
3338template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003339QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003340TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003341 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003342 ElaboratedType *T = TL.getTypePtr();
3343
3344 NestedNameSpecifier *NNS = 0;
3345 // NOTE: the qualifier in an ElaboratedType is optional.
3346 if (T->getQualifier() != 0) {
3347 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003348 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003349 if (!NNS)
3350 return QualType();
3351 }
Mike Stump11289f42009-09-09 15:08:12 +00003352
John McCall31f82722010-11-12 08:19:04 +00003353 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3354 if (NamedT.isNull())
3355 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003356
John McCall550e0c22009-10-21 00:40:46 +00003357 QualType Result = TL.getType();
3358 if (getDerived().AlwaysRebuild() ||
3359 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003360 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003361 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3362 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003363 if (Result.isNull())
3364 return QualType();
3365 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003366
Abramo Bagnara6150c882010-05-11 21:36:43 +00003367 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003368 NewTL.setKeywordLoc(TL.getKeywordLoc());
3369 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003370
3371 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003372}
Mike Stump11289f42009-09-09 15:08:12 +00003373
3374template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003375QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003376 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003377 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003378
Douglas Gregord6ff3322009-08-04 16:50:30 +00003379 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003380 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003381 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003382 if (!NNS)
3383 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003384
John McCallc392f372010-06-11 00:33:02 +00003385 QualType Result
3386 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3387 T->getIdentifier(),
3388 TL.getKeywordLoc(),
3389 TL.getQualifierRange(),
3390 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003391 if (Result.isNull())
3392 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003393
Abramo Bagnarad7548482010-05-19 21:37:53 +00003394 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3395 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003396 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3397
Abramo Bagnarad7548482010-05-19 21:37:53 +00003398 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3399 NewTL.setKeywordLoc(TL.getKeywordLoc());
3400 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003401 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003402 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3403 NewTL.setKeywordLoc(TL.getKeywordLoc());
3404 NewTL.setQualifierRange(TL.getQualifierRange());
3405 NewTL.setNameLoc(TL.getNameLoc());
3406 }
John McCall550e0c22009-10-21 00:40:46 +00003407 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003408}
Mike Stump11289f42009-09-09 15:08:12 +00003409
Douglas Gregord6ff3322009-08-04 16:50:30 +00003410template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003411QualType TreeTransform<Derived>::
3412 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003413 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003414 DependentTemplateSpecializationType *T = TL.getTypePtr();
3415
3416 NestedNameSpecifier *NNS
3417 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003418 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003419 if (!NNS)
3420 return QualType();
3421
John McCall31f82722010-11-12 08:19:04 +00003422 return getDerived()
3423 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3424}
3425
3426template<typename Derived>
3427QualType TreeTransform<Derived>::
3428 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3429 DependentTemplateSpecializationTypeLoc TL,
3430 NestedNameSpecifier *NNS) {
3431 DependentTemplateSpecializationType *T = TL.getTypePtr();
3432
John McCallc392f372010-06-11 00:33:02 +00003433 TemplateArgumentListInfo NewTemplateArgs;
3434 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3435 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3436
3437 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3438 TemplateArgumentLoc Loc;
3439 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3440 return QualType();
3441 NewTemplateArgs.addArgument(Loc);
3442 }
3443
Douglas Gregora5614c52010-09-08 23:56:00 +00003444 QualType Result
3445 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3446 NNS,
3447 TL.getQualifierRange(),
3448 T->getIdentifier(),
3449 TL.getNameLoc(),
3450 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003451 if (Result.isNull())
3452 return QualType();
3453
3454 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3455 QualType NamedT = ElabT->getNamedType();
3456
3457 // Copy information relevant to the template specialization.
3458 TemplateSpecializationTypeLoc NamedTL
3459 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3460 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3461 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3462 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3463 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3464
3465 // Copy information relevant to the elaborated type.
3466 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3467 NewTL.setKeywordLoc(TL.getKeywordLoc());
3468 NewTL.setQualifierRange(TL.getQualifierRange());
3469 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003470 TypeLoc NewTL(Result, TL.getOpaqueData());
3471 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003472 }
3473 return Result;
3474}
3475
3476template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003477QualType
3478TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003479 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003480 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003481 TLB.pushFullCopy(TL);
3482 return TL.getType();
3483}
3484
3485template<typename Derived>
3486QualType
3487TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003488 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003489 // ObjCObjectType is never dependent.
3490 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003491 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003492}
Mike Stump11289f42009-09-09 15:08:12 +00003493
3494template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003495QualType
3496TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003497 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003498 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003499 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003500 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003501}
3502
Douglas Gregord6ff3322009-08-04 16:50:30 +00003503//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003504// Statement transformation
3505//===----------------------------------------------------------------------===//
3506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003507StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003508TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003509 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003510}
3511
3512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003513StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003514TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3515 return getDerived().TransformCompoundStmt(S, false);
3516}
3517
3518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003519StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003520TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003521 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003522 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003523 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003524 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003525 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3526 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003527 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003528 if (Result.isInvalid()) {
3529 // Immediately fail if this was a DeclStmt, since it's very
3530 // likely that this will cause problems for future statements.
3531 if (isa<DeclStmt>(*B))
3532 return StmtError();
3533
3534 // Otherwise, just keep processing substatements and fail later.
3535 SubStmtInvalid = true;
3536 continue;
3537 }
Mike Stump11289f42009-09-09 15:08:12 +00003538
Douglas Gregorebe10102009-08-20 07:17:43 +00003539 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3540 Statements.push_back(Result.takeAs<Stmt>());
3541 }
Mike Stump11289f42009-09-09 15:08:12 +00003542
John McCall1ababa62010-08-27 19:56:05 +00003543 if (SubStmtInvalid)
3544 return StmtError();
3545
Douglas Gregorebe10102009-08-20 07:17:43 +00003546 if (!getDerived().AlwaysRebuild() &&
3547 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003548 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003549
3550 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3551 move_arg(Statements),
3552 S->getRBracLoc(),
3553 IsStmtExpr);
3554}
Mike Stump11289f42009-09-09 15:08:12 +00003555
Douglas Gregorebe10102009-08-20 07:17:43 +00003556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003557StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003558TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003559 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003560 {
3561 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003562 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003563
Eli Friedman06577382009-11-19 03:14:00 +00003564 // Transform the left-hand case value.
3565 LHS = getDerived().TransformExpr(S->getLHS());
3566 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003567 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003568
Eli Friedman06577382009-11-19 03:14:00 +00003569 // Transform the right-hand case value (for the GNU case-range extension).
3570 RHS = getDerived().TransformExpr(S->getRHS());
3571 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003572 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003573 }
Mike Stump11289f42009-09-09 15:08:12 +00003574
Douglas Gregorebe10102009-08-20 07:17:43 +00003575 // Build the case statement.
3576 // Case statements are always rebuilt so that they will attached to their
3577 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003578 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003579 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003580 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003581 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003582 S->getColonLoc());
3583 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003584 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregorebe10102009-08-20 07:17:43 +00003586 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003587 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003588 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003589 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003590
Douglas Gregorebe10102009-08-20 07:17:43 +00003591 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003592 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003593}
3594
3595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003596StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003597TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003598 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003599 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003600 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003601 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003602
Douglas Gregorebe10102009-08-20 07:17:43 +00003603 // Default statements are always rebuilt
3604 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003605 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003606}
Mike Stump11289f42009-09-09 15:08:12 +00003607
Douglas Gregorebe10102009-08-20 07:17:43 +00003608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003609StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003610TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003611 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003612 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003613 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003614
Douglas Gregorebe10102009-08-20 07:17:43 +00003615 // FIXME: Pass the real colon location in.
3616 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3617 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003618 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003619}
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregorebe10102009-08-20 07:17:43 +00003621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003622StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003623TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003624 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003625 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003626 VarDecl *ConditionVar = 0;
3627 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003628 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003629 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003630 getDerived().TransformDefinition(
3631 S->getConditionVariable()->getLocation(),
3632 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003633 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003634 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003635 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003636 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003637
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003638 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003639 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003640
3641 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003642 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003643 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003644 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003645 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003646 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003647 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003648
John McCallb268a282010-08-23 23:25:46 +00003649 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003650 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003651 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003652
John McCallb268a282010-08-23 23:25:46 +00003653 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3654 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003655 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003656
Douglas Gregorebe10102009-08-20 07:17:43 +00003657 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003658 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003659 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003660 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003661
Douglas Gregorebe10102009-08-20 07:17:43 +00003662 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003663 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003664 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003665 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003666
Douglas Gregorebe10102009-08-20 07:17:43 +00003667 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003668 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003669 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003670 Then.get() == S->getThen() &&
3671 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003672 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003674 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00003675 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00003676 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003677}
3678
3679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003680StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003681TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003682 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003683 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003684 VarDecl *ConditionVar = 0;
3685 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003686 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003687 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003688 getDerived().TransformDefinition(
3689 S->getConditionVariable()->getLocation(),
3690 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003691 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003692 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003693 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003694 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003695
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003696 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003697 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003698 }
Mike Stump11289f42009-09-09 15:08:12 +00003699
Douglas Gregorebe10102009-08-20 07:17:43 +00003700 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003701 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003702 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003703 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003705 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003706
Douglas Gregorebe10102009-08-20 07:17:43 +00003707 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003708 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003710 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003711
Douglas Gregorebe10102009-08-20 07:17:43 +00003712 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003713 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3714 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003715}
Mike Stump11289f42009-09-09 15:08:12 +00003716
Douglas Gregorebe10102009-08-20 07:17:43 +00003717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003718StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003719TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003720 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003721 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003722 VarDecl *ConditionVar = 0;
3723 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003724 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003725 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003726 getDerived().TransformDefinition(
3727 S->getConditionVariable()->getLocation(),
3728 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003729 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003730 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003731 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003732 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003733
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003734 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003735 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003736
3737 if (S->getCond()) {
3738 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003739 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003740 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003741 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003742 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003743 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003744 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003745 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003746 }
Mike Stump11289f42009-09-09 15:08:12 +00003747
John McCallb268a282010-08-23 23:25:46 +00003748 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3749 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003750 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003751
Douglas Gregorebe10102009-08-20 07:17:43 +00003752 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003753 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003754 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003755 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003756
Douglas Gregorebe10102009-08-20 07:17:43 +00003757 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003758 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003759 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003760 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003761 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003762
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003763 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003764 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003765}
Mike Stump11289f42009-09-09 15:08:12 +00003766
Douglas Gregorebe10102009-08-20 07:17:43 +00003767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003768StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003769TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003771 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003772 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003773 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003774
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003775 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003776 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003777 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003778 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003779
Douglas Gregorebe10102009-08-20 07:17:43 +00003780 if (!getDerived().AlwaysRebuild() &&
3781 Cond.get() == S->getCond() &&
3782 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003783 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003784
John McCallb268a282010-08-23 23:25:46 +00003785 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3786 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003787 S->getRParenLoc());
3788}
Mike Stump11289f42009-09-09 15:08:12 +00003789
Douglas Gregorebe10102009-08-20 07:17:43 +00003790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003792TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003793 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003794 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003795 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003796 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003797
Douglas Gregorebe10102009-08-20 07:17:43 +00003798 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003799 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003800 VarDecl *ConditionVar = 0;
3801 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003802 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003803 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003804 getDerived().TransformDefinition(
3805 S->getConditionVariable()->getLocation(),
3806 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003807 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003808 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003809 } else {
3810 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003811
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003812 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003813 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003814
3815 if (S->getCond()) {
3816 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003817 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003818 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003819 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003820 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003821 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003822
John McCallb268a282010-08-23 23:25:46 +00003823 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003824 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003825 }
Mike Stump11289f42009-09-09 15:08:12 +00003826
John McCallb268a282010-08-23 23:25:46 +00003827 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3828 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003829 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003830
Douglas Gregorebe10102009-08-20 07:17:43 +00003831 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003832 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003833 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003834 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003835
John McCallb268a282010-08-23 23:25:46 +00003836 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3837 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003838 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003839
Douglas Gregorebe10102009-08-20 07:17:43 +00003840 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003841 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003842 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003843 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003844
Douglas Gregorebe10102009-08-20 07:17:43 +00003845 if (!getDerived().AlwaysRebuild() &&
3846 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003847 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003848 Inc.get() == S->getInc() &&
3849 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003850 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003851
Douglas Gregorebe10102009-08-20 07:17:43 +00003852 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003853 Init.get(), FullCond, ConditionVar,
3854 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003855}
3856
3857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003858StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003859TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003860 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003861 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003862 S->getLabel());
3863}
3864
3865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003866StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003867TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003868 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003869 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003870 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003871
Douglas Gregorebe10102009-08-20 07:17:43 +00003872 if (!getDerived().AlwaysRebuild() &&
3873 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003874 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003875
3876 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003877 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003878}
3879
3880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003881StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003882TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003883 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003884}
Mike Stump11289f42009-09-09 15:08:12 +00003885
Douglas Gregorebe10102009-08-20 07:17:43 +00003886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003887StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003888TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003889 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003890}
Mike Stump11289f42009-09-09 15:08:12 +00003891
Douglas Gregorebe10102009-08-20 07:17:43 +00003892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003893StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003894TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003895 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003896 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003897 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003898
Mike Stump11289f42009-09-09 15:08:12 +00003899 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003900 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003901 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003902}
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregorebe10102009-08-20 07:17:43 +00003904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003905StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003906TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003907 bool DeclChanged = false;
3908 llvm::SmallVector<Decl *, 4> Decls;
3909 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3910 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003911 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3912 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003913 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003914 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003915
Douglas Gregorebe10102009-08-20 07:17:43 +00003916 if (Transformed != *D)
3917 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003918
Douglas Gregorebe10102009-08-20 07:17:43 +00003919 Decls.push_back(Transformed);
3920 }
Mike Stump11289f42009-09-09 15:08:12 +00003921
Douglas Gregorebe10102009-08-20 07:17:43 +00003922 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00003923 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003924
3925 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003926 S->getStartLoc(), S->getEndLoc());
3927}
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregorebe10102009-08-20 07:17:43 +00003929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003930StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003931TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003932 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00003933 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003934}
3935
3936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003937StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003938TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003939
John McCall37ad5512010-08-23 06:44:23 +00003940 ASTOwningVector<Expr*> Constraints(getSema());
3941 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003942 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003943
John McCalldadc5752010-08-24 06:29:42 +00003944 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003945 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003946
3947 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003948
Anders Carlssonaaeef072010-01-24 05:50:09 +00003949 // Go through the outputs.
3950 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003951 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003952
Anders Carlssonaaeef072010-01-24 05:50:09 +00003953 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003954 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003955
Anders Carlssonaaeef072010-01-24 05:50:09 +00003956 // Transform the output expr.
3957 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003958 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003959 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003960 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003961
Anders Carlssonaaeef072010-01-24 05:50:09 +00003962 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003963
John McCallb268a282010-08-23 23:25:46 +00003964 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003965 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003966
Anders Carlssonaaeef072010-01-24 05:50:09 +00003967 // Go through the inputs.
3968 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003969 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003970
Anders Carlssonaaeef072010-01-24 05:50:09 +00003971 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003972 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003973
Anders Carlssonaaeef072010-01-24 05:50:09 +00003974 // Transform the input expr.
3975 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003976 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003977 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003978 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003979
Anders Carlssonaaeef072010-01-24 05:50:09 +00003980 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003981
John McCallb268a282010-08-23 23:25:46 +00003982 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003983 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003984
Anders Carlssonaaeef072010-01-24 05:50:09 +00003985 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00003986 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003987
3988 // Go through the clobbers.
3989 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00003990 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00003991
3992 // No need to transform the asm string literal.
3993 AsmString = SemaRef.Owned(S->getAsmString());
3994
3995 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3996 S->isSimple(),
3997 S->isVolatile(),
3998 S->getNumOutputs(),
3999 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004000 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004001 move_arg(Constraints),
4002 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004003 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004004 move_arg(Clobbers),
4005 S->getRParenLoc(),
4006 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004007}
4008
4009
4010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004011StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004012TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004013 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004014 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004015 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004016 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004017
Douglas Gregor96c79492010-04-23 22:50:49 +00004018 // Transform the @catch statements (if present).
4019 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004020 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004021 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004022 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004023 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004024 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004025 if (Catch.get() != S->getCatchStmt(I))
4026 AnyCatchChanged = true;
4027 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004028 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004029
Douglas Gregor306de2f2010-04-22 23:59:56 +00004030 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004031 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004032 if (S->getFinallyStmt()) {
4033 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4034 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004035 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004036 }
4037
4038 // If nothing changed, just retain this statement.
4039 if (!getDerived().AlwaysRebuild() &&
4040 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004041 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004042 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004043 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004044
Douglas Gregor306de2f2010-04-22 23:59:56 +00004045 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004046 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4047 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004048}
Mike Stump11289f42009-09-09 15:08:12 +00004049
Douglas Gregorebe10102009-08-20 07:17:43 +00004050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004051StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004052TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004053 // Transform the @catch parameter, if there is one.
4054 VarDecl *Var = 0;
4055 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4056 TypeSourceInfo *TSInfo = 0;
4057 if (FromVar->getTypeSourceInfo()) {
4058 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4059 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004060 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004061 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004062
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004063 QualType T;
4064 if (TSInfo)
4065 T = TSInfo->getType();
4066 else {
4067 T = getDerived().TransformType(FromVar->getType());
4068 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004069 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004070 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004071
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004072 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4073 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004074 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004075 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004076
John McCalldadc5752010-08-24 06:29:42 +00004077 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004078 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004079 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004080
4081 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004082 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004083 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004084}
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregorebe10102009-08-20 07:17:43 +00004086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004087StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004088TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004089 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004090 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004091 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004092 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004093
Douglas Gregor306de2f2010-04-22 23:59:56 +00004094 // If nothing changed, just retain this statement.
4095 if (!getDerived().AlwaysRebuild() &&
4096 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004097 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004098
4099 // Build a new statement.
4100 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004101 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004102}
Mike Stump11289f42009-09-09 15:08:12 +00004103
Douglas Gregorebe10102009-08-20 07:17:43 +00004104template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004105StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004106TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004107 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004108 if (S->getThrowExpr()) {
4109 Operand = getDerived().TransformExpr(S->getThrowExpr());
4110 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004111 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004112 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004113
Douglas Gregor2900c162010-04-22 21:44:01 +00004114 if (!getDerived().AlwaysRebuild() &&
4115 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004116 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004117
John McCallb268a282010-08-23 23:25:46 +00004118 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004119}
Mike Stump11289f42009-09-09 15:08:12 +00004120
Douglas Gregorebe10102009-08-20 07:17:43 +00004121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004122StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004123TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004124 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004125 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004126 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004127 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004128 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004129
Douglas Gregor6148de72010-04-22 22:01:21 +00004130 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004131 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004132 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004133 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004134
Douglas Gregor6148de72010-04-22 22:01:21 +00004135 // If nothing change, just retain the current statement.
4136 if (!getDerived().AlwaysRebuild() &&
4137 Object.get() == S->getSynchExpr() &&
4138 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004139 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004140
4141 // Build a new statement.
4142 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004143 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004144}
4145
4146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004147StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004148TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004149 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004150 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004151 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004152 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004153 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004154
Douglas Gregorf68a5082010-04-22 23:10:45 +00004155 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004156 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004157 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004158 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004159
Douglas Gregorf68a5082010-04-22 23:10:45 +00004160 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004161 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004162 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004163 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004164
Douglas Gregorf68a5082010-04-22 23:10:45 +00004165 // If nothing changed, just retain this statement.
4166 if (!getDerived().AlwaysRebuild() &&
4167 Element.get() == S->getElement() &&
4168 Collection.get() == S->getCollection() &&
4169 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004170 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004171
Douglas Gregorf68a5082010-04-22 23:10:45 +00004172 // Build a new statement.
4173 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4174 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004175 Element.get(),
4176 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004177 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004178 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004179}
4180
4181
4182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004183StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004184TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4185 // Transform the exception declaration, if any.
4186 VarDecl *Var = 0;
4187 if (S->getExceptionDecl()) {
4188 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004189 TypeSourceInfo *T = getDerived().TransformType(
4190 ExceptionDecl->getTypeSourceInfo());
4191 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004192 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004193
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004194 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004195 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004196 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004197 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004198 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004199 }
Mike Stump11289f42009-09-09 15:08:12 +00004200
Douglas Gregorebe10102009-08-20 07:17:43 +00004201 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004202 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004203 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004204 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregorebe10102009-08-20 07:17:43 +00004206 if (!getDerived().AlwaysRebuild() &&
4207 !Var &&
4208 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004209 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004210
4211 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4212 Var,
John McCallb268a282010-08-23 23:25:46 +00004213 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004214}
Mike Stump11289f42009-09-09 15:08:12 +00004215
Douglas Gregorebe10102009-08-20 07:17:43 +00004216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004217StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004218TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4219 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004220 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004221 = getDerived().TransformCompoundStmt(S->getTryBlock());
4222 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004223 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004224
Douglas Gregorebe10102009-08-20 07:17:43 +00004225 // Transform the handlers.
4226 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004227 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004228 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004229 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004230 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4231 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004232 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004233
Douglas Gregorebe10102009-08-20 07:17:43 +00004234 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4235 Handlers.push_back(Handler.takeAs<Stmt>());
4236 }
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregorebe10102009-08-20 07:17:43 +00004238 if (!getDerived().AlwaysRebuild() &&
4239 TryBlock.get() == S->getTryBlock() &&
4240 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004241 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004242
John McCallb268a282010-08-23 23:25:46 +00004243 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004244 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004245}
Mike Stump11289f42009-09-09 15:08:12 +00004246
Douglas Gregorebe10102009-08-20 07:17:43 +00004247//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004248// Expression transformation
4249//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004251ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004252TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004253 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004254}
Mike Stump11289f42009-09-09 15:08:12 +00004255
4256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004257ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004258TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004259 NestedNameSpecifier *Qualifier = 0;
4260 if (E->getQualifier()) {
4261 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004262 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004263 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004264 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004265 }
John McCallce546572009-12-08 09:08:17 +00004266
4267 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004268 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4269 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004270 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004272
John McCall815039a2010-08-17 21:27:17 +00004273 DeclarationNameInfo NameInfo = E->getNameInfo();
4274 if (NameInfo.getName()) {
4275 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4276 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004277 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004278 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004279
4280 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004281 Qualifier == E->getQualifier() &&
4282 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004283 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004284 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004285
4286 // Mark it referenced in the new context regardless.
4287 // FIXME: this is a bit instantiation-specific.
4288 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4289
John McCallc3007a22010-10-26 07:05:15 +00004290 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004291 }
John McCallce546572009-12-08 09:08:17 +00004292
4293 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004294 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004295 TemplateArgs = &TransArgs;
4296 TransArgs.setLAngleLoc(E->getLAngleLoc());
4297 TransArgs.setRAngleLoc(E->getRAngleLoc());
4298 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4299 TemplateArgumentLoc Loc;
4300 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004301 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004302 TransArgs.addArgument(Loc);
4303 }
4304 }
4305
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004306 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004307 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004308}
Mike Stump11289f42009-09-09 15:08:12 +00004309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004312TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004313 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004314}
Mike Stump11289f42009-09-09 15:08:12 +00004315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004318TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004319 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004320}
Mike Stump11289f42009-09-09 15:08:12 +00004321
Douglas Gregora16548e2009-08-11 05:31:07 +00004322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004323ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004324TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004325 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004326}
Mike Stump11289f42009-09-09 15:08:12 +00004327
Douglas Gregora16548e2009-08-11 05:31:07 +00004328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004330TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004331 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004332}
Mike Stump11289f42009-09-09 15:08:12 +00004333
Douglas Gregora16548e2009-08-11 05:31:07 +00004334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004336TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004337 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004338}
4339
4340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004341ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004342TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004343 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004345 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004346
Douglas Gregora16548e2009-08-11 05:31:07 +00004347 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004348 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004349
John McCallb268a282010-08-23 23:25:46 +00004350 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 E->getRParen());
4352}
4353
Mike Stump11289f42009-09-09 15:08:12 +00004354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004356TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004357 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004362 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004363
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4365 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004366 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004367}
Mike Stump11289f42009-09-09 15:08:12 +00004368
Douglas Gregora16548e2009-08-11 05:31:07 +00004369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004370ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004371TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4372 // Transform the type.
4373 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4374 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004375 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004376
Douglas Gregor882211c2010-04-28 22:16:22 +00004377 // Transform all of the components into components similar to what the
4378 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004379 // FIXME: It would be slightly more efficient in the non-dependent case to
4380 // just map FieldDecls, rather than requiring the rebuilder to look for
4381 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004382 // template code that we don't care.
4383 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004384 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004385 typedef OffsetOfExpr::OffsetOfNode Node;
4386 llvm::SmallVector<Component, 4> Components;
4387 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4388 const Node &ON = E->getComponent(I);
4389 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004390 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004391 Comp.LocStart = ON.getRange().getBegin();
4392 Comp.LocEnd = ON.getRange().getEnd();
4393 switch (ON.getKind()) {
4394 case Node::Array: {
4395 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004396 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004397 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004398 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004399
Douglas Gregor882211c2010-04-28 22:16:22 +00004400 ExprChanged = ExprChanged || Index.get() != FromIndex;
4401 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004402 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004403 break;
4404 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004405
Douglas Gregor882211c2010-04-28 22:16:22 +00004406 case Node::Field:
4407 case Node::Identifier:
4408 Comp.isBrackets = false;
4409 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004410 if (!Comp.U.IdentInfo)
4411 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004412
Douglas Gregor882211c2010-04-28 22:16:22 +00004413 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004414
Douglas Gregord1702062010-04-29 00:18:15 +00004415 case Node::Base:
4416 // Will be recomputed during the rebuild.
4417 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004418 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004419
Douglas Gregor882211c2010-04-28 22:16:22 +00004420 Components.push_back(Comp);
4421 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004422
Douglas Gregor882211c2010-04-28 22:16:22 +00004423 // If nothing changed, retain the existing expression.
4424 if (!getDerived().AlwaysRebuild() &&
4425 Type == E->getTypeSourceInfo() &&
4426 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004427 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004428
Douglas Gregor882211c2010-04-28 22:16:22 +00004429 // Build a new offsetof expression.
4430 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4431 Components.data(), Components.size(),
4432 E->getRParenLoc());
4433}
4434
4435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004436ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004437TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4438 assert(getDerived().AlreadyTransformed(E->getType()) &&
4439 "opaque value expression requires transformation");
4440 return SemaRef.Owned(E);
4441}
4442
4443template<typename Derived>
4444ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004445TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004447 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004448
John McCallbcd03502009-12-07 02:54:59 +00004449 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004450 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004452
John McCall4c98fd82009-11-04 07:28:41 +00004453 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004454 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004455
John McCall4c98fd82009-11-04 07:28:41 +00004456 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004457 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 E->getSourceRange());
4459 }
Mike Stump11289f42009-09-09 15:08:12 +00004460
John McCalldadc5752010-08-24 06:29:42 +00004461 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004462 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 // C++0x [expr.sizeof]p1:
4464 // The operand is either an expression, which is an unevaluated operand
4465 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004466 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004467
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4469 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004470 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004471
Douglas Gregora16548e2009-08-11 05:31:07 +00004472 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004473 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 }
Mike Stump11289f42009-09-09 15:08:12 +00004475
John McCallb268a282010-08-23 23:25:46 +00004476 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004477 E->isSizeOf(),
4478 E->getSourceRange());
4479}
Mike Stump11289f42009-09-09 15:08:12 +00004480
Douglas Gregora16548e2009-08-11 05:31:07 +00004481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004482ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004483TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004484 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004485 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004487
John McCalldadc5752010-08-24 06:29:42 +00004488 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004489 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004491
4492
Douglas Gregora16548e2009-08-11 05:31:07 +00004493 if (!getDerived().AlwaysRebuild() &&
4494 LHS.get() == E->getLHS() &&
4495 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004496 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004497
John McCallb268a282010-08-23 23:25:46 +00004498 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004499 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004500 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004501 E->getRBracketLoc());
4502}
Mike Stump11289f42009-09-09 15:08:12 +00004503
4504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004506TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004508 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004510 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004511
4512 // Transform arguments.
4513 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004514 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004515 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004516 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004517 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004518 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004519
Mike Stump11289f42009-09-09 15:08:12 +00004520 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004521 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004522 }
Mike Stump11289f42009-09-09 15:08:12 +00004523
Douglas Gregora16548e2009-08-11 05:31:07 +00004524 if (!getDerived().AlwaysRebuild() &&
4525 Callee.get() == E->getCallee() &&
4526 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004527 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004530 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004532 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 E->getRParenLoc());
4535}
Mike Stump11289f42009-09-09 15:08:12 +00004536
4537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004539TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004540 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004541 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004543
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004544 NestedNameSpecifier *Qualifier = 0;
4545 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004546 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004547 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004548 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004549 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004550 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004551 }
Mike Stump11289f42009-09-09 15:08:12 +00004552
Eli Friedman2cfcef62009-12-04 06:40:45 +00004553 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004554 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4555 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004556 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004557 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004558
John McCall16df1e52010-03-30 21:47:33 +00004559 NamedDecl *FoundDecl = E->getFoundDecl();
4560 if (FoundDecl == E->getMemberDecl()) {
4561 FoundDecl = Member;
4562 } else {
4563 FoundDecl = cast_or_null<NamedDecl>(
4564 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4565 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004566 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004567 }
4568
Douglas Gregora16548e2009-08-11 05:31:07 +00004569 if (!getDerived().AlwaysRebuild() &&
4570 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004571 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004572 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004573 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004574 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004575
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004576 // Mark it referenced in the new context regardless.
4577 // FIXME: this is a bit instantiation-specific.
4578 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004579 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004580 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004581
John McCall6b51f282009-11-23 01:53:49 +00004582 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004583 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004584 TransArgs.setLAngleLoc(E->getLAngleLoc());
4585 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004586 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004587 TemplateArgumentLoc Loc;
4588 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004589 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004590 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004591 }
4592 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004593
Douglas Gregora16548e2009-08-11 05:31:07 +00004594 // FIXME: Bogus source location for the operator
4595 SourceLocation FakeOperatorLoc
4596 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4597
John McCall38836f02010-01-15 08:34:02 +00004598 // FIXME: to do this check properly, we will need to preserve the
4599 // first-qualifier-in-scope here, just in case we had a dependent
4600 // base (and therefore couldn't do the check) and a
4601 // nested-name-qualifier (and therefore could do the lookup).
4602 NamedDecl *FirstQualifierInScope = 0;
4603
John McCallb268a282010-08-23 23:25:46 +00004604 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004605 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004606 Qualifier,
4607 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004608 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004609 Member,
John McCall16df1e52010-03-30 21:47:33 +00004610 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004611 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004612 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004613 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004614}
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregora16548e2009-08-11 05:31:07 +00004616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004618TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004619 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004622
John McCalldadc5752010-08-24 06:29:42 +00004623 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 if (!getDerived().AlwaysRebuild() &&
4628 LHS.get() == E->getLHS() &&
4629 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004630 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004631
Douglas Gregora16548e2009-08-11 05:31:07 +00004632 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004633 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004634}
4635
Mike Stump11289f42009-09-09 15:08:12 +00004636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004637ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004638TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004639 CompoundAssignOperator *E) {
4640 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004641}
Mike Stump11289f42009-09-09 15:08:12 +00004642
Douglas Gregora16548e2009-08-11 05:31:07 +00004643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004645TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004646 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004649
John McCalldadc5752010-08-24 06:29:42 +00004650 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004651 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004652 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004653
John McCalldadc5752010-08-24 06:29:42 +00004654 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004656 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 if (!getDerived().AlwaysRebuild() &&
4659 Cond.get() == E->getCond() &&
4660 LHS.get() == E->getLHS() &&
4661 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004662 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004663
John McCallb268a282010-08-23 23:25:46 +00004664 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004665 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004666 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004667 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004668 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004669}
Mike Stump11289f42009-09-09 15:08:12 +00004670
4671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004673TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004674 // Implicit casts are eliminated during transformation, since they
4675 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004676 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004677}
Mike Stump11289f42009-09-09 15:08:12 +00004678
Douglas Gregora16548e2009-08-11 05:31:07 +00004679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004681TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004682 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4683 if (!Type)
4684 return ExprError();
4685
John McCalldadc5752010-08-24 06:29:42 +00004686 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004687 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004689 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004690
Douglas Gregora16548e2009-08-11 05:31:07 +00004691 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004692 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004694 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004695
John McCall97513962010-01-15 18:39:57 +00004696 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004697 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004698 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004699 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004700}
Mike Stump11289f42009-09-09 15:08:12 +00004701
Douglas Gregora16548e2009-08-11 05:31:07 +00004702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004703ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004704TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004705 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4706 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4707 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004708 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
John McCalldadc5752010-08-24 06:29:42 +00004710 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004712 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004715 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004717 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004718
John McCall5d7aa7f2010-01-19 22:33:45 +00004719 // Note: the expression type doesn't necessarily match the
4720 // type-as-written, but that's okay, because it should always be
4721 // derivable from the initializer.
4722
John McCalle15bbff2010-01-18 19:35:47 +00004723 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004725 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004726}
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004730TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004731 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregora16548e2009-08-11 05:31:07 +00004735 if (!getDerived().AlwaysRebuild() &&
4736 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004737 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregora16548e2009-08-11 05:31:07 +00004739 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004740 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004742 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 E->getAccessorLoc(),
4744 E->getAccessor());
4745}
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregora16548e2009-08-11 05:31:07 +00004747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004748ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004749TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004751
John McCall37ad5512010-08-23 06:44:23 +00004752 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004753 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004754 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004756 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004757
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004759 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004760 }
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004763 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004764
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004766 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004767}
Mike Stump11289f42009-09-09 15:08:12 +00004768
Douglas Gregora16548e2009-08-11 05:31:07 +00004769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004771TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregorebe10102009-08-20 07:17:43 +00004774 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004775 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregorebe10102009-08-20 07:17:43 +00004779 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004780 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004781 bool ExprChanged = false;
4782 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4783 DEnd = E->designators_end();
4784 D != DEnd; ++D) {
4785 if (D->isFieldDesignator()) {
4786 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4787 D->getDotLoc(),
4788 D->getFieldLoc()));
4789 continue;
4790 }
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004793 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004796
4797 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004798 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4801 ArrayExprs.push_back(Index.release());
4802 continue;
4803 }
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004806 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4808 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004809 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004810
John McCalldadc5752010-08-24 06:29:42 +00004811 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
4815 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004816 End.get(),
4817 D->getLBracketLoc(),
4818 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4821 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregora16548e2009-08-11 05:31:07 +00004823 ArrayExprs.push_back(Start.release());
4824 ArrayExprs.push_back(End.release());
4825 }
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 if (!getDerived().AlwaysRebuild() &&
4828 Init.get() == E->getInit() &&
4829 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004830 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004831
Douglas Gregora16548e2009-08-11 05:31:07 +00004832 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4833 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004834 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004835}
Mike Stump11289f42009-09-09 15:08:12 +00004836
Douglas Gregora16548e2009-08-11 05:31:07 +00004837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004838ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004839TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004840 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004841 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004842
Douglas Gregor3da3c062009-10-28 00:29:27 +00004843 // FIXME: Will we ever have proper type location here? Will we actually
4844 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004845 QualType T = getDerived().TransformType(E->getType());
4846 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregora16548e2009-08-11 05:31:07 +00004849 if (!getDerived().AlwaysRebuild() &&
4850 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004851 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004852
Douglas Gregora16548e2009-08-11 05:31:07 +00004853 return getDerived().RebuildImplicitValueInitExpr(T);
4854}
Mike Stump11289f42009-09-09 15:08:12 +00004855
Douglas Gregora16548e2009-08-11 05:31:07 +00004856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004858TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004859 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4860 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004862
John McCalldadc5752010-08-24 06:29:42 +00004863 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004864 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004866
Douglas Gregora16548e2009-08-11 05:31:07 +00004867 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004868 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004869 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004870 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004871
John McCallb268a282010-08-23 23:25:46 +00004872 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004873 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004874}
4875
4876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004878TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004879 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004880 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004881 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004882 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004883 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004884 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004885
Douglas Gregora16548e2009-08-11 05:31:07 +00004886 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004887 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 }
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregora16548e2009-08-11 05:31:07 +00004890 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4891 move_arg(Inits),
4892 E->getRParenLoc());
4893}
Mike Stump11289f42009-09-09 15:08:12 +00004894
Douglas Gregora16548e2009-08-11 05:31:07 +00004895/// \brief Transform an address-of-label expression.
4896///
4897/// By default, the transformation of an address-of-label expression always
4898/// rebuilds the expression, so that the label identifier can be resolved to
4899/// the corresponding label statement by semantic analysis.
4900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004901ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004902TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4904 E->getLabel());
4905}
Mike Stump11289f42009-09-09 15:08:12 +00004906
4907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004908ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004909TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004910 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004911 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4912 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004913 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004914
Douglas Gregora16548e2009-08-11 05:31:07 +00004915 if (!getDerived().AlwaysRebuild() &&
4916 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00004917 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004918
4919 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004920 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004921 E->getRParenLoc());
4922}
Mike Stump11289f42009-09-09 15:08:12 +00004923
Douglas Gregora16548e2009-08-11 05:31:07 +00004924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004926TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004927 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004930
John McCalldadc5752010-08-24 06:29:42 +00004931 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004932 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004934
John McCalldadc5752010-08-24 06:29:42 +00004935 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004936 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004938
Douglas Gregora16548e2009-08-11 05:31:07 +00004939 if (!getDerived().AlwaysRebuild() &&
4940 Cond.get() == E->getCond() &&
4941 LHS.get() == E->getLHS() &&
4942 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004943 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregora16548e2009-08-11 05:31:07 +00004945 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004946 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004947 E->getRParenLoc());
4948}
Mike Stump11289f42009-09-09 15:08:12 +00004949
Douglas Gregora16548e2009-08-11 05:31:07 +00004950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004952TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004953 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004954}
4955
4956template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004957ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004958TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004959 switch (E->getOperator()) {
4960 case OO_New:
4961 case OO_Delete:
4962 case OO_Array_New:
4963 case OO_Array_Delete:
4964 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004965 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004966
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004967 case OO_Call: {
4968 // This is a call to an object's operator().
4969 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4970
4971 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004972 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004973 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004974 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004975
4976 // FIXME: Poor location information
4977 SourceLocation FakeLParenLoc
4978 = SemaRef.PP.getLocForEndOfToken(
4979 static_cast<Expr *>(Object.get())->getLocEnd());
4980
4981 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004982 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004983 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004984 if (getDerived().DropCallArgument(E->getArg(I)))
4985 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004986
John McCalldadc5752010-08-24 06:29:42 +00004987 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004988 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004990
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004991 Args.push_back(Arg.release());
4992 }
4993
John McCallb268a282010-08-23 23:25:46 +00004994 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004995 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004996 E->getLocEnd());
4997 }
4998
4999#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5000 case OO_##Name:
5001#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5002#include "clang/Basic/OperatorKinds.def"
5003 case OO_Subscript:
5004 // Handled below.
5005 break;
5006
5007 case OO_Conditional:
5008 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005009 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005010
5011 case OO_None:
5012 case NUM_OVERLOADED_OPERATORS:
5013 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005014 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005015 }
5016
John McCalldadc5752010-08-24 06:29:42 +00005017 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005018 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005020
John McCalldadc5752010-08-24 06:29:42 +00005021 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005022 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005023 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005024
John McCalldadc5752010-08-24 06:29:42 +00005025 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 if (E->getNumArgs() == 2) {
5027 Second = getDerived().TransformExpr(E->getArg(1));
5028 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005029 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005030 }
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 if (!getDerived().AlwaysRebuild() &&
5033 Callee.get() == E->getCallee() &&
5034 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005035 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005036 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregora16548e2009-08-11 05:31:07 +00005038 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5039 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005040 Callee.get(),
5041 First.get(),
5042 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005043}
Mike Stump11289f42009-09-09 15:08:12 +00005044
Douglas Gregora16548e2009-08-11 05:31:07 +00005045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005047TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5048 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005049}
Mike Stump11289f42009-09-09 15:08:12 +00005050
Douglas Gregora16548e2009-08-11 05:31:07 +00005051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005053TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005054 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5055 if (!Type)
5056 return ExprError();
5057
John McCalldadc5752010-08-24 06:29:42 +00005058 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005059 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005060 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005061 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005062
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005064 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005065 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005066 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005067
Douglas Gregora16548e2009-08-11 05:31:07 +00005068 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005069 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005070 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5071 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5072 SourceLocation FakeRParenLoc
5073 = SemaRef.PP.getLocForEndOfToken(
5074 E->getSubExpr()->getSourceRange().getEnd());
5075 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005076 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005077 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005078 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005079 FakeRAngleLoc,
5080 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005081 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005082 FakeRParenLoc);
5083}
Mike Stump11289f42009-09-09 15:08:12 +00005084
Douglas Gregora16548e2009-08-11 05:31:07 +00005085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005087TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5088 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005089}
Mike Stump11289f42009-09-09 15:08:12 +00005090
5091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005093TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5094 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005095}
5096
Douglas Gregora16548e2009-08-11 05:31:07 +00005097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005098ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005099TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005100 CXXReinterpretCastExpr *E) {
5101 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005102}
Mike Stump11289f42009-09-09 15:08:12 +00005103
Douglas Gregora16548e2009-08-11 05:31:07 +00005104template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005105ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005106TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5107 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005108}
Mike Stump11289f42009-09-09 15:08:12 +00005109
Douglas Gregora16548e2009-08-11 05:31:07 +00005110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005111ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005112TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005113 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005114 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5115 if (!Type)
5116 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005117
John McCalldadc5752010-08-24 06:29:42 +00005118 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005119 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005120 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005124 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005126 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005127
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005128 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005130 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 E->getRParenLoc());
5132}
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregora16548e2009-08-11 05:31:07 +00005134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005136TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005138 TypeSourceInfo *TInfo
5139 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5140 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005141 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005142
Douglas Gregora16548e2009-08-11 05:31:07 +00005143 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005144 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005145 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005146
Douglas Gregor9da64192010-04-26 22:37:10 +00005147 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5148 E->getLocStart(),
5149 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005150 E->getLocEnd());
5151 }
Mike Stump11289f42009-09-09 15:08:12 +00005152
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 // We don't know whether the expression is potentially evaluated until
5154 // after we perform semantic analysis, so the expression is potentially
5155 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005156 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005157 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005158
John McCalldadc5752010-08-24 06:29:42 +00005159 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005160 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005161 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 if (!getDerived().AlwaysRebuild() &&
5164 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005165 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005166
Douglas Gregor9da64192010-04-26 22:37:10 +00005167 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5168 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005169 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 E->getLocEnd());
5171}
5172
5173template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005174ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005175TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5176 if (E->isTypeOperand()) {
5177 TypeSourceInfo *TInfo
5178 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5179 if (!TInfo)
5180 return ExprError();
5181
5182 if (!getDerived().AlwaysRebuild() &&
5183 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005184 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005185
5186 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5187 E->getLocStart(),
5188 TInfo,
5189 E->getLocEnd());
5190 }
5191
5192 // We don't know whether the expression is potentially evaluated until
5193 // after we perform semantic analysis, so the expression is potentially
5194 // potentially evaluated.
5195 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5196
5197 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5198 if (SubExpr.isInvalid())
5199 return ExprError();
5200
5201 if (!getDerived().AlwaysRebuild() &&
5202 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005203 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005204
5205 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5206 E->getLocStart(),
5207 SubExpr.get(),
5208 E->getLocEnd());
5209}
5210
5211template<typename Derived>
5212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005213TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005214 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005215}
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregora16548e2009-08-11 05:31:07 +00005217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005218ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005219TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005220 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005221 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005222}
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregora16548e2009-08-11 05:31:07 +00005224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005226TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005227 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5228 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5229 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005231 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005232 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005233
Douglas Gregorb15af892010-01-07 23:12:05 +00005234 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005235}
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregora16548e2009-08-11 05:31:07 +00005237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005239TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005240 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 if (!getDerived().AlwaysRebuild() &&
5245 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005246 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005247
John McCallb268a282010-08-23 23:25:46 +00005248 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005249}
Mike Stump11289f42009-09-09 15:08:12 +00005250
Douglas Gregora16548e2009-08-11 05:31:07 +00005251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005253TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005254 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005255 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5256 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005258 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005259
Chandler Carruth794da4c2010-02-08 06:42:49 +00005260 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005261 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005262 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregor033f6752009-12-23 23:03:06 +00005264 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005265}
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregora16548e2009-08-11 05:31:07 +00005267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005268ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005269TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5270 CXXScalarValueInitExpr *E) {
5271 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5272 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005273 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005274
Douglas Gregora16548e2009-08-11 05:31:07 +00005275 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005276 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005277 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005278
Douglas Gregor2b88c112010-09-08 00:15:04 +00005279 return getDerived().RebuildCXXScalarValueInitExpr(T,
5280 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005281 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005282}
Mike Stump11289f42009-09-09 15:08:12 +00005283
Douglas Gregora16548e2009-08-11 05:31:07 +00005284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005286TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005287 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005288 TypeSourceInfo *AllocTypeInfo
5289 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5290 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005292
Douglas Gregora16548e2009-08-11 05:31:07 +00005293 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005294 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005295 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005296 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005297
Douglas Gregora16548e2009-08-11 05:31:07 +00005298 // Transform the placement arguments (if any).
5299 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005300 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005302 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5303 ArgumentChanged = true;
5304 break;
5305 }
5306
John McCalldadc5752010-08-24 06:29:42 +00005307 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005308 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregora16548e2009-08-11 05:31:07 +00005311 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5312 PlacementArgs.push_back(Arg.take());
5313 }
Mike Stump11289f42009-09-09 15:08:12 +00005314
Douglas Gregorebe10102009-08-20 07:17:43 +00005315 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005316 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005318 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5319 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005320 break;
John McCall09d13692010-10-05 22:36:42 +00005321 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005322
John McCalldadc5752010-08-24 06:29:42 +00005323 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005324 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005325 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005326
Douglas Gregora16548e2009-08-11 05:31:07 +00005327 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5328 ConstructorArgs.push_back(Arg.take());
5329 }
Mike Stump11289f42009-09-09 15:08:12 +00005330
Douglas Gregord2d9da02010-02-26 00:38:10 +00005331 // Transform constructor, new operator, and delete operator.
5332 CXXConstructorDecl *Constructor = 0;
5333 if (E->getConstructor()) {
5334 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005335 getDerived().TransformDecl(E->getLocStart(),
5336 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005337 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005339 }
5340
5341 FunctionDecl *OperatorNew = 0;
5342 if (E->getOperatorNew()) {
5343 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005344 getDerived().TransformDecl(E->getLocStart(),
5345 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005346 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005347 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005348 }
5349
5350 FunctionDecl *OperatorDelete = 0;
5351 if (E->getOperatorDelete()) {
5352 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005353 getDerived().TransformDecl(E->getLocStart(),
5354 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005355 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005356 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005357 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005358
Douglas Gregora16548e2009-08-11 05:31:07 +00005359 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005360 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005361 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005362 Constructor == E->getConstructor() &&
5363 OperatorNew == E->getOperatorNew() &&
5364 OperatorDelete == E->getOperatorDelete() &&
5365 !ArgumentChanged) {
5366 // Mark any declarations we need as referenced.
5367 // FIXME: instantiation-specific.
5368 if (Constructor)
5369 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5370 if (OperatorNew)
5371 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5372 if (OperatorDelete)
5373 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005374 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005375 }
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregor0744ef62010-09-07 21:49:58 +00005377 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005378 if (!ArraySize.get()) {
5379 // If no array size was specified, but the new expression was
5380 // instantiated with an array type (e.g., "new T" where T is
5381 // instantiated with "int[4]"), extract the outer bound from the
5382 // array type as our array size. We do this with constant and
5383 // dependently-sized array types.
5384 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5385 if (!ArrayT) {
5386 // Do nothing
5387 } else if (const ConstantArrayType *ConsArrayT
5388 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005389 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005390 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5391 ConsArrayT->getSize(),
5392 SemaRef.Context.getSizeType(),
5393 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005394 AllocType = ConsArrayT->getElementType();
5395 } else if (const DependentSizedArrayType *DepArrayT
5396 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5397 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005398 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005399 AllocType = DepArrayT->getElementType();
5400 }
5401 }
5402 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005403
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5405 E->isGlobalNew(),
5406 /*FIXME:*/E->getLocStart(),
5407 move_arg(PlacementArgs),
5408 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005409 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005410 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005411 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005412 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005413 /*FIXME:*/E->getLocStart(),
5414 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005415 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005416}
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregora16548e2009-08-11 05:31:07 +00005418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005420TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005421 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005422 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005424
Douglas Gregord2d9da02010-02-26 00:38:10 +00005425 // Transform the delete operator, if known.
5426 FunctionDecl *OperatorDelete = 0;
5427 if (E->getOperatorDelete()) {
5428 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005429 getDerived().TransformDecl(E->getLocStart(),
5430 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005431 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005432 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005433 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005434
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005436 Operand.get() == E->getArgument() &&
5437 OperatorDelete == E->getOperatorDelete()) {
5438 // Mark any declarations we need as referenced.
5439 // FIXME: instantiation-specific.
5440 if (OperatorDelete)
5441 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005442
5443 if (!E->getArgument()->isTypeDependent()) {
5444 QualType Destroyed = SemaRef.Context.getBaseElementType(
5445 E->getDestroyedType());
5446 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5447 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5448 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5449 SemaRef.LookupDestructor(Record));
5450 }
5451 }
5452
John McCallc3007a22010-10-26 07:05:15 +00005453 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005454 }
Mike Stump11289f42009-09-09 15:08:12 +00005455
Douglas Gregora16548e2009-08-11 05:31:07 +00005456 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5457 E->isGlobalDelete(),
5458 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005459 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005460}
Mike Stump11289f42009-09-09 15:08:12 +00005461
Douglas Gregora16548e2009-08-11 05:31:07 +00005462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005463ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005464TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005465 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005466 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005467 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005468 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005469
John McCallba7bf592010-08-24 05:47:05 +00005470 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005471 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005472 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005473 E->getOperatorLoc(),
5474 E->isArrow()? tok::arrow : tok::period,
5475 ObjectTypePtr,
5476 MayBePseudoDestructor);
5477 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005478 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005479
John McCallba7bf592010-08-24 05:47:05 +00005480 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005481 NestedNameSpecifier *Qualifier = E->getQualifier();
5482 if (Qualifier) {
5483 Qualifier
5484 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5485 E->getQualifierRange(),
5486 ObjectType);
5487 if (!Qualifier)
5488 return ExprError();
5489 }
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregor678f90d2010-02-25 01:56:36 +00005491 PseudoDestructorTypeStorage Destroyed;
5492 if (E->getDestroyedTypeInfo()) {
5493 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005494 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5495 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005496 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005497 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005498 Destroyed = DestroyedTypeInfo;
5499 } else if (ObjectType->isDependentType()) {
5500 // We aren't likely to be able to resolve the identifier down to a type
5501 // now anyway, so just retain the identifier.
5502 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5503 E->getDestroyedTypeLoc());
5504 } else {
5505 // Look for a destructor known with the given name.
5506 CXXScopeSpec SS;
5507 if (Qualifier) {
5508 SS.setScopeRep(Qualifier);
5509 SS.setRange(E->getQualifierRange());
5510 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005511
John McCallba7bf592010-08-24 05:47:05 +00005512 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005513 *E->getDestroyedTypeIdentifier(),
5514 E->getDestroyedTypeLoc(),
5515 /*Scope=*/0,
5516 SS, ObjectTypePtr,
5517 false);
5518 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005519 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005520
Douglas Gregor678f90d2010-02-25 01:56:36 +00005521 Destroyed
5522 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5523 E->getDestroyedTypeLoc());
5524 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005525
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005526 TypeSourceInfo *ScopeTypeInfo = 0;
5527 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005528 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005529 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005530 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005531 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005532
John McCallb268a282010-08-23 23:25:46 +00005533 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005534 E->getOperatorLoc(),
5535 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005536 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005537 E->getQualifierRange(),
5538 ScopeTypeInfo,
5539 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005540 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005541 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005542}
Mike Stump11289f42009-09-09 15:08:12 +00005543
Douglas Gregorad8a3362009-09-04 17:36:40 +00005544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005545ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005546TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005547 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005548 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5549
5550 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5551 Sema::LookupOrdinaryName);
5552
5553 // Transform all the decls.
5554 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5555 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005556 NamedDecl *InstD = static_cast<NamedDecl*>(
5557 getDerived().TransformDecl(Old->getNameLoc(),
5558 *I));
John McCall84d87672009-12-10 09:41:52 +00005559 if (!InstD) {
5560 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5561 // This can happen because of dependent hiding.
5562 if (isa<UsingShadowDecl>(*I))
5563 continue;
5564 else
John McCallfaf5fb42010-08-26 23:41:50 +00005565 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005566 }
John McCalle66edc12009-11-24 19:00:30 +00005567
5568 // Expand using declarations.
5569 if (isa<UsingDecl>(InstD)) {
5570 UsingDecl *UD = cast<UsingDecl>(InstD);
5571 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5572 E = UD->shadow_end(); I != E; ++I)
5573 R.addDecl(*I);
5574 continue;
5575 }
5576
5577 R.addDecl(InstD);
5578 }
5579
5580 // Resolve a kind, but don't do any further analysis. If it's
5581 // ambiguous, the callee needs to deal with it.
5582 R.resolveKind();
5583
5584 // Rebuild the nested-name qualifier, if present.
5585 CXXScopeSpec SS;
5586 NestedNameSpecifier *Qualifier = 0;
5587 if (Old->getQualifier()) {
5588 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005589 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005590 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005592
John McCalle66edc12009-11-24 19:00:30 +00005593 SS.setScopeRep(Qualifier);
5594 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005595 }
5596
Douglas Gregor9262f472010-04-27 18:19:34 +00005597 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005598 CXXRecordDecl *NamingClass
5599 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5600 Old->getNameLoc(),
5601 Old->getNamingClass()));
5602 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005603 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005604
Douglas Gregorda7be082010-04-27 16:10:10 +00005605 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005606 }
5607
5608 // If we have no template arguments, it's a normal declaration name.
5609 if (!Old->hasExplicitTemplateArgs())
5610 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5611
5612 // If we have template arguments, rebuild them, then rebuild the
5613 // templateid expression.
5614 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5615 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5616 TemplateArgumentLoc Loc;
5617 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005618 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005619 TransArgs.addArgument(Loc);
5620 }
5621
5622 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5623 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005624}
Mike Stump11289f42009-09-09 15:08:12 +00005625
Douglas Gregora16548e2009-08-11 05:31:07 +00005626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005627ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005628TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005629 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5630 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005632
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005634 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005635 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005636
Mike Stump11289f42009-09-09 15:08:12 +00005637 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 T,
5640 E->getLocEnd());
5641}
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregora16548e2009-08-11 05:31:07 +00005643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005644ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00005645TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
5646 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
5647 if (!LhsT)
5648 return ExprError();
5649
5650 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
5651 if (!RhsT)
5652 return ExprError();
5653
5654 if (!getDerived().AlwaysRebuild() &&
5655 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
5656 return SemaRef.Owned(E);
5657
5658 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
5659 E->getLocStart(),
5660 LhsT, RhsT,
5661 E->getLocEnd());
5662}
5663
5664template<typename Derived>
5665ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005666TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005667 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005668 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005669 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005670 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005671 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005673
John McCall31f82722010-11-12 08:19:04 +00005674 // TODO: If this is a conversion-function-id, verify that the
5675 // destination type name (if present) resolves the same way after
5676 // instantiation as it did in the local scope.
5677
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005678 DeclarationNameInfo NameInfo
5679 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5680 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005681 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005682
John McCalle66edc12009-11-24 19:00:30 +00005683 if (!E->hasExplicitTemplateArgs()) {
5684 if (!getDerived().AlwaysRebuild() &&
5685 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005686 // Note: it is sufficient to compare the Name component of NameInfo:
5687 // if name has not changed, DNLoc has not changed either.
5688 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005689 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005690
John McCalle66edc12009-11-24 19:00:30 +00005691 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5692 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005693 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005694 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005695 }
John McCall6b51f282009-11-23 01:53:49 +00005696
5697 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005698 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005699 TemplateArgumentLoc Loc;
5700 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005701 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005702 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 }
5704
John McCalle66edc12009-11-24 19:00:30 +00005705 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5706 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005707 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005708 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005709}
5710
5711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005712ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005713TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005714 // CXXConstructExprs are always implicit, so when we have a
5715 // 1-argument construction we just transform that argument.
5716 if (E->getNumArgs() == 1 ||
5717 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5718 return getDerived().TransformExpr(E->getArg(0));
5719
Douglas Gregora16548e2009-08-11 05:31:07 +00005720 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5721
5722 QualType T = getDerived().TransformType(E->getType());
5723 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005724 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005725
5726 CXXConstructorDecl *Constructor
5727 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005728 getDerived().TransformDecl(E->getLocStart(),
5729 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005734 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005735 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 ArgEnd = E->arg_end();
5737 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005738 if (getDerived().DropCallArgument(*Arg)) {
5739 ArgumentChanged = true;
5740 break;
5741 }
5742
John McCalldadc5752010-08-24 06:29:42 +00005743 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005746
Douglas Gregora16548e2009-08-11 05:31:07 +00005747 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005748 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 }
5750
5751 if (!getDerived().AlwaysRebuild() &&
5752 T == E->getType() &&
5753 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005754 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005755 // Mark the constructor as referenced.
5756 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005757 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005758 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005759 }
Mike Stump11289f42009-09-09 15:08:12 +00005760
Douglas Gregordb121ba2009-12-14 16:27:04 +00005761 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5762 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005763 move_arg(Args),
5764 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005765 E->getConstructionKind(),
5766 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005767}
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769/// \brief Transform a C++ temporary-binding expression.
5770///
Douglas Gregor363b1512009-12-24 18:51:59 +00005771/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5772/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005774ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005775TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005776 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005777}
Mike Stump11289f42009-09-09 15:08:12 +00005778
John McCall5d413782010-12-06 08:20:24 +00005779/// \brief Transform a C++ expression that contains cleanups that should
5780/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00005781///
John McCall5d413782010-12-06 08:20:24 +00005782/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00005783/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005785ExprResult
John McCall5d413782010-12-06 08:20:24 +00005786TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005787 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005788}
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005791ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005792TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005793 CXXTemporaryObjectExpr *E) {
5794 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5795 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005797
Douglas Gregora16548e2009-08-11 05:31:07 +00005798 CXXConstructorDecl *Constructor
5799 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005800 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005801 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005806 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005808 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005809 ArgEnd = E->arg_end();
5810 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005811 if (getDerived().DropCallArgument(*Arg)) {
5812 ArgumentChanged = true;
5813 break;
5814 }
5815
John McCalldadc5752010-08-24 06:29:42 +00005816 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005818 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005819
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5821 Args.push_back((Expr *)TransArg.release());
5822 }
Mike Stump11289f42009-09-09 15:08:12 +00005823
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005825 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005826 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005827 !ArgumentChanged) {
5828 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005829 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005830 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005831 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005832
5833 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5834 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005835 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005836 E->getLocEnd());
5837}
Mike Stump11289f42009-09-09 15:08:12 +00005838
Douglas Gregora16548e2009-08-11 05:31:07 +00005839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005840ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005841TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005842 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005843 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5844 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005846
Douglas Gregora16548e2009-08-11 05:31:07 +00005847 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005848 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005849 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5850 ArgEnd = E->arg_end();
5851 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005852 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005857 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 }
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005861 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005863 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005864
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005866 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005867 E->getLParenLoc(),
5868 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005869 E->getRParenLoc());
5870}
Mike Stump11289f42009-09-09 15:08:12 +00005871
Douglas Gregora16548e2009-08-11 05:31:07 +00005872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005873ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005874TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005875 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005876 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005877 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005878 Expr *OldBase;
5879 QualType BaseType;
5880 QualType ObjectType;
5881 if (!E->isImplicitAccess()) {
5882 OldBase = E->getBase();
5883 Base = getDerived().TransformExpr(OldBase);
5884 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005886
John McCall2d74de92009-12-01 22:10:20 +00005887 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005888 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005889 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005890 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005891 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005892 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005893 ObjectTy,
5894 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005895 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005896 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005897
John McCallba7bf592010-08-24 05:47:05 +00005898 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005899 BaseType = ((Expr*) Base.get())->getType();
5900 } else {
5901 OldBase = 0;
5902 BaseType = getDerived().TransformType(E->getBaseType());
5903 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5904 }
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005906 // Transform the first part of the nested-name-specifier that qualifies
5907 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005908 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005909 = getDerived().TransformFirstQualifierInScope(
5910 E->getFirstQualifierFoundInScope(),
5911 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005913 NestedNameSpecifier *Qualifier = 0;
5914 if (E->getQualifier()) {
5915 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5916 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005917 ObjectType,
5918 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005919 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005920 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005921 }
Mike Stump11289f42009-09-09 15:08:12 +00005922
John McCall31f82722010-11-12 08:19:04 +00005923 // TODO: If this is a conversion-function-id, verify that the
5924 // destination type name (if present) resolves the same way after
5925 // instantiation as it did in the local scope.
5926
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005927 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00005928 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005929 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005930 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005931
John McCall2d74de92009-12-01 22:10:20 +00005932 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005933 // This is a reference to a member without an explicitly-specified
5934 // template argument list. Optimize for this common case.
5935 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005936 Base.get() == OldBase &&
5937 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005938 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005939 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005940 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00005941 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005942
John McCallb268a282010-08-23 23:25:46 +00005943 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005944 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005945 E->isArrow(),
5946 E->getOperatorLoc(),
5947 Qualifier,
5948 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005949 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005950 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005951 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005952 }
5953
John McCall6b51f282009-11-23 01:53:49 +00005954 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005955 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005956 TemplateArgumentLoc Loc;
5957 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005958 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005959 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005960 }
Mike Stump11289f42009-09-09 15:08:12 +00005961
John McCallb268a282010-08-23 23:25:46 +00005962 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005963 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005964 E->isArrow(),
5965 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005966 Qualifier,
5967 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005968 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005969 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005970 &TransArgs);
5971}
5972
5973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005974ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005975TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005976 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005977 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005978 QualType BaseType;
5979 if (!Old->isImplicitAccess()) {
5980 Base = getDerived().TransformExpr(Old->getBase());
5981 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005982 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005983 BaseType = ((Expr*) Base.get())->getType();
5984 } else {
5985 BaseType = getDerived().TransformType(Old->getBaseType());
5986 }
John McCall10eae182009-11-30 22:42:35 +00005987
5988 NestedNameSpecifier *Qualifier = 0;
5989 if (Old->getQualifier()) {
5990 Qualifier
5991 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005992 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005993 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005994 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005995 }
5996
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005997 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005998 Sema::LookupOrdinaryName);
5999
6000 // Transform all the decls.
6001 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6002 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006003 NamedDecl *InstD = static_cast<NamedDecl*>(
6004 getDerived().TransformDecl(Old->getMemberLoc(),
6005 *I));
John McCall84d87672009-12-10 09:41:52 +00006006 if (!InstD) {
6007 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6008 // This can happen because of dependent hiding.
6009 if (isa<UsingShadowDecl>(*I))
6010 continue;
6011 else
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006013 }
John McCall10eae182009-11-30 22:42:35 +00006014
6015 // Expand using declarations.
6016 if (isa<UsingDecl>(InstD)) {
6017 UsingDecl *UD = cast<UsingDecl>(InstD);
6018 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6019 E = UD->shadow_end(); I != E; ++I)
6020 R.addDecl(*I);
6021 continue;
6022 }
6023
6024 R.addDecl(InstD);
6025 }
6026
6027 R.resolveKind();
6028
Douglas Gregor9262f472010-04-27 18:19:34 +00006029 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006030 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006031 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006032 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006033 Old->getMemberLoc(),
6034 Old->getNamingClass()));
6035 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006037
Douglas Gregorda7be082010-04-27 16:10:10 +00006038 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006039 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006040
John McCall10eae182009-11-30 22:42:35 +00006041 TemplateArgumentListInfo TransArgs;
6042 if (Old->hasExplicitTemplateArgs()) {
6043 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6044 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6045 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6046 TemplateArgumentLoc Loc;
6047 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6048 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006049 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006050 TransArgs.addArgument(Loc);
6051 }
6052 }
John McCall38836f02010-01-15 08:34:02 +00006053
6054 // FIXME: to do this check properly, we will need to preserve the
6055 // first-qualifier-in-scope here, just in case we had a dependent
6056 // base (and therefore couldn't do the check) and a
6057 // nested-name-qualifier (and therefore could do the lookup).
6058 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006059
John McCallb268a282010-08-23 23:25:46 +00006060 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006061 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006062 Old->getOperatorLoc(),
6063 Old->isArrow(),
6064 Qualifier,
6065 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006066 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006067 R,
6068 (Old->hasExplicitTemplateArgs()
6069 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006070}
6071
6072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006073ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006074TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6075 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6076 if (SubExpr.isInvalid())
6077 return ExprError();
6078
6079 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006080 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006081
6082 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6083}
6084
6085template<typename Derived>
6086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006088 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006089}
6090
Mike Stump11289f42009-09-09 15:08:12 +00006091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006093TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006094 TypeSourceInfo *EncodedTypeInfo
6095 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6096 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006098
Douglas Gregora16548e2009-08-11 05:31:07 +00006099 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006100 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006101 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006102
6103 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006104 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 E->getRParenLoc());
6106}
Mike Stump11289f42009-09-09 15:08:12 +00006107
Douglas Gregora16548e2009-08-11 05:31:07 +00006108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006110TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006111 // Transform arguments.
6112 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006113 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006114 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006115 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006116 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006118
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006119 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006120 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006121 }
6122
6123 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6124 // Class message: transform the receiver type.
6125 TypeSourceInfo *ReceiverTypeInfo
6126 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6127 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006129
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006130 // If nothing changed, just retain the existing message send.
6131 if (!getDerived().AlwaysRebuild() &&
6132 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006133 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006134
6135 // Build a new class message send.
6136 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6137 E->getSelector(),
6138 E->getMethodDecl(),
6139 E->getLeftLoc(),
6140 move_arg(Args),
6141 E->getRightLoc());
6142 }
6143
6144 // Instance message: transform the receiver
6145 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6146 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006147 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006148 = getDerived().TransformExpr(E->getInstanceReceiver());
6149 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006150 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006151
6152 // If nothing changed, just retain the existing message send.
6153 if (!getDerived().AlwaysRebuild() &&
6154 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006155 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006156
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006157 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006158 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006159 E->getSelector(),
6160 E->getMethodDecl(),
6161 E->getLeftLoc(),
6162 move_arg(Args),
6163 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006164}
6165
Mike Stump11289f42009-09-09 15:08:12 +00006166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006168TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006169 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006170}
6171
Mike Stump11289f42009-09-09 15:08:12 +00006172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006174TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006181 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006182 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006183 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006184 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006185
6186 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006187
Douglas Gregord51d90d2010-04-26 20:11:03 +00006188 // If nothing changed, just retain the existing expression.
6189 if (!getDerived().AlwaysRebuild() &&
6190 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006191 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006192
John McCallb268a282010-08-23 23:25:46 +00006193 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006194 E->getLocation(),
6195 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006196}
6197
Mike Stump11289f42009-09-09 15:08:12 +00006198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006199ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006200TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006201 // 'super' and types never change. Property never changes. Just
6202 // retain the existing expression.
6203 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006204 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006205
Douglas Gregor9faee212010-04-26 20:47:02 +00006206 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006207 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006208 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006209 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006210
Douglas Gregor9faee212010-04-26 20:47:02 +00006211 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006212
Douglas Gregor9faee212010-04-26 20:47:02 +00006213 // If nothing changed, just retain the existing expression.
6214 if (!getDerived().AlwaysRebuild() &&
6215 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006216 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006217
John McCallb7bd14f2010-12-02 01:19:52 +00006218 if (E->isExplicitProperty())
6219 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6220 E->getExplicitProperty(),
6221 E->getLocation());
6222
6223 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6224 E->getType(),
6225 E->getImplicitPropertyGetter(),
6226 E->getImplicitPropertySetter(),
6227 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006228}
6229
Mike Stump11289f42009-09-09 15:08:12 +00006230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006232TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006233 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006234 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006235 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006236 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006237
Douglas Gregord51d90d2010-04-26 20:11:03 +00006238 // If nothing changed, just retain the existing expression.
6239 if (!getDerived().AlwaysRebuild() &&
6240 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006241 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006242
John McCallb268a282010-08-23 23:25:46 +00006243 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006244 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006245}
6246
Mike Stump11289f42009-09-09 15:08:12 +00006247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006249TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006250 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006251 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006252 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006253 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006254 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006258 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006259 }
Mike Stump11289f42009-09-09 15:08:12 +00006260
Douglas Gregora16548e2009-08-11 05:31:07 +00006261 if (!getDerived().AlwaysRebuild() &&
6262 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006263 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregora16548e2009-08-11 05:31:07 +00006265 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6266 move_arg(SubExprs),
6267 E->getRParenLoc());
6268}
6269
Mike Stump11289f42009-09-09 15:08:12 +00006270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006271ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006272TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006273 SourceLocation CaretLoc(E->getExprLoc());
6274
6275 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6276 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6277 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6278 llvm::SmallVector<ParmVarDecl*, 4> Params;
6279 llvm::SmallVector<QualType, 4> ParamTypes;
6280
6281 // Parameter substitution.
6282 const BlockDecl *BD = E->getBlockDecl();
6283 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6284 EN = BD->param_end(); P != EN; ++P) {
6285 ParmVarDecl *OldParm = (*P);
6286 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6287 QualType NewType = NewParm->getType();
6288 Params.push_back(NewParm);
6289 ParamTypes.push_back(NewParm->getType());
6290 }
6291
6292 const FunctionType *BExprFunctionType = E->getFunctionType();
6293 QualType BExprResultType = BExprFunctionType->getResultType();
6294 if (!BExprResultType.isNull()) {
6295 if (!BExprResultType->isDependentType())
6296 CurBlock->ReturnType = BExprResultType;
6297 else if (BExprResultType != SemaRef.Context.DependentTy)
6298 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6299 }
6300
6301 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006302 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006303 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006304 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006305 // Set the parameters on the block decl.
6306 if (!Params.empty())
6307 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6308
6309 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6310 CurBlock->ReturnType,
6311 ParamTypes.data(),
6312 ParamTypes.size(),
6313 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006314 0,
6315 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006316
6317 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006318 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006319}
6320
Mike Stump11289f42009-09-09 15:08:12 +00006321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006323TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006324 NestedNameSpecifier *Qualifier = 0;
6325
6326 ValueDecl *ND
6327 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6328 E->getDecl()));
6329 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006330 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006331
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006332 if (!getDerived().AlwaysRebuild() &&
6333 ND == E->getDecl()) {
6334 // Mark it referenced in the new context regardless.
6335 // FIXME: this is a bit instantiation-specific.
6336 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6337
John McCallc3007a22010-10-26 07:05:15 +00006338 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006339 }
6340
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006341 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006342 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006343 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006344}
Mike Stump11289f42009-09-09 15:08:12 +00006345
Douglas Gregora16548e2009-08-11 05:31:07 +00006346//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006347// Type reconstruction
6348//===----------------------------------------------------------------------===//
6349
Mike Stump11289f42009-09-09 15:08:12 +00006350template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006351QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6352 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006353 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006354 getDerived().getBaseEntity());
6355}
6356
Mike Stump11289f42009-09-09 15:08:12 +00006357template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006358QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6359 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006360 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006361 getDerived().getBaseEntity());
6362}
6363
Mike Stump11289f42009-09-09 15:08:12 +00006364template<typename Derived>
6365QualType
John McCall70dd5f62009-10-30 00:06:24 +00006366TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6367 bool WrittenAsLValue,
6368 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006369 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006370 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006371}
6372
6373template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006374QualType
John McCall70dd5f62009-10-30 00:06:24 +00006375TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6376 QualType ClassType,
6377 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006378 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006379 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006380}
6381
6382template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006383QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006384TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6385 ArrayType::ArraySizeModifier SizeMod,
6386 const llvm::APInt *Size,
6387 Expr *SizeExpr,
6388 unsigned IndexTypeQuals,
6389 SourceRange BracketsRange) {
6390 if (SizeExpr || !Size)
6391 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6392 IndexTypeQuals, BracketsRange,
6393 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006394
6395 QualType Types[] = {
6396 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6397 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6398 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006399 };
6400 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6401 QualType SizeType;
6402 for (unsigned I = 0; I != NumTypes; ++I)
6403 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6404 SizeType = Types[I];
6405 break;
6406 }
Mike Stump11289f42009-09-09 15:08:12 +00006407
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006408 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6409 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006410 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006411 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006412 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006413}
Mike Stump11289f42009-09-09 15:08:12 +00006414
Douglas Gregord6ff3322009-08-04 16:50:30 +00006415template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006416QualType
6417TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006418 ArrayType::ArraySizeModifier SizeMod,
6419 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006420 unsigned IndexTypeQuals,
6421 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006422 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006423 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006424}
6425
6426template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006427QualType
Mike Stump11289f42009-09-09 15:08:12 +00006428TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006429 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006430 unsigned IndexTypeQuals,
6431 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006432 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006433 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006434}
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregord6ff3322009-08-04 16:50:30 +00006436template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006437QualType
6438TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006439 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006440 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006441 unsigned IndexTypeQuals,
6442 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006443 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006444 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006445 IndexTypeQuals, BracketsRange);
6446}
6447
6448template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006449QualType
6450TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006451 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006452 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006453 unsigned IndexTypeQuals,
6454 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006455 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006456 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006457 IndexTypeQuals, BracketsRange);
6458}
6459
6460template<typename Derived>
6461QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006462 unsigned NumElements,
6463 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006464 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006465 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006466}
Mike Stump11289f42009-09-09 15:08:12 +00006467
Douglas Gregord6ff3322009-08-04 16:50:30 +00006468template<typename Derived>
6469QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6470 unsigned NumElements,
6471 SourceLocation AttributeLoc) {
6472 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6473 NumElements, true);
6474 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006475 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6476 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006477 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006478}
Mike Stump11289f42009-09-09 15:08:12 +00006479
Douglas Gregord6ff3322009-08-04 16:50:30 +00006480template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006481QualType
6482TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006483 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006484 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006485 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006486}
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregord6ff3322009-08-04 16:50:30 +00006488template<typename Derived>
6489QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006490 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006491 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006492 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006493 unsigned Quals,
6494 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006495 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006496 Quals,
6497 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006498 getDerived().getBaseEntity(),
6499 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006500}
Mike Stump11289f42009-09-09 15:08:12 +00006501
Douglas Gregord6ff3322009-08-04 16:50:30 +00006502template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006503QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6504 return SemaRef.Context.getFunctionNoProtoType(T);
6505}
6506
6507template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006508QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6509 assert(D && "no decl found");
6510 if (D->isInvalidDecl()) return QualType();
6511
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006512 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006513 TypeDecl *Ty;
6514 if (isa<UsingDecl>(D)) {
6515 UsingDecl *Using = cast<UsingDecl>(D);
6516 assert(Using->isTypeName() &&
6517 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6518
6519 // A valid resolved using typename decl points to exactly one type decl.
6520 assert(++Using->shadow_begin() == Using->shadow_end());
6521 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006522
John McCallb96ec562009-12-04 22:46:56 +00006523 } else {
6524 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6525 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6526 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6527 }
6528
6529 return SemaRef.Context.getTypeDeclType(Ty);
6530}
6531
6532template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006533QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6534 SourceLocation Loc) {
6535 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006536}
6537
6538template<typename Derived>
6539QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6540 return SemaRef.Context.getTypeOfType(Underlying);
6541}
6542
6543template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006544QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6545 SourceLocation Loc) {
6546 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006547}
6548
6549template<typename Derived>
6550QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006551 TemplateName Template,
6552 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006553 const TemplateArgumentListInfo &TemplateArgs) {
6554 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006555}
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregor1135c352009-08-06 05:28:30 +00006557template<typename Derived>
6558NestedNameSpecifier *
6559TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6560 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006561 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006562 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006563 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006564 CXXScopeSpec SS;
6565 // FIXME: The source location information is all wrong.
6566 SS.setRange(Range);
6567 SS.setScopeRep(Prefix);
6568 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006569 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006570 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006571 ObjectType,
6572 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006573 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006574}
6575
6576template<typename Derived>
6577NestedNameSpecifier *
6578TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6579 SourceRange Range,
6580 NamespaceDecl *NS) {
6581 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6582}
6583
6584template<typename Derived>
6585NestedNameSpecifier *
6586TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6587 SourceRange Range,
6588 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006589 QualType T) {
6590 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006591 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006592 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006593 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6594 T.getTypePtr());
6595 }
Mike Stump11289f42009-09-09 15:08:12 +00006596
Douglas Gregor1135c352009-08-06 05:28:30 +00006597 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6598 return 0;
6599}
Mike Stump11289f42009-09-09 15:08:12 +00006600
Douglas Gregor71dc5092009-08-06 06:41:21 +00006601template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006602TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006603TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6604 bool TemplateKW,
6605 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006606 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006607 Template);
6608}
6609
6610template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006611TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006612TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006613 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006614 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00006615 QualType ObjectType,
6616 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006617 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006618 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006619 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006620 UnqualifiedId Name;
6621 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006622 Sema::TemplateTy Template;
6623 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6624 /*FIXME:*/getDerived().getBaseLocation(),
6625 SS,
6626 Name,
John McCallba7bf592010-08-24 05:47:05 +00006627 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006628 /*EnteringContext=*/false,
6629 Template);
John McCall31f82722010-11-12 08:19:04 +00006630 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006631}
Mike Stump11289f42009-09-09 15:08:12 +00006632
Douglas Gregora16548e2009-08-11 05:31:07 +00006633template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006634TemplateName
6635TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6636 OverloadedOperatorKind Operator,
6637 QualType ObjectType) {
6638 CXXScopeSpec SS;
6639 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6640 SS.setScopeRep(Qualifier);
6641 UnqualifiedId Name;
6642 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6643 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6644 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006645 Sema::TemplateTy Template;
6646 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006647 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006648 SS,
6649 Name,
John McCallba7bf592010-08-24 05:47:05 +00006650 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006651 /*EnteringContext=*/false,
6652 Template);
6653 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006654}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006655
Douglas Gregor71395fa2009-11-04 00:56:37 +00006656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006657ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006658TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6659 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006660 Expr *OrigCallee,
6661 Expr *First,
6662 Expr *Second) {
6663 Expr *Callee = OrigCallee->IgnoreParenCasts();
6664 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006665
Douglas Gregora16548e2009-08-11 05:31:07 +00006666 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006667 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006668 if (!First->getType()->isOverloadableType() &&
6669 !Second->getType()->isOverloadableType())
6670 return getSema().CreateBuiltinArraySubscriptExpr(First,
6671 Callee->getLocStart(),
6672 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006673 } else if (Op == OO_Arrow) {
6674 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006675 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6676 } else if (Second == 0 || isPostIncDec) {
6677 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 // The argument is not of overloadable type, so try to create a
6679 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006680 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006681 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006682
John McCallb268a282010-08-23 23:25:46 +00006683 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 }
6685 } else {
John McCallb268a282010-08-23 23:25:46 +00006686 if (!First->getType()->isOverloadableType() &&
6687 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006688 // Neither of the arguments is an overloadable type, so try to
6689 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006690 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006691 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006692 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006693 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006694 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006695
Douglas Gregora16548e2009-08-11 05:31:07 +00006696 return move(Result);
6697 }
6698 }
Mike Stump11289f42009-09-09 15:08:12 +00006699
6700 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006701 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006702 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006703
John McCallb268a282010-08-23 23:25:46 +00006704 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006705 assert(ULE->requiresADL());
6706
6707 // FIXME: Do we have to check
6708 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006709 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006710 } else {
John McCallb268a282010-08-23 23:25:46 +00006711 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006712 }
Mike Stump11289f42009-09-09 15:08:12 +00006713
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006715 Expr *Args[2] = { First, Second };
6716 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006717
Douglas Gregora16548e2009-08-11 05:31:07 +00006718 // Create the overloaded operator invocation for unary operators.
6719 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006720 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006721 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006722 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 }
Mike Stump11289f42009-09-09 15:08:12 +00006724
Sebastian Redladba46e2009-10-29 20:17:01 +00006725 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006726 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006727 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006728 First,
6729 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006730
Douglas Gregora16548e2009-08-11 05:31:07 +00006731 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006732 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006733 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006734 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6735 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006736 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006737
Mike Stump11289f42009-09-09 15:08:12 +00006738 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006739}
Mike Stump11289f42009-09-09 15:08:12 +00006740
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006742ExprResult
John McCallb268a282010-08-23 23:25:46 +00006743TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006744 SourceLocation OperatorLoc,
6745 bool isArrow,
6746 NestedNameSpecifier *Qualifier,
6747 SourceRange QualifierRange,
6748 TypeSourceInfo *ScopeType,
6749 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006750 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006751 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006752 CXXScopeSpec SS;
6753 if (Qualifier) {
6754 SS.setRange(QualifierRange);
6755 SS.setScopeRep(Qualifier);
6756 }
6757
John McCallb268a282010-08-23 23:25:46 +00006758 QualType BaseType = Base->getType();
6759 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006760 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006761 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006762 !BaseType->getAs<PointerType>()->getPointeeType()
6763 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006764 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006765 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006766 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006767 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006768 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006769 /*FIXME?*/true);
6770 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006771
Douglas Gregor678f90d2010-02-25 01:56:36 +00006772 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006773 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6774 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6775 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6776 NameInfo.setNamedTypeInfo(DestroyedType);
6777
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006778 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006779
John McCallb268a282010-08-23 23:25:46 +00006780 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006781 OperatorLoc, isArrow,
6782 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006783 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006784 /*TemplateArgs*/ 0);
6785}
6786
Douglas Gregord6ff3322009-08-04 16:50:30 +00006787} // end namespace clang
6788
6789#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H