blob: 12192c9ea22a8ff5031bd2c04a23f489e6a9b82d [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 McCall550e0c22009-10-21 00:40:46 +000028#include "clang/AST/TypeLocBuilder.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000036using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000037
Douglas Gregord6ff3322009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump11289f42009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump11289f42009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000093
94public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000097
Douglas Gregord6ff3322009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000104 }
105
John McCalldadc5752010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000119
Douglas Gregord6ff3322009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump11289f42009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregora16548e2009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000141
Douglas Gregora16548e2009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregora16548e2009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Douglas Gregora16548e2009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump11289f42009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregord196a582009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000182
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCall550e0c22009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000192 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000193
John McCall550e0c22009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 ///
John McCall550e0c22009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000203
204 /// \brief Transform the given type-with-location into a new
205 /// type, collecting location information in the given builder
206 /// as necessary.
207 ///
John McCall31f82722010-11-12 08:19:04 +0000208 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000209
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000210 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000211 ///
Mike Stump11289f42009-09-09 15:08:12 +0000212 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000213 /// appropriate TransformXXXStmt function to transform a specific kind of
214 /// statement or the TransformExpr() function to transform an expression.
215 /// Subclasses may override this function to transform statements using some
216 /// other mechanism.
217 ///
218 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000219 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000220
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000221 /// \brief Transform the given expression.
222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 /// By default, this routine transforms an expression by delegating to the
224 /// appropriate TransformXXXExpr function to build a new expression.
225 /// Subclasses may override this function to transform expressions using some
226 /// other mechanism.
227 ///
228 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000229 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000230
Douglas Gregord6ff3322009-08-04 16:50:30 +0000231 /// \brief Transform the given declaration, which is referenced from a type
232 /// or expression.
233 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000234 /// By default, acts as the identity function on declarations. Subclasses
235 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000236 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000237
238 /// \brief Transform the definition of the given declaration.
239 ///
Mike Stump11289f42009-09-09 15:08:12 +0000240 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000241 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000242 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
243 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000244 }
Mike Stump11289f42009-09-09 15:08:12 +0000245
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000249 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000257 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000258
Douglas Gregord6ff3322009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregorf816bd72009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000275 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000276 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000277
Douglas Gregord6ff3322009-08-04 16:50:30 +0000278 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000279 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000280 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000281 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000282 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000283 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000284 QualType ObjectType = QualType(),
285 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000286
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump11289f42009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCallbcd03502009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump11289f42009-09-09 15:08:12 +0000307
John McCall550e0c22009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000311#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000312
John McCall31f82722010-11-12 08:19:04 +0000313 QualType
314 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
315 TemplateSpecializationTypeLoc TL,
316 TemplateName Template);
317
318 QualType
319 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
320 DependentTemplateSpecializationTypeLoc TL,
321 NestedNameSpecifier *Prefix);
322
John McCall58f10c32010-03-11 09:03:00 +0000323 /// \brief Transforms the parameters of a function type into the
324 /// given vectors.
325 ///
326 /// The result vectors should be kept in sync; null entries in the
327 /// variables vector are acceptable.
328 ///
329 /// Return true on error.
330 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
331 llvm::SmallVectorImpl<QualType> &PTypes,
332 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
333
334 /// \brief Transforms a single function-type parameter. Return null
335 /// on error.
336 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
337
John McCall31f82722010-11-12 08:19:04 +0000338 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000339
John McCalldadc5752010-08-24 06:29:42 +0000340 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
341 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000344 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000346 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000424 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000435 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000445 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000461 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000473
John McCall550e0c22009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCallb96ec562009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCallfcc33b02009-09-05 00:15:47 +0000495
Mike Stump11289f42009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000500 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501
Mike Stump11289f42009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump11289f42009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000511 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000521
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000527 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
528 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000529 NestedNameSpecifier *NNS, QualType Named) {
530 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000531 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000532
533 /// \brief Build a new typename type that refers to a template-id.
534 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000535 /// By default, builds a new DependentNameType type from the
536 /// nested-name-specifier and the given type. Subclasses may override
537 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000538 QualType RebuildDependentTemplateSpecializationType(
539 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000540 NestedNameSpecifier *Qualifier,
541 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000542 const IdentifierInfo *Name,
543 SourceLocation NameLoc,
544 const TemplateArgumentListInfo &Args) {
545 // Rebuild the template name.
546 // TODO: avoid TemplateName abstraction
547 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000548 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000549 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000550
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000551 if (InstName.isNull())
552 return QualType();
553
John McCallc392f372010-06-11 00:33:02 +0000554 // If it's still dependent, make a dependent specialization.
555 if (InstName.getAsDependentTemplateName())
556 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000557 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000558
559 // Otherwise, make an elaborated type wrapping a non-dependent
560 // specialization.
561 QualType T =
562 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
563 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000564
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000565 // NOTE: NNS is already recorded in template specialization type T.
566 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000567 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568
569 /// \brief Build a new typename type that refers to an identifier.
570 ///
571 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000573 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000575 NestedNameSpecifier *NNS,
576 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000577 SourceLocation KeywordLoc,
578 SourceRange NNSRange,
579 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000580 CXXScopeSpec SS;
581 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000582 SS.setRange(NNSRange);
583
Douglas Gregore677daf2010-03-31 22:19:08 +0000584 if (NNS->isDependent()) {
585 // If the name is still dependent, just build a new dependent name type.
586 if (!SemaRef.computeDeclContext(SS))
587 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
588 }
589
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000591 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
592 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000593
594 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
595
Abramo Bagnarad7548482010-05-19 21:37:53 +0000596 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000597 // into a non-dependent elaborated-type-specifier. Find the tag we're
598 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000599 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000600 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
601 if (!DC)
602 return QualType();
603
John McCallbf8c5192010-05-27 06:40:31 +0000604 if (SemaRef.RequireCompleteDeclContext(SS, DC))
605 return QualType();
606
Douglas Gregore677daf2010-03-31 22:19:08 +0000607 TagDecl *Tag = 0;
608 SemaRef.LookupQualifiedName(Result, DC);
609 switch (Result.getResultKind()) {
610 case LookupResult::NotFound:
611 case LookupResult::NotFoundInCurrentInstantiation:
612 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000613
Douglas Gregore677daf2010-03-31 22:19:08 +0000614 case LookupResult::Found:
615 Tag = Result.getAsSingle<TagDecl>();
616 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000617
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 case LookupResult::FoundOverloaded:
619 case LookupResult::FoundUnresolvedValue:
620 llvm_unreachable("Tag lookup cannot find non-tags");
621 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000622
Douglas Gregore677daf2010-03-31 22:19:08 +0000623 case LookupResult::Ambiguous:
624 // Let the LookupResult structure handle ambiguities.
625 return QualType();
626 }
627
628 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000629 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000630 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000631 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000632 return QualType();
633 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000634
Abramo Bagnarad7548482010-05-19 21:37:53 +0000635 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
636 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000637 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
638 return QualType();
639 }
640
641 // Build the elaborated-type-specifier type.
642 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000643 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000644 }
Mike Stump11289f42009-09-09 15:08:12 +0000645
Douglas Gregor1135c352009-08-06 05:28:30 +0000646 /// \brief Build a new nested-name-specifier given the prefix and an
647 /// identifier that names the next step in the nested-name-specifier.
648 ///
649 /// By default, performs semantic analysis when building the new
650 /// nested-name-specifier. Subclasses may override this routine to provide
651 /// different behavior.
652 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
653 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000654 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000655 QualType ObjectType,
656 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// namespace named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 NamespaceDecl *NS);
667
668 /// \brief Build a new nested-name-specifier given the prefix and the
669 /// type named in the next step in the nested-name-specifier.
670 ///
671 /// By default, performs semantic analysis when building the new
672 /// nested-name-specifier. Subclasses may override this routine to provide
673 /// different behavior.
674 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
675 SourceRange Range,
676 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000677 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000678
679 /// \brief Build a new template name given a nested name specifier, a flag
680 /// indicating whether the "template" keyword was provided, and the template
681 /// that the template name refers to.
682 ///
683 /// By default, builds the new template name directly. Subclasses may override
684 /// this routine to provide different behavior.
685 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
686 bool TemplateKW,
687 TemplateDecl *Template);
688
Douglas Gregor71dc5092009-08-06 06:41:21 +0000689 /// \brief Build a new template name given a nested name specifier and the
690 /// name that is referred to as a template.
691 ///
692 /// By default, performs semantic analysis to determine whether the name can
693 /// be resolved to a specific template, then builds the appropriate kind of
694 /// template name. Subclasses may override this routine to provide different
695 /// behavior.
696 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000697 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000698 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000699 QualType ObjectType,
700 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregor71395fa2009-11-04 00:56:37 +0000702 /// \brief Build a new template name given a nested name specifier and the
703 /// overloaded operator name that is referred to as a template.
704 ///
705 /// By default, performs semantic analysis to determine whether the name can
706 /// be resolved to a specific template, then builds the appropriate kind of
707 /// template name. Subclasses may override this routine to provide different
708 /// behavior.
709 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
710 OverloadedOperatorKind Operator,
711 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000712
Douglas Gregorebe10102009-08-20 07:17:43 +0000713 /// \brief Build a new compound statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000717 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000718 MultiStmtArg Statements,
719 SourceLocation RBraceLoc,
720 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000721 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000722 IsStmtExpr);
723 }
724
725 /// \brief Build a new case statement.
726 ///
727 /// By default, performs semantic analysis to build the new statement.
728 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000729 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000730 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000732 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000734 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 ColonLoc);
736 }
Mike Stump11289f42009-09-09 15:08:12 +0000737
Douglas Gregorebe10102009-08-20 07:17:43 +0000738 /// \brief Attach the body to a new case statement.
739 ///
740 /// By default, performs semantic analysis to build the new statement.
741 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000742 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000743 getSema().ActOnCaseStmtBody(S, Body);
744 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 }
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 /// \brief Build a new default statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000751 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000753 Stmt *SubStmt) {
754 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /*CurScope=*/0);
756 }
Mike Stump11289f42009-09-09 15:08:12 +0000757
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 /// \brief Build a new label statement.
759 ///
760 /// By default, performs semantic analysis to build the new statement.
761 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000762 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 IdentifierInfo *Id,
764 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000765 Stmt *SubStmt, bool HasUnusedAttr) {
766 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
767 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 }
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 /// \brief Build a new "if" statement.
771 ///
772 /// By default, performs semantic analysis to build the new statement.
773 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000774 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000775 VarDecl *CondVar, Stmt *Then,
776 SourceLocation ElseLoc, Stmt *Else) {
777 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 }
Mike Stump11289f42009-09-09 15:08:12 +0000779
Douglas Gregorebe10102009-08-20 07:17:43 +0000780 /// \brief Start building a new switch statement.
781 ///
782 /// By default, performs semantic analysis to build the new statement.
783 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000784 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000785 Expr *Cond, VarDecl *CondVar) {
786 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000787 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000788 }
Mike Stump11289f42009-09-09 15:08:12 +0000789
Douglas Gregorebe10102009-08-20 07:17:43 +0000790 /// \brief Attach the body to the switch statement.
791 ///
792 /// By default, performs semantic analysis to build the new statement.
793 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000794 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000795 Stmt *Switch, Stmt *Body) {
796 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 }
798
799 /// \brief Build a new while statement.
800 ///
801 /// By default, performs semantic analysis to build the new statement.
802 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000803 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000804 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000805 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000806 Stmt *Body) {
807 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 }
Mike Stump11289f42009-09-09 15:08:12 +0000809
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 /// \brief Build a new do-while statement.
811 ///
812 /// By default, performs semantic analysis to build the new statement.
813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000814 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000815 SourceLocation WhileLoc,
816 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000817 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000819 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
820 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000821 }
822
823 /// \brief Build a new for statement.
824 ///
825 /// By default, performs semantic analysis to build the new statement.
826 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000827 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000828 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000829 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000830 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000831 SourceLocation RParenLoc, Stmt *Body) {
832 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000833 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000834 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000835 }
Mike Stump11289f42009-09-09 15:08:12 +0000836
Douglas Gregorebe10102009-08-20 07:17:43 +0000837 /// \brief Build a new goto statement.
838 ///
839 /// By default, performs semantic analysis to build the new statement.
840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000841 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000842 SourceLocation LabelLoc,
843 LabelStmt *Label) {
844 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
845 }
846
847 /// \brief Build a new indirect goto statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000851 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000853 Expr *Target) {
854 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000855 }
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 /// \brief Build a new return statement.
858 ///
859 /// By default, performs semantic analysis to build the new statement.
860 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000861 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000862 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000863
John McCallb268a282010-08-23 23:25:46 +0000864 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 }
Mike Stump11289f42009-09-09 15:08:12 +0000866
Douglas Gregorebe10102009-08-20 07:17:43 +0000867 /// \brief Build a new declaration statement.
868 ///
869 /// By default, performs semantic analysis to build the new statement.
870 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000871 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000872 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000873 SourceLocation EndLoc) {
874 return getSema().Owned(
875 new (getSema().Context) DeclStmt(
876 DeclGroupRef::Create(getSema().Context,
877 Decls, NumDecls),
878 StartLoc, EndLoc));
879 }
Mike Stump11289f42009-09-09 15:08:12 +0000880
Anders Carlssonaaeef072010-01-24 05:50:09 +0000881 /// \brief Build a new inline asm statement.
882 ///
883 /// By default, performs semantic analysis to build the new statement.
884 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000885 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000886 bool IsSimple,
887 bool IsVolatile,
888 unsigned NumOutputs,
889 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000890 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000891 MultiExprArg Constraints,
892 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000893 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000894 MultiExprArg Clobbers,
895 SourceLocation RParenLoc,
896 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000897 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000898 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000899 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000900 RParenLoc, MSAsm);
901 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000902
903 /// \brief Build a new Objective-C @try statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000907 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000908 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000909 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000910 Stmt *Finally) {
911 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
912 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000913 }
914
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000915 /// \brief Rebuild an Objective-C exception declaration.
916 ///
917 /// By default, performs semantic analysis to build the new declaration.
918 /// Subclasses may override this routine to provide different behavior.
919 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
920 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000921 return getSema().BuildObjCExceptionDecl(TInfo, T,
922 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 ExceptionDecl->getLocation());
924 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000925
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000926 /// \brief Build a new Objective-C @catch statement.
927 ///
928 /// By default, performs semantic analysis to build the new statement.
929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000930 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000931 SourceLocation RParenLoc,
932 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000933 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000934 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000935 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000936 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000937
Douglas Gregor306de2f2010-04-22 23:59:56 +0000938 /// \brief Build a new Objective-C @finally statement.
939 ///
940 /// By default, performs semantic analysis to build the new statement.
941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000942 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000943 Stmt *Body) {
944 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000945 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000946
Douglas Gregor6148de72010-04-22 22:01:21 +0000947 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000948 ///
949 /// By default, performs semantic analysis to build the new statement.
950 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000951 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000952 Expr *Operand) {
953 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000954 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000955
Douglas Gregor6148de72010-04-22 22:01:21 +0000956 /// \brief Build a new Objective-C @synchronized statement.
957 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000958 /// By default, performs semantic analysis to build the new statement.
959 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000960 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000961 Expr *Object,
962 Stmt *Body) {
963 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
964 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000965 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000966
967 /// \brief Build a new Objective-C fast enumeration statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000971 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000972 SourceLocation LParenLoc,
973 Stmt *Element,
974 Expr *Collection,
975 SourceLocation RParenLoc,
976 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000977 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Element,
979 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000980 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000981 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000982 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000983
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 /// \brief Build a new C++ exception declaration.
985 ///
986 /// By default, performs semantic analysis to build the new decaration.
987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000988 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +0000989 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000990 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000991 SourceLocation Loc) {
992 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
994
995 /// \brief Build a new C++ catch statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001000 VarDecl *ExceptionDecl,
1001 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001002 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1003 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new C++ try statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001010 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001011 Stmt *TryBlock,
1012 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001013 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001014 }
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 /// \brief Build a new expression that references a declaration.
1017 ///
1018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001020 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001021 LookupResult &R,
1022 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001023 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1024 }
1025
1026
1027 /// \brief Build a new expression that references a declaration.
1028 ///
1029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001031 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001032 SourceRange QualifierRange,
1033 ValueDecl *VD,
1034 const DeclarationNameInfo &NameInfo,
1035 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001036 CXXScopeSpec SS;
1037 SS.setScopeRep(Qualifier);
1038 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001039
1040 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001041
1042 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 }
Mike Stump11289f42009-09-09 15:08:12 +00001044
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001046 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 /// By default, performs semantic analysis to build the new expression.
1048 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001049 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001051 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 }
1053
Douglas Gregorad8a3362009-09-04 17:36:40 +00001054 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001055 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001056 /// By default, performs semantic analysis to build the new expression.
1057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001058 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001059 SourceLocation OperatorLoc,
1060 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001061 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001062 SourceRange QualifierRange,
1063 TypeSourceInfo *ScopeType,
1064 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001065 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001066 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001072 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001073 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001074 Expr *SubExpr) {
1075 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 }
Mike Stump11289f42009-09-09 15:08:12 +00001077
Douglas Gregor882211c2010-04-28 22:16:22 +00001078 /// \brief Build a new builtin offsetof expression.
1079 ///
1080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001082 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001083 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001084 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001085 unsigned NumComponents,
1086 SourceLocation RParenLoc) {
1087 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1088 NumComponents, RParenLoc);
1089 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001092 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 /// By default, performs semantic analysis to build the new expression.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001095 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001096 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001098 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 }
1100
Mike Stump11289f42009-09-09 15:08:12 +00001101 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// By default, performs semantic analysis to build the new expression.
1105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001106 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001108 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001109 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 return move(Result);
1114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001117 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 /// By default, performs semantic analysis to build the new expression.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001122 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001124 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1125 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 RBracketLoc);
1127 }
1128
1129 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001130 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001131 /// By default, performs semantic analysis to build the new expression.
1132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001133 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001136 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001137 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 }
1139
1140 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001141 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// By default, performs semantic analysis to build the new expression.
1143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001144 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001145 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001146 NestedNameSpecifier *Qualifier,
1147 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001148 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001149 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001150 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001151 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001152 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001153 if (!Member->getDeclName()) {
1154 // We have a reference to an unnamed field.
1155 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001156
John McCallb268a282010-08-23 23:25:46 +00001157 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001158 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001159 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001160
Mike Stump11289f42009-09-09 15:08:12 +00001161 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001162 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001163 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001164 cast<FieldDecl>(Member)->getType());
1165 return getSema().Owned(ME);
1166 }
Mike Stump11289f42009-09-09 15:08:12 +00001167
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001168 CXXScopeSpec SS;
1169 if (Qualifier) {
1170 SS.setRange(QualifierRange);
1171 SS.setScopeRep(Qualifier);
1172 }
1173
John McCallb268a282010-08-23 23:25:46 +00001174 getSema().DefaultFunctionArrayConversion(Base);
1175 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001176
John McCall16df1e52010-03-30 21:47:33 +00001177 // FIXME: this involves duplicating earlier analysis in a lot of
1178 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001179 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001180 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001181 R.resolveKind();
1182
John McCallb268a282010-08-23 23:25:46 +00001183 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001184 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001185 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 }
Mike Stump11289f42009-09-09 15:08:12 +00001187
Douglas Gregora16548e2009-08-11 05:31:07 +00001188 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001189 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001190 /// By default, performs semantic analysis to build the new expression.
1191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001192 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001193 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001194 Expr *LHS, Expr *RHS) {
1195 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 }
1197
1198 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001199 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 /// By default, performs semantic analysis to build the new expression.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001204 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001205 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001206 Expr *RHS) {
1207 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1208 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 }
1210
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 /// By default, performs semantic analysis to build the new expression.
1214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001215 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001216 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001218 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001219 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001220 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 }
Mike Stump11289f42009-09-09 15:08:12 +00001222
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 /// By default, performs semantic analysis to build the new expression.
1226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001227 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001228 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001230 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001231 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001232 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 }
Mike Stump11289f42009-09-09 15:08:12 +00001234
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001236 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 /// By default, performs semantic analysis to build the new expression.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 SourceLocation OpLoc,
1241 SourceLocation AccessorLoc,
1242 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001243
John McCall10eae182009-11-30 22:42:35 +00001244 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001245 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001246 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001247 OpLoc, /*IsArrow*/ false,
1248 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001249 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001250 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 }
Mike Stump11289f42009-09-09 15:08:12 +00001252
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001254 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 /// By default, performs semantic analysis to build the new expression.
1256 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001257 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001259 SourceLocation RBraceLoc,
1260 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001261 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001262 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1263 if (Result.isInvalid() || ResultTy->isDependentType())
1264 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001265
Douglas Gregord3d93062009-11-09 17:16:50 +00001266 // Patch in the result type we were given, which may have been computed
1267 // when the initial InitListExpr was built.
1268 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1269 ILE->setType(ResultTy);
1270 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 }
Mike Stump11289f42009-09-09 15:08:12 +00001272
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001274 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 MultiExprArg ArrayExprs,
1279 SourceLocation EqualOrColonLoc,
1280 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001281 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001282 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001284 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001287
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 ArrayExprs.release();
1289 return move(Result);
1290 }
Mike Stump11289f42009-09-09 15:08:12 +00001291
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001293 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 /// By default, builds the implicit value initialization without performing
1295 /// any semantic analysis. Subclasses may override this routine to provide
1296 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001297 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1299 }
Mike Stump11289f42009-09-09 15:08:12 +00001300
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001302 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 /// By default, performs semantic analysis to build the new expression.
1304 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001305 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001306 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001307 SourceLocation RParenLoc) {
1308 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001309 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001310 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 }
1312
1313 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 /// By default, performs semantic analysis to build the new expression.
1316 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001317 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 MultiExprArg SubExprs,
1319 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001320 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001321 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 }
Mike Stump11289f42009-09-09 15:08:12 +00001323
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001325 ///
1326 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 /// rather than attempting to map the label statement itself.
1328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001329 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 SourceLocation LabelLoc,
1331 LabelStmt *Label) {
1332 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1333 }
Mike Stump11289f42009-09-09 15:08:12 +00001334
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001336 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001340 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001342 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 }
Mike Stump11289f42009-09-09 15:08:12 +00001344
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// \brief Build a new __builtin_types_compatible_p expression.
1346 ///
1347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001349 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001350 TypeSourceInfo *TInfo1,
1351 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001353 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1354 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 RParenLoc);
1356 }
Mike Stump11289f42009-09-09 15:08:12 +00001357
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// \brief Build a new __builtin_choose_expr expression.
1359 ///
1360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001362 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001363 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 SourceLocation RParenLoc) {
1365 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001366 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 RParenLoc);
1368 }
Mike Stump11289f42009-09-09 15:08:12 +00001369
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 /// \brief Build a new overloaded operator call expression.
1371 ///
1372 /// By default, performs semantic analysis to build the new expression.
1373 /// The semantic analysis provides the behavior of template instantiation,
1374 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001375 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 /// argument-dependent lookup, etc. Subclasses may override this routine to
1377 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001378 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001380 Expr *Callee,
1381 Expr *First,
1382 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001383
1384 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// reinterpret_cast.
1386 ///
1387 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001388 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001390 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 Stmt::StmtClass Class,
1392 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001393 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 SourceLocation RAngleLoc,
1395 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001396 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 SourceLocation RParenLoc) {
1398 switch (Class) {
1399 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001402 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001403
1404 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001405 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001406 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001407 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001408
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001410 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001411 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001412 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001416 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001417 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001418 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001419
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 default:
1421 assert(false && "Invalid C++ named cast");
1422 break;
1423 }
Mike Stump11289f42009-09-09 15:08:12 +00001424
John McCallfaf5fb42010-08-26 23:41:50 +00001425 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 }
Mike Stump11289f42009-09-09 15:08:12 +00001427
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 /// \brief Build a new C++ static_cast expression.
1429 ///
1430 /// By default, performs semantic analysis to build the new expression.
1431 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001432 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001434 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 SourceLocation RAngleLoc,
1436 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001437 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001439 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001440 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001441 SourceRange(LAngleLoc, RAngleLoc),
1442 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 }
1444
1445 /// \brief Build a new C++ dynamic_cast expression.
1446 ///
1447 /// By default, performs semantic analysis to build the new expression.
1448 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001449 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001451 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 SourceLocation RAngleLoc,
1453 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001454 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001456 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001457 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001458 SourceRange(LAngleLoc, RAngleLoc),
1459 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 }
1461
1462 /// \brief Build a new C++ reinterpret_cast expression.
1463 ///
1464 /// By default, performs semantic analysis to build the new expression.
1465 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001466 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001468 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 SourceLocation RAngleLoc,
1470 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001471 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001473 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001474 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001475 SourceRange(LAngleLoc, RAngleLoc),
1476 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 }
1478
1479 /// \brief Build a new C++ const_cast expression.
1480 ///
1481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001483 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001485 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 SourceLocation RAngleLoc,
1487 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001488 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001490 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001491 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001492 SourceRange(LAngleLoc, RAngleLoc),
1493 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 }
Mike Stump11289f42009-09-09 15:08:12 +00001495
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 /// \brief Build a new C++ functional-style cast expression.
1497 ///
1498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001500 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1501 SourceLocation LParenLoc,
1502 Expr *Sub,
1503 SourceLocation RParenLoc) {
1504 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001505 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 RParenLoc);
1507 }
Mike Stump11289f42009-09-09 15:08:12 +00001508
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 /// \brief Build a new C++ typeid(type) expression.
1510 ///
1511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001513 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001514 SourceLocation TypeidLoc,
1515 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001517 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001518 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 }
Mike Stump11289f42009-09-09 15:08:12 +00001520
Francois Pichet9f4f2072010-09-08 12:20:18 +00001521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// \brief Build a new C++ typeid(expr) expression.
1523 ///
1524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001526 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001527 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001528 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001530 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001531 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001532 }
1533
Francois Pichet9f4f2072010-09-08 12:20:18 +00001534 /// \brief Build a new C++ __uuidof(type) expression.
1535 ///
1536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
1538 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1539 SourceLocation TypeidLoc,
1540 TypeSourceInfo *Operand,
1541 SourceLocation RParenLoc) {
1542 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1543 RParenLoc);
1544 }
1545
1546 /// \brief Build a new C++ __uuidof(expr) expression.
1547 ///
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
1550 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1551 SourceLocation TypeidLoc,
1552 Expr *Operand,
1553 SourceLocation RParenLoc) {
1554 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1555 RParenLoc);
1556 }
1557
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// \brief Build a new C++ "this" expression.
1559 ///
1560 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001561 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001563 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001564 QualType ThisType,
1565 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001567 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1568 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 }
1570
1571 /// \brief Build a new C++ throw expression.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001575 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001576 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 }
1578
1579 /// \brief Build a new C++ default-argument expression.
1580 ///
1581 /// By default, builds a new default-argument expression, which does not
1582 /// require any semantic analysis. Subclasses may override this routine to
1583 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001584 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001585 ParmVarDecl *Param) {
1586 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1587 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 }
1589
1590 /// \brief Build a new C++ zero-initialization expression.
1591 ///
1592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001594 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1595 SourceLocation LParenLoc,
1596 SourceLocation RParenLoc) {
1597 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001598 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001599 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 }
Mike Stump11289f42009-09-09 15:08:12 +00001601
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 /// \brief Build a new C++ "new" expression.
1603 ///
1604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001606 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001607 bool UseGlobal,
1608 SourceLocation PlacementLParen,
1609 MultiExprArg PlacementArgs,
1610 SourceLocation PlacementRParen,
1611 SourceRange TypeIdParens,
1612 QualType AllocatedType,
1613 TypeSourceInfo *AllocatedTypeInfo,
1614 Expr *ArraySize,
1615 SourceLocation ConstructorLParen,
1616 MultiExprArg ConstructorArgs,
1617 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001618 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 PlacementLParen,
1620 move(PlacementArgs),
1621 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001622 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001623 AllocatedType,
1624 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001625 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 ConstructorLParen,
1627 move(ConstructorArgs),
1628 ConstructorRParen);
1629 }
Mike Stump11289f42009-09-09 15:08:12 +00001630
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 /// \brief Build a new C++ "delete" expression.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001635 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 bool IsGlobalDelete,
1637 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001638 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001640 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 }
Mike Stump11289f42009-09-09 15:08:12 +00001642
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 /// \brief Build a new unary type trait expression.
1644 ///
1645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001647 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001648 SourceLocation StartLoc,
1649 TypeSourceInfo *T,
1650 SourceLocation RParenLoc) {
1651 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 }
1653
Mike Stump11289f42009-09-09 15:08:12 +00001654 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 /// expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001659 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001661 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001662 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 CXXScopeSpec SS;
1664 SS.setRange(QualifierRange);
1665 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001666
1667 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001668 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001669 *TemplateArgs);
1670
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001671 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 }
1673
1674 /// \brief Build a new template-id expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001678 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001679 LookupResult &R,
1680 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001681 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001682 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 }
1684
1685 /// \brief Build a new object-construction expression.
1686 ///
1687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001689 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001690 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 CXXConstructorDecl *Constructor,
1692 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001693 MultiExprArg Args,
1694 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001695 CXXConstructExpr::ConstructionKind ConstructKind,
1696 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001697 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001698 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001699 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001700 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001701
Douglas Gregordb121ba2009-12-14 16:27:04 +00001702 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001703 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001704 RequiresZeroInit, ConstructKind,
1705 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 }
1707
1708 /// \brief Build a new object-construction expression.
1709 ///
1710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001712 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1713 SourceLocation LParenLoc,
1714 MultiExprArg Args,
1715 SourceLocation RParenLoc) {
1716 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 LParenLoc,
1718 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 RParenLoc);
1720 }
1721
1722 /// \brief Build a new object-construction expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001726 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1727 SourceLocation LParenLoc,
1728 MultiExprArg Args,
1729 SourceLocation RParenLoc) {
1730 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 LParenLoc,
1732 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 RParenLoc);
1734 }
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 /// \brief Build a new member reference expression.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001740 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001741 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 bool IsArrow,
1743 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001744 NestedNameSpecifier *Qualifier,
1745 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001746 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001747 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001748 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001750 SS.setRange(QualifierRange);
1751 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001752
John McCallb268a282010-08-23 23:25:46 +00001753 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001754 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001755 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001756 MemberNameInfo,
1757 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 }
1759
John McCall10eae182009-11-30 22:42:35 +00001760 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001764 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001765 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001766 SourceLocation OperatorLoc,
1767 bool IsArrow,
1768 NestedNameSpecifier *Qualifier,
1769 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001770 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001771 LookupResult &R,
1772 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001773 CXXScopeSpec SS;
1774 SS.setRange(QualifierRange);
1775 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001776
John McCallb268a282010-08-23 23:25:46 +00001777 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001778 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001779 SS, FirstQualifierInScope,
1780 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001781 }
Mike Stump11289f42009-09-09 15:08:12 +00001782
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001783 /// \brief Build a new noexcept expression.
1784 ///
1785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
1787 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1788 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1789 }
1790
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 /// \brief Build a new Objective-C @encode expression.
1792 ///
1793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001795 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001796 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001798 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001800 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001801
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001802 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001803 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001804 Selector Sel,
1805 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001806 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001807 MultiExprArg Args,
1808 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001809 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1810 ReceiverTypeInfo->getType(),
1811 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001812 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001813 move(Args));
1814 }
1815
1816 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001817 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001818 Selector Sel,
1819 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001820 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001821 MultiExprArg Args,
1822 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001823 return SemaRef.BuildInstanceMessage(Receiver,
1824 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001825 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001826 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001827 move(Args));
1828 }
1829
Douglas Gregord51d90d2010-04-26 20:11:03 +00001830 /// \brief Build a new Objective-C ivar reference expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001834 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001835 SourceLocation IvarLoc,
1836 bool IsArrow, bool IsFreeIvar) {
1837 // FIXME: We lose track of the IsFreeIvar bit.
1838 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001839 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001840 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1841 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001842 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001843 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001844 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001845 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001846 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001847 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001848
Douglas Gregord51d90d2010-04-26 20:11:03 +00001849 if (Result.get())
1850 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001851
John McCallb268a282010-08-23 23:25:46 +00001852 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001853 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001854 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001855 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001856 /*TemplateArgs=*/0);
1857 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001858
1859 /// \brief Build a new Objective-C property reference expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
1862 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001863 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001864 ObjCPropertyDecl *Property,
1865 SourceLocation PropertyLoc) {
1866 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001867 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001868 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1869 Sema::LookupMemberName);
1870 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001871 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001872 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001873 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001874 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001875 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001876
Douglas Gregor9faee212010-04-26 20:47:02 +00001877 if (Result.get())
1878 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001879
John McCallb268a282010-08-23 23:25:46 +00001880 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001881 /*FIXME:*/PropertyLoc, IsArrow,
1882 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001883 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001884 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001885 /*TemplateArgs=*/0);
1886 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001887
1888 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001889 /// expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001892 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001893 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001894 ObjCMethodDecl *Getter,
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001895 QualType T,
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001896 ObjCMethodDecl *Setter,
1897 SourceLocation NameLoc,
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001898 Expr *Base,
1899 SourceLocation SuperLoc,
1900 QualType SuperTy,
1901 bool Super) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001902 // Since these expressions can only be value-dependent, we do not need to
1903 // perform semantic analysis again.
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001904 if (Super)
1905 return Owned(
1906 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1907 Setter,
1908 NameLoc,
1909 SuperLoc,
1910 SuperTy));
1911 else
1912 return Owned(
1913 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(
1914 Getter, T,
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001915 Setter,
1916 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001917 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001918 }
1919
Douglas Gregord51d90d2010-04-26 20:11:03 +00001920 /// \brief Build a new Objective-C "isa" expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001924 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001925 bool IsArrow) {
1926 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001927 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001928 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1929 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001931 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001932 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001933 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001934 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001935
Douglas Gregord51d90d2010-04-26 20:11:03 +00001936 if (Result.get())
1937 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001938
John McCallb268a282010-08-23 23:25:46 +00001939 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001940 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001941 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001942 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001943 /*TemplateArgs=*/0);
1944 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001945
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// \brief Build a new shuffle vector expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001950 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 MultiExprArg SubExprs,
1952 SourceLocation RParenLoc) {
1953 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001954 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1956 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1957 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1958 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001959
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 // Build a reference to the __builtin_shufflevector builtin
1961 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001962 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001964 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001966
1967 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 unsigned NumSubExprs = SubExprs.size();
1969 Expr **Subs = (Expr **)SubExprs.release();
1970 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1971 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001972 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001974 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001975
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001977 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001980
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001982 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 }
John McCall31f82722010-11-12 08:19:04 +00001984
1985private:
1986 QualType TransformTypeInObjectScope(QualType T,
1987 QualType ObjectType,
1988 NamedDecl *FirstQualifierInScope,
1989 NestedNameSpecifier *Prefix);
1990
1991 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
1992 QualType ObjectType,
1993 NamedDecl *FirstQualifierInScope,
1994 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001995};
Douglas Gregora16548e2009-08-11 05:31:07 +00001996
Douglas Gregorebe10102009-08-20 07:17:43 +00001997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001998StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001999 if (!S)
2000 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002001
Douglas Gregorebe10102009-08-20 07:17:43 +00002002 switch (S->getStmtClass()) {
2003 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002004
Douglas Gregorebe10102009-08-20 07:17:43 +00002005 // Transform individual statement nodes
2006#define STMT(Node, Parent) \
2007 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2008#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002009#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002010
Douglas Gregorebe10102009-08-20 07:17:43 +00002011 // Transform expressions by calling TransformExpr.
2012#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002013#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002014#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002015#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002016 {
John McCalldadc5752010-08-24 06:29:42 +00002017 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002018 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002019 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002020
John McCallb268a282010-08-23 23:25:46 +00002021 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002022 }
Mike Stump11289f42009-09-09 15:08:12 +00002023 }
2024
John McCallc3007a22010-10-26 07:05:15 +00002025 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002026}
Mike Stump11289f42009-09-09 15:08:12 +00002027
2028
Douglas Gregore922c772009-08-04 22:27:00 +00002029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002030ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 if (!E)
2032 return SemaRef.Owned(E);
2033
2034 switch (E->getStmtClass()) {
2035 case Stmt::NoStmtClass: break;
2036#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002037#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002038#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002039 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002040#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002041 }
2042
John McCallc3007a22010-10-26 07:05:15 +00002043 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002044}
2045
2046template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002047NestedNameSpecifier *
2048TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002049 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002050 QualType ObjectType,
2051 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002052 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregorebe10102009-08-20 07:17:43 +00002054 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002055 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002056 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002057 ObjectType,
2058 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002059 if (!Prefix)
2060 return 0;
2061 }
Mike Stump11289f42009-09-09 15:08:12 +00002062
Douglas Gregor1135c352009-08-06 05:28:30 +00002063 switch (NNS->getKind()) {
2064 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002065 if (Prefix) {
2066 // The object type and qualifier-in-scope really apply to the
2067 // leftmost entity.
2068 ObjectType = QualType();
2069 FirstQualifierInScope = 0;
2070 }
2071
Mike Stump11289f42009-09-09 15:08:12 +00002072 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002073 "Identifier nested-name-specifier with no prefix or object type");
2074 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2075 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002076 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002077
2078 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002079 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002080 ObjectType,
2081 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002082
Douglas Gregor1135c352009-08-06 05:28:30 +00002083 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002084 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002085 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002086 getDerived().TransformDecl(Range.getBegin(),
2087 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002088 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002089 Prefix == NNS->getPrefix() &&
2090 NS == NNS->getAsNamespace())
2091 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002092
Douglas Gregor1135c352009-08-06 05:28:30 +00002093 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2094 }
Mike Stump11289f42009-09-09 15:08:12 +00002095
Douglas Gregor1135c352009-08-06 05:28:30 +00002096 case NestedNameSpecifier::Global:
2097 // There is no meaningful transformation that one could perform on the
2098 // global scope.
2099 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002100
Douglas Gregor1135c352009-08-06 05:28:30 +00002101 case NestedNameSpecifier::TypeSpecWithTemplate:
2102 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002103 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002104 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2105 ObjectType,
2106 FirstQualifierInScope,
2107 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002108 if (T.isNull())
2109 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002110
Douglas Gregor1135c352009-08-06 05:28:30 +00002111 if (!getDerived().AlwaysRebuild() &&
2112 Prefix == NNS->getPrefix() &&
2113 T == QualType(NNS->getAsType(), 0))
2114 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002115
2116 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2117 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002118 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002119 }
2120 }
Mike Stump11289f42009-09-09 15:08:12 +00002121
Douglas Gregor1135c352009-08-06 05:28:30 +00002122 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002123 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002124}
2125
2126template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002127DeclarationNameInfo
2128TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002129::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002130 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002131 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002132 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002133
2134 switch (Name.getNameKind()) {
2135 case DeclarationName::Identifier:
2136 case DeclarationName::ObjCZeroArgSelector:
2137 case DeclarationName::ObjCOneArgSelector:
2138 case DeclarationName::ObjCMultiArgSelector:
2139 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002140 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002141 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002142 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002143
Douglas Gregorf816bd72009-09-03 22:13:48 +00002144 case DeclarationName::CXXConstructorName:
2145 case DeclarationName::CXXDestructorName:
2146 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002147 TypeSourceInfo *NewTInfo;
2148 CanQualType NewCanTy;
2149 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002150 NewTInfo = getDerived().TransformType(OldTInfo);
2151 if (!NewTInfo)
2152 return DeclarationNameInfo();
2153 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002154 }
2155 else {
2156 NewTInfo = 0;
2157 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002158 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002159 if (NewT.isNull())
2160 return DeclarationNameInfo();
2161 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2162 }
Mike Stump11289f42009-09-09 15:08:12 +00002163
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002164 DeclarationName NewName
2165 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2166 NewCanTy);
2167 DeclarationNameInfo NewNameInfo(NameInfo);
2168 NewNameInfo.setName(NewName);
2169 NewNameInfo.setNamedTypeInfo(NewTInfo);
2170 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002171 }
Mike Stump11289f42009-09-09 15:08:12 +00002172 }
2173
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002174 assert(0 && "Unknown name kind.");
2175 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002176}
2177
2178template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002179TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002180TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002181 QualType ObjectType,
2182 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002183 SourceLocation Loc = getDerived().getBaseLocation();
2184
Douglas Gregor71dc5092009-08-06 06:41:21 +00002185 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002186 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002188 /*FIXME*/ SourceRange(Loc),
2189 ObjectType,
2190 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002191 if (!NNS)
2192 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002193
Douglas Gregor71dc5092009-08-06 06:41:21 +00002194 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002195 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002196 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002197 if (!TransTemplate)
2198 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregor71dc5092009-08-06 06:41:21 +00002200 if (!getDerived().AlwaysRebuild() &&
2201 NNS == QTN->getQualifier() &&
2202 TransTemplate == Template)
2203 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002204
Douglas Gregor71dc5092009-08-06 06:41:21 +00002205 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2206 TransTemplate);
2207 }
Mike Stump11289f42009-09-09 15:08:12 +00002208
John McCalle66edc12009-11-24 19:00:30 +00002209 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002210 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002211 }
Mike Stump11289f42009-09-09 15:08:12 +00002212
Douglas Gregor71dc5092009-08-06 06:41:21 +00002213 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002214 NestedNameSpecifier *NNS = DTN->getQualifier();
2215 if (NNS) {
2216 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2217 /*FIXME:*/SourceRange(Loc),
2218 ObjectType,
2219 FirstQualifierInScope);
2220 if (!NNS) return TemplateName();
2221
2222 // These apply to the scope specifier, not the template.
2223 ObjectType = QualType();
2224 FirstQualifierInScope = 0;
2225 }
Mike Stump11289f42009-09-09 15:08:12 +00002226
Douglas Gregor71dc5092009-08-06 06:41:21 +00002227 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002228 NNS == DTN->getQualifier() &&
2229 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002230 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002231
Douglas Gregora5614c52010-09-08 23:56:00 +00002232 if (DTN->isIdentifier()) {
2233 // FIXME: Bad range
2234 SourceRange QualifierRange(getDerived().getBaseLocation());
2235 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2236 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002237 ObjectType,
2238 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002239 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002240
2241 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002242 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002243 }
Mike Stump11289f42009-09-09 15:08:12 +00002244
Douglas Gregor71dc5092009-08-06 06:41:21 +00002245 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002246 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002247 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002248 if (!TransTemplate)
2249 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002250
Douglas Gregor71dc5092009-08-06 06:41:21 +00002251 if (!getDerived().AlwaysRebuild() &&
2252 TransTemplate == Template)
2253 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002254
Douglas Gregor71dc5092009-08-06 06:41:21 +00002255 return TemplateName(TransTemplate);
2256 }
Mike Stump11289f42009-09-09 15:08:12 +00002257
John McCalle66edc12009-11-24 19:00:30 +00002258 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002259 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002260 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002261}
2262
2263template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002264void TreeTransform<Derived>::InventTemplateArgumentLoc(
2265 const TemplateArgument &Arg,
2266 TemplateArgumentLoc &Output) {
2267 SourceLocation Loc = getDerived().getBaseLocation();
2268 switch (Arg.getKind()) {
2269 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002270 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002271 break;
2272
2273 case TemplateArgument::Type:
2274 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002275 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002276
John McCall0ad16662009-10-29 08:12:44 +00002277 break;
2278
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002279 case TemplateArgument::Template:
2280 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2281 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002282
John McCall0ad16662009-10-29 08:12:44 +00002283 case TemplateArgument::Expression:
2284 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2285 break;
2286
2287 case TemplateArgument::Declaration:
2288 case TemplateArgument::Integral:
2289 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002290 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002291 break;
2292 }
2293}
2294
2295template<typename Derived>
2296bool TreeTransform<Derived>::TransformTemplateArgument(
2297 const TemplateArgumentLoc &Input,
2298 TemplateArgumentLoc &Output) {
2299 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002300 switch (Arg.getKind()) {
2301 case TemplateArgument::Null:
2302 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002303 Output = Input;
2304 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002305
Douglas Gregore922c772009-08-04 22:27:00 +00002306 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002307 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002308 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002309 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002310
2311 DI = getDerived().TransformType(DI);
2312 if (!DI) return true;
2313
2314 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2315 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002316 }
Mike Stump11289f42009-09-09 15:08:12 +00002317
Douglas Gregore922c772009-08-04 22:27:00 +00002318 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002319 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002320 DeclarationName Name;
2321 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2322 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002323 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002324 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002325 if (!D) return true;
2326
John McCall0d07eb32009-10-29 18:45:58 +00002327 Expr *SourceExpr = Input.getSourceDeclExpression();
2328 if (SourceExpr) {
2329 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002330 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002331 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002332 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002333 }
2334
2335 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002336 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002337 }
Mike Stump11289f42009-09-09 15:08:12 +00002338
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002339 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002340 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002341 TemplateName Template
2342 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2343 if (Template.isNull())
2344 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002345
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002346 Output = TemplateArgumentLoc(TemplateArgument(Template),
2347 Input.getTemplateQualifierRange(),
2348 Input.getTemplateNameLoc());
2349 return false;
2350 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002351
Douglas Gregore922c772009-08-04 22:27:00 +00002352 case TemplateArgument::Expression: {
2353 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002354 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002355 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002356
John McCall0ad16662009-10-29 08:12:44 +00002357 Expr *InputExpr = Input.getSourceExpression();
2358 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2359
John McCalldadc5752010-08-24 06:29:42 +00002360 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002361 = getDerived().TransformExpr(InputExpr);
2362 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002363 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002364 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002365 }
Mike Stump11289f42009-09-09 15:08:12 +00002366
Douglas Gregore922c772009-08-04 22:27:00 +00002367 case TemplateArgument::Pack: {
2368 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2369 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002370 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002371 AEnd = Arg.pack_end();
2372 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002373
John McCall0ad16662009-10-29 08:12:44 +00002374 // FIXME: preserve source information here when we start
2375 // caring about parameter packs.
2376
John McCall0d07eb32009-10-29 18:45:58 +00002377 TemplateArgumentLoc InputArg;
2378 TemplateArgumentLoc OutputArg;
2379 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2380 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002381 return true;
2382
John McCall0d07eb32009-10-29 18:45:58 +00002383 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002384 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002385
2386 TemplateArgument *TransformedArgsPtr
2387 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2388 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2389 TransformedArgsPtr);
2390 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2391 TransformedArgs.size()),
2392 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002393 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002394 }
2395 }
Mike Stump11289f42009-09-09 15:08:12 +00002396
Douglas Gregore922c772009-08-04 22:27:00 +00002397 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002398 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002399}
2400
Douglas Gregord6ff3322009-08-04 16:50:30 +00002401//===----------------------------------------------------------------------===//
2402// Type transformation
2403//===----------------------------------------------------------------------===//
2404
2405template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002406QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002407 if (getDerived().AlreadyTransformed(T))
2408 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002409
John McCall550e0c22009-10-21 00:40:46 +00002410 // Temporary workaround. All of these transformations should
2411 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002412 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002413 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002414
John McCall31f82722010-11-12 08:19:04 +00002415 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002416
John McCall550e0c22009-10-21 00:40:46 +00002417 if (!NewDI)
2418 return QualType();
2419
2420 return NewDI->getType();
2421}
2422
2423template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002424TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002425 if (getDerived().AlreadyTransformed(DI->getType()))
2426 return DI;
2427
2428 TypeLocBuilder TLB;
2429
2430 TypeLoc TL = DI->getTypeLoc();
2431 TLB.reserve(TL.getFullDataSize());
2432
John McCall31f82722010-11-12 08:19:04 +00002433 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002434 if (Result.isNull())
2435 return 0;
2436
John McCallbcd03502009-12-07 02:54:59 +00002437 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002438}
2439
2440template<typename Derived>
2441QualType
John McCall31f82722010-11-12 08:19:04 +00002442TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002443 switch (T.getTypeLocClass()) {
2444#define ABSTRACT_TYPELOC(CLASS, PARENT)
2445#define TYPELOC(CLASS, PARENT) \
2446 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002447 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002448#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002449 }
Mike Stump11289f42009-09-09 15:08:12 +00002450
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002451 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002452 return QualType();
2453}
2454
2455/// FIXME: By default, this routine adds type qualifiers only to types
2456/// that can have qualifiers, and silently suppresses those qualifiers
2457/// that are not permitted (e.g., qualifiers on reference or function
2458/// types). This is the right thing for template instantiation, but
2459/// probably not for other clients.
2460template<typename Derived>
2461QualType
2462TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002463 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002464 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002465
John McCall31f82722010-11-12 08:19:04 +00002466 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002467 if (Result.isNull())
2468 return QualType();
2469
2470 // Silently suppress qualifiers if the result type can't be qualified.
2471 // FIXME: this is the right thing for template instantiation, but
2472 // probably not for other clients.
2473 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002474 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002475
John McCallcb0f89a2010-06-05 06:41:15 +00002476 if (!Quals.empty()) {
2477 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2478 TLB.push<QualifiedTypeLoc>(Result);
2479 // No location information to preserve.
2480 }
John McCall550e0c22009-10-21 00:40:46 +00002481
2482 return Result;
2483}
2484
John McCall31f82722010-11-12 08:19:04 +00002485/// \brief Transforms a type that was written in a scope specifier,
2486/// given an object type, the results of unqualified lookup, and
2487/// an already-instantiated prefix.
2488///
2489/// The object type is provided iff the scope specifier qualifies the
2490/// member of a dependent member-access expression. The prefix is
2491/// provided iff the the scope specifier in which this appears has a
2492/// prefix.
2493///
2494/// This is private to TreeTransform.
2495template<typename Derived>
2496QualType
2497TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2498 QualType ObjectType,
2499 NamedDecl *UnqualLookup,
2500 NestedNameSpecifier *Prefix) {
2501 if (getDerived().AlreadyTransformed(T))
2502 return T;
2503
2504 TypeSourceInfo *TSI =
2505 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2506
2507 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2508 UnqualLookup, Prefix);
2509 if (!TSI) return QualType();
2510 return TSI->getType();
2511}
2512
2513template<typename Derived>
2514TypeSourceInfo *
2515TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2516 QualType ObjectType,
2517 NamedDecl *UnqualLookup,
2518 NestedNameSpecifier *Prefix) {
2519 // TODO: in some cases, we might be some verification to do here.
2520 if (ObjectType.isNull())
2521 return getDerived().TransformType(TSI);
2522
2523 QualType T = TSI->getType();
2524 if (getDerived().AlreadyTransformed(T))
2525 return TSI;
2526
2527 TypeLocBuilder TLB;
2528 QualType Result;
2529
2530 if (isa<TemplateSpecializationType>(T)) {
2531 TemplateSpecializationTypeLoc TL
2532 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2533
2534 TemplateName Template =
2535 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2536 ObjectType, UnqualLookup);
2537 if (Template.isNull()) return 0;
2538
2539 Result = getDerived()
2540 .TransformTemplateSpecializationType(TLB, TL, Template);
2541 } else if (isa<DependentTemplateSpecializationType>(T)) {
2542 DependentTemplateSpecializationTypeLoc TL
2543 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2544
2545 Result = getDerived()
2546 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2547 } else {
2548 // Nothing special needs to be done for these.
2549 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2550 }
2551
2552 if (Result.isNull()) return 0;
2553 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2554}
2555
John McCall550e0c22009-10-21 00:40:46 +00002556template <class TyLoc> static inline
2557QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2558 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2559 NewT.setNameLoc(T.getNameLoc());
2560 return T.getType();
2561}
2562
John McCall550e0c22009-10-21 00:40:46 +00002563template<typename Derived>
2564QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002565 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002566 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2567 NewT.setBuiltinLoc(T.getBuiltinLoc());
2568 if (T.needsExtraLocalData())
2569 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2570 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002571}
Mike Stump11289f42009-09-09 15:08:12 +00002572
Douglas Gregord6ff3322009-08-04 16:50:30 +00002573template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002574QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002575 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002576 // FIXME: recurse?
2577 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002578}
Mike Stump11289f42009-09-09 15:08:12 +00002579
Douglas Gregord6ff3322009-08-04 16:50:30 +00002580template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002581QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002582 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002583 QualType PointeeType
2584 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002585 if (PointeeType.isNull())
2586 return QualType();
2587
2588 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002589 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002590 // A dependent pointer type 'T *' has is being transformed such
2591 // that an Objective-C class type is being replaced for 'T'. The
2592 // resulting pointer type is an ObjCObjectPointerType, not a
2593 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002594 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002595
John McCall8b07ec22010-05-15 11:32:37 +00002596 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2597 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002598 return Result;
2599 }
John McCall31f82722010-11-12 08:19:04 +00002600
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002601 if (getDerived().AlwaysRebuild() ||
2602 PointeeType != TL.getPointeeLoc().getType()) {
2603 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2604 if (Result.isNull())
2605 return QualType();
2606 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002607
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002608 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2609 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002610 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002611}
Mike Stump11289f42009-09-09 15:08:12 +00002612
2613template<typename Derived>
2614QualType
John McCall550e0c22009-10-21 00:40:46 +00002615TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002616 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002617 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002618 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2619 if (PointeeType.isNull())
2620 return QualType();
2621
2622 QualType Result = TL.getType();
2623 if (getDerived().AlwaysRebuild() ||
2624 PointeeType != TL.getPointeeLoc().getType()) {
2625 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002626 TL.getSigilLoc());
2627 if (Result.isNull())
2628 return QualType();
2629 }
2630
Douglas Gregor049211a2010-04-22 16:50:51 +00002631 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002632 NewT.setSigilLoc(TL.getSigilLoc());
2633 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002634}
2635
John McCall70dd5f62009-10-30 00:06:24 +00002636/// Transforms a reference type. Note that somewhat paradoxically we
2637/// don't care whether the type itself is an l-value type or an r-value
2638/// type; we only care if the type was *written* as an l-value type
2639/// or an r-value type.
2640template<typename Derived>
2641QualType
2642TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002643 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002644 const ReferenceType *T = TL.getTypePtr();
2645
2646 // Note that this works with the pointee-as-written.
2647 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2648 if (PointeeType.isNull())
2649 return QualType();
2650
2651 QualType Result = TL.getType();
2652 if (getDerived().AlwaysRebuild() ||
2653 PointeeType != T->getPointeeTypeAsWritten()) {
2654 Result = getDerived().RebuildReferenceType(PointeeType,
2655 T->isSpelledAsLValue(),
2656 TL.getSigilLoc());
2657 if (Result.isNull())
2658 return QualType();
2659 }
2660
2661 // r-value references can be rebuilt as l-value references.
2662 ReferenceTypeLoc NewTL;
2663 if (isa<LValueReferenceType>(Result))
2664 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2665 else
2666 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2667 NewTL.setSigilLoc(TL.getSigilLoc());
2668
2669 return Result;
2670}
2671
Mike Stump11289f42009-09-09 15:08:12 +00002672template<typename Derived>
2673QualType
John McCall550e0c22009-10-21 00:40:46 +00002674TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002675 LValueReferenceTypeLoc TL) {
2676 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002677}
2678
Mike Stump11289f42009-09-09 15:08:12 +00002679template<typename Derived>
2680QualType
John McCall550e0c22009-10-21 00:40:46 +00002681TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002682 RValueReferenceTypeLoc TL) {
2683 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002684}
Mike Stump11289f42009-09-09 15:08:12 +00002685
Douglas Gregord6ff3322009-08-04 16:50:30 +00002686template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002687QualType
John McCall550e0c22009-10-21 00:40:46 +00002688TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002689 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002690 MemberPointerType *T = TL.getTypePtr();
2691
2692 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002693 if (PointeeType.isNull())
2694 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002695
John McCall550e0c22009-10-21 00:40:46 +00002696 // TODO: preserve source information for this.
2697 QualType ClassType
2698 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002699 if (ClassType.isNull())
2700 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002701
John McCall550e0c22009-10-21 00:40:46 +00002702 QualType Result = TL.getType();
2703 if (getDerived().AlwaysRebuild() ||
2704 PointeeType != T->getPointeeType() ||
2705 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002706 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2707 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002708 if (Result.isNull())
2709 return QualType();
2710 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002711
John McCall550e0c22009-10-21 00:40:46 +00002712 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2713 NewTL.setSigilLoc(TL.getSigilLoc());
2714
2715 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002716}
2717
Mike Stump11289f42009-09-09 15:08:12 +00002718template<typename Derived>
2719QualType
John McCall550e0c22009-10-21 00:40:46 +00002720TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002721 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002722 ConstantArrayType *T = TL.getTypePtr();
2723 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002724 if (ElementType.isNull())
2725 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002726
John McCall550e0c22009-10-21 00:40:46 +00002727 QualType Result = TL.getType();
2728 if (getDerived().AlwaysRebuild() ||
2729 ElementType != T->getElementType()) {
2730 Result = getDerived().RebuildConstantArrayType(ElementType,
2731 T->getSizeModifier(),
2732 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002733 T->getIndexTypeCVRQualifiers(),
2734 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002735 if (Result.isNull())
2736 return QualType();
2737 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002738
John McCall550e0c22009-10-21 00:40:46 +00002739 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2740 NewTL.setLBracketLoc(TL.getLBracketLoc());
2741 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002742
John McCall550e0c22009-10-21 00:40:46 +00002743 Expr *Size = TL.getSizeExpr();
2744 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002745 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002746 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2747 }
2748 NewTL.setSizeExpr(Size);
2749
2750 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751}
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregord6ff3322009-08-04 16:50:30 +00002753template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002754QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002755 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002756 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002757 IncompleteArrayType *T = TL.getTypePtr();
2758 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759 if (ElementType.isNull())
2760 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002761
John McCall550e0c22009-10-21 00:40:46 +00002762 QualType Result = TL.getType();
2763 if (getDerived().AlwaysRebuild() ||
2764 ElementType != T->getElementType()) {
2765 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002767 T->getIndexTypeCVRQualifiers(),
2768 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002769 if (Result.isNull())
2770 return QualType();
2771 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002772
John McCall550e0c22009-10-21 00:40:46 +00002773 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2774 NewTL.setLBracketLoc(TL.getLBracketLoc());
2775 NewTL.setRBracketLoc(TL.getRBracketLoc());
2776 NewTL.setSizeExpr(0);
2777
2778 return Result;
2779}
2780
2781template<typename Derived>
2782QualType
2783TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002784 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002785 VariableArrayType *T = TL.getTypePtr();
2786 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2787 if (ElementType.isNull())
2788 return QualType();
2789
2790 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002791 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002792
John McCalldadc5752010-08-24 06:29:42 +00002793 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002794 = getDerived().TransformExpr(T->getSizeExpr());
2795 if (SizeResult.isInvalid())
2796 return QualType();
2797
John McCallb268a282010-08-23 23:25:46 +00002798 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002799
2800 QualType Result = TL.getType();
2801 if (getDerived().AlwaysRebuild() ||
2802 ElementType != T->getElementType() ||
2803 Size != T->getSizeExpr()) {
2804 Result = getDerived().RebuildVariableArrayType(ElementType,
2805 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002806 Size,
John McCall550e0c22009-10-21 00:40:46 +00002807 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002808 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002809 if (Result.isNull())
2810 return QualType();
2811 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002812
John McCall550e0c22009-10-21 00:40:46 +00002813 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2814 NewTL.setLBracketLoc(TL.getLBracketLoc());
2815 NewTL.setRBracketLoc(TL.getRBracketLoc());
2816 NewTL.setSizeExpr(Size);
2817
2818 return Result;
2819}
2820
2821template<typename Derived>
2822QualType
2823TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002824 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002825 DependentSizedArrayType *T = TL.getTypePtr();
2826 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2827 if (ElementType.isNull())
2828 return QualType();
2829
2830 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002831 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002832
John McCalldadc5752010-08-24 06:29:42 +00002833 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002834 = getDerived().TransformExpr(T->getSizeExpr());
2835 if (SizeResult.isInvalid())
2836 return QualType();
2837
2838 Expr *Size = static_cast<Expr*>(SizeResult.get());
2839
2840 QualType Result = TL.getType();
2841 if (getDerived().AlwaysRebuild() ||
2842 ElementType != T->getElementType() ||
2843 Size != T->getSizeExpr()) {
2844 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2845 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002846 Size,
John McCall550e0c22009-10-21 00:40:46 +00002847 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002848 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002849 if (Result.isNull())
2850 return QualType();
2851 }
2852 else SizeResult.take();
2853
2854 // We might have any sort of array type now, but fortunately they
2855 // all have the same location layout.
2856 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2857 NewTL.setLBracketLoc(TL.getLBracketLoc());
2858 NewTL.setRBracketLoc(TL.getRBracketLoc());
2859 NewTL.setSizeExpr(Size);
2860
2861 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002862}
Mike Stump11289f42009-09-09 15:08:12 +00002863
2864template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002865QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002866 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002867 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002868 DependentSizedExtVectorType *T = TL.getTypePtr();
2869
2870 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002871 QualType ElementType = getDerived().TransformType(T->getElementType());
2872 if (ElementType.isNull())
2873 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002874
Douglas Gregore922c772009-08-04 22:27:00 +00002875 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002876 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002877
John McCalldadc5752010-08-24 06:29:42 +00002878 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002879 if (Size.isInvalid())
2880 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002881
John McCall550e0c22009-10-21 00:40:46 +00002882 QualType Result = TL.getType();
2883 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002884 ElementType != T->getElementType() ||
2885 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002886 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002887 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002888 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002889 if (Result.isNull())
2890 return QualType();
2891 }
John McCall550e0c22009-10-21 00:40:46 +00002892
2893 // Result might be dependent or not.
2894 if (isa<DependentSizedExtVectorType>(Result)) {
2895 DependentSizedExtVectorTypeLoc NewTL
2896 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2897 NewTL.setNameLoc(TL.getNameLoc());
2898 } else {
2899 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2900 NewTL.setNameLoc(TL.getNameLoc());
2901 }
2902
2903 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002904}
Mike Stump11289f42009-09-09 15:08:12 +00002905
2906template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002907QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002908 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002909 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002910 QualType ElementType = getDerived().TransformType(T->getElementType());
2911 if (ElementType.isNull())
2912 return QualType();
2913
John McCall550e0c22009-10-21 00:40:46 +00002914 QualType Result = TL.getType();
2915 if (getDerived().AlwaysRebuild() ||
2916 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002917 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00002918 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00002919 if (Result.isNull())
2920 return QualType();
2921 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002922
John McCall550e0c22009-10-21 00:40:46 +00002923 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2924 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002925
John McCall550e0c22009-10-21 00:40:46 +00002926 return Result;
2927}
2928
2929template<typename Derived>
2930QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002931 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002932 VectorType *T = TL.getTypePtr();
2933 QualType ElementType = getDerived().TransformType(T->getElementType());
2934 if (ElementType.isNull())
2935 return QualType();
2936
2937 QualType Result = TL.getType();
2938 if (getDerived().AlwaysRebuild() ||
2939 ElementType != T->getElementType()) {
2940 Result = getDerived().RebuildExtVectorType(ElementType,
2941 T->getNumElements(),
2942 /*FIXME*/ SourceLocation());
2943 if (Result.isNull())
2944 return QualType();
2945 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002946
John McCall550e0c22009-10-21 00:40:46 +00002947 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2948 NewTL.setNameLoc(TL.getNameLoc());
2949
2950 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002951}
Mike Stump11289f42009-09-09 15:08:12 +00002952
2953template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002954ParmVarDecl *
2955TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2956 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2957 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2958 if (!NewDI)
2959 return 0;
2960
2961 if (NewDI == OldDI)
2962 return OldParm;
2963 else
2964 return ParmVarDecl::Create(SemaRef.Context,
2965 OldParm->getDeclContext(),
2966 OldParm->getLocation(),
2967 OldParm->getIdentifier(),
2968 NewDI->getType(),
2969 NewDI,
2970 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002971 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002972 /* DefArg */ NULL);
2973}
2974
2975template<typename Derived>
2976bool TreeTransform<Derived>::
2977 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2978 llvm::SmallVectorImpl<QualType> &PTypes,
2979 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2980 FunctionProtoType *T = TL.getTypePtr();
2981
2982 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2983 ParmVarDecl *OldParm = TL.getArg(i);
2984
2985 QualType NewType;
2986 ParmVarDecl *NewParm;
2987
2988 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002989 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2990 if (!NewParm)
2991 return true;
2992 NewType = NewParm->getType();
2993
2994 // Deal with the possibility that we don't have a parameter
2995 // declaration for this parameter.
2996 } else {
2997 NewParm = 0;
2998
2999 QualType OldType = T->getArgType(i);
3000 NewType = getDerived().TransformType(OldType);
3001 if (NewType.isNull())
3002 return true;
3003 }
3004
3005 PTypes.push_back(NewType);
3006 PVars.push_back(NewParm);
3007 }
3008
3009 return false;
3010}
3011
3012template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003013QualType
John McCall550e0c22009-10-21 00:40:46 +00003014TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003015 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003016 // Transform the parameters and return type.
3017 //
3018 // We instantiate in source order, with the return type first followed by
3019 // the parameters, because users tend to expect this (even if they shouldn't
3020 // rely on it!).
3021 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003022 // When the function has a trailing return type, we instantiate the
3023 // parameters before the return type, since the return type can then refer
3024 // to the parameters themselves (via decltype, sizeof, etc.).
3025 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003026 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003027 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003028 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003029
Douglas Gregor7fb25412010-10-01 18:44:50 +00003030 QualType ResultType;
3031
3032 if (TL.getTrailingReturn()) {
3033 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3034 return QualType();
3035
3036 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3037 if (ResultType.isNull())
3038 return QualType();
3039 }
3040 else {
3041 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3042 if (ResultType.isNull())
3043 return QualType();
3044
3045 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3046 return QualType();
3047 }
3048
John McCall550e0c22009-10-21 00:40:46 +00003049 QualType Result = TL.getType();
3050 if (getDerived().AlwaysRebuild() ||
3051 ResultType != T->getResultType() ||
3052 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3053 Result = getDerived().RebuildFunctionProtoType(ResultType,
3054 ParamTypes.data(),
3055 ParamTypes.size(),
3056 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003057 T->getTypeQuals(),
3058 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003059 if (Result.isNull())
3060 return QualType();
3061 }
Mike Stump11289f42009-09-09 15:08:12 +00003062
John McCall550e0c22009-10-21 00:40:46 +00003063 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3064 NewTL.setLParenLoc(TL.getLParenLoc());
3065 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003066 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003067 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3068 NewTL.setArg(i, ParamDecls[i]);
3069
3070 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003071}
Mike Stump11289f42009-09-09 15:08:12 +00003072
Douglas Gregord6ff3322009-08-04 16:50:30 +00003073template<typename Derived>
3074QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003075 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003076 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003077 FunctionNoProtoType *T = TL.getTypePtr();
3078 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3079 if (ResultType.isNull())
3080 return QualType();
3081
3082 QualType Result = TL.getType();
3083 if (getDerived().AlwaysRebuild() ||
3084 ResultType != T->getResultType())
3085 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3086
3087 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3088 NewTL.setLParenLoc(TL.getLParenLoc());
3089 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003090 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003091
3092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093}
Mike Stump11289f42009-09-09 15:08:12 +00003094
John McCallb96ec562009-12-04 22:46:56 +00003095template<typename Derived> QualType
3096TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003097 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003098 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003099 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003100 if (!D)
3101 return QualType();
3102
3103 QualType Result = TL.getType();
3104 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3105 Result = getDerived().RebuildUnresolvedUsingType(D);
3106 if (Result.isNull())
3107 return QualType();
3108 }
3109
3110 // We might get an arbitrary type spec type back. We should at
3111 // least always get a type spec type, though.
3112 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3113 NewTL.setNameLoc(TL.getNameLoc());
3114
3115 return Result;
3116}
3117
Douglas Gregord6ff3322009-08-04 16:50:30 +00003118template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003119QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003120 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003121 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003122 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003123 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3124 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003125 if (!Typedef)
3126 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003127
John McCall550e0c22009-10-21 00:40:46 +00003128 QualType Result = TL.getType();
3129 if (getDerived().AlwaysRebuild() ||
3130 Typedef != T->getDecl()) {
3131 Result = getDerived().RebuildTypedefType(Typedef);
3132 if (Result.isNull())
3133 return QualType();
3134 }
Mike Stump11289f42009-09-09 15:08:12 +00003135
John McCall550e0c22009-10-21 00:40:46 +00003136 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3137 NewTL.setNameLoc(TL.getNameLoc());
3138
3139 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140}
Mike Stump11289f42009-09-09 15:08:12 +00003141
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003143QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003144 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003145 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003146 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003147
John McCalldadc5752010-08-24 06:29:42 +00003148 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003149 if (E.isInvalid())
3150 return QualType();
3151
John McCall550e0c22009-10-21 00:40:46 +00003152 QualType Result = TL.getType();
3153 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003154 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003155 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003156 if (Result.isNull())
3157 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003158 }
John McCall550e0c22009-10-21 00:40:46 +00003159 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003160
John McCall550e0c22009-10-21 00:40:46 +00003161 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003162 NewTL.setTypeofLoc(TL.getTypeofLoc());
3163 NewTL.setLParenLoc(TL.getLParenLoc());
3164 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003165
3166 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003167}
Mike Stump11289f42009-09-09 15:08:12 +00003168
3169template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003170QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003171 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003172 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3173 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3174 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003175 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003176
John McCall550e0c22009-10-21 00:40:46 +00003177 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003178 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3179 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003180 if (Result.isNull())
3181 return QualType();
3182 }
Mike Stump11289f42009-09-09 15:08:12 +00003183
John McCall550e0c22009-10-21 00:40:46 +00003184 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003185 NewTL.setTypeofLoc(TL.getTypeofLoc());
3186 NewTL.setLParenLoc(TL.getLParenLoc());
3187 NewTL.setRParenLoc(TL.getRParenLoc());
3188 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003189
3190 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003191}
Mike Stump11289f42009-09-09 15:08:12 +00003192
3193template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003194QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003195 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003196 DecltypeType *T = TL.getTypePtr();
3197
Douglas Gregore922c772009-08-04 22:27:00 +00003198 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003199 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003200
John McCalldadc5752010-08-24 06:29:42 +00003201 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003202 if (E.isInvalid())
3203 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003204
John McCall550e0c22009-10-21 00:40:46 +00003205 QualType Result = TL.getType();
3206 if (getDerived().AlwaysRebuild() ||
3207 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003208 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003209 if (Result.isNull())
3210 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003211 }
John McCall550e0c22009-10-21 00:40:46 +00003212 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003213
John McCall550e0c22009-10-21 00:40:46 +00003214 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3215 NewTL.setNameLoc(TL.getNameLoc());
3216
3217 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003218}
3219
3220template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003221QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003222 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003223 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003224 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003225 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3226 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003227 if (!Record)
3228 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003229
John McCall550e0c22009-10-21 00:40:46 +00003230 QualType Result = TL.getType();
3231 if (getDerived().AlwaysRebuild() ||
3232 Record != T->getDecl()) {
3233 Result = getDerived().RebuildRecordType(Record);
3234 if (Result.isNull())
3235 return QualType();
3236 }
Mike Stump11289f42009-09-09 15:08:12 +00003237
John McCall550e0c22009-10-21 00:40:46 +00003238 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3239 NewTL.setNameLoc(TL.getNameLoc());
3240
3241 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003242}
Mike Stump11289f42009-09-09 15:08:12 +00003243
3244template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003245QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003246 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003247 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003248 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003249 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3250 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251 if (!Enum)
3252 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003253
John McCall550e0c22009-10-21 00:40:46 +00003254 QualType Result = TL.getType();
3255 if (getDerived().AlwaysRebuild() ||
3256 Enum != T->getDecl()) {
3257 Result = getDerived().RebuildEnumType(Enum);
3258 if (Result.isNull())
3259 return QualType();
3260 }
Mike Stump11289f42009-09-09 15:08:12 +00003261
John McCall550e0c22009-10-21 00:40:46 +00003262 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3263 NewTL.setNameLoc(TL.getNameLoc());
3264
3265 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003266}
John McCallfcc33b02009-09-05 00:15:47 +00003267
John McCalle78aac42010-03-10 03:28:59 +00003268template<typename Derived>
3269QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3270 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003271 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003272 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3273 TL.getTypePtr()->getDecl());
3274 if (!D) return QualType();
3275
3276 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3277 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3278 return T;
3279}
3280
Mike Stump11289f42009-09-09 15:08:12 +00003281
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282template<typename Derived>
3283QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003284 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003285 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003286 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003287}
3288
Mike Stump11289f42009-09-09 15:08:12 +00003289template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003290QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003291 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003292 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003293 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003294}
3295
3296template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003297QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003298 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003299 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003300 const TemplateSpecializationType *T = TL.getTypePtr();
3301
Mike Stump11289f42009-09-09 15:08:12 +00003302 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003303 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304 if (Template.isNull())
3305 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003306
John McCall31f82722010-11-12 08:19:04 +00003307 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3308}
3309
3310template <typename Derived>
3311QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3312 TypeLocBuilder &TLB,
3313 TemplateSpecializationTypeLoc TL,
3314 TemplateName Template) {
3315 const TemplateSpecializationType *T = TL.getTypePtr();
3316
John McCall6b51f282009-11-23 01:53:49 +00003317 TemplateArgumentListInfo NewTemplateArgs;
3318 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3319 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3320
3321 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3322 TemplateArgumentLoc Loc;
3323 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003324 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003325 NewTemplateArgs.addArgument(Loc);
3326 }
Mike Stump11289f42009-09-09 15:08:12 +00003327
John McCall0ad16662009-10-29 08:12:44 +00003328 // FIXME: maybe don't rebuild if all the template arguments are the same.
3329
3330 QualType Result =
3331 getDerived().RebuildTemplateSpecializationType(Template,
3332 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003333 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003334
3335 if (!Result.isNull()) {
3336 TemplateSpecializationTypeLoc NewTL
3337 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3338 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3339 NewTL.setLAngleLoc(TL.getLAngleLoc());
3340 NewTL.setRAngleLoc(TL.getRAngleLoc());
3341 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3342 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003343 }
Mike Stump11289f42009-09-09 15:08:12 +00003344
John McCall0ad16662009-10-29 08:12:44 +00003345 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003346}
Mike Stump11289f42009-09-09 15:08:12 +00003347
3348template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003349QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003350TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003351 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003352 ElaboratedType *T = TL.getTypePtr();
3353
3354 NestedNameSpecifier *NNS = 0;
3355 // NOTE: the qualifier in an ElaboratedType is optional.
3356 if (T->getQualifier() != 0) {
3357 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003358 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003359 if (!NNS)
3360 return QualType();
3361 }
Mike Stump11289f42009-09-09 15:08:12 +00003362
John McCall31f82722010-11-12 08:19:04 +00003363 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3364 if (NamedT.isNull())
3365 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003366
John McCall550e0c22009-10-21 00:40:46 +00003367 QualType Result = TL.getType();
3368 if (getDerived().AlwaysRebuild() ||
3369 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003370 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003371 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3372 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003373 if (Result.isNull())
3374 return QualType();
3375 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003376
Abramo Bagnara6150c882010-05-11 21:36:43 +00003377 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003378 NewTL.setKeywordLoc(TL.getKeywordLoc());
3379 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003380
3381 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003382}
Mike Stump11289f42009-09-09 15:08:12 +00003383
3384template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003385QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003386 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003387 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003388
Douglas Gregord6ff3322009-08-04 16:50:30 +00003389 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003390 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003391 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003392 if (!NNS)
3393 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003394
John McCallc392f372010-06-11 00:33:02 +00003395 QualType Result
3396 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3397 T->getIdentifier(),
3398 TL.getKeywordLoc(),
3399 TL.getQualifierRange(),
3400 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003401 if (Result.isNull())
3402 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003403
Abramo Bagnarad7548482010-05-19 21:37:53 +00003404 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3405 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003406 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3407
Abramo Bagnarad7548482010-05-19 21:37:53 +00003408 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3409 NewTL.setKeywordLoc(TL.getKeywordLoc());
3410 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003411 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003412 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3413 NewTL.setKeywordLoc(TL.getKeywordLoc());
3414 NewTL.setQualifierRange(TL.getQualifierRange());
3415 NewTL.setNameLoc(TL.getNameLoc());
3416 }
John McCall550e0c22009-10-21 00:40:46 +00003417 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003418}
Mike Stump11289f42009-09-09 15:08:12 +00003419
Douglas Gregord6ff3322009-08-04 16:50:30 +00003420template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003421QualType TreeTransform<Derived>::
3422 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003423 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003424 DependentTemplateSpecializationType *T = TL.getTypePtr();
3425
3426 NestedNameSpecifier *NNS
3427 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003428 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003429 if (!NNS)
3430 return QualType();
3431
John McCall31f82722010-11-12 08:19:04 +00003432 return getDerived()
3433 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3434}
3435
3436template<typename Derived>
3437QualType TreeTransform<Derived>::
3438 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3439 DependentTemplateSpecializationTypeLoc TL,
3440 NestedNameSpecifier *NNS) {
3441 DependentTemplateSpecializationType *T = TL.getTypePtr();
3442
John McCallc392f372010-06-11 00:33:02 +00003443 TemplateArgumentListInfo NewTemplateArgs;
3444 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3445 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3446
3447 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3448 TemplateArgumentLoc Loc;
3449 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3450 return QualType();
3451 NewTemplateArgs.addArgument(Loc);
3452 }
3453
Douglas Gregora5614c52010-09-08 23:56:00 +00003454 QualType Result
3455 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3456 NNS,
3457 TL.getQualifierRange(),
3458 T->getIdentifier(),
3459 TL.getNameLoc(),
3460 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003461 if (Result.isNull())
3462 return QualType();
3463
3464 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3465 QualType NamedT = ElabT->getNamedType();
3466
3467 // Copy information relevant to the template specialization.
3468 TemplateSpecializationTypeLoc NamedTL
3469 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3470 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3471 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3472 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3473 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3474
3475 // Copy information relevant to the elaborated type.
3476 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3477 NewTL.setKeywordLoc(TL.getKeywordLoc());
3478 NewTL.setQualifierRange(TL.getQualifierRange());
3479 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003480 TypeLoc NewTL(Result, TL.getOpaqueData());
3481 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003482 }
3483 return Result;
3484}
3485
3486template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003487QualType
3488TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003489 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003490 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003491 TLB.pushFullCopy(TL);
3492 return TL.getType();
3493}
3494
3495template<typename Derived>
3496QualType
3497TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003498 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003499 // ObjCObjectType is never dependent.
3500 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003501 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003502}
Mike Stump11289f42009-09-09 15:08:12 +00003503
3504template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003505QualType
3506TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003507 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003508 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003509 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003510 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003511}
3512
Douglas Gregord6ff3322009-08-04 16:50:30 +00003513//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003514// Statement transformation
3515//===----------------------------------------------------------------------===//
3516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003517StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003518TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003519 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003520}
3521
3522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003523StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003524TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3525 return getDerived().TransformCompoundStmt(S, false);
3526}
3527
3528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003529StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003530TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003532 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003533 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003534 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003535 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3536 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003537 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003538 if (Result.isInvalid()) {
3539 // Immediately fail if this was a DeclStmt, since it's very
3540 // likely that this will cause problems for future statements.
3541 if (isa<DeclStmt>(*B))
3542 return StmtError();
3543
3544 // Otherwise, just keep processing substatements and fail later.
3545 SubStmtInvalid = true;
3546 continue;
3547 }
Mike Stump11289f42009-09-09 15:08:12 +00003548
Douglas Gregorebe10102009-08-20 07:17:43 +00003549 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3550 Statements.push_back(Result.takeAs<Stmt>());
3551 }
Mike Stump11289f42009-09-09 15:08:12 +00003552
John McCall1ababa62010-08-27 19:56:05 +00003553 if (SubStmtInvalid)
3554 return StmtError();
3555
Douglas Gregorebe10102009-08-20 07:17:43 +00003556 if (!getDerived().AlwaysRebuild() &&
3557 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003558 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003559
3560 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3561 move_arg(Statements),
3562 S->getRBracLoc(),
3563 IsStmtExpr);
3564}
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregorebe10102009-08-20 07:17:43 +00003566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003567StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003568TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003569 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003570 {
3571 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003572 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003573
Eli Friedman06577382009-11-19 03:14:00 +00003574 // Transform the left-hand case value.
3575 LHS = getDerived().TransformExpr(S->getLHS());
3576 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003577 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003578
Eli Friedman06577382009-11-19 03:14:00 +00003579 // Transform the right-hand case value (for the GNU case-range extension).
3580 RHS = getDerived().TransformExpr(S->getRHS());
3581 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003582 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003583 }
Mike Stump11289f42009-09-09 15:08:12 +00003584
Douglas Gregorebe10102009-08-20 07:17:43 +00003585 // Build the case statement.
3586 // Case statements are always rebuilt so that they will attached to their
3587 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003588 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003589 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003590 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003591 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003592 S->getColonLoc());
3593 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003594 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003595
Douglas Gregorebe10102009-08-20 07:17:43 +00003596 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003597 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003598 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003599 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregorebe10102009-08-20 07:17:43 +00003601 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003602 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003603}
3604
3605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003606StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003607TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003608 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003609 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003610 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003611 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003612
Douglas Gregorebe10102009-08-20 07:17:43 +00003613 // Default statements are always rebuilt
3614 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003615 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003616}
Mike Stump11289f42009-09-09 15:08:12 +00003617
Douglas Gregorebe10102009-08-20 07:17:43 +00003618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003619StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003620TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003621 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003622 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003623 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003624
Douglas Gregorebe10102009-08-20 07:17:43 +00003625 // FIXME: Pass the real colon location in.
3626 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3627 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003628 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003629}
Mike Stump11289f42009-09-09 15:08:12 +00003630
Douglas Gregorebe10102009-08-20 07:17:43 +00003631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003632StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003633TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003634 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003635 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003636 VarDecl *ConditionVar = 0;
3637 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003638 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003639 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003640 getDerived().TransformDefinition(
3641 S->getConditionVariable()->getLocation(),
3642 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003643 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003644 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003645 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003646 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003647
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003648 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003649 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003650
3651 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003652 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003653 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003654 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003655 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003656 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003657 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003658
John McCallb268a282010-08-23 23:25:46 +00003659 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003660 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003661 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003662
John McCallb268a282010-08-23 23:25:46 +00003663 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3664 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003665 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003666
Douglas Gregorebe10102009-08-20 07:17:43 +00003667 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003668 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003669 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003670 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003671
Douglas Gregorebe10102009-08-20 07:17:43 +00003672 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003673 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003674 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003675 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003676
Douglas Gregorebe10102009-08-20 07:17:43 +00003677 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003678 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003679 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003680 Then.get() == S->getThen() &&
3681 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003682 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003683
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003684 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003685 Then.get(),
3686 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003687}
3688
3689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003690StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003691TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003692 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003693 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003694 VarDecl *ConditionVar = 0;
3695 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003696 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003697 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003698 getDerived().TransformDefinition(
3699 S->getConditionVariable()->getLocation(),
3700 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003701 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003702 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003703 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003704 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003705
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003706 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003707 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003708 }
Mike Stump11289f42009-09-09 15:08:12 +00003709
Douglas Gregorebe10102009-08-20 07:17:43 +00003710 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003711 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003712 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003713 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003715 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003716
Douglas Gregorebe10102009-08-20 07:17:43 +00003717 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003718 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003719 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003720 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003721
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003723 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3724 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003725}
Mike Stump11289f42009-09-09 15:08:12 +00003726
Douglas Gregorebe10102009-08-20 07:17:43 +00003727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003728StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003729TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003730 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003731 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003732 VarDecl *ConditionVar = 0;
3733 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003734 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003735 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003736 getDerived().TransformDefinition(
3737 S->getConditionVariable()->getLocation(),
3738 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003739 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003740 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003741 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003742 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003743
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003744 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003745 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003746
3747 if (S->getCond()) {
3748 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003749 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003750 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003751 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003752 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003753 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003754 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003755 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003756 }
Mike Stump11289f42009-09-09 15:08:12 +00003757
John McCallb268a282010-08-23 23:25:46 +00003758 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3759 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003760 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003761
Douglas Gregorebe10102009-08-20 07:17:43 +00003762 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003763 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003764 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003765 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003766
Douglas Gregorebe10102009-08-20 07:17:43 +00003767 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003768 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003769 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003771 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003772
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003773 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003774 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003775}
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregorebe10102009-08-20 07:17:43 +00003777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003778StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003779TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003780 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003781 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003783 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003784
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003785 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003786 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003787 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003788 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003789
Douglas Gregorebe10102009-08-20 07:17:43 +00003790 if (!getDerived().AlwaysRebuild() &&
3791 Cond.get() == S->getCond() &&
3792 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003793 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003794
John McCallb268a282010-08-23 23:25:46 +00003795 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3796 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003797 S->getRParenLoc());
3798}
Mike Stump11289f42009-09-09 15:08:12 +00003799
Douglas Gregorebe10102009-08-20 07:17:43 +00003800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003801StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003802TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003803 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003804 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003805 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003806 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003807
Douglas Gregorebe10102009-08-20 07:17:43 +00003808 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003809 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003810 VarDecl *ConditionVar = 0;
3811 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003812 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003813 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003814 getDerived().TransformDefinition(
3815 S->getConditionVariable()->getLocation(),
3816 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003817 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003818 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003819 } else {
3820 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003821
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003822 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003823 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003824
3825 if (S->getCond()) {
3826 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003827 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003828 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003829 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003830 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003831 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003832
John McCallb268a282010-08-23 23:25:46 +00003833 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003834 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003835 }
Mike Stump11289f42009-09-09 15:08:12 +00003836
John McCallb268a282010-08-23 23:25:46 +00003837 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3838 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003839 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003840
Douglas Gregorebe10102009-08-20 07:17:43 +00003841 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003842 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003843 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003844 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003845
John McCallb268a282010-08-23 23:25:46 +00003846 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3847 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003848 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003849
Douglas Gregorebe10102009-08-20 07:17:43 +00003850 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003851 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003852 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003853 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003854
Douglas Gregorebe10102009-08-20 07:17:43 +00003855 if (!getDerived().AlwaysRebuild() &&
3856 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003857 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003858 Inc.get() == S->getInc() &&
3859 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003860 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003861
Douglas Gregorebe10102009-08-20 07:17:43 +00003862 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003863 Init.get(), FullCond, ConditionVar,
3864 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003865}
3866
3867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003868StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003869TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003870 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003871 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003872 S->getLabel());
3873}
3874
3875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003876StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003877TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003878 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003879 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003880 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregorebe10102009-08-20 07:17:43 +00003882 if (!getDerived().AlwaysRebuild() &&
3883 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003884 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003885
3886 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003887 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003888}
3889
3890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003891StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003892TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003893 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003894}
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregorebe10102009-08-20 07:17:43 +00003896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003897StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003898TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003899 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003900}
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregorebe10102009-08-20 07:17:43 +00003902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003903StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003904TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003905 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003906 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003907 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003908
Mike Stump11289f42009-09-09 15:08:12 +00003909 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003910 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003911 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003912}
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregorebe10102009-08-20 07:17:43 +00003914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003915StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003916TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003917 bool DeclChanged = false;
3918 llvm::SmallVector<Decl *, 4> Decls;
3919 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3920 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003921 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3922 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003923 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003924 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003925
Douglas Gregorebe10102009-08-20 07:17:43 +00003926 if (Transformed != *D)
3927 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregorebe10102009-08-20 07:17:43 +00003929 Decls.push_back(Transformed);
3930 }
Mike Stump11289f42009-09-09 15:08:12 +00003931
Douglas Gregorebe10102009-08-20 07:17:43 +00003932 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00003933 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003934
3935 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003936 S->getStartLoc(), S->getEndLoc());
3937}
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregorebe10102009-08-20 07:17:43 +00003939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003940StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003941TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003942 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00003943 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003944}
3945
3946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003947StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003948TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003949
John McCall37ad5512010-08-23 06:44:23 +00003950 ASTOwningVector<Expr*> Constraints(getSema());
3951 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003952 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003953
John McCalldadc5752010-08-24 06:29:42 +00003954 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003955 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003956
3957 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003958
Anders Carlssonaaeef072010-01-24 05:50:09 +00003959 // Go through the outputs.
3960 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003961 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003962
Anders Carlssonaaeef072010-01-24 05:50:09 +00003963 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003964 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003965
Anders Carlssonaaeef072010-01-24 05:50:09 +00003966 // Transform the output expr.
3967 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003968 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003969 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003970 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003971
Anders Carlssonaaeef072010-01-24 05:50:09 +00003972 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003973
John McCallb268a282010-08-23 23:25:46 +00003974 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003975 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003976
Anders Carlssonaaeef072010-01-24 05:50:09 +00003977 // Go through the inputs.
3978 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003979 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003980
Anders Carlssonaaeef072010-01-24 05:50:09 +00003981 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003982 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003983
Anders Carlssonaaeef072010-01-24 05:50:09 +00003984 // Transform the input expr.
3985 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003986 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003987 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003988 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003989
Anders Carlssonaaeef072010-01-24 05:50:09 +00003990 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003991
John McCallb268a282010-08-23 23:25:46 +00003992 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003993 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003994
Anders Carlssonaaeef072010-01-24 05:50:09 +00003995 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00003996 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003997
3998 // Go through the clobbers.
3999 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004000 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004001
4002 // No need to transform the asm string literal.
4003 AsmString = SemaRef.Owned(S->getAsmString());
4004
4005 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4006 S->isSimple(),
4007 S->isVolatile(),
4008 S->getNumOutputs(),
4009 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004010 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004011 move_arg(Constraints),
4012 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004013 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004014 move_arg(Clobbers),
4015 S->getRParenLoc(),
4016 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004017}
4018
4019
4020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004021StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004022TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004023 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004024 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004025 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004026 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004027
Douglas Gregor96c79492010-04-23 22:50:49 +00004028 // Transform the @catch statements (if present).
4029 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004030 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004031 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004032 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004033 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004034 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004035 if (Catch.get() != S->getCatchStmt(I))
4036 AnyCatchChanged = true;
4037 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004038 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004039
Douglas Gregor306de2f2010-04-22 23:59:56 +00004040 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004041 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004042 if (S->getFinallyStmt()) {
4043 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4044 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004045 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004046 }
4047
4048 // If nothing changed, just retain this statement.
4049 if (!getDerived().AlwaysRebuild() &&
4050 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004051 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004052 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004053 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004054
Douglas Gregor306de2f2010-04-22 23:59:56 +00004055 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004056 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4057 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004058}
Mike Stump11289f42009-09-09 15:08:12 +00004059
Douglas Gregorebe10102009-08-20 07:17:43 +00004060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004061StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004062TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004063 // Transform the @catch parameter, if there is one.
4064 VarDecl *Var = 0;
4065 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4066 TypeSourceInfo *TSInfo = 0;
4067 if (FromVar->getTypeSourceInfo()) {
4068 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4069 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004070 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004071 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004072
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004073 QualType T;
4074 if (TSInfo)
4075 T = TSInfo->getType();
4076 else {
4077 T = getDerived().TransformType(FromVar->getType());
4078 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004079 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004080 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004081
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004082 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4083 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004084 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004085 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004086
John McCalldadc5752010-08-24 06:29:42 +00004087 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004088 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004089 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004090
4091 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004092 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004093 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004094}
Mike Stump11289f42009-09-09 15:08:12 +00004095
Douglas Gregorebe10102009-08-20 07:17:43 +00004096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004097StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004098TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004099 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004100 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004101 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004102 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004103
Douglas Gregor306de2f2010-04-22 23:59:56 +00004104 // If nothing changed, just retain this statement.
4105 if (!getDerived().AlwaysRebuild() &&
4106 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004107 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004108
4109 // Build a new statement.
4110 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004111 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004112}
Mike Stump11289f42009-09-09 15:08:12 +00004113
Douglas Gregorebe10102009-08-20 07:17:43 +00004114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004115StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004116TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004117 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004118 if (S->getThrowExpr()) {
4119 Operand = getDerived().TransformExpr(S->getThrowExpr());
4120 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004121 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004122 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004123
Douglas Gregor2900c162010-04-22 21:44:01 +00004124 if (!getDerived().AlwaysRebuild() &&
4125 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004126 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004127
John McCallb268a282010-08-23 23:25:46 +00004128 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004129}
Mike Stump11289f42009-09-09 15:08:12 +00004130
Douglas Gregorebe10102009-08-20 07:17:43 +00004131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004132StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004133TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004134 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004135 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004136 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004137 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004138 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004139
Douglas Gregor6148de72010-04-22 22:01:21 +00004140 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004141 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004142 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004143 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004144
Douglas Gregor6148de72010-04-22 22:01:21 +00004145 // If nothing change, just retain the current statement.
4146 if (!getDerived().AlwaysRebuild() &&
4147 Object.get() == S->getSynchExpr() &&
4148 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004149 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004150
4151 // Build a new statement.
4152 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004153 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004154}
4155
4156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004157StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004158TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004159 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004160 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004161 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004162 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004163 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004164
Douglas Gregorf68a5082010-04-22 23:10:45 +00004165 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004166 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004167 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004168 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004169
Douglas Gregorf68a5082010-04-22 23:10:45 +00004170 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004171 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004172 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004173 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004174
Douglas Gregorf68a5082010-04-22 23:10:45 +00004175 // If nothing changed, just retain this statement.
4176 if (!getDerived().AlwaysRebuild() &&
4177 Element.get() == S->getElement() &&
4178 Collection.get() == S->getCollection() &&
4179 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004180 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004181
Douglas Gregorf68a5082010-04-22 23:10:45 +00004182 // Build a new statement.
4183 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4184 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004185 Element.get(),
4186 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004187 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004188 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004189}
4190
4191
4192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004193StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004194TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4195 // Transform the exception declaration, if any.
4196 VarDecl *Var = 0;
4197 if (S->getExceptionDecl()) {
4198 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004199 TypeSourceInfo *T = getDerived().TransformType(
4200 ExceptionDecl->getTypeSourceInfo());
4201 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004202 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004203
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004204 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004205 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004206 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004207 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004208 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004209 }
Mike Stump11289f42009-09-09 15:08:12 +00004210
Douglas Gregorebe10102009-08-20 07:17:43 +00004211 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004212 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004213 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004214 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004215
Douglas Gregorebe10102009-08-20 07:17:43 +00004216 if (!getDerived().AlwaysRebuild() &&
4217 !Var &&
4218 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004219 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004220
4221 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4222 Var,
John McCallb268a282010-08-23 23:25:46 +00004223 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004224}
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregorebe10102009-08-20 07:17:43 +00004226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004227StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004228TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4229 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004230 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004231 = getDerived().TransformCompoundStmt(S->getTryBlock());
4232 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004233 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004234
Douglas Gregorebe10102009-08-20 07:17:43 +00004235 // Transform the handlers.
4236 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004237 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004238 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004239 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004240 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4241 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004242 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004243
Douglas Gregorebe10102009-08-20 07:17:43 +00004244 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4245 Handlers.push_back(Handler.takeAs<Stmt>());
4246 }
Mike Stump11289f42009-09-09 15:08:12 +00004247
Douglas Gregorebe10102009-08-20 07:17:43 +00004248 if (!getDerived().AlwaysRebuild() &&
4249 TryBlock.get() == S->getTryBlock() &&
4250 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004251 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004252
John McCallb268a282010-08-23 23:25:46 +00004253 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004254 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004255}
Mike Stump11289f42009-09-09 15:08:12 +00004256
Douglas Gregorebe10102009-08-20 07:17:43 +00004257//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004258// Expression transformation
4259//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004262TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004263 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004264}
Mike Stump11289f42009-09-09 15:08:12 +00004265
4266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004268TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004269 NestedNameSpecifier *Qualifier = 0;
4270 if (E->getQualifier()) {
4271 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004272 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004273 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004274 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004275 }
John McCallce546572009-12-08 09:08:17 +00004276
4277 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004278 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4279 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004280 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004282
John McCall815039a2010-08-17 21:27:17 +00004283 DeclarationNameInfo NameInfo = E->getNameInfo();
4284 if (NameInfo.getName()) {
4285 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4286 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004287 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004288 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004289
4290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004291 Qualifier == E->getQualifier() &&
4292 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004293 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004294 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004295
4296 // Mark it referenced in the new context regardless.
4297 // FIXME: this is a bit instantiation-specific.
4298 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4299
John McCallc3007a22010-10-26 07:05:15 +00004300 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004301 }
John McCallce546572009-12-08 09:08:17 +00004302
4303 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004304 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004305 TemplateArgs = &TransArgs;
4306 TransArgs.setLAngleLoc(E->getLAngleLoc());
4307 TransArgs.setRAngleLoc(E->getRAngleLoc());
4308 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4309 TemplateArgumentLoc Loc;
4310 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004311 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004312 TransArgs.addArgument(Loc);
4313 }
4314 }
4315
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004316 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004317 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004318}
Mike Stump11289f42009-09-09 15:08:12 +00004319
Douglas Gregora16548e2009-08-11 05:31:07 +00004320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004322TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004323 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004324}
Mike Stump11289f42009-09-09 15:08:12 +00004325
Douglas Gregora16548e2009-08-11 05:31:07 +00004326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004328TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004329 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004330}
Mike Stump11289f42009-09-09 15:08:12 +00004331
Douglas Gregora16548e2009-08-11 05:31:07 +00004332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004334TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004335 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004336}
Mike Stump11289f42009-09-09 15:08:12 +00004337
Douglas Gregora16548e2009-08-11 05:31:07 +00004338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004340TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004341 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004342}
Mike Stump11289f42009-09-09 15:08:12 +00004343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004346TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004347 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004348}
4349
4350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004352TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004353 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004356
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004358 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004359
John McCallb268a282010-08-23 23:25:46 +00004360 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 E->getRParen());
4362}
4363
Mike Stump11289f42009-09-09 15:08:12 +00004364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004366TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004367 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004368 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004369 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004370
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004372 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4375 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004376 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004377}
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004380ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004381TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4382 // Transform the type.
4383 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4384 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004385 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004386
Douglas Gregor882211c2010-04-28 22:16:22 +00004387 // Transform all of the components into components similar to what the
4388 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004389 // FIXME: It would be slightly more efficient in the non-dependent case to
4390 // just map FieldDecls, rather than requiring the rebuilder to look for
4391 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004392 // template code that we don't care.
4393 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004394 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004395 typedef OffsetOfExpr::OffsetOfNode Node;
4396 llvm::SmallVector<Component, 4> Components;
4397 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4398 const Node &ON = E->getComponent(I);
4399 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004400 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004401 Comp.LocStart = ON.getRange().getBegin();
4402 Comp.LocEnd = ON.getRange().getEnd();
4403 switch (ON.getKind()) {
4404 case Node::Array: {
4405 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004406 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004407 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004408 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004409
Douglas Gregor882211c2010-04-28 22:16:22 +00004410 ExprChanged = ExprChanged || Index.get() != FromIndex;
4411 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004412 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004413 break;
4414 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004415
Douglas Gregor882211c2010-04-28 22:16:22 +00004416 case Node::Field:
4417 case Node::Identifier:
4418 Comp.isBrackets = false;
4419 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004420 if (!Comp.U.IdentInfo)
4421 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004422
Douglas Gregor882211c2010-04-28 22:16:22 +00004423 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004424
Douglas Gregord1702062010-04-29 00:18:15 +00004425 case Node::Base:
4426 // Will be recomputed during the rebuild.
4427 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004428 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004429
Douglas Gregor882211c2010-04-28 22:16:22 +00004430 Components.push_back(Comp);
4431 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004432
Douglas Gregor882211c2010-04-28 22:16:22 +00004433 // If nothing changed, retain the existing expression.
4434 if (!getDerived().AlwaysRebuild() &&
4435 Type == E->getTypeSourceInfo() &&
4436 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004437 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004438
Douglas Gregor882211c2010-04-28 22:16:22 +00004439 // Build a new offsetof expression.
4440 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4441 Components.data(), Components.size(),
4442 E->getRParenLoc());
4443}
4444
4445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004447TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004449 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004450
John McCallbcd03502009-12-07 02:54:59 +00004451 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004452 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004454
John McCall4c98fd82009-11-04 07:28:41 +00004455 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004456 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004457
John McCall4c98fd82009-11-04 07:28:41 +00004458 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004459 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 E->getSourceRange());
4461 }
Mike Stump11289f42009-09-09 15:08:12 +00004462
John McCalldadc5752010-08-24 06:29:42 +00004463 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004464 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004465 // C++0x [expr.sizeof]p1:
4466 // The operand is either an expression, which is an unevaluated operand
4467 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004468 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004469
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4471 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004472 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004475 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 }
Mike Stump11289f42009-09-09 15:08:12 +00004477
John McCallb268a282010-08-23 23:25:46 +00004478 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 E->isSizeOf(),
4480 E->getSourceRange());
4481}
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004485TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004486 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004489
John McCalldadc5752010-08-24 06:29:42 +00004490 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004491 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004493
4494
Douglas Gregora16548e2009-08-11 05:31:07 +00004495 if (!getDerived().AlwaysRebuild() &&
4496 LHS.get() == E->getLHS() &&
4497 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004498 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004499
John McCallb268a282010-08-23 23:25:46 +00004500 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004501 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004502 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004503 E->getRBracketLoc());
4504}
Mike Stump11289f42009-09-09 15:08:12 +00004505
4506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004507ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004508TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004510 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004512 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004513
4514 // Transform arguments.
4515 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004516 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004517 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004518 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004521
Mike Stump11289f42009-09-09 15:08:12 +00004522 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004523 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004524 }
Mike Stump11289f42009-09-09 15:08:12 +00004525
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 if (!getDerived().AlwaysRebuild() &&
4527 Callee.get() == E->getCallee() &&
4528 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004529 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004530
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004532 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004534 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 E->getRParenLoc());
4537}
Mike Stump11289f42009-09-09 15:08:12 +00004538
4539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004541TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004542 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004543 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004545
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004546 NestedNameSpecifier *Qualifier = 0;
4547 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004548 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004549 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004550 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004551 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004552 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004553 }
Mike Stump11289f42009-09-09 15:08:12 +00004554
Eli Friedman2cfcef62009-12-04 06:40:45 +00004555 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004556 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4557 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004559 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004560
John McCall16df1e52010-03-30 21:47:33 +00004561 NamedDecl *FoundDecl = E->getFoundDecl();
4562 if (FoundDecl == E->getMemberDecl()) {
4563 FoundDecl = Member;
4564 } else {
4565 FoundDecl = cast_or_null<NamedDecl>(
4566 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4567 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004568 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004569 }
4570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 if (!getDerived().AlwaysRebuild() &&
4572 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004573 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004574 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004575 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004576 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004577
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004578 // Mark it referenced in the new context regardless.
4579 // FIXME: this is a bit instantiation-specific.
4580 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004581 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004582 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004583
John McCall6b51f282009-11-23 01:53:49 +00004584 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004585 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004586 TransArgs.setLAngleLoc(E->getLAngleLoc());
4587 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004588 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004589 TemplateArgumentLoc Loc;
4590 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004591 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004592 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004593 }
4594 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004595
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 // FIXME: Bogus source location for the operator
4597 SourceLocation FakeOperatorLoc
4598 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4599
John McCall38836f02010-01-15 08:34:02 +00004600 // FIXME: to do this check properly, we will need to preserve the
4601 // first-qualifier-in-scope here, just in case we had a dependent
4602 // base (and therefore couldn't do the check) and a
4603 // nested-name-qualifier (and therefore could do the lookup).
4604 NamedDecl *FirstQualifierInScope = 0;
4605
John McCallb268a282010-08-23 23:25:46 +00004606 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004608 Qualifier,
4609 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004610 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004611 Member,
John McCall16df1e52010-03-30 21:47:33 +00004612 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004613 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004614 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004615 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004616}
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregora16548e2009-08-11 05:31:07 +00004618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004620TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004621 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004624
John McCalldadc5752010-08-24 06:29:42 +00004625 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004626 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004627 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004628
Douglas Gregora16548e2009-08-11 05:31:07 +00004629 if (!getDerived().AlwaysRebuild() &&
4630 LHS.get() == E->getLHS() &&
4631 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004632 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004633
Douglas Gregora16548e2009-08-11 05:31:07 +00004634 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004635 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004636}
4637
Mike Stump11289f42009-09-09 15:08:12 +00004638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004639ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004640TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004641 CompoundAssignOperator *E) {
4642 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004643}
Mike Stump11289f42009-09-09 15:08:12 +00004644
Douglas Gregora16548e2009-08-11 05:31:07 +00004645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004647TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004648 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004649 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004651
John McCalldadc5752010-08-24 06:29:42 +00004652 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004653 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004654 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004655
John McCalldadc5752010-08-24 06:29:42 +00004656 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 if (!getDerived().AlwaysRebuild() &&
4661 Cond.get() == E->getCond() &&
4662 LHS.get() == E->getLHS() &&
4663 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004664 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004665
John McCallb268a282010-08-23 23:25:46 +00004666 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004667 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004668 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004669 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004670 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
4673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004675TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004676 // Implicit casts are eliminated during transformation, since they
4677 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004678 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004679}
Mike Stump11289f42009-09-09 15:08:12 +00004680
Douglas Gregora16548e2009-08-11 05:31:07 +00004681template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004682ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004683TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004684 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4685 if (!Type)
4686 return ExprError();
4687
John McCalldadc5752010-08-24 06:29:42 +00004688 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004689 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004694 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004696 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004697
John McCall97513962010-01-15 18:39:57 +00004698 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004699 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004701 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004702}
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004706TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004707 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4708 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4709 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004711
John McCalldadc5752010-08-24 06:29:42 +00004712 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004715
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004717 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004719 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004720
John McCall5d7aa7f2010-01-19 22:33:45 +00004721 // Note: the expression type doesn't necessarily match the
4722 // type-as-written, but that's okay, because it should always be
4723 // derivable from the initializer.
4724
John McCalle15bbff2010-01-18 19:35:47 +00004725 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004727 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004728}
Mike Stump11289f42009-09-09 15:08:12 +00004729
Douglas Gregora16548e2009-08-11 05:31:07 +00004730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004731ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004732TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004733 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004734 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004736
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 if (!getDerived().AlwaysRebuild() &&
4738 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004739 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004740
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004742 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004744 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004745 E->getAccessorLoc(),
4746 E->getAccessor());
4747}
Mike Stump11289f42009-09-09 15:08:12 +00004748
Douglas Gregora16548e2009-08-11 05:31:07 +00004749template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004750ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004751TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004753
John McCall37ad5512010-08-23 06:44:23 +00004754 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004756 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregora16548e2009-08-11 05:31:07 +00004760 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004761 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 }
Mike Stump11289f42009-09-09 15:08:12 +00004763
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004765 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregora16548e2009-08-11 05:31:07 +00004767 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004768 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004769}
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregora16548e2009-08-11 05:31:07 +00004771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004772ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004773TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004774 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregorebe10102009-08-20 07:17:43 +00004776 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004777 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregorebe10102009-08-20 07:17:43 +00004781 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004782 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 bool ExprChanged = false;
4784 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4785 DEnd = E->designators_end();
4786 D != DEnd; ++D) {
4787 if (D->isFieldDesignator()) {
4788 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4789 D->getDotLoc(),
4790 D->getFieldLoc()));
4791 continue;
4792 }
Mike Stump11289f42009-09-09 15:08:12 +00004793
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004795 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004797 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004798
4799 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregora16548e2009-08-11 05:31:07 +00004802 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4803 ArrayExprs.push_back(Index.release());
4804 continue;
4805 }
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004808 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004809 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4810 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004812
John McCalldadc5752010-08-24 06:29:42 +00004813 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004816
4817 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 End.get(),
4819 D->getLBracketLoc(),
4820 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregora16548e2009-08-11 05:31:07 +00004822 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4823 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004824
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 ArrayExprs.push_back(Start.release());
4826 ArrayExprs.push_back(End.release());
4827 }
Mike Stump11289f42009-09-09 15:08:12 +00004828
Douglas Gregora16548e2009-08-11 05:31:07 +00004829 if (!getDerived().AlwaysRebuild() &&
4830 Init.get() == E->getInit() &&
4831 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004832 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004833
Douglas Gregora16548e2009-08-11 05:31:07 +00004834 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4835 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004836 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004837}
Mike Stump11289f42009-09-09 15:08:12 +00004838
Douglas Gregora16548e2009-08-11 05:31:07 +00004839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004840ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004841TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004842 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004843 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004844
Douglas Gregor3da3c062009-10-28 00:29:27 +00004845 // FIXME: Will we ever have proper type location here? Will we actually
4846 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 QualType T = getDerived().TransformType(E->getType());
4848 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004849 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004850
Douglas Gregora16548e2009-08-11 05:31:07 +00004851 if (!getDerived().AlwaysRebuild() &&
4852 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004853 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004854
Douglas Gregora16548e2009-08-11 05:31:07 +00004855 return getDerived().RebuildImplicitValueInitExpr(T);
4856}
Mike Stump11289f42009-09-09 15:08:12 +00004857
Douglas Gregora16548e2009-08-11 05:31:07 +00004858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004860TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004861 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4862 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004864
John McCalldadc5752010-08-24 06:29:42 +00004865 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004866 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004868
Douglas Gregora16548e2009-08-11 05:31:07 +00004869 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004870 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004872 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004873
John McCallb268a282010-08-23 23:25:46 +00004874 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004875 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004876}
4877
4878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004879ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004880TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004881 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004882 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004883 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004884 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004885 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004886 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004887
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004889 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004890 }
Mike Stump11289f42009-09-09 15:08:12 +00004891
Douglas Gregora16548e2009-08-11 05:31:07 +00004892 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4893 move_arg(Inits),
4894 E->getRParenLoc());
4895}
Mike Stump11289f42009-09-09 15:08:12 +00004896
Douglas Gregora16548e2009-08-11 05:31:07 +00004897/// \brief Transform an address-of-label expression.
4898///
4899/// By default, the transformation of an address-of-label expression always
4900/// rebuilds the expression, so that the label identifier can be resolved to
4901/// the corresponding label statement by semantic analysis.
4902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004903ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004904TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004905 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4906 E->getLabel());
4907}
Mike Stump11289f42009-09-09 15:08:12 +00004908
4909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004910ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004911TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004912 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004913 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4914 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004916
Douglas Gregora16548e2009-08-11 05:31:07 +00004917 if (!getDerived().AlwaysRebuild() &&
4918 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00004919 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004920
4921 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004922 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004923 E->getRParenLoc());
4924}
Mike Stump11289f42009-09-09 15:08:12 +00004925
Douglas Gregora16548e2009-08-11 05:31:07 +00004926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004927ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004928TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004929 TypeSourceInfo *TInfo1;
4930 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004931
4932 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4933 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004935
Douglas Gregor7058c262010-08-10 14:27:00 +00004936 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4937 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004938 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004939
4940 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004941 TInfo1 == E->getArgTInfo1() &&
4942 TInfo2 == E->getArgTInfo2())
John McCallc3007a22010-10-26 07:05:15 +00004943 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregora16548e2009-08-11 05:31:07 +00004945 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004946 TInfo1, TInfo2,
4947 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004948}
Mike Stump11289f42009-09-09 15:08:12 +00004949
Douglas Gregora16548e2009-08-11 05:31:07 +00004950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004952TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004953 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004954 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004956
John McCalldadc5752010-08-24 06:29:42 +00004957 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004958 if (LHS.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 RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004962 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004964
Douglas Gregora16548e2009-08-11 05:31:07 +00004965 if (!getDerived().AlwaysRebuild() &&
4966 Cond.get() == E->getCond() &&
4967 LHS.get() == E->getLHS() &&
4968 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004969 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004970
Douglas Gregora16548e2009-08-11 05:31:07 +00004971 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004972 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004973 E->getRParenLoc());
4974}
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregora16548e2009-08-11 05:31:07 +00004976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004978TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004979 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004980}
4981
4982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004984TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004985 switch (E->getOperator()) {
4986 case OO_New:
4987 case OO_Delete:
4988 case OO_Array_New:
4989 case OO_Array_Delete:
4990 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004991 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004992
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004993 case OO_Call: {
4994 // This is a call to an object's operator().
4995 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4996
4997 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004998 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004999 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005000 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005001
5002 // FIXME: Poor location information
5003 SourceLocation FakeLParenLoc
5004 = SemaRef.PP.getLocForEndOfToken(
5005 static_cast<Expr *>(Object.get())->getLocEnd());
5006
5007 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005008 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005009 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00005010 if (getDerived().DropCallArgument(E->getArg(I)))
5011 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005012
John McCalldadc5752010-08-24 06:29:42 +00005013 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005014 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005015 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005016
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005017 Args.push_back(Arg.release());
5018 }
5019
John McCallb268a282010-08-23 23:25:46 +00005020 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005021 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005022 E->getLocEnd());
5023 }
5024
5025#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5026 case OO_##Name:
5027#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5028#include "clang/Basic/OperatorKinds.def"
5029 case OO_Subscript:
5030 // Handled below.
5031 break;
5032
5033 case OO_Conditional:
5034 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005035 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005036
5037 case OO_None:
5038 case NUM_OVERLOADED_OPERATORS:
5039 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005040 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005041 }
5042
John McCalldadc5752010-08-24 06:29:42 +00005043 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005045 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005046
John McCalldadc5752010-08-24 06:29:42 +00005047 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005048 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005049 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005050
John McCalldadc5752010-08-24 06:29:42 +00005051 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 if (E->getNumArgs() == 2) {
5053 Second = getDerived().TransformExpr(E->getArg(1));
5054 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005055 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 }
Mike Stump11289f42009-09-09 15:08:12 +00005057
Douglas Gregora16548e2009-08-11 05:31:07 +00005058 if (!getDerived().AlwaysRebuild() &&
5059 Callee.get() == E->getCallee() &&
5060 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005061 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005062 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005063
Douglas Gregora16548e2009-08-11 05:31:07 +00005064 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5065 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005066 Callee.get(),
5067 First.get(),
5068 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005069}
Mike Stump11289f42009-09-09 15:08:12 +00005070
Douglas Gregora16548e2009-08-11 05:31:07 +00005071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005073TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5074 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005075}
Mike Stump11289f42009-09-09 15:08:12 +00005076
Douglas Gregora16548e2009-08-11 05:31:07 +00005077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005079TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005080 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5081 if (!Type)
5082 return ExprError();
5083
John McCalldadc5752010-08-24 06:29:42 +00005084 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005085 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005087 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005090 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005091 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005092 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005095 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005096 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5097 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5098 SourceLocation FakeRParenLoc
5099 = SemaRef.PP.getLocForEndOfToken(
5100 E->getSubExpr()->getSourceRange().getEnd());
5101 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005102 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005103 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005104 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 FakeRAngleLoc,
5106 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005107 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005108 FakeRParenLoc);
5109}
Mike Stump11289f42009-09-09 15:08:12 +00005110
Douglas Gregora16548e2009-08-11 05:31:07 +00005111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005113TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5114 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005115}
Mike Stump11289f42009-09-09 15:08:12 +00005116
5117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005118ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005119TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5120 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005121}
5122
Douglas Gregora16548e2009-08-11 05:31:07 +00005123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005124ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005125TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005126 CXXReinterpretCastExpr *E) {
5127 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005128}
Mike Stump11289f42009-09-09 15:08:12 +00005129
Douglas Gregora16548e2009-08-11 05:31:07 +00005130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005132TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5133 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005134}
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregora16548e2009-08-11 05:31:07 +00005136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005137ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005138TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005139 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005140 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5141 if (!Type)
5142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005143
John McCalldadc5752010-08-24 06:29:42 +00005144 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005145 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005147 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005148
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005150 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005152 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005153
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005154 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005156 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005157 E->getRParenLoc());
5158}
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregora16548e2009-08-11 05:31:07 +00005160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005162TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005164 TypeSourceInfo *TInfo
5165 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5166 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005167 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005168
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005170 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005171 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregor9da64192010-04-26 22:37:10 +00005173 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5174 E->getLocStart(),
5175 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005176 E->getLocEnd());
5177 }
Mike Stump11289f42009-09-09 15:08:12 +00005178
Douglas Gregora16548e2009-08-11 05:31:07 +00005179 // We don't know whether the expression is potentially evaluated until
5180 // after we perform semantic analysis, so the expression is potentially
5181 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005182 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005183 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005184
John McCalldadc5752010-08-24 06:29:42 +00005185 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005186 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005188
Douglas Gregora16548e2009-08-11 05:31:07 +00005189 if (!getDerived().AlwaysRebuild() &&
5190 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005191 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregor9da64192010-04-26 22:37:10 +00005193 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5194 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005195 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005196 E->getLocEnd());
5197}
5198
5199template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005200ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005201TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5202 if (E->isTypeOperand()) {
5203 TypeSourceInfo *TInfo
5204 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5205 if (!TInfo)
5206 return ExprError();
5207
5208 if (!getDerived().AlwaysRebuild() &&
5209 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005210 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005211
5212 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5213 E->getLocStart(),
5214 TInfo,
5215 E->getLocEnd());
5216 }
5217
5218 // We don't know whether the expression is potentially evaluated until
5219 // after we perform semantic analysis, so the expression is potentially
5220 // potentially evaluated.
5221 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5222
5223 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5224 if (SubExpr.isInvalid())
5225 return ExprError();
5226
5227 if (!getDerived().AlwaysRebuild() &&
5228 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005229 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005230
5231 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5232 E->getLocStart(),
5233 SubExpr.get(),
5234 E->getLocEnd());
5235}
5236
5237template<typename Derived>
5238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005239TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005240 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005241}
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005244ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005245TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005246 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005247 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005248}
Mike Stump11289f42009-09-09 15:08:12 +00005249
Douglas Gregora16548e2009-08-11 05:31:07 +00005250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005251ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005252TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005253 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5254 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5255 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005257 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005258 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregorb15af892010-01-07 23:12:05 +00005260 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005261}
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregora16548e2009-08-11 05:31:07 +00005263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005265TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005266 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005267 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005269
Douglas Gregora16548e2009-08-11 05:31:07 +00005270 if (!getDerived().AlwaysRebuild() &&
5271 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005272 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005273
John McCallb268a282010-08-23 23:25:46 +00005274 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005275}
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregora16548e2009-08-11 05:31:07 +00005277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005279TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005280 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005281 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5282 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005283 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005285
Chandler Carruth794da4c2010-02-08 06:42:49 +00005286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005287 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005288 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregor033f6752009-12-23 23:03:06 +00005290 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005291}
Mike Stump11289f42009-09-09 15:08:12 +00005292
Douglas Gregora16548e2009-08-11 05:31:07 +00005293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005294ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005295TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5296 CXXScalarValueInitExpr *E) {
5297 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5298 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005299 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005300
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005302 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005303 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregor2b88c112010-09-08 00:15:04 +00005305 return getDerived().RebuildCXXScalarValueInitExpr(T,
5306 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005307 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005308}
Mike Stump11289f42009-09-09 15:08:12 +00005309
Douglas Gregora16548e2009-08-11 05:31:07 +00005310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005312TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005313 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005314 TypeSourceInfo *AllocTypeInfo
5315 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5316 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005317 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005318
Douglas Gregora16548e2009-08-11 05:31:07 +00005319 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005320 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005321 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005322 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregora16548e2009-08-11 05:31:07 +00005324 // Transform the placement arguments (if any).
5325 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005326 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005327 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005328 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5329 ArgumentChanged = true;
5330 break;
5331 }
5332
John McCalldadc5752010-08-24 06:29:42 +00005333 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005334 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005335 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005336
Douglas Gregora16548e2009-08-11 05:31:07 +00005337 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5338 PlacementArgs.push_back(Arg.take());
5339 }
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregorebe10102009-08-20 07:17:43 +00005341 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005342 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005343 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005344 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5345 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005346 break;
John McCall09d13692010-10-05 22:36:42 +00005347 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005348
John McCalldadc5752010-08-24 06:29:42 +00005349 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005350 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005352
Douglas Gregora16548e2009-08-11 05:31:07 +00005353 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5354 ConstructorArgs.push_back(Arg.take());
5355 }
Mike Stump11289f42009-09-09 15:08:12 +00005356
Douglas Gregord2d9da02010-02-26 00:38:10 +00005357 // Transform constructor, new operator, and delete operator.
5358 CXXConstructorDecl *Constructor = 0;
5359 if (E->getConstructor()) {
5360 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005361 getDerived().TransformDecl(E->getLocStart(),
5362 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005363 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005364 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005365 }
5366
5367 FunctionDecl *OperatorNew = 0;
5368 if (E->getOperatorNew()) {
5369 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005370 getDerived().TransformDecl(E->getLocStart(),
5371 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005372 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005373 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005374 }
5375
5376 FunctionDecl *OperatorDelete = 0;
5377 if (E->getOperatorDelete()) {
5378 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005379 getDerived().TransformDecl(E->getLocStart(),
5380 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005381 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005382 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005383 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005384
Douglas Gregora16548e2009-08-11 05:31:07 +00005385 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005386 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005388 Constructor == E->getConstructor() &&
5389 OperatorNew == E->getOperatorNew() &&
5390 OperatorDelete == E->getOperatorDelete() &&
5391 !ArgumentChanged) {
5392 // Mark any declarations we need as referenced.
5393 // FIXME: instantiation-specific.
5394 if (Constructor)
5395 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5396 if (OperatorNew)
5397 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5398 if (OperatorDelete)
5399 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005400 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005401 }
Mike Stump11289f42009-09-09 15:08:12 +00005402
Douglas Gregor0744ef62010-09-07 21:49:58 +00005403 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005404 if (!ArraySize.get()) {
5405 // If no array size was specified, but the new expression was
5406 // instantiated with an array type (e.g., "new T" where T is
5407 // instantiated with "int[4]"), extract the outer bound from the
5408 // array type as our array size. We do this with constant and
5409 // dependently-sized array types.
5410 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5411 if (!ArrayT) {
5412 // Do nothing
5413 } else if (const ConstantArrayType *ConsArrayT
5414 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005415 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005416 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5417 ConsArrayT->getSize(),
5418 SemaRef.Context.getSizeType(),
5419 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005420 AllocType = ConsArrayT->getElementType();
5421 } else if (const DependentSizedArrayType *DepArrayT
5422 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5423 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005424 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005425 AllocType = DepArrayT->getElementType();
5426 }
5427 }
5428 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005429
Douglas Gregora16548e2009-08-11 05:31:07 +00005430 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5431 E->isGlobalNew(),
5432 /*FIXME:*/E->getLocStart(),
5433 move_arg(PlacementArgs),
5434 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005435 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005436 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005437 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005438 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005439 /*FIXME:*/E->getLocStart(),
5440 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005441 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005442}
Mike Stump11289f42009-09-09 15:08:12 +00005443
Douglas Gregora16548e2009-08-11 05:31:07 +00005444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005446TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005447 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005448 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005450
Douglas Gregord2d9da02010-02-26 00:38:10 +00005451 // Transform the delete operator, if known.
5452 FunctionDecl *OperatorDelete = 0;
5453 if (E->getOperatorDelete()) {
5454 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005455 getDerived().TransformDecl(E->getLocStart(),
5456 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005457 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005458 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005459 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005460
Douglas Gregora16548e2009-08-11 05:31:07 +00005461 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005462 Operand.get() == E->getArgument() &&
5463 OperatorDelete == E->getOperatorDelete()) {
5464 // Mark any declarations we need as referenced.
5465 // FIXME: instantiation-specific.
5466 if (OperatorDelete)
5467 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005468
5469 if (!E->getArgument()->isTypeDependent()) {
5470 QualType Destroyed = SemaRef.Context.getBaseElementType(
5471 E->getDestroyedType());
5472 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5473 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5474 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5475 SemaRef.LookupDestructor(Record));
5476 }
5477 }
5478
John McCallc3007a22010-10-26 07:05:15 +00005479 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005480 }
Mike Stump11289f42009-09-09 15:08:12 +00005481
Douglas Gregora16548e2009-08-11 05:31:07 +00005482 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5483 E->isGlobalDelete(),
5484 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005485 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005486}
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregora16548e2009-08-11 05:31:07 +00005488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005489ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005490TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005491 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005492 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005493 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005494 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005495
John McCallba7bf592010-08-24 05:47:05 +00005496 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005497 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005498 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005499 E->getOperatorLoc(),
5500 E->isArrow()? tok::arrow : tok::period,
5501 ObjectTypePtr,
5502 MayBePseudoDestructor);
5503 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005505
John McCallba7bf592010-08-24 05:47:05 +00005506 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005507 NestedNameSpecifier *Qualifier = E->getQualifier();
5508 if (Qualifier) {
5509 Qualifier
5510 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5511 E->getQualifierRange(),
5512 ObjectType);
5513 if (!Qualifier)
5514 return ExprError();
5515 }
Mike Stump11289f42009-09-09 15:08:12 +00005516
Douglas Gregor678f90d2010-02-25 01:56:36 +00005517 PseudoDestructorTypeStorage Destroyed;
5518 if (E->getDestroyedTypeInfo()) {
5519 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005520 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5521 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005522 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005524 Destroyed = DestroyedTypeInfo;
5525 } else if (ObjectType->isDependentType()) {
5526 // We aren't likely to be able to resolve the identifier down to a type
5527 // now anyway, so just retain the identifier.
5528 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5529 E->getDestroyedTypeLoc());
5530 } else {
5531 // Look for a destructor known with the given name.
5532 CXXScopeSpec SS;
5533 if (Qualifier) {
5534 SS.setScopeRep(Qualifier);
5535 SS.setRange(E->getQualifierRange());
5536 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005537
John McCallba7bf592010-08-24 05:47:05 +00005538 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005539 *E->getDestroyedTypeIdentifier(),
5540 E->getDestroyedTypeLoc(),
5541 /*Scope=*/0,
5542 SS, ObjectTypePtr,
5543 false);
5544 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005546
Douglas Gregor678f90d2010-02-25 01:56:36 +00005547 Destroyed
5548 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5549 E->getDestroyedTypeLoc());
5550 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005551
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005552 TypeSourceInfo *ScopeTypeInfo = 0;
5553 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005554 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005555 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005556 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005557 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005558
John McCallb268a282010-08-23 23:25:46 +00005559 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005560 E->getOperatorLoc(),
5561 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005562 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005563 E->getQualifierRange(),
5564 ScopeTypeInfo,
5565 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005566 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005567 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005568}
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregorad8a3362009-09-04 17:36:40 +00005570template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005571ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005572TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005573 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005574 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5575
5576 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5577 Sema::LookupOrdinaryName);
5578
5579 // Transform all the decls.
5580 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5581 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005582 NamedDecl *InstD = static_cast<NamedDecl*>(
5583 getDerived().TransformDecl(Old->getNameLoc(),
5584 *I));
John McCall84d87672009-12-10 09:41:52 +00005585 if (!InstD) {
5586 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5587 // This can happen because of dependent hiding.
5588 if (isa<UsingShadowDecl>(*I))
5589 continue;
5590 else
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005592 }
John McCalle66edc12009-11-24 19:00:30 +00005593
5594 // Expand using declarations.
5595 if (isa<UsingDecl>(InstD)) {
5596 UsingDecl *UD = cast<UsingDecl>(InstD);
5597 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5598 E = UD->shadow_end(); I != E; ++I)
5599 R.addDecl(*I);
5600 continue;
5601 }
5602
5603 R.addDecl(InstD);
5604 }
5605
5606 // Resolve a kind, but don't do any further analysis. If it's
5607 // ambiguous, the callee needs to deal with it.
5608 R.resolveKind();
5609
5610 // Rebuild the nested-name qualifier, if present.
5611 CXXScopeSpec SS;
5612 NestedNameSpecifier *Qualifier = 0;
5613 if (Old->getQualifier()) {
5614 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005615 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005616 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005617 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005618
John McCalle66edc12009-11-24 19:00:30 +00005619 SS.setScopeRep(Qualifier);
5620 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005621 }
5622
Douglas Gregor9262f472010-04-27 18:19:34 +00005623 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005624 CXXRecordDecl *NamingClass
5625 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5626 Old->getNameLoc(),
5627 Old->getNamingClass()));
5628 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005629 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005630
Douglas Gregorda7be082010-04-27 16:10:10 +00005631 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005632 }
5633
5634 // If we have no template arguments, it's a normal declaration name.
5635 if (!Old->hasExplicitTemplateArgs())
5636 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5637
5638 // If we have template arguments, rebuild them, then rebuild the
5639 // templateid expression.
5640 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5641 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5642 TemplateArgumentLoc Loc;
5643 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005645 TransArgs.addArgument(Loc);
5646 }
5647
5648 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5649 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005650}
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregora16548e2009-08-11 05:31:07 +00005652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005654TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005655 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5656 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005658
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005660 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005661 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005662
Mike Stump11289f42009-09-09 15:08:12 +00005663 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005665 T,
5666 E->getLocEnd());
5667}
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregora16548e2009-08-11 05:31:07 +00005669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005670ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005671TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005672 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005673 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005674 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005675 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005676 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005677 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005678
John McCall31f82722010-11-12 08:19:04 +00005679 // TODO: If this is a conversion-function-id, verify that the
5680 // destination type name (if present) resolves the same way after
5681 // instantiation as it did in the local scope.
5682
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005683 DeclarationNameInfo NameInfo
5684 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5685 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005687
John McCalle66edc12009-11-24 19:00:30 +00005688 if (!E->hasExplicitTemplateArgs()) {
5689 if (!getDerived().AlwaysRebuild() &&
5690 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005691 // Note: it is sufficient to compare the Name component of NameInfo:
5692 // if name has not changed, DNLoc has not changed either.
5693 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005694 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005695
John McCalle66edc12009-11-24 19:00:30 +00005696 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5697 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005698 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005699 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005700 }
John McCall6b51f282009-11-23 01:53:49 +00005701
5702 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005704 TemplateArgumentLoc Loc;
5705 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005706 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005707 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 }
5709
John McCalle66edc12009-11-24 19:00:30 +00005710 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5711 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005712 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005713 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005714}
5715
5716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005718TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005719 // CXXConstructExprs are always implicit, so when we have a
5720 // 1-argument construction we just transform that argument.
5721 if (E->getNumArgs() == 1 ||
5722 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5723 return getDerived().TransformExpr(E->getArg(0));
5724
Douglas Gregora16548e2009-08-11 05:31:07 +00005725 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5726
5727 QualType T = getDerived().TransformType(E->getType());
5728 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005729 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005730
5731 CXXConstructorDecl *Constructor
5732 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005733 getDerived().TransformDecl(E->getLocStart(),
5734 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005736 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregora16548e2009-08-11 05:31:07 +00005738 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005739 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005740 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 ArgEnd = E->arg_end();
5742 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005743 if (getDerived().DropCallArgument(*Arg)) {
5744 ArgumentChanged = true;
5745 break;
5746 }
5747
John McCalldadc5752010-08-24 06:29:42 +00005748 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005751
Douglas Gregora16548e2009-08-11 05:31:07 +00005752 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005753 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 }
5755
5756 if (!getDerived().AlwaysRebuild() &&
5757 T == E->getType() &&
5758 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005759 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005760 // Mark the constructor as referenced.
5761 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005762 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005763 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005764 }
Mike Stump11289f42009-09-09 15:08:12 +00005765
Douglas Gregordb121ba2009-12-14 16:27:04 +00005766 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5767 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005768 move_arg(Args),
5769 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005770 E->getConstructionKind(),
5771 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005772}
Mike Stump11289f42009-09-09 15:08:12 +00005773
Douglas Gregora16548e2009-08-11 05:31:07 +00005774/// \brief Transform a C++ temporary-binding expression.
5775///
Douglas Gregor363b1512009-12-24 18:51:59 +00005776/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5777/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005780TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005781 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005782}
Mike Stump11289f42009-09-09 15:08:12 +00005783
5784/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005785/// be destroyed after the expression is evaluated.
5786///
Douglas Gregor363b1512009-12-24 18:51:59 +00005787/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5788/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005790ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005791TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005792 CXXExprWithTemporaries *E) {
5793 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005794}
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregora16548e2009-08-11 05:31:07 +00005796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005797ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005798TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005799 CXXTemporaryObjectExpr *E) {
5800 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5801 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005803
Douglas Gregora16548e2009-08-11 05:31:07 +00005804 CXXConstructorDecl *Constructor
5805 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005806 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005807 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005809 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005810
Douglas Gregora16548e2009-08-11 05:31:07 +00005811 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005812 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005813 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005814 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 ArgEnd = E->arg_end();
5816 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005817 if (getDerived().DropCallArgument(*Arg)) {
5818 ArgumentChanged = true;
5819 break;
5820 }
5821
John McCalldadc5752010-08-24 06:29:42 +00005822 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005825
Douglas Gregora16548e2009-08-11 05:31:07 +00005826 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5827 Args.push_back((Expr *)TransArg.release());
5828 }
Mike Stump11289f42009-09-09 15:08:12 +00005829
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005831 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005832 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005833 !ArgumentChanged) {
5834 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005835 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005836 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005837 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005838
5839 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5840 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005842 E->getLocEnd());
5843}
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora16548e2009-08-11 05:31:07 +00005845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005846ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005847TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005848 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005849 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5850 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005852
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005854 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005855 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5856 ArgEnd = E->arg_end();
5857 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005858 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005859 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005861
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005863 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 }
Mike Stump11289f42009-09-09 15:08:12 +00005865
Douglas Gregora16548e2009-08-11 05:31:07 +00005866 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005867 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005868 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005869 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005870
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005872 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005873 E->getLParenLoc(),
5874 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005875 E->getRParenLoc());
5876}
Mike Stump11289f42009-09-09 15:08:12 +00005877
Douglas Gregora16548e2009-08-11 05:31:07 +00005878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005879ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005880TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005881 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005882 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005883 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005884 Expr *OldBase;
5885 QualType BaseType;
5886 QualType ObjectType;
5887 if (!E->isImplicitAccess()) {
5888 OldBase = E->getBase();
5889 Base = getDerived().TransformExpr(OldBase);
5890 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005892
John McCall2d74de92009-12-01 22:10:20 +00005893 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005894 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005895 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005896 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005897 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005898 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005899 ObjectTy,
5900 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005901 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005903
John McCallba7bf592010-08-24 05:47:05 +00005904 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005905 BaseType = ((Expr*) Base.get())->getType();
5906 } else {
5907 OldBase = 0;
5908 BaseType = getDerived().TransformType(E->getBaseType());
5909 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5910 }
Mike Stump11289f42009-09-09 15:08:12 +00005911
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005912 // Transform the first part of the nested-name-specifier that qualifies
5913 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005914 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005915 = getDerived().TransformFirstQualifierInScope(
5916 E->getFirstQualifierFoundInScope(),
5917 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005918
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005919 NestedNameSpecifier *Qualifier = 0;
5920 if (E->getQualifier()) {
5921 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5922 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005923 ObjectType,
5924 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005925 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005926 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005927 }
Mike Stump11289f42009-09-09 15:08:12 +00005928
John McCall31f82722010-11-12 08:19:04 +00005929 // TODO: If this is a conversion-function-id, verify that the
5930 // destination type name (if present) resolves the same way after
5931 // instantiation as it did in the local scope.
5932
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005933 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00005934 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005935 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005937
John McCall2d74de92009-12-01 22:10:20 +00005938 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005939 // This is a reference to a member without an explicitly-specified
5940 // template argument list. Optimize for this common case.
5941 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005942 Base.get() == OldBase &&
5943 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005944 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005945 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005946 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00005947 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005948
John McCallb268a282010-08-23 23:25:46 +00005949 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005950 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005951 E->isArrow(),
5952 E->getOperatorLoc(),
5953 Qualifier,
5954 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005955 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005956 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005957 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005958 }
5959
John McCall6b51f282009-11-23 01:53:49 +00005960 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005961 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005962 TemplateArgumentLoc Loc;
5963 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005965 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005966 }
Mike Stump11289f42009-09-09 15:08:12 +00005967
John McCallb268a282010-08-23 23:25:46 +00005968 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005969 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 E->isArrow(),
5971 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005972 Qualifier,
5973 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005974 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005975 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005976 &TransArgs);
5977}
5978
5979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005980ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005981TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005982 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005983 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005984 QualType BaseType;
5985 if (!Old->isImplicitAccess()) {
5986 Base = getDerived().TransformExpr(Old->getBase());
5987 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005989 BaseType = ((Expr*) Base.get())->getType();
5990 } else {
5991 BaseType = getDerived().TransformType(Old->getBaseType());
5992 }
John McCall10eae182009-11-30 22:42:35 +00005993
5994 NestedNameSpecifier *Qualifier = 0;
5995 if (Old->getQualifier()) {
5996 Qualifier
5997 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005998 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005999 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006000 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006001 }
6002
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006003 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006004 Sema::LookupOrdinaryName);
6005
6006 // Transform all the decls.
6007 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6008 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006009 NamedDecl *InstD = static_cast<NamedDecl*>(
6010 getDerived().TransformDecl(Old->getMemberLoc(),
6011 *I));
John McCall84d87672009-12-10 09:41:52 +00006012 if (!InstD) {
6013 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6014 // This can happen because of dependent hiding.
6015 if (isa<UsingShadowDecl>(*I))
6016 continue;
6017 else
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006019 }
John McCall10eae182009-11-30 22:42:35 +00006020
6021 // Expand using declarations.
6022 if (isa<UsingDecl>(InstD)) {
6023 UsingDecl *UD = cast<UsingDecl>(InstD);
6024 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6025 E = UD->shadow_end(); I != E; ++I)
6026 R.addDecl(*I);
6027 continue;
6028 }
6029
6030 R.addDecl(InstD);
6031 }
6032
6033 R.resolveKind();
6034
Douglas Gregor9262f472010-04-27 18:19:34 +00006035 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006036 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006037 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006038 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006039 Old->getMemberLoc(),
6040 Old->getNamingClass()));
6041 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006043
Douglas Gregorda7be082010-04-27 16:10:10 +00006044 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006045 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006046
John McCall10eae182009-11-30 22:42:35 +00006047 TemplateArgumentListInfo TransArgs;
6048 if (Old->hasExplicitTemplateArgs()) {
6049 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6050 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6051 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6052 TemplateArgumentLoc Loc;
6053 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6054 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006055 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006056 TransArgs.addArgument(Loc);
6057 }
6058 }
John McCall38836f02010-01-15 08:34:02 +00006059
6060 // FIXME: to do this check properly, we will need to preserve the
6061 // first-qualifier-in-scope here, just in case we had a dependent
6062 // base (and therefore couldn't do the check) and a
6063 // nested-name-qualifier (and therefore could do the lookup).
6064 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006065
John McCallb268a282010-08-23 23:25:46 +00006066 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006067 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006068 Old->getOperatorLoc(),
6069 Old->isArrow(),
6070 Qualifier,
6071 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006072 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006073 R,
6074 (Old->hasExplicitTemplateArgs()
6075 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006076}
6077
6078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006079ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006080TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6081 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6082 if (SubExpr.isInvalid())
6083 return ExprError();
6084
6085 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006086 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006087
6088 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6089}
6090
6091template<typename Derived>
6092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006093TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006094 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006095}
6096
Mike Stump11289f42009-09-09 15:08:12 +00006097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006098ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006099TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006100 TypeSourceInfo *EncodedTypeInfo
6101 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6102 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006103 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006104
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006106 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006107 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006108
6109 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006110 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006111 E->getRParenLoc());
6112}
Mike Stump11289f42009-09-09 15:08:12 +00006113
Douglas Gregora16548e2009-08-11 05:31:07 +00006114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006115ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006116TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006117 // Transform arguments.
6118 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006119 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006120 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006121 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006122 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006123 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006124
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006125 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006126 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006127 }
6128
6129 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6130 // Class message: transform the receiver type.
6131 TypeSourceInfo *ReceiverTypeInfo
6132 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6133 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006134 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006135
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006136 // If nothing changed, just retain the existing message send.
6137 if (!getDerived().AlwaysRebuild() &&
6138 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006139 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006140
6141 // Build a new class message send.
6142 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6143 E->getSelector(),
6144 E->getMethodDecl(),
6145 E->getLeftLoc(),
6146 move_arg(Args),
6147 E->getRightLoc());
6148 }
6149
6150 // Instance message: transform the receiver
6151 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6152 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006153 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006154 = getDerived().TransformExpr(E->getInstanceReceiver());
6155 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006156 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006157
6158 // If nothing changed, just retain the existing message send.
6159 if (!getDerived().AlwaysRebuild() &&
6160 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006161 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006162
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006163 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006164 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006165 E->getSelector(),
6166 E->getMethodDecl(),
6167 E->getLeftLoc(),
6168 move_arg(Args),
6169 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006170}
6171
Mike Stump11289f42009-09-09 15:08:12 +00006172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006174TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006175 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006176}
6177
Mike Stump11289f42009-09-09 15:08:12 +00006178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006180TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006181 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006182}
6183
Mike Stump11289f42009-09-09 15:08:12 +00006184template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006185ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006186TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006187 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006188 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006189 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006190 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006191
6192 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006193
Douglas Gregord51d90d2010-04-26 20:11:03 +00006194 // If nothing changed, just retain the existing expression.
6195 if (!getDerived().AlwaysRebuild() &&
6196 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006197 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006198
John McCallb268a282010-08-23 23:25:46 +00006199 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006200 E->getLocation(),
6201 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006202}
6203
Mike Stump11289f42009-09-09 15:08:12 +00006204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006207 // 'super' never changes. Property never changes. Just retain the existing
6208 // expression.
6209 if (E->isSuperReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006210 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006211
Douglas Gregor9faee212010-04-26 20:47:02 +00006212 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006213 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006214 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006215 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006216
Douglas Gregor9faee212010-04-26 20:47:02 +00006217 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006218
Douglas Gregor9faee212010-04-26 20:47:02 +00006219 // If nothing changed, just retain the existing expression.
6220 if (!getDerived().AlwaysRebuild() &&
6221 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006222 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006223
John McCallb268a282010-08-23 23:25:46 +00006224 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006225 E->getLocation());
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
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006230TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006231 ObjCImplicitSetterGetterRefExpr *E) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006232 // If this implicit setter/getter refers to super, it cannot have any
6233 // dependent parts. Just retain the existing declaration.
6234 if (E->isSuperReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006235 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006236
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006237 // If this implicit setter/getter refers to class methods, it cannot have any
6238 // dependent parts. Just retain the existing declaration.
6239 if (E->getInterfaceDecl())
John McCallc3007a22010-10-26 07:05:15 +00006240 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006241
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006242 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006243 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006244 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006245 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006246
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006247 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006248
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006249 // If nothing changed, just retain the existing expression.
6250 if (!getDerived().AlwaysRebuild() &&
6251 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006252 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006253
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006254 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6255 E->getGetterMethod(),
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006256 E->getType(),
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006257 E->getSetterMethod(),
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006258 E->getLocation(),
6259 Base.get(),
6260 E->getSuperLocation(),
6261 E->getSuperType(),
6262 E->isSuperReceiver());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006263
Douglas Gregora16548e2009-08-11 05:31:07 +00006264}
6265
Mike Stump11289f42009-09-09 15:08:12 +00006266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006268TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006269 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006270 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006271 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006272 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006273
Douglas Gregord51d90d2010-04-26 20:11:03 +00006274 // If nothing changed, just retain the existing expression.
6275 if (!getDerived().AlwaysRebuild() &&
6276 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006277 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006278
John McCallb268a282010-08-23 23:25:46 +00006279 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006280 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006281}
6282
Mike Stump11289f42009-09-09 15:08:12 +00006283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006284ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006285TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006286 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006287 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006288 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006289 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregora16548e2009-08-11 05:31:07 +00006293 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006294 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006295 }
Mike Stump11289f42009-09-09 15:08:12 +00006296
Douglas Gregora16548e2009-08-11 05:31:07 +00006297 if (!getDerived().AlwaysRebuild() &&
6298 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006299 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregora16548e2009-08-11 05:31:07 +00006301 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6302 move_arg(SubExprs),
6303 E->getRParenLoc());
6304}
6305
Mike Stump11289f42009-09-09 15:08:12 +00006306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006307ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006308TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006309 SourceLocation CaretLoc(E->getExprLoc());
6310
6311 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6312 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6313 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6314 llvm::SmallVector<ParmVarDecl*, 4> Params;
6315 llvm::SmallVector<QualType, 4> ParamTypes;
6316
6317 // Parameter substitution.
6318 const BlockDecl *BD = E->getBlockDecl();
6319 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6320 EN = BD->param_end(); P != EN; ++P) {
6321 ParmVarDecl *OldParm = (*P);
6322 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6323 QualType NewType = NewParm->getType();
6324 Params.push_back(NewParm);
6325 ParamTypes.push_back(NewParm->getType());
6326 }
6327
6328 const FunctionType *BExprFunctionType = E->getFunctionType();
6329 QualType BExprResultType = BExprFunctionType->getResultType();
6330 if (!BExprResultType.isNull()) {
6331 if (!BExprResultType->isDependentType())
6332 CurBlock->ReturnType = BExprResultType;
6333 else if (BExprResultType != SemaRef.Context.DependentTy)
6334 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6335 }
6336
6337 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006338 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006339 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006340 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006341 // Set the parameters on the block decl.
6342 if (!Params.empty())
6343 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6344
6345 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6346 CurBlock->ReturnType,
6347 ParamTypes.data(),
6348 ParamTypes.size(),
6349 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006350 0,
6351 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006352
6353 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006354 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006355}
6356
Mike Stump11289f42009-09-09 15:08:12 +00006357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006358ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006359TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006360 NestedNameSpecifier *Qualifier = 0;
6361
6362 ValueDecl *ND
6363 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6364 E->getDecl()));
6365 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006366 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006367
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006368 if (!getDerived().AlwaysRebuild() &&
6369 ND == E->getDecl()) {
6370 // Mark it referenced in the new context regardless.
6371 // FIXME: this is a bit instantiation-specific.
6372 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6373
John McCallc3007a22010-10-26 07:05:15 +00006374 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006375 }
6376
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006377 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006378 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006379 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006380}
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregora16548e2009-08-11 05:31:07 +00006382//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006383// Type reconstruction
6384//===----------------------------------------------------------------------===//
6385
Mike Stump11289f42009-09-09 15:08:12 +00006386template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006387QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6388 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006389 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006390 getDerived().getBaseEntity());
6391}
6392
Mike Stump11289f42009-09-09 15:08:12 +00006393template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006394QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6395 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006396 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006397 getDerived().getBaseEntity());
6398}
6399
Mike Stump11289f42009-09-09 15:08:12 +00006400template<typename Derived>
6401QualType
John McCall70dd5f62009-10-30 00:06:24 +00006402TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6403 bool WrittenAsLValue,
6404 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006405 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006406 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006407}
6408
6409template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006410QualType
John McCall70dd5f62009-10-30 00:06:24 +00006411TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6412 QualType ClassType,
6413 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006414 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006415 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006416}
6417
6418template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006419QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006420TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6421 ArrayType::ArraySizeModifier SizeMod,
6422 const llvm::APInt *Size,
6423 Expr *SizeExpr,
6424 unsigned IndexTypeQuals,
6425 SourceRange BracketsRange) {
6426 if (SizeExpr || !Size)
6427 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6428 IndexTypeQuals, BracketsRange,
6429 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006430
6431 QualType Types[] = {
6432 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6433 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6434 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006435 };
6436 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6437 QualType SizeType;
6438 for (unsigned I = 0; I != NumTypes; ++I)
6439 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6440 SizeType = Types[I];
6441 break;
6442 }
Mike Stump11289f42009-09-09 15:08:12 +00006443
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006444 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6445 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006446 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006447 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006448 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006449}
Mike Stump11289f42009-09-09 15:08:12 +00006450
Douglas Gregord6ff3322009-08-04 16:50:30 +00006451template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006452QualType
6453TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006454 ArrayType::ArraySizeModifier SizeMod,
6455 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006456 unsigned IndexTypeQuals,
6457 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006458 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006459 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006460}
6461
6462template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006463QualType
Mike Stump11289f42009-09-09 15:08:12 +00006464TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006465 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006466 unsigned IndexTypeQuals,
6467 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006468 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006469 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006470}
Mike Stump11289f42009-09-09 15:08:12 +00006471
Douglas Gregord6ff3322009-08-04 16:50:30 +00006472template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006473QualType
6474TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006475 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006476 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006477 unsigned IndexTypeQuals,
6478 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006479 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006480 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006481 IndexTypeQuals, BracketsRange);
6482}
6483
6484template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006485QualType
6486TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006487 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006488 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006489 unsigned IndexTypeQuals,
6490 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006491 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006492 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006493 IndexTypeQuals, BracketsRange);
6494}
6495
6496template<typename Derived>
6497QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006498 unsigned NumElements,
6499 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006500 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006501 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006502}
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregord6ff3322009-08-04 16:50:30 +00006504template<typename Derived>
6505QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6506 unsigned NumElements,
6507 SourceLocation AttributeLoc) {
6508 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6509 NumElements, true);
6510 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006511 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6512 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006513 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006514}
Mike Stump11289f42009-09-09 15:08:12 +00006515
Douglas Gregord6ff3322009-08-04 16:50:30 +00006516template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006517QualType
6518TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006519 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006520 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006521 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006522}
Mike Stump11289f42009-09-09 15:08:12 +00006523
Douglas Gregord6ff3322009-08-04 16:50:30 +00006524template<typename Derived>
6525QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006526 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006527 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006528 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006529 unsigned Quals,
6530 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006531 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006532 Quals,
6533 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006534 getDerived().getBaseEntity(),
6535 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006536}
Mike Stump11289f42009-09-09 15:08:12 +00006537
Douglas Gregord6ff3322009-08-04 16:50:30 +00006538template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006539QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6540 return SemaRef.Context.getFunctionNoProtoType(T);
6541}
6542
6543template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006544QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6545 assert(D && "no decl found");
6546 if (D->isInvalidDecl()) return QualType();
6547
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006548 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006549 TypeDecl *Ty;
6550 if (isa<UsingDecl>(D)) {
6551 UsingDecl *Using = cast<UsingDecl>(D);
6552 assert(Using->isTypeName() &&
6553 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6554
6555 // A valid resolved using typename decl points to exactly one type decl.
6556 assert(++Using->shadow_begin() == Using->shadow_end());
6557 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006558
John McCallb96ec562009-12-04 22:46:56 +00006559 } else {
6560 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6561 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6562 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6563 }
6564
6565 return SemaRef.Context.getTypeDeclType(Ty);
6566}
6567
6568template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006569QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6570 SourceLocation Loc) {
6571 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006572}
6573
6574template<typename Derived>
6575QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6576 return SemaRef.Context.getTypeOfType(Underlying);
6577}
6578
6579template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006580QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6581 SourceLocation Loc) {
6582 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006583}
6584
6585template<typename Derived>
6586QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006587 TemplateName Template,
6588 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006589 const TemplateArgumentListInfo &TemplateArgs) {
6590 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006591}
Mike Stump11289f42009-09-09 15:08:12 +00006592
Douglas Gregor1135c352009-08-06 05:28:30 +00006593template<typename Derived>
6594NestedNameSpecifier *
6595TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6596 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006597 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006598 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006599 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006600 CXXScopeSpec SS;
6601 // FIXME: The source location information is all wrong.
6602 SS.setRange(Range);
6603 SS.setScopeRep(Prefix);
6604 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006605 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006606 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006607 ObjectType,
6608 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006609 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006610}
6611
6612template<typename Derived>
6613NestedNameSpecifier *
6614TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6615 SourceRange Range,
6616 NamespaceDecl *NS) {
6617 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6618}
6619
6620template<typename Derived>
6621NestedNameSpecifier *
6622TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6623 SourceRange Range,
6624 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006625 QualType T) {
6626 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006627 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006628 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006629 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6630 T.getTypePtr());
6631 }
Mike Stump11289f42009-09-09 15:08:12 +00006632
Douglas Gregor1135c352009-08-06 05:28:30 +00006633 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6634 return 0;
6635}
Mike Stump11289f42009-09-09 15:08:12 +00006636
Douglas Gregor71dc5092009-08-06 06:41:21 +00006637template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006638TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006639TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6640 bool TemplateKW,
6641 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006642 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006643 Template);
6644}
6645
6646template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006647TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006648TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006649 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006650 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00006651 QualType ObjectType,
6652 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006653 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006654 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006655 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006656 UnqualifiedId Name;
6657 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006658 Sema::TemplateTy Template;
6659 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6660 /*FIXME:*/getDerived().getBaseLocation(),
6661 SS,
6662 Name,
John McCallba7bf592010-08-24 05:47:05 +00006663 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006664 /*EnteringContext=*/false,
6665 Template);
John McCall31f82722010-11-12 08:19:04 +00006666 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006667}
Mike Stump11289f42009-09-09 15:08:12 +00006668
Douglas Gregora16548e2009-08-11 05:31:07 +00006669template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006670TemplateName
6671TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6672 OverloadedOperatorKind Operator,
6673 QualType ObjectType) {
6674 CXXScopeSpec SS;
6675 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6676 SS.setScopeRep(Qualifier);
6677 UnqualifiedId Name;
6678 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6679 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6680 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006681 Sema::TemplateTy Template;
6682 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006683 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006684 SS,
6685 Name,
John McCallba7bf592010-08-24 05:47:05 +00006686 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006687 /*EnteringContext=*/false,
6688 Template);
6689 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006690}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006691
Douglas Gregor71395fa2009-11-04 00:56:37 +00006692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006693ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006694TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6695 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006696 Expr *OrigCallee,
6697 Expr *First,
6698 Expr *Second) {
6699 Expr *Callee = OrigCallee->IgnoreParenCasts();
6700 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006701
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006703 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006704 if (!First->getType()->isOverloadableType() &&
6705 !Second->getType()->isOverloadableType())
6706 return getSema().CreateBuiltinArraySubscriptExpr(First,
6707 Callee->getLocStart(),
6708 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006709 } else if (Op == OO_Arrow) {
6710 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006711 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6712 } else if (Second == 0 || isPostIncDec) {
6713 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 // The argument is not of overloadable type, so try to create a
6715 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006716 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006718
John McCallb268a282010-08-23 23:25:46 +00006719 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006720 }
6721 } else {
John McCallb268a282010-08-23 23:25:46 +00006722 if (!First->getType()->isOverloadableType() &&
6723 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006724 // Neither of the arguments is an overloadable type, so try to
6725 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006726 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006727 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006728 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006729 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006731
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 return move(Result);
6733 }
6734 }
Mike Stump11289f42009-09-09 15:08:12 +00006735
6736 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006737 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006738 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006739
John McCallb268a282010-08-23 23:25:46 +00006740 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006741 assert(ULE->requiresADL());
6742
6743 // FIXME: Do we have to check
6744 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006745 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006746 } else {
John McCallb268a282010-08-23 23:25:46 +00006747 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006748 }
Mike Stump11289f42009-09-09 15:08:12 +00006749
Douglas Gregora16548e2009-08-11 05:31:07 +00006750 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006751 Expr *Args[2] = { First, Second };
6752 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006753
Douglas Gregora16548e2009-08-11 05:31:07 +00006754 // Create the overloaded operator invocation for unary operators.
6755 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006756 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006757 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006758 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006759 }
Mike Stump11289f42009-09-09 15:08:12 +00006760
Sebastian Redladba46e2009-10-29 20:17:01 +00006761 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006762 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006763 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006764 First,
6765 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006766
Douglas Gregora16548e2009-08-11 05:31:07 +00006767 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006768 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006769 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006770 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6771 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006772 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006773
Mike Stump11289f42009-09-09 15:08:12 +00006774 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006775}
Mike Stump11289f42009-09-09 15:08:12 +00006776
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006778ExprResult
John McCallb268a282010-08-23 23:25:46 +00006779TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006780 SourceLocation OperatorLoc,
6781 bool isArrow,
6782 NestedNameSpecifier *Qualifier,
6783 SourceRange QualifierRange,
6784 TypeSourceInfo *ScopeType,
6785 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006786 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006787 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006788 CXXScopeSpec SS;
6789 if (Qualifier) {
6790 SS.setRange(QualifierRange);
6791 SS.setScopeRep(Qualifier);
6792 }
6793
John McCallb268a282010-08-23 23:25:46 +00006794 QualType BaseType = Base->getType();
6795 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006796 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006797 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006798 !BaseType->getAs<PointerType>()->getPointeeType()
6799 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006800 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006801 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006802 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006803 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006804 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006805 /*FIXME?*/true);
6806 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006807
Douglas Gregor678f90d2010-02-25 01:56:36 +00006808 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006809 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6810 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6811 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6812 NameInfo.setNamedTypeInfo(DestroyedType);
6813
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006814 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006815
John McCallb268a282010-08-23 23:25:46 +00006816 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006817 OperatorLoc, isArrow,
6818 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006819 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006820 /*TemplateArgs*/ 0);
6821}
6822
Douglas Gregord6ff3322009-08-04 16:50:30 +00006823} // end namespace clang
6824
6825#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H