blob: 9f6f84bec898b6a228eab550fe380a67151b07de [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
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000522 /// \brief Build a new parenthesized type.
523 ///
524 /// By default, builds a new ParenType type from the inner type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildParenType(QualType InnerType) {
527 return SemaRef.Context.getParenType(InnerType);
528 }
529
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// \brief Build a new qualified name type.
531 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000532 /// By default, builds a new ElaboratedType type from the keyword,
533 /// the nested-name-specifier and the named type.
534 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000535 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
536 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000537 NestedNameSpecifier *NNS, QualType Named) {
538 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000539 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540
541 /// \brief Build a new typename type that refers to a template-id.
542 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000543 /// By default, builds a new DependentNameType type from the
544 /// nested-name-specifier and the given type. Subclasses may override
545 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000546 QualType RebuildDependentTemplateSpecializationType(
547 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000548 NestedNameSpecifier *Qualifier,
549 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000550 const IdentifierInfo *Name,
551 SourceLocation NameLoc,
552 const TemplateArgumentListInfo &Args) {
553 // Rebuild the template name.
554 // TODO: avoid TemplateName abstraction
555 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000556 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000557 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000558
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000559 if (InstName.isNull())
560 return QualType();
561
John McCallc392f372010-06-11 00:33:02 +0000562 // If it's still dependent, make a dependent specialization.
563 if (InstName.getAsDependentTemplateName())
564 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000565 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000566
567 // Otherwise, make an elaborated type wrapping a non-dependent
568 // specialization.
569 QualType T =
570 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
571 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000572
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000573 // NOTE: NNS is already recorded in template specialization type T.
574 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000575 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000576
577 /// \brief Build a new typename type that refers to an identifier.
578 ///
579 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000580 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000581 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000582 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000583 NestedNameSpecifier *NNS,
584 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000585 SourceLocation KeywordLoc,
586 SourceRange NNSRange,
587 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000588 CXXScopeSpec SS;
589 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000590 SS.setRange(NNSRange);
591
Douglas Gregore677daf2010-03-31 22:19:08 +0000592 if (NNS->isDependent()) {
593 // If the name is still dependent, just build a new dependent name type.
594 if (!SemaRef.computeDeclContext(SS))
595 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
596 }
597
Abramo Bagnara6150c882010-05-11 21:36:43 +0000598 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000599 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
600 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000601
602 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
603
Abramo Bagnarad7548482010-05-19 21:37:53 +0000604 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000605 // into a non-dependent elaborated-type-specifier. Find the tag we're
606 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000607 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000608 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
609 if (!DC)
610 return QualType();
611
John McCallbf8c5192010-05-27 06:40:31 +0000612 if (SemaRef.RequireCompleteDeclContext(SS, DC))
613 return QualType();
614
Douglas Gregore677daf2010-03-31 22:19:08 +0000615 TagDecl *Tag = 0;
616 SemaRef.LookupQualifiedName(Result, DC);
617 switch (Result.getResultKind()) {
618 case LookupResult::NotFound:
619 case LookupResult::NotFoundInCurrentInstantiation:
620 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000621
Douglas Gregore677daf2010-03-31 22:19:08 +0000622 case LookupResult::Found:
623 Tag = Result.getAsSingle<TagDecl>();
624 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000625
Douglas Gregore677daf2010-03-31 22:19:08 +0000626 case LookupResult::FoundOverloaded:
627 case LookupResult::FoundUnresolvedValue:
628 llvm_unreachable("Tag lookup cannot find non-tags");
629 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000630
Douglas Gregore677daf2010-03-31 22:19:08 +0000631 case LookupResult::Ambiguous:
632 // Let the LookupResult structure handle ambiguities.
633 return QualType();
634 }
635
636 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000637 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000638 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000639 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000640 return QualType();
641 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000642
Abramo Bagnarad7548482010-05-19 21:37:53 +0000643 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
644 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000645 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
646 return QualType();
647 }
648
649 // Build the elaborated-type-specifier type.
650 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000651 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000652 }
Mike Stump11289f42009-09-09 15:08:12 +0000653
Douglas Gregor1135c352009-08-06 05:28:30 +0000654 /// \brief Build a new nested-name-specifier given the prefix and an
655 /// identifier that names the next step in the nested-name-specifier.
656 ///
657 /// By default, performs semantic analysis when building the new
658 /// nested-name-specifier. Subclasses may override this routine to provide
659 /// different behavior.
660 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
661 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000662 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000663 QualType ObjectType,
664 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000665
666 /// \brief Build a new nested-name-specifier given the prefix and the
667 /// namespace named in the next step in the nested-name-specifier.
668 ///
669 /// By default, performs semantic analysis when building the new
670 /// nested-name-specifier. Subclasses may override this routine to provide
671 /// different behavior.
672 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
673 SourceRange Range,
674 NamespaceDecl *NS);
675
676 /// \brief Build a new nested-name-specifier given the prefix and the
677 /// type named in the next step in the nested-name-specifier.
678 ///
679 /// By default, performs semantic analysis when building the new
680 /// nested-name-specifier. Subclasses may override this routine to provide
681 /// different behavior.
682 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
683 SourceRange Range,
684 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000685 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000686
687 /// \brief Build a new template name given a nested name specifier, a flag
688 /// indicating whether the "template" keyword was provided, and the template
689 /// that the template name refers to.
690 ///
691 /// By default, builds the new template name directly. Subclasses may override
692 /// this routine to provide different behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
694 bool TemplateKW,
695 TemplateDecl *Template);
696
Douglas Gregor71dc5092009-08-06 06:41:21 +0000697 /// \brief Build a new template name given a nested name specifier and the
698 /// name that is referred to as a template.
699 ///
700 /// By default, performs semantic analysis to determine whether the name can
701 /// be resolved to a specific template, then builds the appropriate kind of
702 /// template name. Subclasses may override this routine to provide different
703 /// behavior.
704 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000705 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000706 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000707 QualType ObjectType,
708 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000709
Douglas Gregor71395fa2009-11-04 00:56:37 +0000710 /// \brief Build a new template name given a nested name specifier and the
711 /// overloaded operator name that is referred to as a template.
712 ///
713 /// By default, performs semantic analysis to determine whether the name can
714 /// be resolved to a specific template, then builds the appropriate kind of
715 /// template name. Subclasses may override this routine to provide different
716 /// behavior.
717 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
718 OverloadedOperatorKind Operator,
719 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000720
Douglas Gregorebe10102009-08-20 07:17:43 +0000721 /// \brief Build a new compound statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000725 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 MultiStmtArg Statements,
727 SourceLocation RBraceLoc,
728 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000729 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000730 IsStmtExpr);
731 }
732
733 /// \brief Build a new case statement.
734 ///
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000737 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000738 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000740 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000741 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000742 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 ColonLoc);
744 }
Mike Stump11289f42009-09-09 15:08:12 +0000745
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 /// \brief Attach the body to a new case statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000750 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000751 getSema().ActOnCaseStmtBody(S, Body);
752 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000753 }
Mike Stump11289f42009-09-09 15:08:12 +0000754
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /// \brief Build a new default statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000759 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000760 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000761 Stmt *SubStmt) {
762 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 /*CurScope=*/0);
764 }
Mike Stump11289f42009-09-09 15:08:12 +0000765
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 /// \brief Build a new label statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000770 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000771 IdentifierInfo *Id,
772 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000773 Stmt *SubStmt, bool HasUnusedAttr) {
774 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
775 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000776 }
Mike Stump11289f42009-09-09 15:08:12 +0000777
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 /// \brief Build a new "if" statement.
779 ///
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000782 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000783 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000784 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000785 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000786 }
Mike Stump11289f42009-09-09 15:08:12 +0000787
Douglas Gregorebe10102009-08-20 07:17:43 +0000788 /// \brief Start building a new switch statement.
789 ///
790 /// By default, performs semantic analysis to build the new statement.
791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000792 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000793 Expr *Cond, VarDecl *CondVar) {
794 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000795 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000796 }
Mike Stump11289f42009-09-09 15:08:12 +0000797
Douglas Gregorebe10102009-08-20 07:17:43 +0000798 /// \brief Attach the body to the switch statement.
799 ///
800 /// By default, performs semantic analysis to build the new statement.
801 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000802 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000803 Stmt *Switch, Stmt *Body) {
804 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 }
806
807 /// \brief Build a new while statement.
808 ///
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000811 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000812 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000813 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000814 Stmt *Body) {
815 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000816 }
Mike Stump11289f42009-09-09 15:08:12 +0000817
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 /// \brief Build a new do-while statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000822 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000823 SourceLocation WhileLoc,
824 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000825 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000827 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
828 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 }
830
831 /// \brief Build a new for statement.
832 ///
833 /// By default, performs semantic analysis to build the new statement.
834 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000835 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000836 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000837 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000838 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000839 SourceLocation RParenLoc, Stmt *Body) {
840 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000841 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000842 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000843 }
Mike Stump11289f42009-09-09 15:08:12 +0000844
Douglas Gregorebe10102009-08-20 07:17:43 +0000845 /// \brief Build a new goto statement.
846 ///
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000849 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000850 SourceLocation LabelLoc,
851 LabelStmt *Label) {
852 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
853 }
854
855 /// \brief Build a new indirect goto statement.
856 ///
857 /// By default, performs semantic analysis to build the new statement.
858 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000859 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000860 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000861 Expr *Target) {
862 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000863 }
Mike Stump11289f42009-09-09 15:08:12 +0000864
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 /// \brief Build a new return statement.
866 ///
867 /// By default, performs semantic analysis to build the new statement.
868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000869 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000870 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000871
John McCallb268a282010-08-23 23:25:46 +0000872 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000873 }
Mike Stump11289f42009-09-09 15:08:12 +0000874
Douglas Gregorebe10102009-08-20 07:17:43 +0000875 /// \brief Build a new declaration statement.
876 ///
877 /// By default, performs semantic analysis to build the new statement.
878 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000879 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000880 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000881 SourceLocation EndLoc) {
882 return getSema().Owned(
883 new (getSema().Context) DeclStmt(
884 DeclGroupRef::Create(getSema().Context,
885 Decls, NumDecls),
886 StartLoc, EndLoc));
887 }
Mike Stump11289f42009-09-09 15:08:12 +0000888
Anders Carlssonaaeef072010-01-24 05:50:09 +0000889 /// \brief Build a new inline asm statement.
890 ///
891 /// By default, performs semantic analysis to build the new statement.
892 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000893 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000894 bool IsSimple,
895 bool IsVolatile,
896 unsigned NumOutputs,
897 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000898 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000899 MultiExprArg Constraints,
900 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000901 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000902 MultiExprArg Clobbers,
903 SourceLocation RParenLoc,
904 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000905 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000906 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000907 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000908 RParenLoc, MSAsm);
909 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000910
911 /// \brief Build a new Objective-C @try statement.
912 ///
913 /// By default, performs semantic analysis to build the new statement.
914 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000915 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000916 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000917 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000918 Stmt *Finally) {
919 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
920 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000921 }
922
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 /// \brief Rebuild an Objective-C exception declaration.
924 ///
925 /// By default, performs semantic analysis to build the new declaration.
926 /// Subclasses may override this routine to provide different behavior.
927 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
928 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000929 return getSema().BuildObjCExceptionDecl(TInfo, T,
930 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000931 ExceptionDecl->getLocation());
932 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000933
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000934 /// \brief Build a new Objective-C @catch statement.
935 ///
936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000938 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000939 SourceLocation RParenLoc,
940 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000941 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000942 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000943 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000944 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000945
Douglas Gregor306de2f2010-04-22 23:59:56 +0000946 /// \brief Build a new Objective-C @finally statement.
947 ///
948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000950 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000951 Stmt *Body) {
952 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000953 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000954
Douglas Gregor6148de72010-04-22 22:01:21 +0000955 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000959 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000960 Expr *Operand) {
961 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000962 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000963
Douglas Gregor6148de72010-04-22 22:01:21 +0000964 /// \brief Build a new Objective-C @synchronized statement.
965 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000968 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000969 Expr *Object,
970 Stmt *Body) {
971 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
972 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000973 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000974
975 /// \brief Build a new Objective-C fast enumeration statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000979 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000980 SourceLocation LParenLoc,
981 Stmt *Element,
982 Expr *Collection,
983 SourceLocation RParenLoc,
984 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000985 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000986 Element,
987 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000988 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000989 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000990 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000991
Douglas Gregorebe10102009-08-20 07:17:43 +0000992 /// \brief Build a new C++ exception declaration.
993 ///
994 /// By default, performs semantic analysis to build the new decaration.
995 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000996 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +0000997 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000998 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000999 SourceLocation Loc) {
1000 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 }
1002
1003 /// \brief Build a new C++ catch statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001007 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001008 VarDecl *ExceptionDecl,
1009 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001010 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1011 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001012 }
Mike Stump11289f42009-09-09 15:08:12 +00001013
Douglas Gregorebe10102009-08-20 07:17:43 +00001014 /// \brief Build a new C++ try statement.
1015 ///
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001018 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001019 Stmt *TryBlock,
1020 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001021 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001022 }
Mike Stump11289f42009-09-09 15:08:12 +00001023
Douglas Gregora16548e2009-08-11 05:31:07 +00001024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001028 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001029 LookupResult &R,
1030 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001031 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1032 }
1033
1034
1035 /// \brief Build a new expression that references a declaration.
1036 ///
1037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001039 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001040 SourceRange QualifierRange,
1041 ValueDecl *VD,
1042 const DeclarationNameInfo &NameInfo,
1043 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001044 CXXScopeSpec SS;
1045 SS.setScopeRep(Qualifier);
1046 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001047
1048 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001049
1050 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001051 }
Mike Stump11289f42009-09-09 15:08:12 +00001052
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001054 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001059 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 }
1061
Douglas Gregorad8a3362009-09-04 17:36:40 +00001062 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001063 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001066 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001067 SourceLocation OperatorLoc,
1068 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001069 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001070 SourceRange QualifierRange,
1071 TypeSourceInfo *ScopeType,
1072 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001073 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001074 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001077 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 /// By default, performs semantic analysis to build the new expression.
1079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001080 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001081 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001082 Expr *SubExpr) {
1083 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregor882211c2010-04-28 22:16:22 +00001086 /// \brief Build a new builtin offsetof expression.
1087 ///
1088 /// By default, performs semantic analysis to build the new expression.
1089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001090 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001091 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001092 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001093 unsigned NumComponents,
1094 SourceLocation RParenLoc) {
1095 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1096 NumComponents, RParenLoc);
1097 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001098
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001100 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001103 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001104 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001106 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 }
1108
Mike Stump11289f42009-09-09 15:08:12 +00001109 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001114 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001116 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001117 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 return move(Result);
1122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// By default, performs semantic analysis to build the new expression.
1127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001128 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001130 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001131 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001132 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1133 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 RBracketLoc);
1135 }
1136
1137 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001138 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001141 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001143 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001144 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001145 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 }
1147
1148 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001149 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001150 /// By default, performs semantic analysis to build the new expression.
1151 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001152 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001153 bool isArrow,
1154 NestedNameSpecifier *Qualifier,
1155 SourceRange QualifierRange,
1156 const DeclarationNameInfo &MemberNameInfo,
1157 ValueDecl *Member,
1158 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001159 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001160 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001161 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001162 // We have a reference to an unnamed field. This is always the
1163 // base of an anonymous struct/union member access, i.e. the
1164 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001165 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001166 assert(Member->getType()->isRecordType() &&
1167 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001168
John McCallb268a282010-08-23 23:25:46 +00001169 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001170 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001171 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001172
John McCall7decc9e2010-11-18 06:31:45 +00001173 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001174 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001175 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001176 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001177 cast<FieldDecl>(Member)->getType(),
1178 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001179 return getSema().Owned(ME);
1180 }
Mike Stump11289f42009-09-09 15:08:12 +00001181
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001182 CXXScopeSpec SS;
1183 if (Qualifier) {
1184 SS.setRange(QualifierRange);
1185 SS.setScopeRep(Qualifier);
1186 }
1187
John McCallb268a282010-08-23 23:25:46 +00001188 getSema().DefaultFunctionArrayConversion(Base);
1189 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001190
John McCall16df1e52010-03-30 21:47:33 +00001191 // FIXME: this involves duplicating earlier analysis in a lot of
1192 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001193 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001194 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001195 R.resolveKind();
1196
John McCallb268a282010-08-23 23:25:46 +00001197 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001198 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001199 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 }
Mike Stump11289f42009-09-09 15:08:12 +00001201
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001203 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 /// By default, performs semantic analysis to build the new expression.
1205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001206 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001207 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001208 Expr *LHS, Expr *RHS) {
1209 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 }
1211
1212 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001213 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 /// By default, performs semantic analysis to build the new expression.
1215 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001216 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001218 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001220 Expr *RHS) {
1221 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1222 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 }
1224
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 /// By default, performs semantic analysis to build the new expression.
1228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001229 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001230 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001232 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001233 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001234 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 }
Mike Stump11289f42009-09-09 15:08:12 +00001236
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001238 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// By default, performs semantic analysis to build the new expression.
1240 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001241 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001242 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001244 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001245 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001246 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 }
Mike Stump11289f42009-09-09 15:08:12 +00001248
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001250 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001253 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 SourceLocation OpLoc,
1255 SourceLocation AccessorLoc,
1256 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001257
John McCall10eae182009-11-30 22:42:35 +00001258 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001259 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001260 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001261 OpLoc, /*IsArrow*/ false,
1262 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001263 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001264 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 }
Mike Stump11289f42009-09-09 15:08:12 +00001266
Douglas Gregora16548e2009-08-11 05:31:07 +00001267 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001268 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001271 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001273 SourceLocation RBraceLoc,
1274 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001275 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001276 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1277 if (Result.isInvalid() || ResultTy->isDependentType())
1278 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001279
Douglas Gregord3d93062009-11-09 17:16:50 +00001280 // Patch in the result type we were given, which may have been computed
1281 // when the initial InitListExpr was built.
1282 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1283 ILE->setType(ResultTy);
1284 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001288 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001291 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 MultiExprArg ArrayExprs,
1293 SourceLocation EqualOrColonLoc,
1294 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001295 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001296 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001298 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001300 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001301
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 ArrayExprs.release();
1303 return move(Result);
1304 }
Mike Stump11289f42009-09-09 15:08:12 +00001305
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001307 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 /// By default, builds the implicit value initialization without performing
1309 /// any semantic analysis. Subclasses may override this routine to provide
1310 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001311 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1313 }
Mike Stump11289f42009-09-09 15:08:12 +00001314
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001316 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001319 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001320 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001321 SourceLocation RParenLoc) {
1322 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001323 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001324 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 }
1326
1327 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001328 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001331 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 MultiExprArg SubExprs,
1333 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001334 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001335 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 }
Mike Stump11289f42009-09-09 15:08:12 +00001337
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001339 ///
1340 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// rather than attempting to map the label statement itself.
1342 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001343 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 SourceLocation LabelLoc,
1345 LabelStmt *Label) {
1346 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1347 }
Mike Stump11289f42009-09-09 15:08:12 +00001348
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001350 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001353 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001354 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001356 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 }
Mike Stump11289f42009-09-09 15:08:12 +00001358
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 /// \brief Build a new __builtin_choose_expr expression.
1360 ///
1361 /// By default, performs semantic analysis to build the new expression.
1362 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001363 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001364 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 SourceLocation RParenLoc) {
1366 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001367 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 RParenLoc);
1369 }
Mike Stump11289f42009-09-09 15:08:12 +00001370
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// \brief Build a new overloaded operator call expression.
1372 ///
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// The semantic analysis provides the behavior of template instantiation,
1375 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001376 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// argument-dependent lookup, etc. Subclasses may override this routine to
1378 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001379 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001381 Expr *Callee,
1382 Expr *First,
1383 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001384
1385 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// reinterpret_cast.
1387 ///
1388 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001389 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001391 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 Stmt::StmtClass Class,
1393 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001394 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 SourceLocation RAngleLoc,
1396 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001397 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 SourceLocation RParenLoc) {
1399 switch (Class) {
1400 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001403 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001404
1405 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001408 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001413 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001415
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001417 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001418 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001419 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 default:
1422 assert(false && "Invalid C++ named cast");
1423 break;
1424 }
Mike Stump11289f42009-09-09 15:08:12 +00001425
John McCallfaf5fb42010-08-26 23:41:50 +00001426 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 }
Mike Stump11289f42009-09-09 15:08:12 +00001428
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 /// \brief Build a new C++ static_cast expression.
1430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001433 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RAngleLoc,
1437 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001438 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001440 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001441 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001442 SourceRange(LAngleLoc, RAngleLoc),
1443 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new C++ dynamic_cast expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001450 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001452 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceLocation RAngleLoc,
1454 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001455 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001457 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001458 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001459 SourceRange(LAngleLoc, RAngleLoc),
1460 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 }
1462
1463 /// \brief Build a new C++ reinterpret_cast expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001467 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001468 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001469 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 SourceLocation RAngleLoc,
1471 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001472 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001474 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001475 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001476 SourceRange(LAngleLoc, RAngleLoc),
1477 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 }
1479
1480 /// \brief Build a new C++ const_cast expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001484 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001486 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 SourceLocation RAngleLoc,
1488 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001489 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001491 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001492 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001493 SourceRange(LAngleLoc, RAngleLoc),
1494 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 }
Mike Stump11289f42009-09-09 15:08:12 +00001496
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 /// \brief Build a new C++ functional-style cast expression.
1498 ///
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001501 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1502 SourceLocation LParenLoc,
1503 Expr *Sub,
1504 SourceLocation RParenLoc) {
1505 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001506 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 RParenLoc);
1508 }
Mike Stump11289f42009-09-09 15:08:12 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// \brief Build a new C++ typeid(type) expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001514 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001515 SourceLocation TypeidLoc,
1516 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001518 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001519 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 }
Mike Stump11289f42009-09-09 15:08:12 +00001521
Francois Pichet9f4f2072010-09-08 12:20:18 +00001522
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 /// \brief Build a new C++ typeid(expr) expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001527 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001528 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001529 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001531 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001532 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001533 }
1534
Francois Pichet9f4f2072010-09-08 12:20:18 +00001535 /// \brief Build a new C++ __uuidof(type) expression.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
1539 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1540 SourceLocation TypeidLoc,
1541 TypeSourceInfo *Operand,
1542 SourceLocation RParenLoc) {
1543 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1544 RParenLoc);
1545 }
1546
1547 /// \brief Build a new C++ __uuidof(expr) expression.
1548 ///
1549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
1551 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1552 SourceLocation TypeidLoc,
1553 Expr *Operand,
1554 SourceLocation RParenLoc) {
1555 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1556 RParenLoc);
1557 }
1558
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 /// \brief Build a new C++ "this" expression.
1560 ///
1561 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001562 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001564 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001565 QualType ThisType,
1566 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001568 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1569 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 }
1571
1572 /// \brief Build a new C++ throw expression.
1573 ///
1574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001576 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001577 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 }
1579
1580 /// \brief Build a new C++ default-argument expression.
1581 ///
1582 /// By default, builds a new default-argument expression, which does not
1583 /// require any semantic analysis. Subclasses may override this routine to
1584 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001585 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001586 ParmVarDecl *Param) {
1587 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1588 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 }
1590
1591 /// \brief Build a new C++ zero-initialization expression.
1592 ///
1593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001595 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1596 SourceLocation LParenLoc,
1597 SourceLocation RParenLoc) {
1598 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001599 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001600 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 }
Mike Stump11289f42009-09-09 15:08:12 +00001602
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 /// \brief Build a new C++ "new" expression.
1604 ///
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001607 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001608 bool UseGlobal,
1609 SourceLocation PlacementLParen,
1610 MultiExprArg PlacementArgs,
1611 SourceLocation PlacementRParen,
1612 SourceRange TypeIdParens,
1613 QualType AllocatedType,
1614 TypeSourceInfo *AllocatedTypeInfo,
1615 Expr *ArraySize,
1616 SourceLocation ConstructorLParen,
1617 MultiExprArg ConstructorArgs,
1618 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001619 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 PlacementLParen,
1621 move(PlacementArgs),
1622 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001623 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001624 AllocatedType,
1625 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001626 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 ConstructorLParen,
1628 move(ConstructorArgs),
1629 ConstructorRParen);
1630 }
Mike Stump11289f42009-09-09 15:08:12 +00001631
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 /// \brief Build a new C++ "delete" expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001636 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 bool IsGlobalDelete,
1638 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001639 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001641 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 }
Mike Stump11289f42009-09-09 15:08:12 +00001643
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 /// \brief Build a new unary type trait expression.
1645 ///
1646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001648 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001649 SourceLocation StartLoc,
1650 TypeSourceInfo *T,
1651 SourceLocation RParenLoc) {
1652 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 }
1654
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001655 /// \brief Build a new binary type trait expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
1659 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1660 SourceLocation StartLoc,
1661 TypeSourceInfo *LhsT,
1662 TypeSourceInfo *RhsT,
1663 SourceLocation RParenLoc) {
1664 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1665 }
1666
Mike Stump11289f42009-09-09 15:08:12 +00001667 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 /// expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001672 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001674 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001675 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 CXXScopeSpec SS;
1677 SS.setRange(QualifierRange);
1678 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001679
1680 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001681 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001682 *TemplateArgs);
1683
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001684 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new template-id expression.
1688 ///
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001691 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001692 LookupResult &R,
1693 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001694 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001695 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 }
1697
1698 /// \brief Build a new object-construction expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001702 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001703 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 CXXConstructorDecl *Constructor,
1705 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001706 MultiExprArg Args,
1707 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001708 CXXConstructExpr::ConstructionKind ConstructKind,
1709 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001710 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001711 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001712 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001713 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001714
Douglas Gregordb121ba2009-12-14 16:27:04 +00001715 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001716 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001717 RequiresZeroInit, ConstructKind,
1718 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 }
1720
1721 /// \brief Build a new object-construction expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001725 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1726 SourceLocation LParenLoc,
1727 MultiExprArg Args,
1728 SourceLocation RParenLoc) {
1729 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 LParenLoc,
1731 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 RParenLoc);
1733 }
1734
1735 /// \brief Build a new object-construction expression.
1736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001739 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1740 SourceLocation LParenLoc,
1741 MultiExprArg Args,
1742 SourceLocation RParenLoc) {
1743 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 LParenLoc,
1745 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 RParenLoc);
1747 }
Mike Stump11289f42009-09-09 15:08:12 +00001748
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 /// \brief Build a new member reference expression.
1750 ///
1751 /// By default, performs semantic analysis to build the new expression.
1752 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001753 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001754 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 bool IsArrow,
1756 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001757 NestedNameSpecifier *Qualifier,
1758 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001759 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001760 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001761 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001763 SS.setRange(QualifierRange);
1764 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001765
John McCallb268a282010-08-23 23:25:46 +00001766 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001767 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001768 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001769 MemberNameInfo,
1770 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
1772
John McCall10eae182009-11-30 22:42:35 +00001773 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001777 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001778 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001779 SourceLocation OperatorLoc,
1780 bool IsArrow,
1781 NestedNameSpecifier *Qualifier,
1782 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001783 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001784 LookupResult &R,
1785 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001786 CXXScopeSpec SS;
1787 SS.setRange(QualifierRange);
1788 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001789
John McCallb268a282010-08-23 23:25:46 +00001790 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001791 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001792 SS, FirstQualifierInScope,
1793 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001794 }
Mike Stump11289f42009-09-09 15:08:12 +00001795
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001796 /// \brief Build a new noexcept expression.
1797 ///
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
1800 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1801 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1802 }
1803
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// \brief Build a new Objective-C @encode expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001808 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001809 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001811 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001813 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001814
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001815 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001817 Selector Sel,
1818 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001819 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001820 MultiExprArg Args,
1821 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001822 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1823 ReceiverTypeInfo->getType(),
1824 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001825 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001826 move(Args));
1827 }
1828
1829 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001830 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001831 Selector Sel,
1832 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001833 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001834 MultiExprArg Args,
1835 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001836 return SemaRef.BuildInstanceMessage(Receiver,
1837 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001838 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001839 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001840 move(Args));
1841 }
1842
Douglas Gregord51d90d2010-04-26 20:11:03 +00001843 /// \brief Build a new Objective-C ivar reference expression.
1844 ///
1845 /// By default, performs semantic analysis to build the new expression.
1846 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001847 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001848 SourceLocation IvarLoc,
1849 bool IsArrow, bool IsFreeIvar) {
1850 // FIXME: We lose track of the IsFreeIvar bit.
1851 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001852 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001853 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1854 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001856 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001857 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001858 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001859 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001860 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001861
Douglas Gregord51d90d2010-04-26 20:11:03 +00001862 if (Result.get())
1863 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001864
John McCallb268a282010-08-23 23:25:46 +00001865 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001866 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001867 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001868 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001869 /*TemplateArgs=*/0);
1870 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001871
1872 /// \brief Build a new Objective-C property reference expression.
1873 ///
1874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001876 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001877 ObjCPropertyDecl *Property,
1878 SourceLocation PropertyLoc) {
1879 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001880 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001881 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1882 Sema::LookupMemberName);
1883 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001884 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001885 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001886 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001887 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001888 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001889
Douglas Gregor9faee212010-04-26 20:47:02 +00001890 if (Result.get())
1891 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001892
John McCallb268a282010-08-23 23:25:46 +00001893 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001894 /*FIXME:*/PropertyLoc, IsArrow,
1895 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001896 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001897 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001898 /*TemplateArgs=*/0);
1899 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001900
John McCallb7bd14f2010-12-02 01:19:52 +00001901 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001902 ///
1903 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00001904 /// Subclasses may override this routine to provide different behavior.
1905 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1906 ObjCMethodDecl *Getter,
1907 ObjCMethodDecl *Setter,
1908 SourceLocation PropertyLoc) {
1909 // Since these expressions can only be value-dependent, we do not
1910 // need to perform semantic analysis again.
1911 return Owned(
1912 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
1913 VK_LValue, OK_ObjCProperty,
1914 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001915 }
1916
Douglas Gregord51d90d2010-04-26 20:11:03 +00001917 /// \brief Build a new Objective-C "isa" expression.
1918 ///
1919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001921 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001922 bool IsArrow) {
1923 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001924 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001925 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1926 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001927 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001928 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001929 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001930 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001931 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001932
Douglas Gregord51d90d2010-04-26 20:11:03 +00001933 if (Result.get())
1934 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001935
John McCallb268a282010-08-23 23:25:46 +00001936 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001937 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001938 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001939 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001940 /*TemplateArgs=*/0);
1941 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// \brief Build a new shuffle vector expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001947 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001948 MultiExprArg SubExprs,
1949 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001951 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1953 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1954 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1955 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 // Build a reference to the __builtin_shufflevector builtin
1958 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001959 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00001961 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001963
1964 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 unsigned NumSubExprs = SubExprs.size();
1966 Expr **Subs = (Expr **)SubExprs.release();
1967 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1968 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001969 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00001970 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001972 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001973
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001978
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001980 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 }
John McCall31f82722010-11-12 08:19:04 +00001982
1983private:
1984 QualType TransformTypeInObjectScope(QualType T,
1985 QualType ObjectType,
1986 NamedDecl *FirstQualifierInScope,
1987 NestedNameSpecifier *Prefix);
1988
1989 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
1990 QualType ObjectType,
1991 NamedDecl *FirstQualifierInScope,
1992 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001993};
Douglas Gregora16548e2009-08-11 05:31:07 +00001994
Douglas Gregorebe10102009-08-20 07:17:43 +00001995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001996StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001997 if (!S)
1998 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001999
Douglas Gregorebe10102009-08-20 07:17:43 +00002000 switch (S->getStmtClass()) {
2001 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregorebe10102009-08-20 07:17:43 +00002003 // Transform individual statement nodes
2004#define STMT(Node, Parent) \
2005 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2006#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002007#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002008
Douglas Gregorebe10102009-08-20 07:17:43 +00002009 // Transform expressions by calling TransformExpr.
2010#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002011#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002012#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002013#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002014 {
John McCalldadc5752010-08-24 06:29:42 +00002015 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002016 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002017 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002018
John McCallb268a282010-08-23 23:25:46 +00002019 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002020 }
Mike Stump11289f42009-09-09 15:08:12 +00002021 }
2022
John McCallc3007a22010-10-26 07:05:15 +00002023 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002024}
Mike Stump11289f42009-09-09 15:08:12 +00002025
2026
Douglas Gregore922c772009-08-04 22:27:00 +00002027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002028ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 if (!E)
2030 return SemaRef.Owned(E);
2031
2032 switch (E->getStmtClass()) {
2033 case Stmt::NoStmtClass: break;
2034#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002035#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002036#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002037 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002038#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002039 }
2040
John McCallc3007a22010-10-26 07:05:15 +00002041 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002042}
2043
2044template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002045NestedNameSpecifier *
2046TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002047 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002048 QualType ObjectType,
2049 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002050 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002051
Douglas Gregorebe10102009-08-20 07:17:43 +00002052 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002054 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002055 ObjectType,
2056 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002057 if (!Prefix)
2058 return 0;
2059 }
Mike Stump11289f42009-09-09 15:08:12 +00002060
Douglas Gregor1135c352009-08-06 05:28:30 +00002061 switch (NNS->getKind()) {
2062 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002063 if (Prefix) {
2064 // The object type and qualifier-in-scope really apply to the
2065 // leftmost entity.
2066 ObjectType = QualType();
2067 FirstQualifierInScope = 0;
2068 }
2069
Mike Stump11289f42009-09-09 15:08:12 +00002070 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002071 "Identifier nested-name-specifier with no prefix or object type");
2072 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2073 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002074 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002075
2076 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002077 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002078 ObjectType,
2079 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002080
Douglas Gregor1135c352009-08-06 05:28:30 +00002081 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002082 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002083 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002084 getDerived().TransformDecl(Range.getBegin(),
2085 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002086 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002087 Prefix == NNS->getPrefix() &&
2088 NS == NNS->getAsNamespace())
2089 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002090
Douglas Gregor1135c352009-08-06 05:28:30 +00002091 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
Douglas Gregor1135c352009-08-06 05:28:30 +00002094 case NestedNameSpecifier::Global:
2095 // There is no meaningful transformation that one could perform on the
2096 // global scope.
2097 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregor1135c352009-08-06 05:28:30 +00002099 case NestedNameSpecifier::TypeSpecWithTemplate:
2100 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002101 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002102 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2103 ObjectType,
2104 FirstQualifierInScope,
2105 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002106 if (T.isNull())
2107 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002108
Douglas Gregor1135c352009-08-06 05:28:30 +00002109 if (!getDerived().AlwaysRebuild() &&
2110 Prefix == NNS->getPrefix() &&
2111 T == QualType(NNS->getAsType(), 0))
2112 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002113
2114 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2115 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002116 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002117 }
2118 }
Mike Stump11289f42009-09-09 15:08:12 +00002119
Douglas Gregor1135c352009-08-06 05:28:30 +00002120 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002121 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002122}
2123
2124template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002125DeclarationNameInfo
2126TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002127::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002128 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002129 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002130 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002131
2132 switch (Name.getNameKind()) {
2133 case DeclarationName::Identifier:
2134 case DeclarationName::ObjCZeroArgSelector:
2135 case DeclarationName::ObjCOneArgSelector:
2136 case DeclarationName::ObjCMultiArgSelector:
2137 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002138 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002139 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002140 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002141
Douglas Gregorf816bd72009-09-03 22:13:48 +00002142 case DeclarationName::CXXConstructorName:
2143 case DeclarationName::CXXDestructorName:
2144 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002145 TypeSourceInfo *NewTInfo;
2146 CanQualType NewCanTy;
2147 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002148 NewTInfo = getDerived().TransformType(OldTInfo);
2149 if (!NewTInfo)
2150 return DeclarationNameInfo();
2151 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002152 }
2153 else {
2154 NewTInfo = 0;
2155 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002156 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002157 if (NewT.isNull())
2158 return DeclarationNameInfo();
2159 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2160 }
Mike Stump11289f42009-09-09 15:08:12 +00002161
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002162 DeclarationName NewName
2163 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2164 NewCanTy);
2165 DeclarationNameInfo NewNameInfo(NameInfo);
2166 NewNameInfo.setName(NewName);
2167 NewNameInfo.setNamedTypeInfo(NewTInfo);
2168 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002169 }
Mike Stump11289f42009-09-09 15:08:12 +00002170 }
2171
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002172 assert(0 && "Unknown name kind.");
2173 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002174}
2175
2176template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002177TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002178TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002179 QualType ObjectType,
2180 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002181 SourceLocation Loc = getDerived().getBaseLocation();
2182
Douglas Gregor71dc5092009-08-06 06:41:21 +00002183 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002184 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002185 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002186 /*FIXME*/ SourceRange(Loc),
2187 ObjectType,
2188 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002189 if (!NNS)
2190 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002191
Douglas Gregor71dc5092009-08-06 06:41:21 +00002192 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002193 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002194 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002195 if (!TransTemplate)
2196 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002197
Douglas Gregor71dc5092009-08-06 06:41:21 +00002198 if (!getDerived().AlwaysRebuild() &&
2199 NNS == QTN->getQualifier() &&
2200 TransTemplate == Template)
2201 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregor71dc5092009-08-06 06:41:21 +00002203 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2204 TransTemplate);
2205 }
Mike Stump11289f42009-09-09 15:08:12 +00002206
John McCalle66edc12009-11-24 19:00:30 +00002207 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002208 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002209 }
Mike Stump11289f42009-09-09 15:08:12 +00002210
Douglas Gregor71dc5092009-08-06 06:41:21 +00002211 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002212 NestedNameSpecifier *NNS = DTN->getQualifier();
2213 if (NNS) {
2214 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2215 /*FIXME:*/SourceRange(Loc),
2216 ObjectType,
2217 FirstQualifierInScope);
2218 if (!NNS) return TemplateName();
2219
2220 // These apply to the scope specifier, not the template.
2221 ObjectType = QualType();
2222 FirstQualifierInScope = 0;
2223 }
Mike Stump11289f42009-09-09 15:08:12 +00002224
Douglas Gregor71dc5092009-08-06 06:41:21 +00002225 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002226 NNS == DTN->getQualifier() &&
2227 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002228 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002229
Douglas Gregora5614c52010-09-08 23:56:00 +00002230 if (DTN->isIdentifier()) {
2231 // FIXME: Bad range
2232 SourceRange QualifierRange(getDerived().getBaseLocation());
2233 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2234 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002235 ObjectType,
2236 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002237 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002238
2239 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002240 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002241 }
Mike Stump11289f42009-09-09 15:08:12 +00002242
Douglas Gregor71dc5092009-08-06 06:41:21 +00002243 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002244 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002245 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002246 if (!TransTemplate)
2247 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002248
Douglas Gregor71dc5092009-08-06 06:41:21 +00002249 if (!getDerived().AlwaysRebuild() &&
2250 TransTemplate == Template)
2251 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002252
Douglas Gregor71dc5092009-08-06 06:41:21 +00002253 return TemplateName(TransTemplate);
2254 }
Mike Stump11289f42009-09-09 15:08:12 +00002255
John McCalle66edc12009-11-24 19:00:30 +00002256 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002257 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002258 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002259}
2260
2261template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002262void TreeTransform<Derived>::InventTemplateArgumentLoc(
2263 const TemplateArgument &Arg,
2264 TemplateArgumentLoc &Output) {
2265 SourceLocation Loc = getDerived().getBaseLocation();
2266 switch (Arg.getKind()) {
2267 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002268 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002269 break;
2270
2271 case TemplateArgument::Type:
2272 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002273 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002274
John McCall0ad16662009-10-29 08:12:44 +00002275 break;
2276
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002277 case TemplateArgument::Template:
2278 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2279 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002280
John McCall0ad16662009-10-29 08:12:44 +00002281 case TemplateArgument::Expression:
2282 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2283 break;
2284
2285 case TemplateArgument::Declaration:
2286 case TemplateArgument::Integral:
2287 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002288 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002289 break;
2290 }
2291}
2292
2293template<typename Derived>
2294bool TreeTransform<Derived>::TransformTemplateArgument(
2295 const TemplateArgumentLoc &Input,
2296 TemplateArgumentLoc &Output) {
2297 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002298 switch (Arg.getKind()) {
2299 case TemplateArgument::Null:
2300 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002301 Output = Input;
2302 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002303
Douglas Gregore922c772009-08-04 22:27:00 +00002304 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002305 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002306 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002307 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002308
2309 DI = getDerived().TransformType(DI);
2310 if (!DI) return true;
2311
2312 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2313 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002314 }
Mike Stump11289f42009-09-09 15:08:12 +00002315
Douglas Gregore922c772009-08-04 22:27:00 +00002316 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002317 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002318 DeclarationName Name;
2319 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2320 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002321 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002322 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002323 if (!D) return true;
2324
John McCall0d07eb32009-10-29 18:45:58 +00002325 Expr *SourceExpr = Input.getSourceDeclExpression();
2326 if (SourceExpr) {
2327 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002328 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002329 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002330 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002331 }
2332
2333 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002334 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002337 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002338 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002339 TemplateName Template
2340 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2341 if (Template.isNull())
2342 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002343
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002344 Output = TemplateArgumentLoc(TemplateArgument(Template),
2345 Input.getTemplateQualifierRange(),
2346 Input.getTemplateNameLoc());
2347 return false;
2348 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002349
Douglas Gregore922c772009-08-04 22:27:00 +00002350 case TemplateArgument::Expression: {
2351 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002352 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002353 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002354
John McCall0ad16662009-10-29 08:12:44 +00002355 Expr *InputExpr = Input.getSourceExpression();
2356 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2357
John McCalldadc5752010-08-24 06:29:42 +00002358 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002359 = getDerived().TransformExpr(InputExpr);
2360 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002361 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002362 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002363 }
Mike Stump11289f42009-09-09 15:08:12 +00002364
Douglas Gregore922c772009-08-04 22:27:00 +00002365 case TemplateArgument::Pack: {
2366 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2367 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002368 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002369 AEnd = Arg.pack_end();
2370 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002371
John McCall0ad16662009-10-29 08:12:44 +00002372 // FIXME: preserve source information here when we start
2373 // caring about parameter packs.
2374
John McCall0d07eb32009-10-29 18:45:58 +00002375 TemplateArgumentLoc InputArg;
2376 TemplateArgumentLoc OutputArg;
2377 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2378 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002379 return true;
2380
John McCall0d07eb32009-10-29 18:45:58 +00002381 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002382 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002383
2384 TemplateArgument *TransformedArgsPtr
2385 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2386 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2387 TransformedArgsPtr);
2388 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2389 TransformedArgs.size()),
2390 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002391 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002392 }
2393 }
Mike Stump11289f42009-09-09 15:08:12 +00002394
Douglas Gregore922c772009-08-04 22:27:00 +00002395 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002396 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002397}
2398
Douglas Gregord6ff3322009-08-04 16:50:30 +00002399//===----------------------------------------------------------------------===//
2400// Type transformation
2401//===----------------------------------------------------------------------===//
2402
2403template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002404QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002405 if (getDerived().AlreadyTransformed(T))
2406 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002407
John McCall550e0c22009-10-21 00:40:46 +00002408 // Temporary workaround. All of these transformations should
2409 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002410 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002411 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002412
John McCall31f82722010-11-12 08:19:04 +00002413 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002414
John McCall550e0c22009-10-21 00:40:46 +00002415 if (!NewDI)
2416 return QualType();
2417
2418 return NewDI->getType();
2419}
2420
2421template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002422TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002423 if (getDerived().AlreadyTransformed(DI->getType()))
2424 return DI;
2425
2426 TypeLocBuilder TLB;
2427
2428 TypeLoc TL = DI->getTypeLoc();
2429 TLB.reserve(TL.getFullDataSize());
2430
John McCall31f82722010-11-12 08:19:04 +00002431 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002432 if (Result.isNull())
2433 return 0;
2434
John McCallbcd03502009-12-07 02:54:59 +00002435 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002436}
2437
2438template<typename Derived>
2439QualType
John McCall31f82722010-11-12 08:19:04 +00002440TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002441 switch (T.getTypeLocClass()) {
2442#define ABSTRACT_TYPELOC(CLASS, PARENT)
2443#define TYPELOC(CLASS, PARENT) \
2444 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002445 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002446#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002447 }
Mike Stump11289f42009-09-09 15:08:12 +00002448
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002449 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002450 return QualType();
2451}
2452
2453/// FIXME: By default, this routine adds type qualifiers only to types
2454/// that can have qualifiers, and silently suppresses those qualifiers
2455/// that are not permitted (e.g., qualifiers on reference or function
2456/// types). This is the right thing for template instantiation, but
2457/// probably not for other clients.
2458template<typename Derived>
2459QualType
2460TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002461 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002462 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002463
John McCall31f82722010-11-12 08:19:04 +00002464 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002465 if (Result.isNull())
2466 return QualType();
2467
2468 // Silently suppress qualifiers if the result type can't be qualified.
2469 // FIXME: this is the right thing for template instantiation, but
2470 // probably not for other clients.
2471 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002472 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002473
John McCallcb0f89a2010-06-05 06:41:15 +00002474 if (!Quals.empty()) {
2475 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2476 TLB.push<QualifiedTypeLoc>(Result);
2477 // No location information to preserve.
2478 }
John McCall550e0c22009-10-21 00:40:46 +00002479
2480 return Result;
2481}
2482
John McCall31f82722010-11-12 08:19:04 +00002483/// \brief Transforms a type that was written in a scope specifier,
2484/// given an object type, the results of unqualified lookup, and
2485/// an already-instantiated prefix.
2486///
2487/// The object type is provided iff the scope specifier qualifies the
2488/// member of a dependent member-access expression. The prefix is
2489/// provided iff the the scope specifier in which this appears has a
2490/// prefix.
2491///
2492/// This is private to TreeTransform.
2493template<typename Derived>
2494QualType
2495TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2496 QualType ObjectType,
2497 NamedDecl *UnqualLookup,
2498 NestedNameSpecifier *Prefix) {
2499 if (getDerived().AlreadyTransformed(T))
2500 return T;
2501
2502 TypeSourceInfo *TSI =
2503 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2504
2505 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2506 UnqualLookup, Prefix);
2507 if (!TSI) return QualType();
2508 return TSI->getType();
2509}
2510
2511template<typename Derived>
2512TypeSourceInfo *
2513TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2514 QualType ObjectType,
2515 NamedDecl *UnqualLookup,
2516 NestedNameSpecifier *Prefix) {
2517 // TODO: in some cases, we might be some verification to do here.
2518 if (ObjectType.isNull())
2519 return getDerived().TransformType(TSI);
2520
2521 QualType T = TSI->getType();
2522 if (getDerived().AlreadyTransformed(T))
2523 return TSI;
2524
2525 TypeLocBuilder TLB;
2526 QualType Result;
2527
2528 if (isa<TemplateSpecializationType>(T)) {
2529 TemplateSpecializationTypeLoc TL
2530 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2531
2532 TemplateName Template =
2533 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2534 ObjectType, UnqualLookup);
2535 if (Template.isNull()) return 0;
2536
2537 Result = getDerived()
2538 .TransformTemplateSpecializationType(TLB, TL, Template);
2539 } else if (isa<DependentTemplateSpecializationType>(T)) {
2540 DependentTemplateSpecializationTypeLoc TL
2541 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2542
2543 Result = getDerived()
2544 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2545 } else {
2546 // Nothing special needs to be done for these.
2547 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2548 }
2549
2550 if (Result.isNull()) return 0;
2551 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2552}
2553
John McCall550e0c22009-10-21 00:40:46 +00002554template <class TyLoc> static inline
2555QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2556 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2557 NewT.setNameLoc(T.getNameLoc());
2558 return T.getType();
2559}
2560
John McCall550e0c22009-10-21 00:40:46 +00002561template<typename Derived>
2562QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002563 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002564 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2565 NewT.setBuiltinLoc(T.getBuiltinLoc());
2566 if (T.needsExtraLocalData())
2567 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2568 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002569}
Mike Stump11289f42009-09-09 15:08:12 +00002570
Douglas Gregord6ff3322009-08-04 16:50:30 +00002571template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002572QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002573 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002574 // FIXME: recurse?
2575 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002576}
Mike Stump11289f42009-09-09 15:08:12 +00002577
Douglas Gregord6ff3322009-08-04 16:50:30 +00002578template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002579QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002580 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002581 QualType PointeeType
2582 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002583 if (PointeeType.isNull())
2584 return QualType();
2585
2586 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002587 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002588 // A dependent pointer type 'T *' has is being transformed such
2589 // that an Objective-C class type is being replaced for 'T'. The
2590 // resulting pointer type is an ObjCObjectPointerType, not a
2591 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002592 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002593
John McCall8b07ec22010-05-15 11:32:37 +00002594 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2595 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002596 return Result;
2597 }
John McCall31f82722010-11-12 08:19:04 +00002598
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002599 if (getDerived().AlwaysRebuild() ||
2600 PointeeType != TL.getPointeeLoc().getType()) {
2601 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2602 if (Result.isNull())
2603 return QualType();
2604 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002605
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002606 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2607 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002608 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002609}
Mike Stump11289f42009-09-09 15:08:12 +00002610
2611template<typename Derived>
2612QualType
John McCall550e0c22009-10-21 00:40:46 +00002613TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002614 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002615 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002616 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2617 if (PointeeType.isNull())
2618 return QualType();
2619
2620 QualType Result = TL.getType();
2621 if (getDerived().AlwaysRebuild() ||
2622 PointeeType != TL.getPointeeLoc().getType()) {
2623 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002624 TL.getSigilLoc());
2625 if (Result.isNull())
2626 return QualType();
2627 }
2628
Douglas Gregor049211a2010-04-22 16:50:51 +00002629 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002630 NewT.setSigilLoc(TL.getSigilLoc());
2631 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002632}
2633
John McCall70dd5f62009-10-30 00:06:24 +00002634/// Transforms a reference type. Note that somewhat paradoxically we
2635/// don't care whether the type itself is an l-value type or an r-value
2636/// type; we only care if the type was *written* as an l-value type
2637/// or an r-value type.
2638template<typename Derived>
2639QualType
2640TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002641 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002642 const ReferenceType *T = TL.getTypePtr();
2643
2644 // Note that this works with the pointee-as-written.
2645 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2646 if (PointeeType.isNull())
2647 return QualType();
2648
2649 QualType Result = TL.getType();
2650 if (getDerived().AlwaysRebuild() ||
2651 PointeeType != T->getPointeeTypeAsWritten()) {
2652 Result = getDerived().RebuildReferenceType(PointeeType,
2653 T->isSpelledAsLValue(),
2654 TL.getSigilLoc());
2655 if (Result.isNull())
2656 return QualType();
2657 }
2658
2659 // r-value references can be rebuilt as l-value references.
2660 ReferenceTypeLoc NewTL;
2661 if (isa<LValueReferenceType>(Result))
2662 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2663 else
2664 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2665 NewTL.setSigilLoc(TL.getSigilLoc());
2666
2667 return Result;
2668}
2669
Mike Stump11289f42009-09-09 15:08:12 +00002670template<typename Derived>
2671QualType
John McCall550e0c22009-10-21 00:40:46 +00002672TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002673 LValueReferenceTypeLoc TL) {
2674 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002675}
2676
Mike Stump11289f42009-09-09 15:08:12 +00002677template<typename Derived>
2678QualType
John McCall550e0c22009-10-21 00:40:46 +00002679TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002680 RValueReferenceTypeLoc TL) {
2681 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002682}
Mike Stump11289f42009-09-09 15:08:12 +00002683
Douglas Gregord6ff3322009-08-04 16:50:30 +00002684template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002685QualType
John McCall550e0c22009-10-21 00:40:46 +00002686TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002687 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002688 MemberPointerType *T = TL.getTypePtr();
2689
2690 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002691 if (PointeeType.isNull())
2692 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002693
John McCall550e0c22009-10-21 00:40:46 +00002694 // TODO: preserve source information for this.
2695 QualType ClassType
2696 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002697 if (ClassType.isNull())
2698 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002699
John McCall550e0c22009-10-21 00:40:46 +00002700 QualType Result = TL.getType();
2701 if (getDerived().AlwaysRebuild() ||
2702 PointeeType != T->getPointeeType() ||
2703 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002704 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2705 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002706 if (Result.isNull())
2707 return QualType();
2708 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002709
John McCall550e0c22009-10-21 00:40:46 +00002710 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2711 NewTL.setSigilLoc(TL.getSigilLoc());
2712
2713 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002714}
2715
Mike Stump11289f42009-09-09 15:08:12 +00002716template<typename Derived>
2717QualType
John McCall550e0c22009-10-21 00:40:46 +00002718TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002719 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002720 ConstantArrayType *T = TL.getTypePtr();
2721 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002722 if (ElementType.isNull())
2723 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002724
John McCall550e0c22009-10-21 00:40:46 +00002725 QualType Result = TL.getType();
2726 if (getDerived().AlwaysRebuild() ||
2727 ElementType != T->getElementType()) {
2728 Result = getDerived().RebuildConstantArrayType(ElementType,
2729 T->getSizeModifier(),
2730 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002731 T->getIndexTypeCVRQualifiers(),
2732 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002733 if (Result.isNull())
2734 return QualType();
2735 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002736
John McCall550e0c22009-10-21 00:40:46 +00002737 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2738 NewTL.setLBracketLoc(TL.getLBracketLoc());
2739 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002740
John McCall550e0c22009-10-21 00:40:46 +00002741 Expr *Size = TL.getSizeExpr();
2742 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002743 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002744 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2745 }
2746 NewTL.setSizeExpr(Size);
2747
2748 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749}
Mike Stump11289f42009-09-09 15:08:12 +00002750
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002752QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002753 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002754 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002755 IncompleteArrayType *T = TL.getTypePtr();
2756 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002757 if (ElementType.isNull())
2758 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002759
John McCall550e0c22009-10-21 00:40:46 +00002760 QualType Result = TL.getType();
2761 if (getDerived().AlwaysRebuild() ||
2762 ElementType != T->getElementType()) {
2763 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002764 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002765 T->getIndexTypeCVRQualifiers(),
2766 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002767 if (Result.isNull())
2768 return QualType();
2769 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2772 NewTL.setLBracketLoc(TL.getLBracketLoc());
2773 NewTL.setRBracketLoc(TL.getRBracketLoc());
2774 NewTL.setSizeExpr(0);
2775
2776 return Result;
2777}
2778
2779template<typename Derived>
2780QualType
2781TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002782 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002783 VariableArrayType *T = TL.getTypePtr();
2784 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2785 if (ElementType.isNull())
2786 return QualType();
2787
2788 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002789 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002790
John McCalldadc5752010-08-24 06:29:42 +00002791 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002792 = getDerived().TransformExpr(T->getSizeExpr());
2793 if (SizeResult.isInvalid())
2794 return QualType();
2795
John McCallb268a282010-08-23 23:25:46 +00002796 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002797
2798 QualType Result = TL.getType();
2799 if (getDerived().AlwaysRebuild() ||
2800 ElementType != T->getElementType() ||
2801 Size != T->getSizeExpr()) {
2802 Result = getDerived().RebuildVariableArrayType(ElementType,
2803 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002804 Size,
John McCall550e0c22009-10-21 00:40:46 +00002805 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002806 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002807 if (Result.isNull())
2808 return QualType();
2809 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002810
John McCall550e0c22009-10-21 00:40:46 +00002811 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2812 NewTL.setLBracketLoc(TL.getLBracketLoc());
2813 NewTL.setRBracketLoc(TL.getRBracketLoc());
2814 NewTL.setSizeExpr(Size);
2815
2816 return Result;
2817}
2818
2819template<typename Derived>
2820QualType
2821TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002822 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002823 DependentSizedArrayType *T = TL.getTypePtr();
2824 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2825 if (ElementType.isNull())
2826 return QualType();
2827
2828 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002829 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002830
John McCalldadc5752010-08-24 06:29:42 +00002831 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002832 = getDerived().TransformExpr(T->getSizeExpr());
2833 if (SizeResult.isInvalid())
2834 return QualType();
2835
2836 Expr *Size = static_cast<Expr*>(SizeResult.get());
2837
2838 QualType Result = TL.getType();
2839 if (getDerived().AlwaysRebuild() ||
2840 ElementType != T->getElementType() ||
2841 Size != T->getSizeExpr()) {
2842 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2843 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002844 Size,
John McCall550e0c22009-10-21 00:40:46 +00002845 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002846 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002847 if (Result.isNull())
2848 return QualType();
2849 }
2850 else SizeResult.take();
2851
2852 // We might have any sort of array type now, but fortunately they
2853 // all have the same location layout.
2854 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2855 NewTL.setLBracketLoc(TL.getLBracketLoc());
2856 NewTL.setRBracketLoc(TL.getRBracketLoc());
2857 NewTL.setSizeExpr(Size);
2858
2859 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002860}
Mike Stump11289f42009-09-09 15:08:12 +00002861
2862template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002863QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002864 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002865 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002866 DependentSizedExtVectorType *T = TL.getTypePtr();
2867
2868 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002869 QualType ElementType = getDerived().TransformType(T->getElementType());
2870 if (ElementType.isNull())
2871 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002872
Douglas Gregore922c772009-08-04 22:27:00 +00002873 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002874 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002875
John McCalldadc5752010-08-24 06:29:42 +00002876 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002877 if (Size.isInvalid())
2878 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002879
John McCall550e0c22009-10-21 00:40:46 +00002880 QualType Result = TL.getType();
2881 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002882 ElementType != T->getElementType() ||
2883 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002884 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002885 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002886 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002887 if (Result.isNull())
2888 return QualType();
2889 }
John McCall550e0c22009-10-21 00:40:46 +00002890
2891 // Result might be dependent or not.
2892 if (isa<DependentSizedExtVectorType>(Result)) {
2893 DependentSizedExtVectorTypeLoc NewTL
2894 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2895 NewTL.setNameLoc(TL.getNameLoc());
2896 } else {
2897 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2898 NewTL.setNameLoc(TL.getNameLoc());
2899 }
2900
2901 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002902}
Mike Stump11289f42009-09-09 15:08:12 +00002903
2904template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002905QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002906 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002907 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002908 QualType ElementType = getDerived().TransformType(T->getElementType());
2909 if (ElementType.isNull())
2910 return QualType();
2911
John McCall550e0c22009-10-21 00:40:46 +00002912 QualType Result = TL.getType();
2913 if (getDerived().AlwaysRebuild() ||
2914 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002915 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00002916 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00002917 if (Result.isNull())
2918 return QualType();
2919 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002920
John McCall550e0c22009-10-21 00:40:46 +00002921 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2922 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002923
John McCall550e0c22009-10-21 00:40:46 +00002924 return Result;
2925}
2926
2927template<typename Derived>
2928QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002929 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002930 VectorType *T = TL.getTypePtr();
2931 QualType ElementType = getDerived().TransformType(T->getElementType());
2932 if (ElementType.isNull())
2933 return QualType();
2934
2935 QualType Result = TL.getType();
2936 if (getDerived().AlwaysRebuild() ||
2937 ElementType != T->getElementType()) {
2938 Result = getDerived().RebuildExtVectorType(ElementType,
2939 T->getNumElements(),
2940 /*FIXME*/ SourceLocation());
2941 if (Result.isNull())
2942 return QualType();
2943 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002944
John McCall550e0c22009-10-21 00:40:46 +00002945 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2946 NewTL.setNameLoc(TL.getNameLoc());
2947
2948 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002949}
Mike Stump11289f42009-09-09 15:08:12 +00002950
2951template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002952ParmVarDecl *
2953TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2954 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2955 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2956 if (!NewDI)
2957 return 0;
2958
2959 if (NewDI == OldDI)
2960 return OldParm;
2961 else
2962 return ParmVarDecl::Create(SemaRef.Context,
2963 OldParm->getDeclContext(),
2964 OldParm->getLocation(),
2965 OldParm->getIdentifier(),
2966 NewDI->getType(),
2967 NewDI,
2968 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002969 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002970 /* DefArg */ NULL);
2971}
2972
2973template<typename Derived>
2974bool TreeTransform<Derived>::
2975 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2976 llvm::SmallVectorImpl<QualType> &PTypes,
2977 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2978 FunctionProtoType *T = TL.getTypePtr();
2979
2980 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2981 ParmVarDecl *OldParm = TL.getArg(i);
2982
2983 QualType NewType;
2984 ParmVarDecl *NewParm;
2985
2986 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002987 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2988 if (!NewParm)
2989 return true;
2990 NewType = NewParm->getType();
2991
2992 // Deal with the possibility that we don't have a parameter
2993 // declaration for this parameter.
2994 } else {
2995 NewParm = 0;
2996
2997 QualType OldType = T->getArgType(i);
2998 NewType = getDerived().TransformType(OldType);
2999 if (NewType.isNull())
3000 return true;
3001 }
3002
3003 PTypes.push_back(NewType);
3004 PVars.push_back(NewParm);
3005 }
3006
3007 return false;
3008}
3009
3010template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003011QualType
John McCall550e0c22009-10-21 00:40:46 +00003012TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003013 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003014 // Transform the parameters and return type.
3015 //
3016 // We instantiate in source order, with the return type first followed by
3017 // the parameters, because users tend to expect this (even if they shouldn't
3018 // rely on it!).
3019 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003020 // When the function has a trailing return type, we instantiate the
3021 // parameters before the return type, since the return type can then refer
3022 // to the parameters themselves (via decltype, sizeof, etc.).
3023 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003024 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003025 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003026 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003027
Douglas Gregor7fb25412010-10-01 18:44:50 +00003028 QualType ResultType;
3029
3030 if (TL.getTrailingReturn()) {
3031 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3032 return QualType();
3033
3034 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3035 if (ResultType.isNull())
3036 return QualType();
3037 }
3038 else {
3039 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3040 if (ResultType.isNull())
3041 return QualType();
3042
3043 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3044 return QualType();
3045 }
3046
John McCall550e0c22009-10-21 00:40:46 +00003047 QualType Result = TL.getType();
3048 if (getDerived().AlwaysRebuild() ||
3049 ResultType != T->getResultType() ||
3050 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3051 Result = getDerived().RebuildFunctionProtoType(ResultType,
3052 ParamTypes.data(),
3053 ParamTypes.size(),
3054 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003055 T->getTypeQuals(),
3056 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003057 if (Result.isNull())
3058 return QualType();
3059 }
Mike Stump11289f42009-09-09 15:08:12 +00003060
John McCall550e0c22009-10-21 00:40:46 +00003061 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3062 NewTL.setLParenLoc(TL.getLParenLoc());
3063 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003064 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003065 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3066 NewTL.setArg(i, ParamDecls[i]);
3067
3068 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003069}
Mike Stump11289f42009-09-09 15:08:12 +00003070
Douglas Gregord6ff3322009-08-04 16:50:30 +00003071template<typename Derived>
3072QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003073 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003074 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003075 FunctionNoProtoType *T = TL.getTypePtr();
3076 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3077 if (ResultType.isNull())
3078 return QualType();
3079
3080 QualType Result = TL.getType();
3081 if (getDerived().AlwaysRebuild() ||
3082 ResultType != T->getResultType())
3083 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3084
3085 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3086 NewTL.setLParenLoc(TL.getLParenLoc());
3087 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003088 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003089
3090 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003091}
Mike Stump11289f42009-09-09 15:08:12 +00003092
John McCallb96ec562009-12-04 22:46:56 +00003093template<typename Derived> QualType
3094TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003095 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003096 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003097 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003098 if (!D)
3099 return QualType();
3100
3101 QualType Result = TL.getType();
3102 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3103 Result = getDerived().RebuildUnresolvedUsingType(D);
3104 if (Result.isNull())
3105 return QualType();
3106 }
3107
3108 // We might get an arbitrary type spec type back. We should at
3109 // least always get a type spec type, though.
3110 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3111 NewTL.setNameLoc(TL.getNameLoc());
3112
3113 return Result;
3114}
3115
Douglas Gregord6ff3322009-08-04 16:50:30 +00003116template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003117QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003118 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003119 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003120 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003121 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3122 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003123 if (!Typedef)
3124 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003125
John McCall550e0c22009-10-21 00:40:46 +00003126 QualType Result = TL.getType();
3127 if (getDerived().AlwaysRebuild() ||
3128 Typedef != T->getDecl()) {
3129 Result = getDerived().RebuildTypedefType(Typedef);
3130 if (Result.isNull())
3131 return QualType();
3132 }
Mike Stump11289f42009-09-09 15:08:12 +00003133
John McCall550e0c22009-10-21 00:40:46 +00003134 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3135 NewTL.setNameLoc(TL.getNameLoc());
3136
3137 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003138}
Mike Stump11289f42009-09-09 15:08:12 +00003139
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003141QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003142 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003143 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003144 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003145
John McCalldadc5752010-08-24 06:29:42 +00003146 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147 if (E.isInvalid())
3148 return QualType();
3149
John McCall550e0c22009-10-21 00:40:46 +00003150 QualType Result = TL.getType();
3151 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003152 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003153 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003154 if (Result.isNull())
3155 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003156 }
John McCall550e0c22009-10-21 00:40:46 +00003157 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003158
John McCall550e0c22009-10-21 00:40:46 +00003159 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003160 NewTL.setTypeofLoc(TL.getTypeofLoc());
3161 NewTL.setLParenLoc(TL.getLParenLoc());
3162 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003163
3164 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003165}
Mike Stump11289f42009-09-09 15:08:12 +00003166
3167template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003168QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003169 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003170 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3171 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3172 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003173 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003174
John McCall550e0c22009-10-21 00:40:46 +00003175 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003176 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3177 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003178 if (Result.isNull())
3179 return QualType();
3180 }
Mike Stump11289f42009-09-09 15:08:12 +00003181
John McCall550e0c22009-10-21 00:40:46 +00003182 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003183 NewTL.setTypeofLoc(TL.getTypeofLoc());
3184 NewTL.setLParenLoc(TL.getLParenLoc());
3185 NewTL.setRParenLoc(TL.getRParenLoc());
3186 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003187
3188 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003189}
Mike Stump11289f42009-09-09 15:08:12 +00003190
3191template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003192QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003193 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003194 DecltypeType *T = TL.getTypePtr();
3195
Douglas Gregore922c772009-08-04 22:27:00 +00003196 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003197 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003198
John McCalldadc5752010-08-24 06:29:42 +00003199 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003200 if (E.isInvalid())
3201 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003202
John McCall550e0c22009-10-21 00:40:46 +00003203 QualType Result = TL.getType();
3204 if (getDerived().AlwaysRebuild() ||
3205 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003206 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003207 if (Result.isNull())
3208 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003209 }
John McCall550e0c22009-10-21 00:40:46 +00003210 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003211
John McCall550e0c22009-10-21 00:40:46 +00003212 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3213 NewTL.setNameLoc(TL.getNameLoc());
3214
3215 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003216}
3217
3218template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003219QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003220 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003221 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003222 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003223 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3224 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003225 if (!Record)
3226 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003227
John McCall550e0c22009-10-21 00:40:46 +00003228 QualType Result = TL.getType();
3229 if (getDerived().AlwaysRebuild() ||
3230 Record != T->getDecl()) {
3231 Result = getDerived().RebuildRecordType(Record);
3232 if (Result.isNull())
3233 return QualType();
3234 }
Mike Stump11289f42009-09-09 15:08:12 +00003235
John McCall550e0c22009-10-21 00:40:46 +00003236 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3237 NewTL.setNameLoc(TL.getNameLoc());
3238
3239 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003240}
Mike Stump11289f42009-09-09 15:08:12 +00003241
3242template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003243QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003244 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003245 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003246 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003247 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3248 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003249 if (!Enum)
3250 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003251
John McCall550e0c22009-10-21 00:40:46 +00003252 QualType Result = TL.getType();
3253 if (getDerived().AlwaysRebuild() ||
3254 Enum != T->getDecl()) {
3255 Result = getDerived().RebuildEnumType(Enum);
3256 if (Result.isNull())
3257 return QualType();
3258 }
Mike Stump11289f42009-09-09 15:08:12 +00003259
John McCall550e0c22009-10-21 00:40:46 +00003260 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3261 NewTL.setNameLoc(TL.getNameLoc());
3262
3263 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003264}
John McCallfcc33b02009-09-05 00:15:47 +00003265
John McCalle78aac42010-03-10 03:28:59 +00003266template<typename Derived>
3267QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3268 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003269 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003270 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3271 TL.getTypePtr()->getDecl());
3272 if (!D) return QualType();
3273
3274 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3275 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3276 return T;
3277}
3278
Mike Stump11289f42009-09-09 15:08:12 +00003279
Douglas Gregord6ff3322009-08-04 16:50:30 +00003280template<typename Derived>
3281QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003282 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003283 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003284 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285}
3286
Mike Stump11289f42009-09-09 15:08:12 +00003287template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003288QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003289 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003290 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003291 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003292}
3293
3294template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003295QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003296 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003297 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003298 const TemplateSpecializationType *T = TL.getTypePtr();
3299
Mike Stump11289f42009-09-09 15:08:12 +00003300 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003301 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003302 if (Template.isNull())
3303 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003304
John McCall31f82722010-11-12 08:19:04 +00003305 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3306}
3307
3308template <typename Derived>
3309QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3310 TypeLocBuilder &TLB,
3311 TemplateSpecializationTypeLoc TL,
3312 TemplateName Template) {
3313 const TemplateSpecializationType *T = TL.getTypePtr();
3314
John McCall6b51f282009-11-23 01:53:49 +00003315 TemplateArgumentListInfo NewTemplateArgs;
3316 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3317 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3318
3319 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3320 TemplateArgumentLoc Loc;
3321 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003323 NewTemplateArgs.addArgument(Loc);
3324 }
Mike Stump11289f42009-09-09 15:08:12 +00003325
John McCall0ad16662009-10-29 08:12:44 +00003326 // FIXME: maybe don't rebuild if all the template arguments are the same.
3327
3328 QualType Result =
3329 getDerived().RebuildTemplateSpecializationType(Template,
3330 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003331 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003332
3333 if (!Result.isNull()) {
3334 TemplateSpecializationTypeLoc NewTL
3335 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3336 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3337 NewTL.setLAngleLoc(TL.getLAngleLoc());
3338 NewTL.setRAngleLoc(TL.getRAngleLoc());
3339 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3340 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003341 }
Mike Stump11289f42009-09-09 15:08:12 +00003342
John McCall0ad16662009-10-29 08:12:44 +00003343 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003344}
Mike Stump11289f42009-09-09 15:08:12 +00003345
3346template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003347QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003348TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003349 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003350 ElaboratedType *T = TL.getTypePtr();
3351
3352 NestedNameSpecifier *NNS = 0;
3353 // NOTE: the qualifier in an ElaboratedType is optional.
3354 if (T->getQualifier() != 0) {
3355 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003356 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003357 if (!NNS)
3358 return QualType();
3359 }
Mike Stump11289f42009-09-09 15:08:12 +00003360
John McCall31f82722010-11-12 08:19:04 +00003361 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3362 if (NamedT.isNull())
3363 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003364
John McCall550e0c22009-10-21 00:40:46 +00003365 QualType Result = TL.getType();
3366 if (getDerived().AlwaysRebuild() ||
3367 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003368 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003369 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3370 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003371 if (Result.isNull())
3372 return QualType();
3373 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003374
Abramo Bagnara6150c882010-05-11 21:36:43 +00003375 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003376 NewTL.setKeywordLoc(TL.getKeywordLoc());
3377 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003378
3379 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003380}
Mike Stump11289f42009-09-09 15:08:12 +00003381
3382template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00003383QualType
3384TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3385 ParenTypeLoc TL) {
3386 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3387 if (Inner.isNull())
3388 return QualType();
3389
3390 QualType Result = TL.getType();
3391 if (getDerived().AlwaysRebuild() ||
3392 Inner != TL.getInnerLoc().getType()) {
3393 Result = getDerived().RebuildParenType(Inner);
3394 if (Result.isNull())
3395 return QualType();
3396 }
3397
3398 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3399 NewTL.setLParenLoc(TL.getLParenLoc());
3400 NewTL.setRParenLoc(TL.getRParenLoc());
3401 return Result;
3402}
3403
3404template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003405QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003406 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003407 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003408
Douglas Gregord6ff3322009-08-04 16:50:30 +00003409 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003410 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003411 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003412 if (!NNS)
3413 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003414
John McCallc392f372010-06-11 00:33:02 +00003415 QualType Result
3416 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3417 T->getIdentifier(),
3418 TL.getKeywordLoc(),
3419 TL.getQualifierRange(),
3420 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003421 if (Result.isNull())
3422 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003423
Abramo Bagnarad7548482010-05-19 21:37:53 +00003424 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3425 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003426 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3427
Abramo Bagnarad7548482010-05-19 21:37:53 +00003428 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3429 NewTL.setKeywordLoc(TL.getKeywordLoc());
3430 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003431 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003432 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3433 NewTL.setKeywordLoc(TL.getKeywordLoc());
3434 NewTL.setQualifierRange(TL.getQualifierRange());
3435 NewTL.setNameLoc(TL.getNameLoc());
3436 }
John McCall550e0c22009-10-21 00:40:46 +00003437 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003438}
Mike Stump11289f42009-09-09 15:08:12 +00003439
Douglas Gregord6ff3322009-08-04 16:50:30 +00003440template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003441QualType TreeTransform<Derived>::
3442 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003443 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003444 DependentTemplateSpecializationType *T = TL.getTypePtr();
3445
3446 NestedNameSpecifier *NNS
3447 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003448 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003449 if (!NNS)
3450 return QualType();
3451
John McCall31f82722010-11-12 08:19:04 +00003452 return getDerived()
3453 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3454}
3455
3456template<typename Derived>
3457QualType TreeTransform<Derived>::
3458 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3459 DependentTemplateSpecializationTypeLoc TL,
3460 NestedNameSpecifier *NNS) {
3461 DependentTemplateSpecializationType *T = TL.getTypePtr();
3462
John McCallc392f372010-06-11 00:33:02 +00003463 TemplateArgumentListInfo NewTemplateArgs;
3464 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3465 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3466
3467 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3468 TemplateArgumentLoc Loc;
3469 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3470 return QualType();
3471 NewTemplateArgs.addArgument(Loc);
3472 }
3473
Douglas Gregora5614c52010-09-08 23:56:00 +00003474 QualType Result
3475 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3476 NNS,
3477 TL.getQualifierRange(),
3478 T->getIdentifier(),
3479 TL.getNameLoc(),
3480 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003481 if (Result.isNull())
3482 return QualType();
3483
3484 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3485 QualType NamedT = ElabT->getNamedType();
3486
3487 // Copy information relevant to the template specialization.
3488 TemplateSpecializationTypeLoc NamedTL
3489 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3490 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3491 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3492 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3493 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3494
3495 // Copy information relevant to the elaborated type.
3496 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3497 NewTL.setKeywordLoc(TL.getKeywordLoc());
3498 NewTL.setQualifierRange(TL.getQualifierRange());
3499 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003500 TypeLoc NewTL(Result, TL.getOpaqueData());
3501 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003502 }
3503 return Result;
3504}
3505
3506template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003507QualType
3508TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003509 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003510 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003511 TLB.pushFullCopy(TL);
3512 return TL.getType();
3513}
3514
3515template<typename Derived>
3516QualType
3517TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003518 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003519 // ObjCObjectType is never dependent.
3520 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003521 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003522}
Mike Stump11289f42009-09-09 15:08:12 +00003523
3524template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003525QualType
3526TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003527 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003528 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003529 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003530 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003531}
3532
Douglas Gregord6ff3322009-08-04 16:50:30 +00003533//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003534// Statement transformation
3535//===----------------------------------------------------------------------===//
3536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003537StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003538TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003539 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003540}
3541
3542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003543StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003544TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3545 return getDerived().TransformCompoundStmt(S, false);
3546}
3547
3548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003549StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003550TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003551 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003552 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003553 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003554 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003555 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3556 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003557 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003558 if (Result.isInvalid()) {
3559 // Immediately fail if this was a DeclStmt, since it's very
3560 // likely that this will cause problems for future statements.
3561 if (isa<DeclStmt>(*B))
3562 return StmtError();
3563
3564 // Otherwise, just keep processing substatements and fail later.
3565 SubStmtInvalid = true;
3566 continue;
3567 }
Mike Stump11289f42009-09-09 15:08:12 +00003568
Douglas Gregorebe10102009-08-20 07:17:43 +00003569 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3570 Statements.push_back(Result.takeAs<Stmt>());
3571 }
Mike Stump11289f42009-09-09 15:08:12 +00003572
John McCall1ababa62010-08-27 19:56:05 +00003573 if (SubStmtInvalid)
3574 return StmtError();
3575
Douglas Gregorebe10102009-08-20 07:17:43 +00003576 if (!getDerived().AlwaysRebuild() &&
3577 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003578 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003579
3580 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3581 move_arg(Statements),
3582 S->getRBracLoc(),
3583 IsStmtExpr);
3584}
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregorebe10102009-08-20 07:17:43 +00003586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003587StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003588TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003589 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003590 {
3591 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003592 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003593
Eli Friedman06577382009-11-19 03:14:00 +00003594 // Transform the left-hand case value.
3595 LHS = getDerived().TransformExpr(S->getLHS());
3596 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003597 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003598
Eli Friedman06577382009-11-19 03:14:00 +00003599 // Transform the right-hand case value (for the GNU case-range extension).
3600 RHS = getDerived().TransformExpr(S->getRHS());
3601 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003602 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003603 }
Mike Stump11289f42009-09-09 15:08:12 +00003604
Douglas Gregorebe10102009-08-20 07:17:43 +00003605 // Build the case statement.
3606 // Case statements are always rebuilt so that they will attached to their
3607 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003608 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003609 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003610 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003611 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003612 S->getColonLoc());
3613 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003614 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003615
Douglas Gregorebe10102009-08-20 07:17:43 +00003616 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003617 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003618 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003619 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregorebe10102009-08-20 07:17:43 +00003621 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003622 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003623}
3624
3625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003626StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003627TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003628 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003629 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003630 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003631 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003632
Douglas Gregorebe10102009-08-20 07:17:43 +00003633 // Default statements are always rebuilt
3634 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003635 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003636}
Mike Stump11289f42009-09-09 15:08:12 +00003637
Douglas Gregorebe10102009-08-20 07:17:43 +00003638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003639StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003640TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003641 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003642 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003643 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003644
Douglas Gregorebe10102009-08-20 07:17:43 +00003645 // FIXME: Pass the real colon location in.
3646 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3647 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003648 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003649}
Mike Stump11289f42009-09-09 15:08:12 +00003650
Douglas Gregorebe10102009-08-20 07:17:43 +00003651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003652StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003653TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003654 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003655 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003656 VarDecl *ConditionVar = 0;
3657 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003658 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003659 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003660 getDerived().TransformDefinition(
3661 S->getConditionVariable()->getLocation(),
3662 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003663 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003664 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003665 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003666 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003667
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003668 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003669 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003670
3671 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003672 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003673 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003674 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003675 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003676 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003677 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003678
John McCallb268a282010-08-23 23:25:46 +00003679 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003680 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003681 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003682
John McCallb268a282010-08-23 23:25:46 +00003683 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3684 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003685 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003686
Douglas Gregorebe10102009-08-20 07:17:43 +00003687 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003688 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003689 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003690 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003691
Douglas Gregorebe10102009-08-20 07:17:43 +00003692 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003693 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003694 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003695 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003696
Douglas Gregorebe10102009-08-20 07:17:43 +00003697 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003698 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003699 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003700 Then.get() == S->getThen() &&
3701 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003702 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003704 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00003705 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00003706 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003707}
3708
3709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003710StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003711TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003712 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003713 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003714 VarDecl *ConditionVar = 0;
3715 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003716 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003717 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003718 getDerived().TransformDefinition(
3719 S->getConditionVariable()->getLocation(),
3720 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003721 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003722 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003723 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003724 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003725
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003726 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003727 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003728 }
Mike Stump11289f42009-09-09 15:08:12 +00003729
Douglas Gregorebe10102009-08-20 07:17:43 +00003730 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003731 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003732 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003733 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003734 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003735 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregorebe10102009-08-20 07:17:43 +00003737 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003738 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003739 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003740 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003741
Douglas Gregorebe10102009-08-20 07:17:43 +00003742 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003743 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3744 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003745}
Mike Stump11289f42009-09-09 15:08:12 +00003746
Douglas Gregorebe10102009-08-20 07:17:43 +00003747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003748StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003749TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003750 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003751 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003752 VarDecl *ConditionVar = 0;
3753 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003754 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003755 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003756 getDerived().TransformDefinition(
3757 S->getConditionVariable()->getLocation(),
3758 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003759 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003760 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003761 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003762 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003763
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003764 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003765 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003766
3767 if (S->getCond()) {
3768 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003769 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003770 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003771 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003772 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003773 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003774 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003775 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003776 }
Mike Stump11289f42009-09-09 15:08:12 +00003777
John McCallb268a282010-08-23 23:25:46 +00003778 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3779 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003780 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003781
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003783 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003784 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003785 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003786
Douglas Gregorebe10102009-08-20 07:17:43 +00003787 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003788 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003789 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003790 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003791 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003793 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003794 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003795}
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregorebe10102009-08-20 07:17:43 +00003797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003798StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003799TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003800 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003801 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003802 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003803 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003804
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003805 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003806 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003807 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003808 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003809
Douglas Gregorebe10102009-08-20 07:17:43 +00003810 if (!getDerived().AlwaysRebuild() &&
3811 Cond.get() == S->getCond() &&
3812 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003813 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003814
John McCallb268a282010-08-23 23:25:46 +00003815 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3816 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003817 S->getRParenLoc());
3818}
Mike Stump11289f42009-09-09 15:08:12 +00003819
Douglas Gregorebe10102009-08-20 07:17:43 +00003820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003821StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003822TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003823 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003824 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003825 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003826 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003827
Douglas Gregorebe10102009-08-20 07:17:43 +00003828 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003829 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003830 VarDecl *ConditionVar = 0;
3831 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003832 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003833 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003834 getDerived().TransformDefinition(
3835 S->getConditionVariable()->getLocation(),
3836 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003837 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003838 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003839 } else {
3840 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003841
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003842 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003843 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003844
3845 if (S->getCond()) {
3846 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003847 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003848 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003849 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003850 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003851 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003852
John McCallb268a282010-08-23 23:25:46 +00003853 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003854 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003855 }
Mike Stump11289f42009-09-09 15:08:12 +00003856
John McCallb268a282010-08-23 23:25:46 +00003857 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3858 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003859 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003860
Douglas Gregorebe10102009-08-20 07:17:43 +00003861 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003862 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003863 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003864 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003865
John McCallb268a282010-08-23 23:25:46 +00003866 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3867 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003868 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003869
Douglas Gregorebe10102009-08-20 07:17:43 +00003870 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003871 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003872 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003873 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003874
Douglas Gregorebe10102009-08-20 07:17:43 +00003875 if (!getDerived().AlwaysRebuild() &&
3876 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003877 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003878 Inc.get() == S->getInc() &&
3879 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003880 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregorebe10102009-08-20 07:17:43 +00003882 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003883 Init.get(), FullCond, ConditionVar,
3884 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003885}
3886
3887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003888StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003889TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003890 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003891 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003892 S->getLabel());
3893}
3894
3895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003896StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003897TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003898 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003899 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003900 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregorebe10102009-08-20 07:17:43 +00003902 if (!getDerived().AlwaysRebuild() &&
3903 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003904 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003905
3906 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003907 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003908}
3909
3910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003911StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003912TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003913 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003914}
Mike Stump11289f42009-09-09 15:08:12 +00003915
Douglas Gregorebe10102009-08-20 07:17:43 +00003916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003917StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003918TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003919 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003920}
Mike Stump11289f42009-09-09 15:08:12 +00003921
Douglas Gregorebe10102009-08-20 07:17:43 +00003922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003923StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003924TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003925 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003926 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003927 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003928
Mike Stump11289f42009-09-09 15:08:12 +00003929 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003930 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003931 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003932}
Mike Stump11289f42009-09-09 15:08:12 +00003933
Douglas Gregorebe10102009-08-20 07:17:43 +00003934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003935StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003936TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003937 bool DeclChanged = false;
3938 llvm::SmallVector<Decl *, 4> Decls;
3939 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3940 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003941 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3942 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003943 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003944 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003945
Douglas Gregorebe10102009-08-20 07:17:43 +00003946 if (Transformed != *D)
3947 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003948
Douglas Gregorebe10102009-08-20 07:17:43 +00003949 Decls.push_back(Transformed);
3950 }
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregorebe10102009-08-20 07:17:43 +00003952 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00003953 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003954
3955 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003956 S->getStartLoc(), S->getEndLoc());
3957}
Mike Stump11289f42009-09-09 15:08:12 +00003958
Douglas Gregorebe10102009-08-20 07:17:43 +00003959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003960StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003961TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003962 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00003963 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003964}
3965
3966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003967StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003968TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003969
John McCall37ad5512010-08-23 06:44:23 +00003970 ASTOwningVector<Expr*> Constraints(getSema());
3971 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003972 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003973
John McCalldadc5752010-08-24 06:29:42 +00003974 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003975 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003976
3977 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003978
Anders Carlssonaaeef072010-01-24 05:50:09 +00003979 // Go through the outputs.
3980 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003981 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003982
Anders Carlssonaaeef072010-01-24 05:50:09 +00003983 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003984 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003985
Anders Carlssonaaeef072010-01-24 05:50:09 +00003986 // Transform the output expr.
3987 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003988 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003989 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003990 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003991
Anders Carlssonaaeef072010-01-24 05:50:09 +00003992 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003993
John McCallb268a282010-08-23 23:25:46 +00003994 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003995 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003996
Anders Carlssonaaeef072010-01-24 05:50:09 +00003997 // Go through the inputs.
3998 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003999 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004000
Anders Carlssonaaeef072010-01-24 05:50:09 +00004001 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004002 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004003
Anders Carlssonaaeef072010-01-24 05:50:09 +00004004 // Transform the input expr.
4005 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004006 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004007 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004008 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004009
Anders Carlssonaaeef072010-01-24 05:50:09 +00004010 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004011
John McCallb268a282010-08-23 23:25:46 +00004012 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004013 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004014
Anders Carlssonaaeef072010-01-24 05:50:09 +00004015 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004016 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004017
4018 // Go through the clobbers.
4019 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004020 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004021
4022 // No need to transform the asm string literal.
4023 AsmString = SemaRef.Owned(S->getAsmString());
4024
4025 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4026 S->isSimple(),
4027 S->isVolatile(),
4028 S->getNumOutputs(),
4029 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004030 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004031 move_arg(Constraints),
4032 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004033 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004034 move_arg(Clobbers),
4035 S->getRParenLoc(),
4036 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004037}
4038
4039
4040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004041StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004042TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004043 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004044 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004045 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004046 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004047
Douglas Gregor96c79492010-04-23 22:50:49 +00004048 // Transform the @catch statements (if present).
4049 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004050 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004051 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004052 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004053 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004054 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004055 if (Catch.get() != S->getCatchStmt(I))
4056 AnyCatchChanged = true;
4057 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004058 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004059
Douglas Gregor306de2f2010-04-22 23:59:56 +00004060 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004061 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004062 if (S->getFinallyStmt()) {
4063 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4064 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004065 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004066 }
4067
4068 // If nothing changed, just retain this statement.
4069 if (!getDerived().AlwaysRebuild() &&
4070 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004071 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004072 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004073 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004074
Douglas Gregor306de2f2010-04-22 23:59:56 +00004075 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004076 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4077 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004078}
Mike Stump11289f42009-09-09 15:08:12 +00004079
Douglas Gregorebe10102009-08-20 07:17:43 +00004080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004081StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004082TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004083 // Transform the @catch parameter, if there is one.
4084 VarDecl *Var = 0;
4085 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4086 TypeSourceInfo *TSInfo = 0;
4087 if (FromVar->getTypeSourceInfo()) {
4088 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4089 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004090 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004091 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004092
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004093 QualType T;
4094 if (TSInfo)
4095 T = TSInfo->getType();
4096 else {
4097 T = getDerived().TransformType(FromVar->getType());
4098 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004099 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004100 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004101
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004102 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4103 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004104 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004105 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004106
John McCalldadc5752010-08-24 06:29:42 +00004107 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004108 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004109 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004110
4111 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004112 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004113 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004114}
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregorebe10102009-08-20 07:17:43 +00004116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004117StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004118TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004119 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004120 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004121 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004122 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004123
Douglas Gregor306de2f2010-04-22 23:59:56 +00004124 // If nothing changed, just retain this statement.
4125 if (!getDerived().AlwaysRebuild() &&
4126 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004127 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004128
4129 // Build a new statement.
4130 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004131 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregorebe10102009-08-20 07:17:43 +00004134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004135StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004136TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004137 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004138 if (S->getThrowExpr()) {
4139 Operand = getDerived().TransformExpr(S->getThrowExpr());
4140 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004141 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004142 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004143
Douglas Gregor2900c162010-04-22 21:44:01 +00004144 if (!getDerived().AlwaysRebuild() &&
4145 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004146 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004147
John McCallb268a282010-08-23 23:25:46 +00004148 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004149}
Mike Stump11289f42009-09-09 15:08:12 +00004150
Douglas Gregorebe10102009-08-20 07:17:43 +00004151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004152StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004153TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004154 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004155 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004156 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004157 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004158 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004159
Douglas Gregor6148de72010-04-22 22:01:21 +00004160 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004161 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004162 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004163 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004164
Douglas Gregor6148de72010-04-22 22:01:21 +00004165 // If nothing change, just retain the current statement.
4166 if (!getDerived().AlwaysRebuild() &&
4167 Object.get() == S->getSynchExpr() &&
4168 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004169 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004170
4171 // Build a new statement.
4172 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004173 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004174}
4175
4176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004177StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004178TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004179 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004180 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004181 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004182 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004183 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004184
Douglas Gregorf68a5082010-04-22 23:10:45 +00004185 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004186 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004187 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004188 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004189
Douglas Gregorf68a5082010-04-22 23:10:45 +00004190 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004191 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004192 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004193 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004194
Douglas Gregorf68a5082010-04-22 23:10:45 +00004195 // If nothing changed, just retain this statement.
4196 if (!getDerived().AlwaysRebuild() &&
4197 Element.get() == S->getElement() &&
4198 Collection.get() == S->getCollection() &&
4199 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004200 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004201
Douglas Gregorf68a5082010-04-22 23:10:45 +00004202 // Build a new statement.
4203 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4204 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004205 Element.get(),
4206 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004207 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004208 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004209}
4210
4211
4212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004213StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004214TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4215 // Transform the exception declaration, if any.
4216 VarDecl *Var = 0;
4217 if (S->getExceptionDecl()) {
4218 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004219 TypeSourceInfo *T = getDerived().TransformType(
4220 ExceptionDecl->getTypeSourceInfo());
4221 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004222 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004223
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004224 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004225 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004226 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004227 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004228 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004229 }
Mike Stump11289f42009-09-09 15:08:12 +00004230
Douglas Gregorebe10102009-08-20 07:17:43 +00004231 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004232 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004233 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004234 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004235
Douglas Gregorebe10102009-08-20 07:17:43 +00004236 if (!getDerived().AlwaysRebuild() &&
4237 !Var &&
4238 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004239 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004240
4241 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4242 Var,
John McCallb268a282010-08-23 23:25:46 +00004243 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004244}
Mike Stump11289f42009-09-09 15:08:12 +00004245
Douglas Gregorebe10102009-08-20 07:17:43 +00004246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004247StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004248TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4249 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004250 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004251 = getDerived().TransformCompoundStmt(S->getTryBlock());
4252 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004253 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregorebe10102009-08-20 07:17:43 +00004255 // Transform the handlers.
4256 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004257 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004258 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004259 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004260 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4261 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004262 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004263
Douglas Gregorebe10102009-08-20 07:17:43 +00004264 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4265 Handlers.push_back(Handler.takeAs<Stmt>());
4266 }
Mike Stump11289f42009-09-09 15:08:12 +00004267
Douglas Gregorebe10102009-08-20 07:17:43 +00004268 if (!getDerived().AlwaysRebuild() &&
4269 TryBlock.get() == S->getTryBlock() &&
4270 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004271 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004272
John McCallb268a282010-08-23 23:25:46 +00004273 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004274 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004275}
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregorebe10102009-08-20 07:17:43 +00004277//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004278// Expression transformation
4279//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004281ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004282TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004283 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004284}
Mike Stump11289f42009-09-09 15:08:12 +00004285
4286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004287ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004288TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004289 NestedNameSpecifier *Qualifier = 0;
4290 if (E->getQualifier()) {
4291 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004292 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004293 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004294 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004295 }
John McCallce546572009-12-08 09:08:17 +00004296
4297 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004298 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4299 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004301 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004302
John McCall815039a2010-08-17 21:27:17 +00004303 DeclarationNameInfo NameInfo = E->getNameInfo();
4304 if (NameInfo.getName()) {
4305 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4306 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004307 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004308 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004309
4310 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004311 Qualifier == E->getQualifier() &&
4312 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004313 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004314 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004315
4316 // Mark it referenced in the new context regardless.
4317 // FIXME: this is a bit instantiation-specific.
4318 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4319
John McCallc3007a22010-10-26 07:05:15 +00004320 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004321 }
John McCallce546572009-12-08 09:08:17 +00004322
4323 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004324 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004325 TemplateArgs = &TransArgs;
4326 TransArgs.setLAngleLoc(E->getLAngleLoc());
4327 TransArgs.setRAngleLoc(E->getRAngleLoc());
4328 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4329 TemplateArgumentLoc Loc;
4330 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004331 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004332 TransArgs.addArgument(Loc);
4333 }
4334 }
4335
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004336 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004337 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004338}
Mike Stump11289f42009-09-09 15:08:12 +00004339
Douglas Gregora16548e2009-08-11 05:31:07 +00004340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004341ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004342TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004343 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004344}
Mike Stump11289f42009-09-09 15:08:12 +00004345
Douglas Gregora16548e2009-08-11 05:31:07 +00004346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004347ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004348TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004349 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004350}
Mike Stump11289f42009-09-09 15:08:12 +00004351
Douglas Gregora16548e2009-08-11 05:31:07 +00004352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004354TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004355 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004356}
Mike Stump11289f42009-09-09 15:08:12 +00004357
Douglas Gregora16548e2009-08-11 05:31:07 +00004358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004360TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004361 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004362}
Mike Stump11289f42009-09-09 15:08:12 +00004363
Douglas Gregora16548e2009-08-11 05:31:07 +00004364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004366TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004367 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004368}
4369
4370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004372TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004373 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004378 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004379
John McCallb268a282010-08-23 23:25:46 +00004380 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 E->getRParen());
4382}
4383
Mike Stump11289f42009-09-09 15:08:12 +00004384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004385ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004386TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004387 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004389 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004390
Douglas Gregora16548e2009-08-11 05:31:07 +00004391 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004392 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004393
Douglas Gregora16548e2009-08-11 05:31:07 +00004394 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4395 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004396 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004397}
Mike Stump11289f42009-09-09 15:08:12 +00004398
Douglas Gregora16548e2009-08-11 05:31:07 +00004399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004400ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004401TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4402 // Transform the type.
4403 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4404 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004405 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004406
Douglas Gregor882211c2010-04-28 22:16:22 +00004407 // Transform all of the components into components similar to what the
4408 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004409 // FIXME: It would be slightly more efficient in the non-dependent case to
4410 // just map FieldDecls, rather than requiring the rebuilder to look for
4411 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004412 // template code that we don't care.
4413 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004414 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004415 typedef OffsetOfExpr::OffsetOfNode Node;
4416 llvm::SmallVector<Component, 4> Components;
4417 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4418 const Node &ON = E->getComponent(I);
4419 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004420 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004421 Comp.LocStart = ON.getRange().getBegin();
4422 Comp.LocEnd = ON.getRange().getEnd();
4423 switch (ON.getKind()) {
4424 case Node::Array: {
4425 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004426 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004427 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004428 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004429
Douglas Gregor882211c2010-04-28 22:16:22 +00004430 ExprChanged = ExprChanged || Index.get() != FromIndex;
4431 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004432 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004433 break;
4434 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004435
Douglas Gregor882211c2010-04-28 22:16:22 +00004436 case Node::Field:
4437 case Node::Identifier:
4438 Comp.isBrackets = false;
4439 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004440 if (!Comp.U.IdentInfo)
4441 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004442
Douglas Gregor882211c2010-04-28 22:16:22 +00004443 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004444
Douglas Gregord1702062010-04-29 00:18:15 +00004445 case Node::Base:
4446 // Will be recomputed during the rebuild.
4447 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004448 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004449
Douglas Gregor882211c2010-04-28 22:16:22 +00004450 Components.push_back(Comp);
4451 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004452
Douglas Gregor882211c2010-04-28 22:16:22 +00004453 // If nothing changed, retain the existing expression.
4454 if (!getDerived().AlwaysRebuild() &&
4455 Type == E->getTypeSourceInfo() &&
4456 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004457 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004458
Douglas Gregor882211c2010-04-28 22:16:22 +00004459 // Build a new offsetof expression.
4460 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4461 Components.data(), Components.size(),
4462 E->getRParenLoc());
4463}
4464
4465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004466ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004467TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4468 assert(getDerived().AlreadyTransformed(E->getType()) &&
4469 "opaque value expression requires transformation");
4470 return SemaRef.Owned(E);
4471}
4472
4473template<typename Derived>
4474ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004475TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004477 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004478
John McCallbcd03502009-12-07 02:54:59 +00004479 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004480 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004482
John McCall4c98fd82009-11-04 07:28:41 +00004483 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004484 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004485
John McCall4c98fd82009-11-04 07:28:41 +00004486 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004487 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004488 E->getSourceRange());
4489 }
Mike Stump11289f42009-09-09 15:08:12 +00004490
John McCalldadc5752010-08-24 06:29:42 +00004491 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004492 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004493 // C++0x [expr.sizeof]p1:
4494 // The operand is either an expression, which is an unevaluated operand
4495 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004496 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004497
Douglas Gregora16548e2009-08-11 05:31:07 +00004498 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4499 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004500 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004501
Douglas Gregora16548e2009-08-11 05:31:07 +00004502 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004503 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 }
Mike Stump11289f42009-09-09 15:08:12 +00004505
John McCallb268a282010-08-23 23:25:46 +00004506 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 E->isSizeOf(),
4508 E->getSourceRange());
4509}
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004512ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004513TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004514 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004515 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004516 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004517
John McCalldadc5752010-08-24 06:29:42 +00004518 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004521
4522
Douglas Gregora16548e2009-08-11 05:31:07 +00004523 if (!getDerived().AlwaysRebuild() &&
4524 LHS.get() == E->getLHS() &&
4525 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004526 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004527
John McCallb268a282010-08-23 23:25:46 +00004528 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004530 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 E->getRBracketLoc());
4532}
Mike Stump11289f42009-09-09 15:08:12 +00004533
4534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004535ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004536TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004538 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004540 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004541
4542 // Transform arguments.
4543 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004544 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004546 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004548 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004549
Mike Stump11289f42009-09-09 15:08:12 +00004550 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004551 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004552 }
Mike Stump11289f42009-09-09 15:08:12 +00004553
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 if (!getDerived().AlwaysRebuild() &&
4555 Callee.get() == E->getCallee() &&
4556 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004557 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004558
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004560 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004562 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 E->getRParenLoc());
4565}
Mike Stump11289f42009-09-09 15:08:12 +00004566
4567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004568ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004569TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004570 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004572 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004574 NestedNameSpecifier *Qualifier = 0;
4575 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004576 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004577 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004578 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004579 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004580 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004581 }
Mike Stump11289f42009-09-09 15:08:12 +00004582
Eli Friedman2cfcef62009-12-04 06:40:45 +00004583 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004584 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4585 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004586 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004588
John McCall16df1e52010-03-30 21:47:33 +00004589 NamedDecl *FoundDecl = E->getFoundDecl();
4590 if (FoundDecl == E->getMemberDecl()) {
4591 FoundDecl = Member;
4592 } else {
4593 FoundDecl = cast_or_null<NamedDecl>(
4594 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4595 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004596 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004597 }
4598
Douglas Gregora16548e2009-08-11 05:31:07 +00004599 if (!getDerived().AlwaysRebuild() &&
4600 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004601 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004602 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004603 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004604 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004605
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004606 // Mark it referenced in the new context regardless.
4607 // FIXME: this is a bit instantiation-specific.
4608 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004609 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004610 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004611
John McCall6b51f282009-11-23 01:53:49 +00004612 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004613 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004614 TransArgs.setLAngleLoc(E->getLAngleLoc());
4615 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004616 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004617 TemplateArgumentLoc Loc;
4618 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004619 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004620 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004621 }
4622 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004623
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 // FIXME: Bogus source location for the operator
4625 SourceLocation FakeOperatorLoc
4626 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4627
John McCall38836f02010-01-15 08:34:02 +00004628 // FIXME: to do this check properly, we will need to preserve the
4629 // first-qualifier-in-scope here, just in case we had a dependent
4630 // base (and therefore couldn't do the check) and a
4631 // nested-name-qualifier (and therefore could do the lookup).
4632 NamedDecl *FirstQualifierInScope = 0;
4633
John McCallb268a282010-08-23 23:25:46 +00004634 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004636 Qualifier,
4637 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004638 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004639 Member,
John McCall16df1e52010-03-30 21:47:33 +00004640 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004641 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004642 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004643 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004644}
Mike Stump11289f42009-09-09 15:08:12 +00004645
Douglas Gregora16548e2009-08-11 05:31:07 +00004646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004647ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004648TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004649 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004652
John McCalldadc5752010-08-24 06:29:42 +00004653 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004654 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004656
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 if (!getDerived().AlwaysRebuild() &&
4658 LHS.get() == E->getLHS() &&
4659 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004660 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004663 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004664}
4665
Mike Stump11289f42009-09-09 15:08:12 +00004666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004667ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004668TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004669 CompoundAssignOperator *E) {
4670 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
Douglas Gregora16548e2009-08-11 05:31:07 +00004673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004675TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004676 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004678 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004679
John McCalldadc5752010-08-24 06:29:42 +00004680 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004681 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004682 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004683
John McCalldadc5752010-08-24 06:29:42 +00004684 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004687
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 if (!getDerived().AlwaysRebuild() &&
4689 Cond.get() == E->getCond() &&
4690 LHS.get() == E->getLHS() &&
4691 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004692 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004693
John McCallb268a282010-08-23 23:25:46 +00004694 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004695 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004696 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004697 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004698 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004699}
Mike Stump11289f42009-09-09 15:08:12 +00004700
4701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004702ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004703TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004704 // Implicit casts are eliminated during transformation, since they
4705 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004706 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004707}
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregora16548e2009-08-11 05:31:07 +00004709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004710ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004711TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004712 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4713 if (!Type)
4714 return ExprError();
4715
John McCalldadc5752010-08-24 06:29:42 +00004716 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004717 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004720
Douglas Gregora16548e2009-08-11 05:31:07 +00004721 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004722 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004724 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004725
John McCall97513962010-01-15 18:39:57 +00004726 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004727 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004729 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004730}
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregora16548e2009-08-11 05:31:07 +00004732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004733ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004734TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004735 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4736 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4737 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004738 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004739
John McCalldadc5752010-08-24 06:29:42 +00004740 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004742 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004745 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004746 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004747 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004748
John McCall5d7aa7f2010-01-19 22:33:45 +00004749 // Note: the expression type doesn't necessarily match the
4750 // type-as-written, but that's okay, because it should always be
4751 // derivable from the initializer.
4752
John McCalle15bbff2010-01-18 19:35:47 +00004753 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004755 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004756}
Mike Stump11289f42009-09-09 15:08:12 +00004757
Douglas Gregora16548e2009-08-11 05:31:07 +00004758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004759ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004760TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004761 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004764
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 if (!getDerived().AlwaysRebuild() &&
4766 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004767 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004768
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004770 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004772 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 E->getAccessorLoc(),
4774 E->getAccessor());
4775}
Mike Stump11289f42009-09-09 15:08:12 +00004776
Douglas Gregora16548e2009-08-11 05:31:07 +00004777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004779TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004781
John McCall37ad5512010-08-23 06:44:23 +00004782 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004784 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004789 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004790 }
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004793 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004796 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004797}
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004800ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004801TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004802 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004803
Douglas Gregorebe10102009-08-20 07:17:43 +00004804 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004805 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004808
Douglas Gregorebe10102009-08-20 07:17:43 +00004809 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004810 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 bool ExprChanged = false;
4812 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4813 DEnd = E->designators_end();
4814 D != DEnd; ++D) {
4815 if (D->isFieldDesignator()) {
4816 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4817 D->getDotLoc(),
4818 D->getFieldLoc()));
4819 continue;
4820 }
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregora16548e2009-08-11 05:31:07 +00004822 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004823 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004826
4827 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004828 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4831 ArrayExprs.push_back(Index.release());
4832 continue;
4833 }
Mike Stump11289f42009-09-09 15:08:12 +00004834
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004836 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4838 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004840
John McCalldadc5752010-08-24 06:29:42 +00004841 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004844
4845 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004846 End.get(),
4847 D->getLBracketLoc(),
4848 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregora16548e2009-08-11 05:31:07 +00004850 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4851 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004852
Douglas Gregora16548e2009-08-11 05:31:07 +00004853 ArrayExprs.push_back(Start.release());
4854 ArrayExprs.push_back(End.release());
4855 }
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregora16548e2009-08-11 05:31:07 +00004857 if (!getDerived().AlwaysRebuild() &&
4858 Init.get() == E->getInit() &&
4859 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004860 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregora16548e2009-08-11 05:31:07 +00004862 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4863 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004864 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004865}
Mike Stump11289f42009-09-09 15:08:12 +00004866
Douglas Gregora16548e2009-08-11 05:31:07 +00004867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004868ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004869TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004870 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004871 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004872
Douglas Gregor3da3c062009-10-28 00:29:27 +00004873 // FIXME: Will we ever have proper type location here? Will we actually
4874 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004875 QualType T = getDerived().TransformType(E->getType());
4876 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004878
Douglas Gregora16548e2009-08-11 05:31:07 +00004879 if (!getDerived().AlwaysRebuild() &&
4880 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004881 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004882
Douglas Gregora16548e2009-08-11 05:31:07 +00004883 return getDerived().RebuildImplicitValueInitExpr(T);
4884}
Mike Stump11289f42009-09-09 15:08:12 +00004885
Douglas Gregora16548e2009-08-11 05:31:07 +00004886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004887ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004888TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004889 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4890 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004892
John McCalldadc5752010-08-24 06:29:42 +00004893 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004895 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004896
Douglas Gregora16548e2009-08-11 05:31:07 +00004897 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004898 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004900 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004901
John McCallb268a282010-08-23 23:25:46 +00004902 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004903 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004904}
4905
4906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004907ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004908TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004909 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004910 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004911 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004912 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004913 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004915
Douglas Gregora16548e2009-08-11 05:31:07 +00004916 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004917 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004918 }
Mike Stump11289f42009-09-09 15:08:12 +00004919
Douglas Gregora16548e2009-08-11 05:31:07 +00004920 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4921 move_arg(Inits),
4922 E->getRParenLoc());
4923}
Mike Stump11289f42009-09-09 15:08:12 +00004924
Douglas Gregora16548e2009-08-11 05:31:07 +00004925/// \brief Transform an address-of-label expression.
4926///
4927/// By default, the transformation of an address-of-label expression always
4928/// rebuilds the expression, so that the label identifier can be resolved to
4929/// the corresponding label statement by semantic analysis.
4930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004932TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004933 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4934 E->getLabel());
4935}
Mike Stump11289f42009-09-09 15:08:12 +00004936
4937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004938ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004939TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004940 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004941 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4942 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004943 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregora16548e2009-08-11 05:31:07 +00004945 if (!getDerived().AlwaysRebuild() &&
4946 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00004947 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004948
4949 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004950 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004951 E->getRParenLoc());
4952}
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregora16548e2009-08-11 05:31:07 +00004954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004955ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004956TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004957 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004958 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004959 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004960
John McCalldadc5752010-08-24 06:29:42 +00004961 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004962 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004964
John McCalldadc5752010-08-24 06:29:42 +00004965 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004966 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004968
Douglas Gregora16548e2009-08-11 05:31:07 +00004969 if (!getDerived().AlwaysRebuild() &&
4970 Cond.get() == E->getCond() &&
4971 LHS.get() == E->getLHS() &&
4972 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004973 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregora16548e2009-08-11 05:31:07 +00004975 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004976 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004977 E->getRParenLoc());
4978}
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregora16548e2009-08-11 05:31:07 +00004980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004981ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004982TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004983 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004984}
4985
4986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004988TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004989 switch (E->getOperator()) {
4990 case OO_New:
4991 case OO_Delete:
4992 case OO_Array_New:
4993 case OO_Array_Delete:
4994 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004995 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004996
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004997 case OO_Call: {
4998 // This is a call to an object's operator().
4999 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5000
5001 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005002 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005003 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005004 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005005
5006 // FIXME: Poor location information
5007 SourceLocation FakeLParenLoc
5008 = SemaRef.PP.getLocForEndOfToken(
5009 static_cast<Expr *>(Object.get())->getLocEnd());
5010
5011 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005012 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005013 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00005014 if (getDerived().DropCallArgument(E->getArg(I)))
5015 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005016
John McCalldadc5752010-08-24 06:29:42 +00005017 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005018 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005019 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005020
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005021 Args.push_back(Arg.release());
5022 }
5023
John McCallb268a282010-08-23 23:25:46 +00005024 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005025 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005026 E->getLocEnd());
5027 }
5028
5029#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5030 case OO_##Name:
5031#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5032#include "clang/Basic/OperatorKinds.def"
5033 case OO_Subscript:
5034 // Handled below.
5035 break;
5036
5037 case OO_Conditional:
5038 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005039 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005040
5041 case OO_None:
5042 case NUM_OVERLOADED_OPERATORS:
5043 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005044 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005045 }
5046
John McCalldadc5752010-08-24 06:29:42 +00005047 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005048 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005050
John McCalldadc5752010-08-24 06:29:42 +00005051 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005053 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005054
John McCalldadc5752010-08-24 06:29:42 +00005055 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 if (E->getNumArgs() == 2) {
5057 Second = getDerived().TransformExpr(E->getArg(1));
5058 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005059 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005060 }
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 if (!getDerived().AlwaysRebuild() &&
5063 Callee.get() == E->getCallee() &&
5064 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005065 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
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 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5069 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005070 Callee.get(),
5071 First.get(),
5072 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005073}
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregora16548e2009-08-11 05:31:07 +00005075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005076ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005077TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5078 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005079}
Mike Stump11289f42009-09-09 15:08:12 +00005080
Douglas Gregora16548e2009-08-11 05:31:07 +00005081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005082ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005083TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005084 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5085 if (!Type)
5086 return ExprError();
5087
John McCalldadc5752010-08-24 06:29:42 +00005088 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005089 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005090 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005091 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregora16548e2009-08-11 05:31:07 +00005093 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005094 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005095 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005096 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005099 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5101 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5102 SourceLocation FakeRParenLoc
5103 = SemaRef.PP.getLocForEndOfToken(
5104 E->getSubExpr()->getSourceRange().getEnd());
5105 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005106 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005108 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 FakeRAngleLoc,
5110 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005111 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 FakeRParenLoc);
5113}
Mike Stump11289f42009-09-09 15:08:12 +00005114
Douglas Gregora16548e2009-08-11 05:31:07 +00005115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005117TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5118 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005119}
Mike Stump11289f42009-09-09 15:08:12 +00005120
5121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005123TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5124 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005125}
5126
Douglas Gregora16548e2009-08-11 05:31:07 +00005127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005128ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005129TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005130 CXXReinterpretCastExpr *E) {
5131 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005132}
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>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5137 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005138}
Mike Stump11289f42009-09-09 15:08:12 +00005139
Douglas Gregora16548e2009-08-11 05:31:07 +00005140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005141ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005142TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005143 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005144 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5145 if (!Type)
5146 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005147
John McCalldadc5752010-08-24 06:29:42 +00005148 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005149 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005150 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005151 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005152
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005154 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005156 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005157
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005158 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005160 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 E->getRParenLoc());
5162}
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregora16548e2009-08-11 05:31:07 +00005164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005166TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005168 TypeSourceInfo *TInfo
5169 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5170 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005174 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005175 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregor9da64192010-04-26 22:37:10 +00005177 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5178 E->getLocStart(),
5179 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005180 E->getLocEnd());
5181 }
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregora16548e2009-08-11 05:31:07 +00005183 // We don't know whether the expression is potentially evaluated until
5184 // after we perform semantic analysis, so the expression is potentially
5185 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005186 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005187 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005188
John McCalldadc5752010-08-24 06:29:42 +00005189 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005190 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregora16548e2009-08-11 05:31:07 +00005193 if (!getDerived().AlwaysRebuild() &&
5194 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005195 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregor9da64192010-04-26 22:37:10 +00005197 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5198 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005199 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 E->getLocEnd());
5201}
5202
5203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005204ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005205TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5206 if (E->isTypeOperand()) {
5207 TypeSourceInfo *TInfo
5208 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5209 if (!TInfo)
5210 return ExprError();
5211
5212 if (!getDerived().AlwaysRebuild() &&
5213 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005214 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005215
5216 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5217 E->getLocStart(),
5218 TInfo,
5219 E->getLocEnd());
5220 }
5221
5222 // We don't know whether the expression is potentially evaluated until
5223 // after we perform semantic analysis, so the expression is potentially
5224 // potentially evaluated.
5225 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5226
5227 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5228 if (SubExpr.isInvalid())
5229 return ExprError();
5230
5231 if (!getDerived().AlwaysRebuild() &&
5232 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005233 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005234
5235 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5236 E->getLocStart(),
5237 SubExpr.get(),
5238 E->getLocEnd());
5239}
5240
5241template<typename Derived>
5242ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005243TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005244 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005245}
Mike Stump11289f42009-09-09 15:08:12 +00005246
Douglas Gregora16548e2009-08-11 05:31:07 +00005247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005248ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005249TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005250 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005251 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005252}
Mike Stump11289f42009-09-09 15:08:12 +00005253
Douglas Gregora16548e2009-08-11 05:31:07 +00005254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005256TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005257 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5258 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5259 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005261 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005262 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregorb15af892010-01-07 23:12:05 +00005264 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
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
John McCall47f29ea2009-12-08 09:21:05 +00005269TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005270 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005271 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 if (!getDerived().AlwaysRebuild() &&
5275 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005276 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005277
John McCallb268a282010-08-23 23:25:46 +00005278 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005279}
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregora16548e2009-08-11 05:31:07 +00005281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005283TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005284 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005285 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5286 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005287 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005288 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005289
Chandler Carruth794da4c2010-02-08 06:42:49 +00005290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005291 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005292 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregor033f6752009-12-23 23:03:06 +00005294 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005295}
Mike Stump11289f42009-09-09 15:08:12 +00005296
Douglas Gregora16548e2009-08-11 05:31:07 +00005297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005298ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005299TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5300 CXXScalarValueInitExpr *E) {
5301 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5302 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005303 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005304
Douglas Gregora16548e2009-08-11 05:31:07 +00005305 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005306 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005307 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregor2b88c112010-09-08 00:15:04 +00005309 return getDerived().RebuildCXXScalarValueInitExpr(T,
5310 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005311 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005312}
Mike Stump11289f42009-09-09 15:08:12 +00005313
Douglas Gregora16548e2009-08-11 05:31:07 +00005314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005316TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005318 TypeSourceInfo *AllocTypeInfo
5319 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5320 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005322
Douglas Gregora16548e2009-08-11 05:31:07 +00005323 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005324 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005325 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregora16548e2009-08-11 05:31:07 +00005328 // Transform the placement arguments (if any).
5329 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005330 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005331 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005332 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5333 ArgumentChanged = true;
5334 break;
5335 }
5336
John McCalldadc5752010-08-24 06:29:42 +00005337 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005338 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregora16548e2009-08-11 05:31:07 +00005341 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5342 PlacementArgs.push_back(Arg.take());
5343 }
Mike Stump11289f42009-09-09 15:08:12 +00005344
Douglas Gregorebe10102009-08-20 07:17:43 +00005345 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005346 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005347 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005348 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5349 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005350 break;
John McCall09d13692010-10-05 22:36:42 +00005351 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005352
John McCalldadc5752010-08-24 06:29:42 +00005353 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005354 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005356
Douglas Gregora16548e2009-08-11 05:31:07 +00005357 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5358 ConstructorArgs.push_back(Arg.take());
5359 }
Mike Stump11289f42009-09-09 15:08:12 +00005360
Douglas Gregord2d9da02010-02-26 00:38:10 +00005361 // Transform constructor, new operator, and delete operator.
5362 CXXConstructorDecl *Constructor = 0;
5363 if (E->getConstructor()) {
5364 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005365 getDerived().TransformDecl(E->getLocStart(),
5366 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005367 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005368 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005369 }
5370
5371 FunctionDecl *OperatorNew = 0;
5372 if (E->getOperatorNew()) {
5373 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005374 getDerived().TransformDecl(E->getLocStart(),
5375 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005376 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005377 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005378 }
5379
5380 FunctionDecl *OperatorDelete = 0;
5381 if (E->getOperatorDelete()) {
5382 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005383 getDerived().TransformDecl(E->getLocStart(),
5384 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005385 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005386 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005387 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005388
Douglas Gregora16548e2009-08-11 05:31:07 +00005389 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005390 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005391 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005392 Constructor == E->getConstructor() &&
5393 OperatorNew == E->getOperatorNew() &&
5394 OperatorDelete == E->getOperatorDelete() &&
5395 !ArgumentChanged) {
5396 // Mark any declarations we need as referenced.
5397 // FIXME: instantiation-specific.
5398 if (Constructor)
5399 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5400 if (OperatorNew)
5401 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5402 if (OperatorDelete)
5403 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005404 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005405 }
Mike Stump11289f42009-09-09 15:08:12 +00005406
Douglas Gregor0744ef62010-09-07 21:49:58 +00005407 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005408 if (!ArraySize.get()) {
5409 // If no array size was specified, but the new expression was
5410 // instantiated with an array type (e.g., "new T" where T is
5411 // instantiated with "int[4]"), extract the outer bound from the
5412 // array type as our array size. We do this with constant and
5413 // dependently-sized array types.
5414 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5415 if (!ArrayT) {
5416 // Do nothing
5417 } else if (const ConstantArrayType *ConsArrayT
5418 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005419 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005420 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5421 ConsArrayT->getSize(),
5422 SemaRef.Context.getSizeType(),
5423 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005424 AllocType = ConsArrayT->getElementType();
5425 } else if (const DependentSizedArrayType *DepArrayT
5426 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5427 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005428 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005429 AllocType = DepArrayT->getElementType();
5430 }
5431 }
5432 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005433
Douglas Gregora16548e2009-08-11 05:31:07 +00005434 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5435 E->isGlobalNew(),
5436 /*FIXME:*/E->getLocStart(),
5437 move_arg(PlacementArgs),
5438 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005439 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005440 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005441 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005442 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005443 /*FIXME:*/E->getLocStart(),
5444 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005445 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005446}
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregora16548e2009-08-11 05:31:07 +00005448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005449ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005450TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005451 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005452 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005454
Douglas Gregord2d9da02010-02-26 00:38:10 +00005455 // Transform the delete operator, if known.
5456 FunctionDecl *OperatorDelete = 0;
5457 if (E->getOperatorDelete()) {
5458 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005459 getDerived().TransformDecl(E->getLocStart(),
5460 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005461 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005462 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005463 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005464
Douglas Gregora16548e2009-08-11 05:31:07 +00005465 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005466 Operand.get() == E->getArgument() &&
5467 OperatorDelete == E->getOperatorDelete()) {
5468 // Mark any declarations we need as referenced.
5469 // FIXME: instantiation-specific.
5470 if (OperatorDelete)
5471 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005472
5473 if (!E->getArgument()->isTypeDependent()) {
5474 QualType Destroyed = SemaRef.Context.getBaseElementType(
5475 E->getDestroyedType());
5476 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5477 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5478 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5479 SemaRef.LookupDestructor(Record));
5480 }
5481 }
5482
John McCallc3007a22010-10-26 07:05:15 +00005483 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005484 }
Mike Stump11289f42009-09-09 15:08:12 +00005485
Douglas Gregora16548e2009-08-11 05:31:07 +00005486 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5487 E->isGlobalDelete(),
5488 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005489 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005490}
Mike Stump11289f42009-09-09 15:08:12 +00005491
Douglas Gregora16548e2009-08-11 05:31:07 +00005492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005493ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005494TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005495 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005496 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005497 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005499
John McCallba7bf592010-08-24 05:47:05 +00005500 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005501 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005502 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005503 E->getOperatorLoc(),
5504 E->isArrow()? tok::arrow : tok::period,
5505 ObjectTypePtr,
5506 MayBePseudoDestructor);
5507 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005508 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005509
John McCallba7bf592010-08-24 05:47:05 +00005510 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005511 NestedNameSpecifier *Qualifier = E->getQualifier();
5512 if (Qualifier) {
5513 Qualifier
5514 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5515 E->getQualifierRange(),
5516 ObjectType);
5517 if (!Qualifier)
5518 return ExprError();
5519 }
Mike Stump11289f42009-09-09 15:08:12 +00005520
Douglas Gregor678f90d2010-02-25 01:56:36 +00005521 PseudoDestructorTypeStorage Destroyed;
5522 if (E->getDestroyedTypeInfo()) {
5523 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005524 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5525 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005526 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005527 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005528 Destroyed = DestroyedTypeInfo;
5529 } else if (ObjectType->isDependentType()) {
5530 // We aren't likely to be able to resolve the identifier down to a type
5531 // now anyway, so just retain the identifier.
5532 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5533 E->getDestroyedTypeLoc());
5534 } else {
5535 // Look for a destructor known with the given name.
5536 CXXScopeSpec SS;
5537 if (Qualifier) {
5538 SS.setScopeRep(Qualifier);
5539 SS.setRange(E->getQualifierRange());
5540 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005541
John McCallba7bf592010-08-24 05:47:05 +00005542 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005543 *E->getDestroyedTypeIdentifier(),
5544 E->getDestroyedTypeLoc(),
5545 /*Scope=*/0,
5546 SS, ObjectTypePtr,
5547 false);
5548 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005550
Douglas Gregor678f90d2010-02-25 01:56:36 +00005551 Destroyed
5552 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5553 E->getDestroyedTypeLoc());
5554 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005555
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005556 TypeSourceInfo *ScopeTypeInfo = 0;
5557 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005558 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005559 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005560 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005561 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005562
John McCallb268a282010-08-23 23:25:46 +00005563 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005564 E->getOperatorLoc(),
5565 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005566 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005567 E->getQualifierRange(),
5568 ScopeTypeInfo,
5569 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005570 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005571 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005572}
Mike Stump11289f42009-09-09 15:08:12 +00005573
Douglas Gregorad8a3362009-09-04 17:36:40 +00005574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005575ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005576TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005577 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005578 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5579
5580 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5581 Sema::LookupOrdinaryName);
5582
5583 // Transform all the decls.
5584 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5585 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005586 NamedDecl *InstD = static_cast<NamedDecl*>(
5587 getDerived().TransformDecl(Old->getNameLoc(),
5588 *I));
John McCall84d87672009-12-10 09:41:52 +00005589 if (!InstD) {
5590 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5591 // This can happen because of dependent hiding.
5592 if (isa<UsingShadowDecl>(*I))
5593 continue;
5594 else
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005596 }
John McCalle66edc12009-11-24 19:00:30 +00005597
5598 // Expand using declarations.
5599 if (isa<UsingDecl>(InstD)) {
5600 UsingDecl *UD = cast<UsingDecl>(InstD);
5601 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5602 E = UD->shadow_end(); I != E; ++I)
5603 R.addDecl(*I);
5604 continue;
5605 }
5606
5607 R.addDecl(InstD);
5608 }
5609
5610 // Resolve a kind, but don't do any further analysis. If it's
5611 // ambiguous, the callee needs to deal with it.
5612 R.resolveKind();
5613
5614 // Rebuild the nested-name qualifier, if present.
5615 CXXScopeSpec SS;
5616 NestedNameSpecifier *Qualifier = 0;
5617 if (Old->getQualifier()) {
5618 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005619 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005620 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005621 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005622
John McCalle66edc12009-11-24 19:00:30 +00005623 SS.setScopeRep(Qualifier);
5624 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005625 }
5626
Douglas Gregor9262f472010-04-27 18:19:34 +00005627 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005628 CXXRecordDecl *NamingClass
5629 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5630 Old->getNameLoc(),
5631 Old->getNamingClass()));
5632 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005633 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005634
Douglas Gregorda7be082010-04-27 16:10:10 +00005635 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005636 }
5637
5638 // If we have no template arguments, it's a normal declaration name.
5639 if (!Old->hasExplicitTemplateArgs())
5640 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5641
5642 // If we have template arguments, rebuild them, then rebuild the
5643 // templateid expression.
5644 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5645 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5646 TemplateArgumentLoc Loc;
5647 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005648 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005649 TransArgs.addArgument(Loc);
5650 }
5651
5652 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5653 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005654}
Mike Stump11289f42009-09-09 15:08:12 +00005655
Douglas Gregora16548e2009-08-11 05:31:07 +00005656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005657ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005658TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005659 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5660 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005664 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005665 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005666
Mike Stump11289f42009-09-09 15:08:12 +00005667 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005668 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 T,
5670 E->getLocEnd());
5671}
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregora16548e2009-08-11 05:31:07 +00005673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005674ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00005675TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
5676 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
5677 if (!LhsT)
5678 return ExprError();
5679
5680 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
5681 if (!RhsT)
5682 return ExprError();
5683
5684 if (!getDerived().AlwaysRebuild() &&
5685 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
5686 return SemaRef.Owned(E);
5687
5688 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
5689 E->getLocStart(),
5690 LhsT, RhsT,
5691 E->getLocEnd());
5692}
5693
5694template<typename Derived>
5695ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005696TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005697 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005698 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005699 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005700 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005701 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005703
John McCall31f82722010-11-12 08:19:04 +00005704 // TODO: If this is a conversion-function-id, verify that the
5705 // destination type name (if present) resolves the same way after
5706 // instantiation as it did in the local scope.
5707
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005708 DeclarationNameInfo NameInfo
5709 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5710 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005712
John McCalle66edc12009-11-24 19:00:30 +00005713 if (!E->hasExplicitTemplateArgs()) {
5714 if (!getDerived().AlwaysRebuild() &&
5715 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005716 // Note: it is sufficient to compare the Name component of NameInfo:
5717 // if name has not changed, DNLoc has not changed either.
5718 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005719 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005720
John McCalle66edc12009-11-24 19:00:30 +00005721 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5722 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005723 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005724 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005725 }
John McCall6b51f282009-11-23 01:53:49 +00005726
5727 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005728 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005729 TemplateArgumentLoc Loc;
5730 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005732 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 }
5734
John McCalle66edc12009-11-24 19:00:30 +00005735 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5736 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005737 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005738 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005739}
5740
5741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005743TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005744 // CXXConstructExprs are always implicit, so when we have a
5745 // 1-argument construction we just transform that argument.
5746 if (E->getNumArgs() == 1 ||
5747 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5748 return getDerived().TransformExpr(E->getArg(0));
5749
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5751
5752 QualType T = getDerived().TransformType(E->getType());
5753 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005754 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005755
5756 CXXConstructorDecl *Constructor
5757 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005758 getDerived().TransformDecl(E->getLocStart(),
5759 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005762
Douglas Gregora16548e2009-08-11 05:31:07 +00005763 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005764 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005765 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005766 ArgEnd = E->arg_end();
5767 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005768 if (getDerived().DropCallArgument(*Arg)) {
5769 ArgumentChanged = true;
5770 break;
5771 }
5772
John McCalldadc5752010-08-24 06:29:42 +00005773 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005774 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005778 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 }
5780
5781 if (!getDerived().AlwaysRebuild() &&
5782 T == E->getType() &&
5783 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005784 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005785 // Mark the constructor as referenced.
5786 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005787 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005788 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005789 }
Mike Stump11289f42009-09-09 15:08:12 +00005790
Douglas Gregordb121ba2009-12-14 16:27:04 +00005791 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5792 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005793 move_arg(Args),
5794 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005795 E->getConstructionKind(),
5796 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005797}
Mike Stump11289f42009-09-09 15:08:12 +00005798
Douglas Gregora16548e2009-08-11 05:31:07 +00005799/// \brief Transform a C++ temporary-binding expression.
5800///
Douglas Gregor363b1512009-12-24 18:51:59 +00005801/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5802/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005806 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005807}
Mike Stump11289f42009-09-09 15:08:12 +00005808
John McCall5d413782010-12-06 08:20:24 +00005809/// \brief Transform a C++ expression that contains cleanups that should
5810/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00005811///
John McCall5d413782010-12-06 08:20:24 +00005812/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00005813/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005815ExprResult
John McCall5d413782010-12-06 08:20:24 +00005816TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005817 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005818}
Mike Stump11289f42009-09-09 15:08:12 +00005819
Douglas Gregora16548e2009-08-11 05:31:07 +00005820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005821ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005822TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005823 CXXTemporaryObjectExpr *E) {
5824 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5825 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 CXXConstructorDecl *Constructor
5829 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005830 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005831 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005832 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005834
Douglas Gregora16548e2009-08-11 05:31:07 +00005835 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005836 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005837 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005838 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 ArgEnd = E->arg_end();
5840 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005841 if (getDerived().DropCallArgument(*Arg)) {
5842 ArgumentChanged = true;
5843 break;
5844 }
5845
John McCalldadc5752010-08-24 06:29:42 +00005846 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005847 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5851 Args.push_back((Expr *)TransArg.release());
5852 }
Mike Stump11289f42009-09-09 15:08:12 +00005853
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005855 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005857 !ArgumentChanged) {
5858 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005859 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005860 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005861 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005862
5863 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5864 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005866 E->getLocEnd());
5867}
Mike Stump11289f42009-09-09 15:08:12 +00005868
Douglas Gregora16548e2009-08-11 05:31:07 +00005869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005870ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005871TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005872 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005873 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5874 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005875 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005878 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005879 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5880 ArgEnd = E->arg_end();
5881 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005882 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005883 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005884 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005887 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005888 }
Mike Stump11289f42009-09-09 15:08:12 +00005889
Douglas Gregora16548e2009-08-11 05:31:07 +00005890 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005891 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005892 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005893 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005894
Douglas Gregora16548e2009-08-11 05:31:07 +00005895 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005896 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 E->getLParenLoc(),
5898 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 E->getRParenLoc());
5900}
Mike Stump11289f42009-09-09 15:08:12 +00005901
Douglas Gregora16548e2009-08-11 05:31:07 +00005902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005903ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005904TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005905 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005906 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005907 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005908 Expr *OldBase;
5909 QualType BaseType;
5910 QualType ObjectType;
5911 if (!E->isImplicitAccess()) {
5912 OldBase = E->getBase();
5913 Base = getDerived().TransformExpr(OldBase);
5914 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005916
John McCall2d74de92009-12-01 22:10:20 +00005917 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005918 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005919 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005920 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005921 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005922 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005923 ObjectTy,
5924 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005925 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005926 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005927
John McCallba7bf592010-08-24 05:47:05 +00005928 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005929 BaseType = ((Expr*) Base.get())->getType();
5930 } else {
5931 OldBase = 0;
5932 BaseType = getDerived().TransformType(E->getBaseType());
5933 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5934 }
Mike Stump11289f42009-09-09 15:08:12 +00005935
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005936 // Transform the first part of the nested-name-specifier that qualifies
5937 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005938 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005939 = getDerived().TransformFirstQualifierInScope(
5940 E->getFirstQualifierFoundInScope(),
5941 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005942
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005943 NestedNameSpecifier *Qualifier = 0;
5944 if (E->getQualifier()) {
5945 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5946 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005947 ObjectType,
5948 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005949 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005950 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005951 }
Mike Stump11289f42009-09-09 15:08:12 +00005952
John McCall31f82722010-11-12 08:19:04 +00005953 // TODO: If this is a conversion-function-id, verify that the
5954 // destination type name (if present) resolves the same way after
5955 // instantiation as it did in the local scope.
5956
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005957 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00005958 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005959 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005960 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005961
John McCall2d74de92009-12-01 22:10:20 +00005962 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005963 // This is a reference to a member without an explicitly-specified
5964 // template argument list. Optimize for this common case.
5965 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005966 Base.get() == OldBase &&
5967 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005968 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005969 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005970 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00005971 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005972
John McCallb268a282010-08-23 23:25:46 +00005973 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005974 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005975 E->isArrow(),
5976 E->getOperatorLoc(),
5977 Qualifier,
5978 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005979 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005980 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005981 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005982 }
5983
John McCall6b51f282009-11-23 01:53:49 +00005984 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005985 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005986 TemplateArgumentLoc Loc;
5987 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005989 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005990 }
Mike Stump11289f42009-09-09 15:08:12 +00005991
John McCallb268a282010-08-23 23:25:46 +00005992 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005993 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 E->isArrow(),
5995 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005996 Qualifier,
5997 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005998 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005999 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006000 &TransArgs);
6001}
6002
6003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006004ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006005TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006006 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006007 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006008 QualType BaseType;
6009 if (!Old->isImplicitAccess()) {
6010 Base = getDerived().TransformExpr(Old->getBase());
6011 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006013 BaseType = ((Expr*) Base.get())->getType();
6014 } else {
6015 BaseType = getDerived().TransformType(Old->getBaseType());
6016 }
John McCall10eae182009-11-30 22:42:35 +00006017
6018 NestedNameSpecifier *Qualifier = 0;
6019 if (Old->getQualifier()) {
6020 Qualifier
6021 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006022 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006023 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006024 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006025 }
6026
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006027 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006028 Sema::LookupOrdinaryName);
6029
6030 // Transform all the decls.
6031 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6032 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006033 NamedDecl *InstD = static_cast<NamedDecl*>(
6034 getDerived().TransformDecl(Old->getMemberLoc(),
6035 *I));
John McCall84d87672009-12-10 09:41:52 +00006036 if (!InstD) {
6037 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6038 // This can happen because of dependent hiding.
6039 if (isa<UsingShadowDecl>(*I))
6040 continue;
6041 else
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006043 }
John McCall10eae182009-11-30 22:42:35 +00006044
6045 // Expand using declarations.
6046 if (isa<UsingDecl>(InstD)) {
6047 UsingDecl *UD = cast<UsingDecl>(InstD);
6048 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6049 E = UD->shadow_end(); I != E; ++I)
6050 R.addDecl(*I);
6051 continue;
6052 }
6053
6054 R.addDecl(InstD);
6055 }
6056
6057 R.resolveKind();
6058
Douglas Gregor9262f472010-04-27 18:19:34 +00006059 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006060 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006061 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006062 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006063 Old->getMemberLoc(),
6064 Old->getNamingClass()));
6065 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006067
Douglas Gregorda7be082010-04-27 16:10:10 +00006068 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006069 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006070
John McCall10eae182009-11-30 22:42:35 +00006071 TemplateArgumentListInfo TransArgs;
6072 if (Old->hasExplicitTemplateArgs()) {
6073 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6074 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6075 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6076 TemplateArgumentLoc Loc;
6077 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6078 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006080 TransArgs.addArgument(Loc);
6081 }
6082 }
John McCall38836f02010-01-15 08:34:02 +00006083
6084 // FIXME: to do this check properly, we will need to preserve the
6085 // first-qualifier-in-scope here, just in case we had a dependent
6086 // base (and therefore couldn't do the check) and a
6087 // nested-name-qualifier (and therefore could do the lookup).
6088 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006089
John McCallb268a282010-08-23 23:25:46 +00006090 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006091 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006092 Old->getOperatorLoc(),
6093 Old->isArrow(),
6094 Qualifier,
6095 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006096 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006097 R,
6098 (Old->hasExplicitTemplateArgs()
6099 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006100}
6101
6102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006103ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006104TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6105 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6106 if (SubExpr.isInvalid())
6107 return ExprError();
6108
6109 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006110 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006111
6112 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6113}
6114
6115template<typename Derived>
6116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006117TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006118 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006119}
6120
Mike Stump11289f42009-09-09 15:08:12 +00006121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006124 TypeSourceInfo *EncodedTypeInfo
6125 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6126 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006128
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006130 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006131 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006132
6133 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006134 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006135 E->getRParenLoc());
6136}
Mike Stump11289f42009-09-09 15:08:12 +00006137
Douglas Gregora16548e2009-08-11 05:31:07 +00006138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006140TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006141 // Transform arguments.
6142 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006143 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006144 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006145 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006146 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006147 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006148
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006149 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006150 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006151 }
6152
6153 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6154 // Class message: transform the receiver type.
6155 TypeSourceInfo *ReceiverTypeInfo
6156 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6157 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006158 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006159
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006160 // If nothing changed, just retain the existing message send.
6161 if (!getDerived().AlwaysRebuild() &&
6162 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006163 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006164
6165 // Build a new class message send.
6166 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6167 E->getSelector(),
6168 E->getMethodDecl(),
6169 E->getLeftLoc(),
6170 move_arg(Args),
6171 E->getRightLoc());
6172 }
6173
6174 // Instance message: transform the receiver
6175 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6176 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006177 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006178 = getDerived().TransformExpr(E->getInstanceReceiver());
6179 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006181
6182 // If nothing changed, just retain the existing message send.
6183 if (!getDerived().AlwaysRebuild() &&
6184 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006185 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006186
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006187 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006188 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006189 E->getSelector(),
6190 E->getMethodDecl(),
6191 E->getLeftLoc(),
6192 move_arg(Args),
6193 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006194}
6195
Mike Stump11289f42009-09-09 15:08:12 +00006196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006198TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006199 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006200}
6201
Mike Stump11289f42009-09-09 15:08:12 +00006202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006205 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006206}
6207
Mike Stump11289f42009-09-09 15:08:12 +00006208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006209ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006210TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006211 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006212 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006213 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006214 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006215
6216 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006217
Douglas Gregord51d90d2010-04-26 20:11:03 +00006218 // If nothing changed, just retain the existing expression.
6219 if (!getDerived().AlwaysRebuild() &&
6220 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006221 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006222
John McCallb268a282010-08-23 23:25:46 +00006223 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006224 E->getLocation(),
6225 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006226}
6227
Mike Stump11289f42009-09-09 15:08:12 +00006228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006231 // 'super' and types never change. Property never changes. Just
6232 // retain the existing expression.
6233 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006234 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006235
Douglas Gregor9faee212010-04-26 20:47:02 +00006236 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006237 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006238 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006239 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006240
Douglas Gregor9faee212010-04-26 20:47:02 +00006241 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006242
Douglas Gregor9faee212010-04-26 20:47:02 +00006243 // If nothing changed, just retain the existing expression.
6244 if (!getDerived().AlwaysRebuild() &&
6245 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006246 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006247
John McCallb7bd14f2010-12-02 01:19:52 +00006248 if (E->isExplicitProperty())
6249 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6250 E->getExplicitProperty(),
6251 E->getLocation());
6252
6253 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6254 E->getType(),
6255 E->getImplicitPropertyGetter(),
6256 E->getImplicitPropertySetter(),
6257 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006258}
6259
Mike Stump11289f42009-09-09 15:08:12 +00006260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006262TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006263 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006264 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006265 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006266 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006267
Douglas Gregord51d90d2010-04-26 20:11:03 +00006268 // If nothing changed, just retain the existing expression.
6269 if (!getDerived().AlwaysRebuild() &&
6270 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006271 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006272
John McCallb268a282010-08-23 23:25:46 +00006273 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006274 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006275}
6276
Mike Stump11289f42009-09-09 15:08:12 +00006277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006279TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006281 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006282 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006283 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006285 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006286
Douglas Gregora16548e2009-08-11 05:31:07 +00006287 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006288 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006289 }
Mike Stump11289f42009-09-09 15:08:12 +00006290
Douglas Gregora16548e2009-08-11 05:31:07 +00006291 if (!getDerived().AlwaysRebuild() &&
6292 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006293 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006294
Douglas Gregora16548e2009-08-11 05:31:07 +00006295 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6296 move_arg(SubExprs),
6297 E->getRParenLoc());
6298}
6299
Mike Stump11289f42009-09-09 15:08:12 +00006300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006301ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006302TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006303 SourceLocation CaretLoc(E->getExprLoc());
6304
6305 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6306 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6307 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6308 llvm::SmallVector<ParmVarDecl*, 4> Params;
6309 llvm::SmallVector<QualType, 4> ParamTypes;
6310
6311 // Parameter substitution.
6312 const BlockDecl *BD = E->getBlockDecl();
6313 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6314 EN = BD->param_end(); P != EN; ++P) {
6315 ParmVarDecl *OldParm = (*P);
6316 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6317 QualType NewType = NewParm->getType();
6318 Params.push_back(NewParm);
6319 ParamTypes.push_back(NewParm->getType());
6320 }
6321
6322 const FunctionType *BExprFunctionType = E->getFunctionType();
6323 QualType BExprResultType = BExprFunctionType->getResultType();
6324 if (!BExprResultType.isNull()) {
6325 if (!BExprResultType->isDependentType())
6326 CurBlock->ReturnType = BExprResultType;
6327 else if (BExprResultType != SemaRef.Context.DependentTy)
6328 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6329 }
6330
6331 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006332 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006333 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006334 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006335 // Set the parameters on the block decl.
6336 if (!Params.empty())
6337 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6338
6339 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6340 CurBlock->ReturnType,
6341 ParamTypes.data(),
6342 ParamTypes.size(),
6343 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006344 0,
6345 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006346
6347 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006348 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006349}
6350
Mike Stump11289f42009-09-09 15:08:12 +00006351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006352ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006353TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006354 NestedNameSpecifier *Qualifier = 0;
6355
6356 ValueDecl *ND
6357 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6358 E->getDecl()));
6359 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006360 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006361
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006362 if (!getDerived().AlwaysRebuild() &&
6363 ND == E->getDecl()) {
6364 // Mark it referenced in the new context regardless.
6365 // FIXME: this is a bit instantiation-specific.
6366 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6367
John McCallc3007a22010-10-26 07:05:15 +00006368 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006369 }
6370
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006371 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006372 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006373 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006374}
Mike Stump11289f42009-09-09 15:08:12 +00006375
Douglas Gregora16548e2009-08-11 05:31:07 +00006376//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006377// Type reconstruction
6378//===----------------------------------------------------------------------===//
6379
Mike Stump11289f42009-09-09 15:08:12 +00006380template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006381QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6382 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006383 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006384 getDerived().getBaseEntity());
6385}
6386
Mike Stump11289f42009-09-09 15:08:12 +00006387template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006388QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6389 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006390 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391 getDerived().getBaseEntity());
6392}
6393
Mike Stump11289f42009-09-09 15:08:12 +00006394template<typename Derived>
6395QualType
John McCall70dd5f62009-10-30 00:06:24 +00006396TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6397 bool WrittenAsLValue,
6398 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006399 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006400 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006401}
6402
6403template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006404QualType
John McCall70dd5f62009-10-30 00:06:24 +00006405TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6406 QualType ClassType,
6407 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006408 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006409 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006410}
6411
6412template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006413QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6415 ArrayType::ArraySizeModifier SizeMod,
6416 const llvm::APInt *Size,
6417 Expr *SizeExpr,
6418 unsigned IndexTypeQuals,
6419 SourceRange BracketsRange) {
6420 if (SizeExpr || !Size)
6421 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6422 IndexTypeQuals, BracketsRange,
6423 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006424
6425 QualType Types[] = {
6426 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6427 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6428 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006429 };
6430 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6431 QualType SizeType;
6432 for (unsigned I = 0; I != NumTypes; ++I)
6433 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6434 SizeType = Types[I];
6435 break;
6436 }
Mike Stump11289f42009-09-09 15:08:12 +00006437
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006438 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6439 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006440 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006441 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006442 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006443}
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregord6ff3322009-08-04 16:50:30 +00006445template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006446QualType
6447TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006448 ArrayType::ArraySizeModifier SizeMod,
6449 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006450 unsigned IndexTypeQuals,
6451 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006452 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006453 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006454}
6455
6456template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006457QualType
Mike Stump11289f42009-09-09 15:08:12 +00006458TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006459 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006460 unsigned IndexTypeQuals,
6461 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006462 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006463 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006464}
Mike Stump11289f42009-09-09 15:08:12 +00006465
Douglas Gregord6ff3322009-08-04 16:50:30 +00006466template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006467QualType
6468TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006469 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006470 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006471 unsigned IndexTypeQuals,
6472 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006473 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006474 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006475 IndexTypeQuals, BracketsRange);
6476}
6477
6478template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006479QualType
6480TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006481 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006482 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006483 unsigned IndexTypeQuals,
6484 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006485 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006486 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006487 IndexTypeQuals, BracketsRange);
6488}
6489
6490template<typename Derived>
6491QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006492 unsigned NumElements,
6493 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006494 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006495 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006496}
Mike Stump11289f42009-09-09 15:08:12 +00006497
Douglas Gregord6ff3322009-08-04 16:50:30 +00006498template<typename Derived>
6499QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6500 unsigned NumElements,
6501 SourceLocation AttributeLoc) {
6502 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6503 NumElements, true);
6504 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006505 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6506 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006507 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006508}
Mike Stump11289f42009-09-09 15:08:12 +00006509
Douglas Gregord6ff3322009-08-04 16:50:30 +00006510template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006511QualType
6512TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006513 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006514 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006515 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006516}
Mike Stump11289f42009-09-09 15:08:12 +00006517
Douglas Gregord6ff3322009-08-04 16:50:30 +00006518template<typename Derived>
6519QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006520 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006521 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006522 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006523 unsigned Quals,
6524 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006525 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006526 Quals,
6527 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006528 getDerived().getBaseEntity(),
6529 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006530}
Mike Stump11289f42009-09-09 15:08:12 +00006531
Douglas Gregord6ff3322009-08-04 16:50:30 +00006532template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006533QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6534 return SemaRef.Context.getFunctionNoProtoType(T);
6535}
6536
6537template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006538QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6539 assert(D && "no decl found");
6540 if (D->isInvalidDecl()) return QualType();
6541
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006542 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006543 TypeDecl *Ty;
6544 if (isa<UsingDecl>(D)) {
6545 UsingDecl *Using = cast<UsingDecl>(D);
6546 assert(Using->isTypeName() &&
6547 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6548
6549 // A valid resolved using typename decl points to exactly one type decl.
6550 assert(++Using->shadow_begin() == Using->shadow_end());
6551 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006552
John McCallb96ec562009-12-04 22:46:56 +00006553 } else {
6554 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6555 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6556 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6557 }
6558
6559 return SemaRef.Context.getTypeDeclType(Ty);
6560}
6561
6562template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006563QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6564 SourceLocation Loc) {
6565 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006566}
6567
6568template<typename Derived>
6569QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6570 return SemaRef.Context.getTypeOfType(Underlying);
6571}
6572
6573template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006574QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6575 SourceLocation Loc) {
6576 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006577}
6578
6579template<typename Derived>
6580QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006581 TemplateName Template,
6582 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006583 const TemplateArgumentListInfo &TemplateArgs) {
6584 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006585}
Mike Stump11289f42009-09-09 15:08:12 +00006586
Douglas Gregor1135c352009-08-06 05:28:30 +00006587template<typename Derived>
6588NestedNameSpecifier *
6589TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6590 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006591 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006592 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006593 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006594 CXXScopeSpec SS;
6595 // FIXME: The source location information is all wrong.
6596 SS.setRange(Range);
6597 SS.setScopeRep(Prefix);
6598 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006599 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006600 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006601 ObjectType,
6602 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006603 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006604}
6605
6606template<typename Derived>
6607NestedNameSpecifier *
6608TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6609 SourceRange Range,
6610 NamespaceDecl *NS) {
6611 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6612}
6613
6614template<typename Derived>
6615NestedNameSpecifier *
6616TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6617 SourceRange Range,
6618 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006619 QualType T) {
6620 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006621 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006622 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006623 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6624 T.getTypePtr());
6625 }
Mike Stump11289f42009-09-09 15:08:12 +00006626
Douglas Gregor1135c352009-08-06 05:28:30 +00006627 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6628 return 0;
6629}
Mike Stump11289f42009-09-09 15:08:12 +00006630
Douglas Gregor71dc5092009-08-06 06:41:21 +00006631template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006632TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006633TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6634 bool TemplateKW,
6635 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006636 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006637 Template);
6638}
6639
6640template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006641TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006642TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006643 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006644 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00006645 QualType ObjectType,
6646 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006647 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006648 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006649 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006650 UnqualifiedId Name;
6651 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006652 Sema::TemplateTy Template;
6653 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6654 /*FIXME:*/getDerived().getBaseLocation(),
6655 SS,
6656 Name,
John McCallba7bf592010-08-24 05:47:05 +00006657 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006658 /*EnteringContext=*/false,
6659 Template);
John McCall31f82722010-11-12 08:19:04 +00006660 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006661}
Mike Stump11289f42009-09-09 15:08:12 +00006662
Douglas Gregora16548e2009-08-11 05:31:07 +00006663template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006664TemplateName
6665TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6666 OverloadedOperatorKind Operator,
6667 QualType ObjectType) {
6668 CXXScopeSpec SS;
6669 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6670 SS.setScopeRep(Qualifier);
6671 UnqualifiedId Name;
6672 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6673 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6674 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006675 Sema::TemplateTy Template;
6676 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006677 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006678 SS,
6679 Name,
John McCallba7bf592010-08-24 05:47:05 +00006680 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006681 /*EnteringContext=*/false,
6682 Template);
6683 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006684}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006685
Douglas Gregor71395fa2009-11-04 00:56:37 +00006686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006687ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006688TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6689 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006690 Expr *OrigCallee,
6691 Expr *First,
6692 Expr *Second) {
6693 Expr *Callee = OrigCallee->IgnoreParenCasts();
6694 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006695
Douglas Gregora16548e2009-08-11 05:31:07 +00006696 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006697 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006698 if (!First->getType()->isOverloadableType() &&
6699 !Second->getType()->isOverloadableType())
6700 return getSema().CreateBuiltinArraySubscriptExpr(First,
6701 Callee->getLocStart(),
6702 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006703 } else if (Op == OO_Arrow) {
6704 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006705 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6706 } else if (Second == 0 || isPostIncDec) {
6707 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006708 // The argument is not of overloadable type, so try to create a
6709 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006710 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006711 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006712
John McCallb268a282010-08-23 23:25:46 +00006713 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 }
6715 } else {
John McCallb268a282010-08-23 23:25:46 +00006716 if (!First->getType()->isOverloadableType() &&
6717 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006718 // Neither of the arguments is an overloadable type, so try to
6719 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006720 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006721 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006722 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006724 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006725
Douglas Gregora16548e2009-08-11 05:31:07 +00006726 return move(Result);
6727 }
6728 }
Mike Stump11289f42009-09-09 15:08:12 +00006729
6730 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006731 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006732 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006733
John McCallb268a282010-08-23 23:25:46 +00006734 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006735 assert(ULE->requiresADL());
6736
6737 // FIXME: Do we have to check
6738 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006739 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006740 } else {
John McCallb268a282010-08-23 23:25:46 +00006741 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006742 }
Mike Stump11289f42009-09-09 15:08:12 +00006743
Douglas Gregora16548e2009-08-11 05:31:07 +00006744 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006745 Expr *Args[2] = { First, Second };
6746 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006747
Douglas Gregora16548e2009-08-11 05:31:07 +00006748 // Create the overloaded operator invocation for unary operators.
6749 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006750 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006751 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006752 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006753 }
Mike Stump11289f42009-09-09 15:08:12 +00006754
Sebastian Redladba46e2009-10-29 20:17:01 +00006755 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006756 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006757 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006758 First,
6759 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006760
Douglas Gregora16548e2009-08-11 05:31:07 +00006761 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006762 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006763 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006764 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6765 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006767
Mike Stump11289f42009-09-09 15:08:12 +00006768 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006769}
Mike Stump11289f42009-09-09 15:08:12 +00006770
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006772ExprResult
John McCallb268a282010-08-23 23:25:46 +00006773TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006774 SourceLocation OperatorLoc,
6775 bool isArrow,
6776 NestedNameSpecifier *Qualifier,
6777 SourceRange QualifierRange,
6778 TypeSourceInfo *ScopeType,
6779 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006780 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006781 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006782 CXXScopeSpec SS;
6783 if (Qualifier) {
6784 SS.setRange(QualifierRange);
6785 SS.setScopeRep(Qualifier);
6786 }
6787
John McCallb268a282010-08-23 23:25:46 +00006788 QualType BaseType = Base->getType();
6789 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006790 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006791 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006792 !BaseType->getAs<PointerType>()->getPointeeType()
6793 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006794 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006795 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006796 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006797 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006798 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006799 /*FIXME?*/true);
6800 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006801
Douglas Gregor678f90d2010-02-25 01:56:36 +00006802 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006803 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6804 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6805 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6806 NameInfo.setNamedTypeInfo(DestroyedType);
6807
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006808 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006809
John McCallb268a282010-08-23 23:25:46 +00006810 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006811 OperatorLoc, isArrow,
6812 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006813 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006814 /*TemplateArgs*/ 0);
6815}
6816
Douglas Gregord6ff3322009-08-04 16:50:30 +00006817} // end namespace clang
6818
6819#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H