blob: 807346c4c57a52a9657158159529f182ac8e99fa [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,
John McCall7decc9e2010-11-18 06:31:45 +00001145 bool isArrow,
1146 NestedNameSpecifier *Qualifier,
1147 SourceRange QualifierRange,
1148 const DeclarationNameInfo &MemberNameInfo,
1149 ValueDecl *Member,
1150 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001151 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001152 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001153 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001154 // We have a reference to an unnamed field. This is always the
1155 // base of an anonymous struct/union member access, i.e. the
1156 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001157 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001158 assert(Member->getType()->isRecordType() &&
1159 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001160
John McCallb268a282010-08-23 23:25:46 +00001161 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001162 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001163 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001164
John McCall7decc9e2010-11-18 06:31:45 +00001165 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001166 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001167 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001168 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001169 cast<FieldDecl>(Member)->getType(),
1170 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001171 return getSema().Owned(ME);
1172 }
Mike Stump11289f42009-09-09 15:08:12 +00001173
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001174 CXXScopeSpec SS;
1175 if (Qualifier) {
1176 SS.setRange(QualifierRange);
1177 SS.setScopeRep(Qualifier);
1178 }
1179
John McCallb268a282010-08-23 23:25:46 +00001180 getSema().DefaultFunctionArrayConversion(Base);
1181 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001182
John McCall16df1e52010-03-30 21:47:33 +00001183 // FIXME: this involves duplicating earlier analysis in a lot of
1184 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001185 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001186 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001187 R.resolveKind();
1188
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001190 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001191 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001195 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001198 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001199 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001200 Expr *LHS, Expr *RHS) {
1201 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 }
1203
1204 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001205 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// By default, performs semantic analysis to build the new expression.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001210 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001212 Expr *RHS) {
1213 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1214 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 }
1216
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001218 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 /// By default, performs semantic analysis to build the new expression.
1220 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001221 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001222 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001224 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001225 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001226 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 }
Mike Stump11289f42009-09-09 15:08:12 +00001228
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001230 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001233 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001234 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001236 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001237 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 }
Mike Stump11289f42009-09-09 15:08:12 +00001240
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001242 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 /// By default, performs semantic analysis to build the new expression.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 SourceLocation OpLoc,
1247 SourceLocation AccessorLoc,
1248 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001249
John McCall10eae182009-11-30 22:42:35 +00001250 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001251 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001252 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001253 OpLoc, /*IsArrow*/ false,
1254 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001255 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001256 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001265 SourceLocation RBraceLoc,
1266 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001267 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001268 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1269 if (Result.isInvalid() || ResultTy->isDependentType())
1270 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001271
Douglas Gregord3d93062009-11-09 17:16:50 +00001272 // Patch in the result type we were given, which may have been computed
1273 // when the initial InitListExpr was built.
1274 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1275 ILE->setType(ResultTy);
1276 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 }
Mike Stump11289f42009-09-09 15:08:12 +00001278
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001280 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// By default, performs semantic analysis to build the new expression.
1282 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001283 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 MultiExprArg ArrayExprs,
1285 SourceLocation EqualOrColonLoc,
1286 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001287 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001288 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001290 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001293
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 ArrayExprs.release();
1295 return move(Result);
1296 }
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001299 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// By default, builds the implicit value initialization without performing
1301 /// any semantic analysis. Subclasses may override this routine to provide
1302 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001303 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1305 }
Mike Stump11289f42009-09-09 15:08:12 +00001306
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001308 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001311 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001312 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001313 SourceLocation RParenLoc) {
1314 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001315 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001316 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
1318
1319 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 MultiExprArg SubExprs,
1325 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001326 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001327 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
1332 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// rather than attempting to map the label statement itself.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation LabelLoc,
1337 LabelStmt *Label) {
1338 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001342 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001346 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001348 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 }
Mike Stump11289f42009-09-09 15:08:12 +00001350
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// \brief Build a new __builtin_types_compatible_p expression.
1352 ///
1353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001355 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001356 TypeSourceInfo *TInfo1,
1357 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001359 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1360 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 RParenLoc);
1362 }
Mike Stump11289f42009-09-09 15:08:12 +00001363
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 /// \brief Build a new __builtin_choose_expr expression.
1365 ///
1366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001368 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001369 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 SourceLocation RParenLoc) {
1371 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001372 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 RParenLoc);
1374 }
Mike Stump11289f42009-09-09 15:08:12 +00001375
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 /// \brief Build a new overloaded operator call expression.
1377 ///
1378 /// By default, performs semantic analysis to build the new expression.
1379 /// The semantic analysis provides the behavior of template instantiation,
1380 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001381 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// argument-dependent lookup, etc. Subclasses may override this routine to
1383 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001384 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001386 Expr *Callee,
1387 Expr *First,
1388 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001389
1390 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 /// reinterpret_cast.
1392 ///
1393 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001394 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001396 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 Stmt::StmtClass Class,
1398 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001399 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 SourceLocation RAngleLoc,
1401 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001402 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 SourceLocation RParenLoc) {
1404 switch (Class) {
1405 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001408 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001409
1410 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001413 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001416 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001417 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001418 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001422 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001423 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001424 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 default:
1427 assert(false && "Invalid C++ named cast");
1428 break;
1429 }
Mike Stump11289f42009-09-09 15:08:12 +00001430
John McCallfaf5fb42010-08-26 23:41:50 +00001431 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 }
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new C++ static_cast expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001440 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RAngleLoc,
1442 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001443 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001445 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001446 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001447 SourceRange(LAngleLoc, RAngleLoc),
1448 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 }
1450
1451 /// \brief Build a new C++ dynamic_cast expression.
1452 ///
1453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001455 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001457 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 SourceLocation RAngleLoc,
1459 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001460 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001462 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001463 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001464 SourceRange(LAngleLoc, RAngleLoc),
1465 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 }
1467
1468 /// \brief Build a new C++ reinterpret_cast expression.
1469 ///
1470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001472 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001474 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 SourceLocation RAngleLoc,
1476 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001477 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001479 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001480 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001481 SourceRange(LAngleLoc, RAngleLoc),
1482 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 }
1484
1485 /// \brief Build a new C++ const_cast expression.
1486 ///
1487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001489 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001491 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 SourceLocation RAngleLoc,
1493 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001494 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001496 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001497 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001498 SourceRange(LAngleLoc, RAngleLoc),
1499 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 }
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// \brief Build a new C++ functional-style cast expression.
1503 ///
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001506 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1507 SourceLocation LParenLoc,
1508 Expr *Sub,
1509 SourceLocation RParenLoc) {
1510 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001511 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 RParenLoc);
1513 }
Mike Stump11289f42009-09-09 15:08:12 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new C++ typeid(type) expression.
1516 ///
1517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001519 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001520 SourceLocation TypeidLoc,
1521 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001523 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001524 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 }
Mike Stump11289f42009-09-09 15:08:12 +00001526
Francois Pichet9f4f2072010-09-08 12:20:18 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new C++ typeid(expr) expression.
1529 ///
1530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001532 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001533 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001534 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001536 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001537 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001538 }
1539
Francois Pichet9f4f2072010-09-08 12:20:18 +00001540 /// \brief Build a new C++ __uuidof(type) expression.
1541 ///
1542 /// By default, performs semantic analysis to build the new expression.
1543 /// Subclasses may override this routine to provide different behavior.
1544 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1545 SourceLocation TypeidLoc,
1546 TypeSourceInfo *Operand,
1547 SourceLocation RParenLoc) {
1548 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1549 RParenLoc);
1550 }
1551
1552 /// \brief Build a new C++ __uuidof(expr) expression.
1553 ///
1554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
1556 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1557 SourceLocation TypeidLoc,
1558 Expr *Operand,
1559 SourceLocation RParenLoc) {
1560 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1561 RParenLoc);
1562 }
1563
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 /// \brief Build a new C++ "this" expression.
1565 ///
1566 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001567 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001569 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001570 QualType ThisType,
1571 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001573 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1574 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 }
1576
1577 /// \brief Build a new C++ throw expression.
1578 ///
1579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001581 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001582 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 }
1584
1585 /// \brief Build a new C++ default-argument expression.
1586 ///
1587 /// By default, builds a new default-argument expression, which does not
1588 /// require any semantic analysis. Subclasses may override this routine to
1589 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001590 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001591 ParmVarDecl *Param) {
1592 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1593 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 }
1595
1596 /// \brief Build a new C++ zero-initialization expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001600 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1601 SourceLocation LParenLoc,
1602 SourceLocation RParenLoc) {
1603 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001604 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001605 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 }
Mike Stump11289f42009-09-09 15:08:12 +00001607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// \brief Build a new C++ "new" expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001612 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001613 bool UseGlobal,
1614 SourceLocation PlacementLParen,
1615 MultiExprArg PlacementArgs,
1616 SourceLocation PlacementRParen,
1617 SourceRange TypeIdParens,
1618 QualType AllocatedType,
1619 TypeSourceInfo *AllocatedTypeInfo,
1620 Expr *ArraySize,
1621 SourceLocation ConstructorLParen,
1622 MultiExprArg ConstructorArgs,
1623 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001624 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 PlacementLParen,
1626 move(PlacementArgs),
1627 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001628 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001629 AllocatedType,
1630 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001631 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 ConstructorLParen,
1633 move(ConstructorArgs),
1634 ConstructorRParen);
1635 }
Mike Stump11289f42009-09-09 15:08:12 +00001636
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// \brief Build a new C++ "delete" expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001641 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 bool IsGlobalDelete,
1643 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001644 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001646 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 }
Mike Stump11289f42009-09-09 15:08:12 +00001648
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 /// \brief Build a new unary type trait expression.
1650 ///
1651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001653 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001654 SourceLocation StartLoc,
1655 TypeSourceInfo *T,
1656 SourceLocation RParenLoc) {
1657 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 }
1659
Mike Stump11289f42009-09-09 15:08:12 +00001660 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 /// expression.
1662 ///
1663 /// By default, performs semantic analysis to build the new expression.
1664 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001665 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001667 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001668 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 CXXScopeSpec SS;
1670 SS.setRange(QualifierRange);
1671 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001672
1673 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001674 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001675 *TemplateArgs);
1676
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001677 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 }
1679
1680 /// \brief Build a new template-id expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001685 LookupResult &R,
1686 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001687 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001688 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 }
1690
1691 /// \brief Build a new object-construction expression.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001695 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001696 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 CXXConstructorDecl *Constructor,
1698 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001699 MultiExprArg Args,
1700 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001701 CXXConstructExpr::ConstructionKind ConstructKind,
1702 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001703 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001704 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001705 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001706 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001707
Douglas Gregordb121ba2009-12-14 16:27:04 +00001708 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001709 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001710 RequiresZeroInit, ConstructKind,
1711 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 }
1713
1714 /// \brief Build a new object-construction expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001718 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1719 SourceLocation LParenLoc,
1720 MultiExprArg Args,
1721 SourceLocation RParenLoc) {
1722 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 LParenLoc,
1724 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 RParenLoc);
1726 }
1727
1728 /// \brief Build a new object-construction expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001732 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1733 SourceLocation LParenLoc,
1734 MultiExprArg Args,
1735 SourceLocation RParenLoc) {
1736 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 LParenLoc,
1738 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 RParenLoc);
1740 }
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 /// \brief Build a new member reference expression.
1743 ///
1744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001746 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001747 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 bool IsArrow,
1749 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001750 NestedNameSpecifier *Qualifier,
1751 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001752 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001753 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001754 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001756 SS.setRange(QualifierRange);
1757 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001758
John McCallb268a282010-08-23 23:25:46 +00001759 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001760 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001761 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001762 MemberNameInfo,
1763 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 }
1765
John McCall10eae182009-11-30 22:42:35 +00001766 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001767 ///
1768 /// By default, performs semantic analysis to build the new expression.
1769 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001770 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001771 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001772 SourceLocation OperatorLoc,
1773 bool IsArrow,
1774 NestedNameSpecifier *Qualifier,
1775 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001776 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001777 LookupResult &R,
1778 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001779 CXXScopeSpec SS;
1780 SS.setRange(QualifierRange);
1781 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001782
John McCallb268a282010-08-23 23:25:46 +00001783 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001784 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001785 SS, FirstQualifierInScope,
1786 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001787 }
Mike Stump11289f42009-09-09 15:08:12 +00001788
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001789 /// \brief Build a new noexcept expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
1793 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1794 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1795 }
1796
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 /// \brief Build a new Objective-C @encode expression.
1798 ///
1799 /// By default, performs semantic analysis to build the new expression.
1800 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001801 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001802 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001804 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001806 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001807
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001808 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001809 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001810 Selector Sel,
1811 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001812 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001813 MultiExprArg Args,
1814 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001815 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1816 ReceiverTypeInfo->getType(),
1817 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001818 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001819 move(Args));
1820 }
1821
1822 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001823 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001824 Selector Sel,
1825 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001826 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001827 MultiExprArg Args,
1828 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001829 return SemaRef.BuildInstanceMessage(Receiver,
1830 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001831 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001832 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001833 move(Args));
1834 }
1835
Douglas Gregord51d90d2010-04-26 20:11:03 +00001836 /// \brief Build a new Objective-C ivar reference expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001840 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001841 SourceLocation IvarLoc,
1842 bool IsArrow, bool IsFreeIvar) {
1843 // FIXME: We lose track of the IsFreeIvar bit.
1844 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001845 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001846 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1847 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001848 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001849 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001850 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001851 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001852 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001853 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001854
Douglas Gregord51d90d2010-04-26 20:11:03 +00001855 if (Result.get())
1856 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001857
John McCallb268a282010-08-23 23:25:46 +00001858 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001859 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001860 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001861 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001862 /*TemplateArgs=*/0);
1863 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001864
1865 /// \brief Build a new Objective-C property reference expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001869 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001870 ObjCPropertyDecl *Property,
1871 SourceLocation PropertyLoc) {
1872 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001873 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001874 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1875 Sema::LookupMemberName);
1876 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001877 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001878 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001879 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001880 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001881 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001882
Douglas Gregor9faee212010-04-26 20:47:02 +00001883 if (Result.get())
1884 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001885
John McCallb268a282010-08-23 23:25:46 +00001886 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001887 /*FIXME:*/PropertyLoc, IsArrow,
1888 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001889 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001890 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001891 /*TemplateArgs=*/0);
1892 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001893
1894 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001895 /// expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001900 ObjCMethodDecl *Getter,
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001901 QualType T,
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001902 ObjCMethodDecl *Setter,
1903 SourceLocation NameLoc,
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001904 Expr *Base,
1905 SourceLocation SuperLoc,
1906 QualType SuperTy,
1907 bool Super) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001908 // Since these expressions can only be value-dependent, we do not need to
1909 // perform semantic analysis again.
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001910 if (Super)
1911 return Owned(
John McCall7decc9e2010-11-18 06:31:45 +00001912 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1913 VK_LValue,
1914 OK_Ordinary,
1915 Setter,
1916 NameLoc,
1917 SuperLoc,
1918 SuperTy));
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001919 else
1920 return Owned(
John McCall7decc9e2010-11-18 06:31:45 +00001921 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1922 VK_LValue,
1923 OK_Ordinary,
1924 Setter,
1925 NameLoc,
1926 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001927 }
1928
Douglas Gregord51d90d2010-04-26 20:11:03 +00001929 /// \brief Build a new Objective-C "isa" expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001933 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001934 bool IsArrow) {
1935 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001936 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001937 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1938 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001939 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001940 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001941 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001942 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001943 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001944
Douglas Gregord51d90d2010-04-26 20:11:03 +00001945 if (Result.get())
1946 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001947
John McCallb268a282010-08-23 23:25:46 +00001948 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001949 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001950 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001951 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001952 /*TemplateArgs=*/0);
1953 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001954
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 /// \brief Build a new shuffle vector expression.
1956 ///
1957 /// By default, performs semantic analysis to build the new expression.
1958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001959 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001960 MultiExprArg SubExprs,
1961 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001963 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1965 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1966 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1967 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001968
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 // Build a reference to the __builtin_shufflevector builtin
1970 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001971 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00001973 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001975
1976 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 unsigned NumSubExprs = SubExprs.size();
1978 Expr **Subs = (Expr **)SubExprs.release();
1979 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1980 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001981 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00001982 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001984 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001985
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001990
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001992 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
John McCall31f82722010-11-12 08:19:04 +00001994
1995private:
1996 QualType TransformTypeInObjectScope(QualType T,
1997 QualType ObjectType,
1998 NamedDecl *FirstQualifierInScope,
1999 NestedNameSpecifier *Prefix);
2000
2001 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2002 QualType ObjectType,
2003 NamedDecl *FirstQualifierInScope,
2004 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002005};
Douglas Gregora16548e2009-08-11 05:31:07 +00002006
Douglas Gregorebe10102009-08-20 07:17:43 +00002007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002008StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002009 if (!S)
2010 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002011
Douglas Gregorebe10102009-08-20 07:17:43 +00002012 switch (S->getStmtClass()) {
2013 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002014
Douglas Gregorebe10102009-08-20 07:17:43 +00002015 // Transform individual statement nodes
2016#define STMT(Node, Parent) \
2017 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2018#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002019#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002020
Douglas Gregorebe10102009-08-20 07:17:43 +00002021 // Transform expressions by calling TransformExpr.
2022#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002023#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002024#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002025#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002026 {
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002028 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002029 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002030
John McCallb268a282010-08-23 23:25:46 +00002031 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002032 }
Mike Stump11289f42009-09-09 15:08:12 +00002033 }
2034
John McCallc3007a22010-10-26 07:05:15 +00002035 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002036}
Mike Stump11289f42009-09-09 15:08:12 +00002037
2038
Douglas Gregore922c772009-08-04 22:27:00 +00002039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002040ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 if (!E)
2042 return SemaRef.Owned(E);
2043
2044 switch (E->getStmtClass()) {
2045 case Stmt::NoStmtClass: break;
2046#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002047#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002048#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002049 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002050#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002051 }
2052
John McCallc3007a22010-10-26 07:05:15 +00002053 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002054}
2055
2056template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002057NestedNameSpecifier *
2058TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002059 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002060 QualType ObjectType,
2061 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002062 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002063
Douglas Gregorebe10102009-08-20 07:17:43 +00002064 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002065 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002066 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002067 ObjectType,
2068 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002069 if (!Prefix)
2070 return 0;
2071 }
Mike Stump11289f42009-09-09 15:08:12 +00002072
Douglas Gregor1135c352009-08-06 05:28:30 +00002073 switch (NNS->getKind()) {
2074 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002075 if (Prefix) {
2076 // The object type and qualifier-in-scope really apply to the
2077 // leftmost entity.
2078 ObjectType = QualType();
2079 FirstQualifierInScope = 0;
2080 }
2081
Mike Stump11289f42009-09-09 15:08:12 +00002082 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002083 "Identifier nested-name-specifier with no prefix or object type");
2084 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2085 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002086 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002087
2088 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002089 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002090 ObjectType,
2091 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002092
Douglas Gregor1135c352009-08-06 05:28:30 +00002093 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002094 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002095 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002096 getDerived().TransformDecl(Range.getBegin(),
2097 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002098 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002099 Prefix == NNS->getPrefix() &&
2100 NS == NNS->getAsNamespace())
2101 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002102
Douglas Gregor1135c352009-08-06 05:28:30 +00002103 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2104 }
Mike Stump11289f42009-09-09 15:08:12 +00002105
Douglas Gregor1135c352009-08-06 05:28:30 +00002106 case NestedNameSpecifier::Global:
2107 // There is no meaningful transformation that one could perform on the
2108 // global scope.
2109 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002110
Douglas Gregor1135c352009-08-06 05:28:30 +00002111 case NestedNameSpecifier::TypeSpecWithTemplate:
2112 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002113 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002114 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2115 ObjectType,
2116 FirstQualifierInScope,
2117 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002118 if (T.isNull())
2119 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002120
Douglas Gregor1135c352009-08-06 05:28:30 +00002121 if (!getDerived().AlwaysRebuild() &&
2122 Prefix == NNS->getPrefix() &&
2123 T == QualType(NNS->getAsType(), 0))
2124 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002125
2126 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2127 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002128 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002129 }
2130 }
Mike Stump11289f42009-09-09 15:08:12 +00002131
Douglas Gregor1135c352009-08-06 05:28:30 +00002132 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002133 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002134}
2135
2136template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002137DeclarationNameInfo
2138TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002139::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002140 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002141 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002142 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002143
2144 switch (Name.getNameKind()) {
2145 case DeclarationName::Identifier:
2146 case DeclarationName::ObjCZeroArgSelector:
2147 case DeclarationName::ObjCOneArgSelector:
2148 case DeclarationName::ObjCMultiArgSelector:
2149 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002150 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002151 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002152 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002153
Douglas Gregorf816bd72009-09-03 22:13:48 +00002154 case DeclarationName::CXXConstructorName:
2155 case DeclarationName::CXXDestructorName:
2156 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002157 TypeSourceInfo *NewTInfo;
2158 CanQualType NewCanTy;
2159 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002160 NewTInfo = getDerived().TransformType(OldTInfo);
2161 if (!NewTInfo)
2162 return DeclarationNameInfo();
2163 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002164 }
2165 else {
2166 NewTInfo = 0;
2167 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002168 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002169 if (NewT.isNull())
2170 return DeclarationNameInfo();
2171 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2172 }
Mike Stump11289f42009-09-09 15:08:12 +00002173
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002174 DeclarationName NewName
2175 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2176 NewCanTy);
2177 DeclarationNameInfo NewNameInfo(NameInfo);
2178 NewNameInfo.setName(NewName);
2179 NewNameInfo.setNamedTypeInfo(NewTInfo);
2180 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002181 }
Mike Stump11289f42009-09-09 15:08:12 +00002182 }
2183
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002184 assert(0 && "Unknown name kind.");
2185 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002186}
2187
2188template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002189TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002190TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002191 QualType ObjectType,
2192 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002193 SourceLocation Loc = getDerived().getBaseLocation();
2194
Douglas Gregor71dc5092009-08-06 06:41:21 +00002195 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002196 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002197 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002198 /*FIXME*/ SourceRange(Loc),
2199 ObjectType,
2200 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002201 if (!NNS)
2202 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002203
Douglas Gregor71dc5092009-08-06 06:41:21 +00002204 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002205 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002206 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002207 if (!TransTemplate)
2208 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregor71dc5092009-08-06 06:41:21 +00002210 if (!getDerived().AlwaysRebuild() &&
2211 NNS == QTN->getQualifier() &&
2212 TransTemplate == Template)
2213 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002214
Douglas Gregor71dc5092009-08-06 06:41:21 +00002215 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2216 TransTemplate);
2217 }
Mike Stump11289f42009-09-09 15:08:12 +00002218
John McCalle66edc12009-11-24 19:00:30 +00002219 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002220 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregor71dc5092009-08-06 06:41:21 +00002223 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002224 NestedNameSpecifier *NNS = DTN->getQualifier();
2225 if (NNS) {
2226 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2227 /*FIXME:*/SourceRange(Loc),
2228 ObjectType,
2229 FirstQualifierInScope);
2230 if (!NNS) return TemplateName();
2231
2232 // These apply to the scope specifier, not the template.
2233 ObjectType = QualType();
2234 FirstQualifierInScope = 0;
2235 }
Mike Stump11289f42009-09-09 15:08:12 +00002236
Douglas Gregor71dc5092009-08-06 06:41:21 +00002237 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002238 NNS == DTN->getQualifier() &&
2239 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002240 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002241
Douglas Gregora5614c52010-09-08 23:56:00 +00002242 if (DTN->isIdentifier()) {
2243 // FIXME: Bad range
2244 SourceRange QualifierRange(getDerived().getBaseLocation());
2245 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2246 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002247 ObjectType,
2248 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002249 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002250
2251 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002252 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002253 }
Mike Stump11289f42009-09-09 15:08:12 +00002254
Douglas Gregor71dc5092009-08-06 06:41:21 +00002255 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002256 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002257 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002258 if (!TransTemplate)
2259 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregor71dc5092009-08-06 06:41:21 +00002261 if (!getDerived().AlwaysRebuild() &&
2262 TransTemplate == Template)
2263 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregor71dc5092009-08-06 06:41:21 +00002265 return TemplateName(TransTemplate);
2266 }
Mike Stump11289f42009-09-09 15:08:12 +00002267
John McCalle66edc12009-11-24 19:00:30 +00002268 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002269 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002270 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002271}
2272
2273template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002274void TreeTransform<Derived>::InventTemplateArgumentLoc(
2275 const TemplateArgument &Arg,
2276 TemplateArgumentLoc &Output) {
2277 SourceLocation Loc = getDerived().getBaseLocation();
2278 switch (Arg.getKind()) {
2279 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002280 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002281 break;
2282
2283 case TemplateArgument::Type:
2284 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002285 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002286
John McCall0ad16662009-10-29 08:12:44 +00002287 break;
2288
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002289 case TemplateArgument::Template:
2290 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2291 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002292
John McCall0ad16662009-10-29 08:12:44 +00002293 case TemplateArgument::Expression:
2294 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2295 break;
2296
2297 case TemplateArgument::Declaration:
2298 case TemplateArgument::Integral:
2299 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002300 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002301 break;
2302 }
2303}
2304
2305template<typename Derived>
2306bool TreeTransform<Derived>::TransformTemplateArgument(
2307 const TemplateArgumentLoc &Input,
2308 TemplateArgumentLoc &Output) {
2309 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002310 switch (Arg.getKind()) {
2311 case TemplateArgument::Null:
2312 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002313 Output = Input;
2314 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002315
Douglas Gregore922c772009-08-04 22:27:00 +00002316 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002317 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002318 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002319 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002320
2321 DI = getDerived().TransformType(DI);
2322 if (!DI) return true;
2323
2324 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2325 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002326 }
Mike Stump11289f42009-09-09 15:08:12 +00002327
Douglas Gregore922c772009-08-04 22:27:00 +00002328 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002329 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002330 DeclarationName Name;
2331 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2332 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002333 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002334 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002335 if (!D) return true;
2336
John McCall0d07eb32009-10-29 18:45:58 +00002337 Expr *SourceExpr = Input.getSourceDeclExpression();
2338 if (SourceExpr) {
2339 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002340 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002341 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002342 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002343 }
2344
2345 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002346 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002347 }
Mike Stump11289f42009-09-09 15:08:12 +00002348
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002349 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002350 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002351 TemplateName Template
2352 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2353 if (Template.isNull())
2354 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002355
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002356 Output = TemplateArgumentLoc(TemplateArgument(Template),
2357 Input.getTemplateQualifierRange(),
2358 Input.getTemplateNameLoc());
2359 return false;
2360 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002361
Douglas Gregore922c772009-08-04 22:27:00 +00002362 case TemplateArgument::Expression: {
2363 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002364 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002365 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002366
John McCall0ad16662009-10-29 08:12:44 +00002367 Expr *InputExpr = Input.getSourceExpression();
2368 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2369
John McCalldadc5752010-08-24 06:29:42 +00002370 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002371 = getDerived().TransformExpr(InputExpr);
2372 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002373 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002374 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002375 }
Mike Stump11289f42009-09-09 15:08:12 +00002376
Douglas Gregore922c772009-08-04 22:27:00 +00002377 case TemplateArgument::Pack: {
2378 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2379 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002380 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002381 AEnd = Arg.pack_end();
2382 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002383
John McCall0ad16662009-10-29 08:12:44 +00002384 // FIXME: preserve source information here when we start
2385 // caring about parameter packs.
2386
John McCall0d07eb32009-10-29 18:45:58 +00002387 TemplateArgumentLoc InputArg;
2388 TemplateArgumentLoc OutputArg;
2389 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2390 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002391 return true;
2392
John McCall0d07eb32009-10-29 18:45:58 +00002393 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002394 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002395
2396 TemplateArgument *TransformedArgsPtr
2397 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2398 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2399 TransformedArgsPtr);
2400 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2401 TransformedArgs.size()),
2402 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002403 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002404 }
2405 }
Mike Stump11289f42009-09-09 15:08:12 +00002406
Douglas Gregore922c772009-08-04 22:27:00 +00002407 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002408 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002409}
2410
Douglas Gregord6ff3322009-08-04 16:50:30 +00002411//===----------------------------------------------------------------------===//
2412// Type transformation
2413//===----------------------------------------------------------------------===//
2414
2415template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002416QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002417 if (getDerived().AlreadyTransformed(T))
2418 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002419
John McCall550e0c22009-10-21 00:40:46 +00002420 // Temporary workaround. All of these transformations should
2421 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002422 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002423 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002424
John McCall31f82722010-11-12 08:19:04 +00002425 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002426
John McCall550e0c22009-10-21 00:40:46 +00002427 if (!NewDI)
2428 return QualType();
2429
2430 return NewDI->getType();
2431}
2432
2433template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002434TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002435 if (getDerived().AlreadyTransformed(DI->getType()))
2436 return DI;
2437
2438 TypeLocBuilder TLB;
2439
2440 TypeLoc TL = DI->getTypeLoc();
2441 TLB.reserve(TL.getFullDataSize());
2442
John McCall31f82722010-11-12 08:19:04 +00002443 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002444 if (Result.isNull())
2445 return 0;
2446
John McCallbcd03502009-12-07 02:54:59 +00002447 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002448}
2449
2450template<typename Derived>
2451QualType
John McCall31f82722010-11-12 08:19:04 +00002452TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002453 switch (T.getTypeLocClass()) {
2454#define ABSTRACT_TYPELOC(CLASS, PARENT)
2455#define TYPELOC(CLASS, PARENT) \
2456 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002457 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002458#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002459 }
Mike Stump11289f42009-09-09 15:08:12 +00002460
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002461 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002462 return QualType();
2463}
2464
2465/// FIXME: By default, this routine adds type qualifiers only to types
2466/// that can have qualifiers, and silently suppresses those qualifiers
2467/// that are not permitted (e.g., qualifiers on reference or function
2468/// types). This is the right thing for template instantiation, but
2469/// probably not for other clients.
2470template<typename Derived>
2471QualType
2472TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002473 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002474 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002475
John McCall31f82722010-11-12 08:19:04 +00002476 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002477 if (Result.isNull())
2478 return QualType();
2479
2480 // Silently suppress qualifiers if the result type can't be qualified.
2481 // FIXME: this is the right thing for template instantiation, but
2482 // probably not for other clients.
2483 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002484 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002485
John McCallcb0f89a2010-06-05 06:41:15 +00002486 if (!Quals.empty()) {
2487 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2488 TLB.push<QualifiedTypeLoc>(Result);
2489 // No location information to preserve.
2490 }
John McCall550e0c22009-10-21 00:40:46 +00002491
2492 return Result;
2493}
2494
John McCall31f82722010-11-12 08:19:04 +00002495/// \brief Transforms a type that was written in a scope specifier,
2496/// given an object type, the results of unqualified lookup, and
2497/// an already-instantiated prefix.
2498///
2499/// The object type is provided iff the scope specifier qualifies the
2500/// member of a dependent member-access expression. The prefix is
2501/// provided iff the the scope specifier in which this appears has a
2502/// prefix.
2503///
2504/// This is private to TreeTransform.
2505template<typename Derived>
2506QualType
2507TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2508 QualType ObjectType,
2509 NamedDecl *UnqualLookup,
2510 NestedNameSpecifier *Prefix) {
2511 if (getDerived().AlreadyTransformed(T))
2512 return T;
2513
2514 TypeSourceInfo *TSI =
2515 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2516
2517 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2518 UnqualLookup, Prefix);
2519 if (!TSI) return QualType();
2520 return TSI->getType();
2521}
2522
2523template<typename Derived>
2524TypeSourceInfo *
2525TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2526 QualType ObjectType,
2527 NamedDecl *UnqualLookup,
2528 NestedNameSpecifier *Prefix) {
2529 // TODO: in some cases, we might be some verification to do here.
2530 if (ObjectType.isNull())
2531 return getDerived().TransformType(TSI);
2532
2533 QualType T = TSI->getType();
2534 if (getDerived().AlreadyTransformed(T))
2535 return TSI;
2536
2537 TypeLocBuilder TLB;
2538 QualType Result;
2539
2540 if (isa<TemplateSpecializationType>(T)) {
2541 TemplateSpecializationTypeLoc TL
2542 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2543
2544 TemplateName Template =
2545 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2546 ObjectType, UnqualLookup);
2547 if (Template.isNull()) return 0;
2548
2549 Result = getDerived()
2550 .TransformTemplateSpecializationType(TLB, TL, Template);
2551 } else if (isa<DependentTemplateSpecializationType>(T)) {
2552 DependentTemplateSpecializationTypeLoc TL
2553 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2554
2555 Result = getDerived()
2556 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2557 } else {
2558 // Nothing special needs to be done for these.
2559 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2560 }
2561
2562 if (Result.isNull()) return 0;
2563 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2564}
2565
John McCall550e0c22009-10-21 00:40:46 +00002566template <class TyLoc> static inline
2567QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2568 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2569 NewT.setNameLoc(T.getNameLoc());
2570 return T.getType();
2571}
2572
John McCall550e0c22009-10-21 00:40:46 +00002573template<typename Derived>
2574QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002575 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002576 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2577 NewT.setBuiltinLoc(T.getBuiltinLoc());
2578 if (T.needsExtraLocalData())
2579 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2580 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002581}
Mike Stump11289f42009-09-09 15:08:12 +00002582
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002584QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002585 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002586 // FIXME: recurse?
2587 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002588}
Mike Stump11289f42009-09-09 15:08:12 +00002589
Douglas Gregord6ff3322009-08-04 16:50:30 +00002590template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002591QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002592 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002593 QualType PointeeType
2594 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002595 if (PointeeType.isNull())
2596 return QualType();
2597
2598 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002599 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002600 // A dependent pointer type 'T *' has is being transformed such
2601 // that an Objective-C class type is being replaced for 'T'. The
2602 // resulting pointer type is an ObjCObjectPointerType, not a
2603 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002604 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002605
John McCall8b07ec22010-05-15 11:32:37 +00002606 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2607 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002608 return Result;
2609 }
John McCall31f82722010-11-12 08:19:04 +00002610
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002611 if (getDerived().AlwaysRebuild() ||
2612 PointeeType != TL.getPointeeLoc().getType()) {
2613 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2614 if (Result.isNull())
2615 return QualType();
2616 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002617
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002618 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2619 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002620 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002621}
Mike Stump11289f42009-09-09 15:08:12 +00002622
2623template<typename Derived>
2624QualType
John McCall550e0c22009-10-21 00:40:46 +00002625TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002626 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002627 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002628 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2629 if (PointeeType.isNull())
2630 return QualType();
2631
2632 QualType Result = TL.getType();
2633 if (getDerived().AlwaysRebuild() ||
2634 PointeeType != TL.getPointeeLoc().getType()) {
2635 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002636 TL.getSigilLoc());
2637 if (Result.isNull())
2638 return QualType();
2639 }
2640
Douglas Gregor049211a2010-04-22 16:50:51 +00002641 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002642 NewT.setSigilLoc(TL.getSigilLoc());
2643 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002644}
2645
John McCall70dd5f62009-10-30 00:06:24 +00002646/// Transforms a reference type. Note that somewhat paradoxically we
2647/// don't care whether the type itself is an l-value type or an r-value
2648/// type; we only care if the type was *written* as an l-value type
2649/// or an r-value type.
2650template<typename Derived>
2651QualType
2652TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002653 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002654 const ReferenceType *T = TL.getTypePtr();
2655
2656 // Note that this works with the pointee-as-written.
2657 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2658 if (PointeeType.isNull())
2659 return QualType();
2660
2661 QualType Result = TL.getType();
2662 if (getDerived().AlwaysRebuild() ||
2663 PointeeType != T->getPointeeTypeAsWritten()) {
2664 Result = getDerived().RebuildReferenceType(PointeeType,
2665 T->isSpelledAsLValue(),
2666 TL.getSigilLoc());
2667 if (Result.isNull())
2668 return QualType();
2669 }
2670
2671 // r-value references can be rebuilt as l-value references.
2672 ReferenceTypeLoc NewTL;
2673 if (isa<LValueReferenceType>(Result))
2674 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2675 else
2676 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2677 NewTL.setSigilLoc(TL.getSigilLoc());
2678
2679 return Result;
2680}
2681
Mike Stump11289f42009-09-09 15:08:12 +00002682template<typename Derived>
2683QualType
John McCall550e0c22009-10-21 00:40:46 +00002684TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002685 LValueReferenceTypeLoc TL) {
2686 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002687}
2688
Mike Stump11289f42009-09-09 15:08:12 +00002689template<typename Derived>
2690QualType
John McCall550e0c22009-10-21 00:40:46 +00002691TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002692 RValueReferenceTypeLoc TL) {
2693 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002694}
Mike Stump11289f42009-09-09 15:08:12 +00002695
Douglas Gregord6ff3322009-08-04 16:50:30 +00002696template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002697QualType
John McCall550e0c22009-10-21 00:40:46 +00002698TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002699 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002700 MemberPointerType *T = TL.getTypePtr();
2701
2702 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002703 if (PointeeType.isNull())
2704 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002705
John McCall550e0c22009-10-21 00:40:46 +00002706 // TODO: preserve source information for this.
2707 QualType ClassType
2708 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002709 if (ClassType.isNull())
2710 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002711
John McCall550e0c22009-10-21 00:40:46 +00002712 QualType Result = TL.getType();
2713 if (getDerived().AlwaysRebuild() ||
2714 PointeeType != T->getPointeeType() ||
2715 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002716 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2717 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002718 if (Result.isNull())
2719 return QualType();
2720 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002721
John McCall550e0c22009-10-21 00:40:46 +00002722 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2723 NewTL.setSigilLoc(TL.getSigilLoc());
2724
2725 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002726}
2727
Mike Stump11289f42009-09-09 15:08:12 +00002728template<typename Derived>
2729QualType
John McCall550e0c22009-10-21 00:40:46 +00002730TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002731 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002732 ConstantArrayType *T = TL.getTypePtr();
2733 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002734 if (ElementType.isNull())
2735 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002736
John McCall550e0c22009-10-21 00:40:46 +00002737 QualType Result = TL.getType();
2738 if (getDerived().AlwaysRebuild() ||
2739 ElementType != T->getElementType()) {
2740 Result = getDerived().RebuildConstantArrayType(ElementType,
2741 T->getSizeModifier(),
2742 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002743 T->getIndexTypeCVRQualifiers(),
2744 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002745 if (Result.isNull())
2746 return QualType();
2747 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002748
John McCall550e0c22009-10-21 00:40:46 +00002749 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2750 NewTL.setLBracketLoc(TL.getLBracketLoc());
2751 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002752
John McCall550e0c22009-10-21 00:40:46 +00002753 Expr *Size = TL.getSizeExpr();
2754 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002755 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002756 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2757 }
2758 NewTL.setSizeExpr(Size);
2759
2760 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002761}
Mike Stump11289f42009-09-09 15:08:12 +00002762
Douglas Gregord6ff3322009-08-04 16:50:30 +00002763template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002764QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002765 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002766 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002767 IncompleteArrayType *T = TL.getTypePtr();
2768 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002769 if (ElementType.isNull())
2770 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002771
John McCall550e0c22009-10-21 00:40:46 +00002772 QualType Result = TL.getType();
2773 if (getDerived().AlwaysRebuild() ||
2774 ElementType != T->getElementType()) {
2775 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002776 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002777 T->getIndexTypeCVRQualifiers(),
2778 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002779 if (Result.isNull())
2780 return QualType();
2781 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002782
John McCall550e0c22009-10-21 00:40:46 +00002783 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2784 NewTL.setLBracketLoc(TL.getLBracketLoc());
2785 NewTL.setRBracketLoc(TL.getRBracketLoc());
2786 NewTL.setSizeExpr(0);
2787
2788 return Result;
2789}
2790
2791template<typename Derived>
2792QualType
2793TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002794 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002795 VariableArrayType *T = TL.getTypePtr();
2796 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2797 if (ElementType.isNull())
2798 return QualType();
2799
2800 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002801 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002802
John McCalldadc5752010-08-24 06:29:42 +00002803 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002804 = getDerived().TransformExpr(T->getSizeExpr());
2805 if (SizeResult.isInvalid())
2806 return QualType();
2807
John McCallb268a282010-08-23 23:25:46 +00002808 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002809
2810 QualType Result = TL.getType();
2811 if (getDerived().AlwaysRebuild() ||
2812 ElementType != T->getElementType() ||
2813 Size != T->getSizeExpr()) {
2814 Result = getDerived().RebuildVariableArrayType(ElementType,
2815 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002816 Size,
John McCall550e0c22009-10-21 00:40:46 +00002817 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002818 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002819 if (Result.isNull())
2820 return QualType();
2821 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002822
John McCall550e0c22009-10-21 00:40:46 +00002823 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2824 NewTL.setLBracketLoc(TL.getLBracketLoc());
2825 NewTL.setRBracketLoc(TL.getRBracketLoc());
2826 NewTL.setSizeExpr(Size);
2827
2828 return Result;
2829}
2830
2831template<typename Derived>
2832QualType
2833TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002834 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002835 DependentSizedArrayType *T = TL.getTypePtr();
2836 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2837 if (ElementType.isNull())
2838 return QualType();
2839
2840 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002841 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002842
John McCalldadc5752010-08-24 06:29:42 +00002843 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002844 = getDerived().TransformExpr(T->getSizeExpr());
2845 if (SizeResult.isInvalid())
2846 return QualType();
2847
2848 Expr *Size = static_cast<Expr*>(SizeResult.get());
2849
2850 QualType Result = TL.getType();
2851 if (getDerived().AlwaysRebuild() ||
2852 ElementType != T->getElementType() ||
2853 Size != T->getSizeExpr()) {
2854 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2855 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002856 Size,
John McCall550e0c22009-10-21 00:40:46 +00002857 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002858 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002859 if (Result.isNull())
2860 return QualType();
2861 }
2862 else SizeResult.take();
2863
2864 // We might have any sort of array type now, but fortunately they
2865 // all have the same location layout.
2866 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2867 NewTL.setLBracketLoc(TL.getLBracketLoc());
2868 NewTL.setRBracketLoc(TL.getRBracketLoc());
2869 NewTL.setSizeExpr(Size);
2870
2871 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002872}
Mike Stump11289f42009-09-09 15:08:12 +00002873
2874template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002875QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002876 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002877 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002878 DependentSizedExtVectorType *T = TL.getTypePtr();
2879
2880 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002881 QualType ElementType = getDerived().TransformType(T->getElementType());
2882 if (ElementType.isNull())
2883 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002884
Douglas Gregore922c772009-08-04 22:27:00 +00002885 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002886 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002887
John McCalldadc5752010-08-24 06:29:42 +00002888 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002889 if (Size.isInvalid())
2890 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002891
John McCall550e0c22009-10-21 00:40:46 +00002892 QualType Result = TL.getType();
2893 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002894 ElementType != T->getElementType() ||
2895 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002896 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002897 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002898 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002899 if (Result.isNull())
2900 return QualType();
2901 }
John McCall550e0c22009-10-21 00:40:46 +00002902
2903 // Result might be dependent or not.
2904 if (isa<DependentSizedExtVectorType>(Result)) {
2905 DependentSizedExtVectorTypeLoc NewTL
2906 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2907 NewTL.setNameLoc(TL.getNameLoc());
2908 } else {
2909 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2910 NewTL.setNameLoc(TL.getNameLoc());
2911 }
2912
2913 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002914}
Mike Stump11289f42009-09-09 15:08:12 +00002915
2916template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002917QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002918 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002919 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002920 QualType ElementType = getDerived().TransformType(T->getElementType());
2921 if (ElementType.isNull())
2922 return QualType();
2923
John McCall550e0c22009-10-21 00:40:46 +00002924 QualType Result = TL.getType();
2925 if (getDerived().AlwaysRebuild() ||
2926 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002927 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00002928 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00002929 if (Result.isNull())
2930 return QualType();
2931 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002932
John McCall550e0c22009-10-21 00:40:46 +00002933 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2934 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002935
John McCall550e0c22009-10-21 00:40:46 +00002936 return Result;
2937}
2938
2939template<typename Derived>
2940QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002941 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002942 VectorType *T = TL.getTypePtr();
2943 QualType ElementType = getDerived().TransformType(T->getElementType());
2944 if (ElementType.isNull())
2945 return QualType();
2946
2947 QualType Result = TL.getType();
2948 if (getDerived().AlwaysRebuild() ||
2949 ElementType != T->getElementType()) {
2950 Result = getDerived().RebuildExtVectorType(ElementType,
2951 T->getNumElements(),
2952 /*FIXME*/ SourceLocation());
2953 if (Result.isNull())
2954 return QualType();
2955 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002956
John McCall550e0c22009-10-21 00:40:46 +00002957 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2958 NewTL.setNameLoc(TL.getNameLoc());
2959
2960 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002961}
Mike Stump11289f42009-09-09 15:08:12 +00002962
2963template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002964ParmVarDecl *
2965TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2966 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2967 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2968 if (!NewDI)
2969 return 0;
2970
2971 if (NewDI == OldDI)
2972 return OldParm;
2973 else
2974 return ParmVarDecl::Create(SemaRef.Context,
2975 OldParm->getDeclContext(),
2976 OldParm->getLocation(),
2977 OldParm->getIdentifier(),
2978 NewDI->getType(),
2979 NewDI,
2980 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002981 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002982 /* DefArg */ NULL);
2983}
2984
2985template<typename Derived>
2986bool TreeTransform<Derived>::
2987 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2988 llvm::SmallVectorImpl<QualType> &PTypes,
2989 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2990 FunctionProtoType *T = TL.getTypePtr();
2991
2992 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2993 ParmVarDecl *OldParm = TL.getArg(i);
2994
2995 QualType NewType;
2996 ParmVarDecl *NewParm;
2997
2998 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002999 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3000 if (!NewParm)
3001 return true;
3002 NewType = NewParm->getType();
3003
3004 // Deal with the possibility that we don't have a parameter
3005 // declaration for this parameter.
3006 } else {
3007 NewParm = 0;
3008
3009 QualType OldType = T->getArgType(i);
3010 NewType = getDerived().TransformType(OldType);
3011 if (NewType.isNull())
3012 return true;
3013 }
3014
3015 PTypes.push_back(NewType);
3016 PVars.push_back(NewParm);
3017 }
3018
3019 return false;
3020}
3021
3022template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003023QualType
John McCall550e0c22009-10-21 00:40:46 +00003024TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003025 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003026 // Transform the parameters and return type.
3027 //
3028 // We instantiate in source order, with the return type first followed by
3029 // the parameters, because users tend to expect this (even if they shouldn't
3030 // rely on it!).
3031 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003032 // When the function has a trailing return type, we instantiate the
3033 // parameters before the return type, since the return type can then refer
3034 // to the parameters themselves (via decltype, sizeof, etc.).
3035 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003036 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003037 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003038 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003039
Douglas Gregor7fb25412010-10-01 18:44:50 +00003040 QualType ResultType;
3041
3042 if (TL.getTrailingReturn()) {
3043 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3044 return QualType();
3045
3046 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3047 if (ResultType.isNull())
3048 return QualType();
3049 }
3050 else {
3051 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3052 if (ResultType.isNull())
3053 return QualType();
3054
3055 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3056 return QualType();
3057 }
3058
John McCall550e0c22009-10-21 00:40:46 +00003059 QualType Result = TL.getType();
3060 if (getDerived().AlwaysRebuild() ||
3061 ResultType != T->getResultType() ||
3062 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3063 Result = getDerived().RebuildFunctionProtoType(ResultType,
3064 ParamTypes.data(),
3065 ParamTypes.size(),
3066 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003067 T->getTypeQuals(),
3068 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003069 if (Result.isNull())
3070 return QualType();
3071 }
Mike Stump11289f42009-09-09 15:08:12 +00003072
John McCall550e0c22009-10-21 00:40:46 +00003073 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3074 NewTL.setLParenLoc(TL.getLParenLoc());
3075 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003076 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003077 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3078 NewTL.setArg(i, ParamDecls[i]);
3079
3080 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003081}
Mike Stump11289f42009-09-09 15:08:12 +00003082
Douglas Gregord6ff3322009-08-04 16:50:30 +00003083template<typename Derived>
3084QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003085 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003086 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003087 FunctionNoProtoType *T = TL.getTypePtr();
3088 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3089 if (ResultType.isNull())
3090 return QualType();
3091
3092 QualType Result = TL.getType();
3093 if (getDerived().AlwaysRebuild() ||
3094 ResultType != T->getResultType())
3095 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3096
3097 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3098 NewTL.setLParenLoc(TL.getLParenLoc());
3099 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003100 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003101
3102 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003103}
Mike Stump11289f42009-09-09 15:08:12 +00003104
John McCallb96ec562009-12-04 22:46:56 +00003105template<typename Derived> QualType
3106TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003107 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003108 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003109 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003110 if (!D)
3111 return QualType();
3112
3113 QualType Result = TL.getType();
3114 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3115 Result = getDerived().RebuildUnresolvedUsingType(D);
3116 if (Result.isNull())
3117 return QualType();
3118 }
3119
3120 // We might get an arbitrary type spec type back. We should at
3121 // least always get a type spec type, though.
3122 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3123 NewTL.setNameLoc(TL.getNameLoc());
3124
3125 return Result;
3126}
3127
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003129QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003130 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003131 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003132 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003133 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3134 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003135 if (!Typedef)
3136 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003137
John McCall550e0c22009-10-21 00:40:46 +00003138 QualType Result = TL.getType();
3139 if (getDerived().AlwaysRebuild() ||
3140 Typedef != T->getDecl()) {
3141 Result = getDerived().RebuildTypedefType(Typedef);
3142 if (Result.isNull())
3143 return QualType();
3144 }
Mike Stump11289f42009-09-09 15:08:12 +00003145
John McCall550e0c22009-10-21 00:40:46 +00003146 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3147 NewTL.setNameLoc(TL.getNameLoc());
3148
3149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003150}
Mike Stump11289f42009-09-09 15:08:12 +00003151
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003153QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003154 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003155 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003156 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003157
John McCalldadc5752010-08-24 06:29:42 +00003158 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003159 if (E.isInvalid())
3160 return QualType();
3161
John McCall550e0c22009-10-21 00:40:46 +00003162 QualType Result = TL.getType();
3163 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003164 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003165 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003166 if (Result.isNull())
3167 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003168 }
John McCall550e0c22009-10-21 00:40:46 +00003169 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003170
John McCall550e0c22009-10-21 00:40:46 +00003171 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003172 NewTL.setTypeofLoc(TL.getTypeofLoc());
3173 NewTL.setLParenLoc(TL.getLParenLoc());
3174 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003175
3176 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003177}
Mike Stump11289f42009-09-09 15:08:12 +00003178
3179template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003180QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003181 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003182 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3183 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3184 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003185 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003186
John McCall550e0c22009-10-21 00:40:46 +00003187 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003188 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3189 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003190 if (Result.isNull())
3191 return QualType();
3192 }
Mike Stump11289f42009-09-09 15:08:12 +00003193
John McCall550e0c22009-10-21 00:40:46 +00003194 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003195 NewTL.setTypeofLoc(TL.getTypeofLoc());
3196 NewTL.setLParenLoc(TL.getLParenLoc());
3197 NewTL.setRParenLoc(TL.getRParenLoc());
3198 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003199
3200 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003201}
Mike Stump11289f42009-09-09 15:08:12 +00003202
3203template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003204QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003205 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003206 DecltypeType *T = TL.getTypePtr();
3207
Douglas Gregore922c772009-08-04 22:27:00 +00003208 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003209 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003210
John McCalldadc5752010-08-24 06:29:42 +00003211 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003212 if (E.isInvalid())
3213 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003214
John McCall550e0c22009-10-21 00:40:46 +00003215 QualType Result = TL.getType();
3216 if (getDerived().AlwaysRebuild() ||
3217 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003218 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003219 if (Result.isNull())
3220 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003221 }
John McCall550e0c22009-10-21 00:40:46 +00003222 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003223
John McCall550e0c22009-10-21 00:40:46 +00003224 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3225 NewTL.setNameLoc(TL.getNameLoc());
3226
3227 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003228}
3229
3230template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003231QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003232 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003233 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003234 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003235 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3236 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003237 if (!Record)
3238 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003239
John McCall550e0c22009-10-21 00:40:46 +00003240 QualType Result = TL.getType();
3241 if (getDerived().AlwaysRebuild() ||
3242 Record != T->getDecl()) {
3243 Result = getDerived().RebuildRecordType(Record);
3244 if (Result.isNull())
3245 return QualType();
3246 }
Mike Stump11289f42009-09-09 15:08:12 +00003247
John McCall550e0c22009-10-21 00:40:46 +00003248 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3249 NewTL.setNameLoc(TL.getNameLoc());
3250
3251 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003252}
Mike Stump11289f42009-09-09 15:08:12 +00003253
3254template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003255QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003256 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003257 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003258 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003259 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3260 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003261 if (!Enum)
3262 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003263
John McCall550e0c22009-10-21 00:40:46 +00003264 QualType Result = TL.getType();
3265 if (getDerived().AlwaysRebuild() ||
3266 Enum != T->getDecl()) {
3267 Result = getDerived().RebuildEnumType(Enum);
3268 if (Result.isNull())
3269 return QualType();
3270 }
Mike Stump11289f42009-09-09 15:08:12 +00003271
John McCall550e0c22009-10-21 00:40:46 +00003272 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3273 NewTL.setNameLoc(TL.getNameLoc());
3274
3275 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003276}
John McCallfcc33b02009-09-05 00:15:47 +00003277
John McCalle78aac42010-03-10 03:28:59 +00003278template<typename Derived>
3279QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3280 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003281 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003282 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3283 TL.getTypePtr()->getDecl());
3284 if (!D) return QualType();
3285
3286 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3287 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3288 return T;
3289}
3290
Mike Stump11289f42009-09-09 15:08:12 +00003291
Douglas Gregord6ff3322009-08-04 16:50:30 +00003292template<typename Derived>
3293QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003294 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003295 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003296 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003297}
3298
Mike Stump11289f42009-09-09 15:08:12 +00003299template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003300QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003301 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003302 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003303 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003304}
3305
3306template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003307QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003308 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003309 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003310 const TemplateSpecializationType *T = TL.getTypePtr();
3311
Mike Stump11289f42009-09-09 15:08:12 +00003312 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003313 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003314 if (Template.isNull())
3315 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003316
John McCall31f82722010-11-12 08:19:04 +00003317 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3318}
3319
3320template <typename Derived>
3321QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3322 TypeLocBuilder &TLB,
3323 TemplateSpecializationTypeLoc TL,
3324 TemplateName Template) {
3325 const TemplateSpecializationType *T = TL.getTypePtr();
3326
John McCall6b51f282009-11-23 01:53:49 +00003327 TemplateArgumentListInfo NewTemplateArgs;
3328 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3329 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3330
3331 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3332 TemplateArgumentLoc Loc;
3333 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003335 NewTemplateArgs.addArgument(Loc);
3336 }
Mike Stump11289f42009-09-09 15:08:12 +00003337
John McCall0ad16662009-10-29 08:12:44 +00003338 // FIXME: maybe don't rebuild if all the template arguments are the same.
3339
3340 QualType Result =
3341 getDerived().RebuildTemplateSpecializationType(Template,
3342 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003343 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003344
3345 if (!Result.isNull()) {
3346 TemplateSpecializationTypeLoc NewTL
3347 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3348 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3349 NewTL.setLAngleLoc(TL.getLAngleLoc());
3350 NewTL.setRAngleLoc(TL.getRAngleLoc());
3351 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3352 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003353 }
Mike Stump11289f42009-09-09 15:08:12 +00003354
John McCall0ad16662009-10-29 08:12:44 +00003355 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003356}
Mike Stump11289f42009-09-09 15:08:12 +00003357
3358template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003359QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003360TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003361 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003362 ElaboratedType *T = TL.getTypePtr();
3363
3364 NestedNameSpecifier *NNS = 0;
3365 // NOTE: the qualifier in an ElaboratedType is optional.
3366 if (T->getQualifier() != 0) {
3367 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003368 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003369 if (!NNS)
3370 return QualType();
3371 }
Mike Stump11289f42009-09-09 15:08:12 +00003372
John McCall31f82722010-11-12 08:19:04 +00003373 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3374 if (NamedT.isNull())
3375 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003376
John McCall550e0c22009-10-21 00:40:46 +00003377 QualType Result = TL.getType();
3378 if (getDerived().AlwaysRebuild() ||
3379 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003380 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003381 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3382 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003383 if (Result.isNull())
3384 return QualType();
3385 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003386
Abramo Bagnara6150c882010-05-11 21:36:43 +00003387 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003388 NewTL.setKeywordLoc(TL.getKeywordLoc());
3389 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003390
3391 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003392}
Mike Stump11289f42009-09-09 15:08:12 +00003393
3394template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003395QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003396 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003397 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003398
Douglas Gregord6ff3322009-08-04 16:50:30 +00003399 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003400 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003401 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003402 if (!NNS)
3403 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003404
John McCallc392f372010-06-11 00:33:02 +00003405 QualType Result
3406 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3407 T->getIdentifier(),
3408 TL.getKeywordLoc(),
3409 TL.getQualifierRange(),
3410 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003411 if (Result.isNull())
3412 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003413
Abramo Bagnarad7548482010-05-19 21:37:53 +00003414 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3415 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003416 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3417
Abramo Bagnarad7548482010-05-19 21:37:53 +00003418 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3419 NewTL.setKeywordLoc(TL.getKeywordLoc());
3420 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003421 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003422 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3423 NewTL.setKeywordLoc(TL.getKeywordLoc());
3424 NewTL.setQualifierRange(TL.getQualifierRange());
3425 NewTL.setNameLoc(TL.getNameLoc());
3426 }
John McCall550e0c22009-10-21 00:40:46 +00003427 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003428}
Mike Stump11289f42009-09-09 15:08:12 +00003429
Douglas Gregord6ff3322009-08-04 16:50:30 +00003430template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003431QualType TreeTransform<Derived>::
3432 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003433 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003434 DependentTemplateSpecializationType *T = TL.getTypePtr();
3435
3436 NestedNameSpecifier *NNS
3437 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003438 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003439 if (!NNS)
3440 return QualType();
3441
John McCall31f82722010-11-12 08:19:04 +00003442 return getDerived()
3443 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3444}
3445
3446template<typename Derived>
3447QualType TreeTransform<Derived>::
3448 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3449 DependentTemplateSpecializationTypeLoc TL,
3450 NestedNameSpecifier *NNS) {
3451 DependentTemplateSpecializationType *T = TL.getTypePtr();
3452
John McCallc392f372010-06-11 00:33:02 +00003453 TemplateArgumentListInfo NewTemplateArgs;
3454 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3455 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3456
3457 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3458 TemplateArgumentLoc Loc;
3459 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3460 return QualType();
3461 NewTemplateArgs.addArgument(Loc);
3462 }
3463
Douglas Gregora5614c52010-09-08 23:56:00 +00003464 QualType Result
3465 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3466 NNS,
3467 TL.getQualifierRange(),
3468 T->getIdentifier(),
3469 TL.getNameLoc(),
3470 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003471 if (Result.isNull())
3472 return QualType();
3473
3474 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3475 QualType NamedT = ElabT->getNamedType();
3476
3477 // Copy information relevant to the template specialization.
3478 TemplateSpecializationTypeLoc NamedTL
3479 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3480 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3481 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3482 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3483 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3484
3485 // Copy information relevant to the elaborated type.
3486 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3487 NewTL.setKeywordLoc(TL.getKeywordLoc());
3488 NewTL.setQualifierRange(TL.getQualifierRange());
3489 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003490 TypeLoc NewTL(Result, TL.getOpaqueData());
3491 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003492 }
3493 return Result;
3494}
3495
3496template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003497QualType
3498TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003499 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003500 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003501 TLB.pushFullCopy(TL);
3502 return TL.getType();
3503}
3504
3505template<typename Derived>
3506QualType
3507TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003508 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003509 // ObjCObjectType is never dependent.
3510 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003511 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003512}
Mike Stump11289f42009-09-09 15:08:12 +00003513
3514template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003515QualType
3516TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003517 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003518 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003519 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003520 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003521}
3522
Douglas Gregord6ff3322009-08-04 16:50:30 +00003523//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003524// Statement transformation
3525//===----------------------------------------------------------------------===//
3526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003527StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003528TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003529 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003530}
3531
3532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003533StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003534TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3535 return getDerived().TransformCompoundStmt(S, false);
3536}
3537
3538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003539StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003540TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003541 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003542 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003543 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003544 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3546 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003547 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003548 if (Result.isInvalid()) {
3549 // Immediately fail if this was a DeclStmt, since it's very
3550 // likely that this will cause problems for future statements.
3551 if (isa<DeclStmt>(*B))
3552 return StmtError();
3553
3554 // Otherwise, just keep processing substatements and fail later.
3555 SubStmtInvalid = true;
3556 continue;
3557 }
Mike Stump11289f42009-09-09 15:08:12 +00003558
Douglas Gregorebe10102009-08-20 07:17:43 +00003559 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3560 Statements.push_back(Result.takeAs<Stmt>());
3561 }
Mike Stump11289f42009-09-09 15:08:12 +00003562
John McCall1ababa62010-08-27 19:56:05 +00003563 if (SubStmtInvalid)
3564 return StmtError();
3565
Douglas Gregorebe10102009-08-20 07:17:43 +00003566 if (!getDerived().AlwaysRebuild() &&
3567 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003568 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003569
3570 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3571 move_arg(Statements),
3572 S->getRBracLoc(),
3573 IsStmtExpr);
3574}
Mike Stump11289f42009-09-09 15:08:12 +00003575
Douglas Gregorebe10102009-08-20 07:17:43 +00003576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003577StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003578TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003579 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003580 {
3581 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003582 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003583
Eli Friedman06577382009-11-19 03:14:00 +00003584 // Transform the left-hand case value.
3585 LHS = getDerived().TransformExpr(S->getLHS());
3586 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003587 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003588
Eli Friedman06577382009-11-19 03:14:00 +00003589 // Transform the right-hand case value (for the GNU case-range extension).
3590 RHS = getDerived().TransformExpr(S->getRHS());
3591 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003592 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003593 }
Mike Stump11289f42009-09-09 15:08:12 +00003594
Douglas Gregorebe10102009-08-20 07:17:43 +00003595 // Build the case statement.
3596 // Case statements are always rebuilt so that they will attached to their
3597 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003598 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003599 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003600 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003601 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003602 S->getColonLoc());
3603 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003604 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003607 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003608 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003609 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003612 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003613}
3614
3615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003616StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003617TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003618 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003619 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003620 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003621 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003622
Douglas Gregorebe10102009-08-20 07:17:43 +00003623 // Default statements are always rebuilt
3624 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003625 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003626}
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregorebe10102009-08-20 07:17:43 +00003628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003629StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003630TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003631 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003632 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003633 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003634
Douglas Gregorebe10102009-08-20 07:17:43 +00003635 // FIXME: Pass the real colon location in.
3636 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3637 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003638 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003639}
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregorebe10102009-08-20 07:17:43 +00003641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003642StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003643TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003644 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003645 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003646 VarDecl *ConditionVar = 0;
3647 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003648 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003649 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003650 getDerived().TransformDefinition(
3651 S->getConditionVariable()->getLocation(),
3652 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003653 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003654 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003655 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003656 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003657
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003658 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003659 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003660
3661 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003662 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003663 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003664 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003665 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003666 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003667 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003668
John McCallb268a282010-08-23 23:25:46 +00003669 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003670 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003671 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003672
John McCallb268a282010-08-23 23:25:46 +00003673 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3674 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003675 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003676
Douglas Gregorebe10102009-08-20 07:17:43 +00003677 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003678 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003679 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003680 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003681
Douglas Gregorebe10102009-08-20 07:17:43 +00003682 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003683 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003684 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003685 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003686
Douglas Gregorebe10102009-08-20 07:17:43 +00003687 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003688 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003689 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003690 Then.get() == S->getThen() &&
3691 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003692 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003693
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003694 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003695 Then.get(),
3696 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003697}
3698
3699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003700StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003701TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003702 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003703 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003704 VarDecl *ConditionVar = 0;
3705 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003706 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003707 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003708 getDerived().TransformDefinition(
3709 S->getConditionVariable()->getLocation(),
3710 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003711 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003712 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003713 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003714 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003715
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003716 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003717 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003718 }
Mike Stump11289f42009-09-09 15:08:12 +00003719
Douglas Gregorebe10102009-08-20 07:17:43 +00003720 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003721 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003722 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003723 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003724 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003725 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003726
Douglas Gregorebe10102009-08-20 07:17:43 +00003727 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003728 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003729 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003730 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003731
Douglas Gregorebe10102009-08-20 07:17:43 +00003732 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003733 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3734 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003735}
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregorebe10102009-08-20 07:17:43 +00003737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003738StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003739TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003740 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003741 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003742 VarDecl *ConditionVar = 0;
3743 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003744 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003745 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003746 getDerived().TransformDefinition(
3747 S->getConditionVariable()->getLocation(),
3748 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003749 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003750 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003751 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003752 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003753
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003754 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003755 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003756
3757 if (S->getCond()) {
3758 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003759 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003760 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003761 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003762 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003763 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003764 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003765 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003766 }
Mike Stump11289f42009-09-09 15:08:12 +00003767
John McCallb268a282010-08-23 23:25:46 +00003768 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3769 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003770 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003771
Douglas Gregorebe10102009-08-20 07:17:43 +00003772 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003773 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003774 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003775 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregorebe10102009-08-20 07:17:43 +00003777 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003778 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003779 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003780 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003781 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003782
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003783 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003784 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003785}
Mike Stump11289f42009-09-09 15:08:12 +00003786
Douglas Gregorebe10102009-08-20 07:17:43 +00003787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003788StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003789TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003790 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003791 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003792 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003793 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003794
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003795 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003796 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003797 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003798 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003799
Douglas Gregorebe10102009-08-20 07:17:43 +00003800 if (!getDerived().AlwaysRebuild() &&
3801 Cond.get() == S->getCond() &&
3802 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003803 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003804
John McCallb268a282010-08-23 23:25:46 +00003805 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3806 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003807 S->getRParenLoc());
3808}
Mike Stump11289f42009-09-09 15:08:12 +00003809
Douglas Gregorebe10102009-08-20 07:17:43 +00003810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003811StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003812TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003813 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003814 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003815 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003816 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003817
Douglas Gregorebe10102009-08-20 07:17:43 +00003818 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003819 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003820 VarDecl *ConditionVar = 0;
3821 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003822 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003823 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003824 getDerived().TransformDefinition(
3825 S->getConditionVariable()->getLocation(),
3826 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003827 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003828 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003829 } else {
3830 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003831
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003832 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003833 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003834
3835 if (S->getCond()) {
3836 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003837 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003838 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003839 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003840 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003841 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003842
John McCallb268a282010-08-23 23:25:46 +00003843 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003844 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003845 }
Mike Stump11289f42009-09-09 15:08:12 +00003846
John McCallb268a282010-08-23 23:25:46 +00003847 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3848 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003849 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003850
Douglas Gregorebe10102009-08-20 07:17:43 +00003851 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003852 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003853 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003854 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003855
John McCallb268a282010-08-23 23:25:46 +00003856 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3857 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003858 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003859
Douglas Gregorebe10102009-08-20 07:17:43 +00003860 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003861 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003862 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003863 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003864
Douglas Gregorebe10102009-08-20 07:17:43 +00003865 if (!getDerived().AlwaysRebuild() &&
3866 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003867 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003868 Inc.get() == S->getInc() &&
3869 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003870 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003871
Douglas Gregorebe10102009-08-20 07:17:43 +00003872 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003873 Init.get(), FullCond, ConditionVar,
3874 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003875}
3876
3877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003878StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003879TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003880 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003881 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003882 S->getLabel());
3883}
3884
3885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003886StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003887TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003888 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003889 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003890 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003891
Douglas Gregorebe10102009-08-20 07:17:43 +00003892 if (!getDerived().AlwaysRebuild() &&
3893 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003894 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003895
3896 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003897 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003898}
3899
3900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003901StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003902TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003903 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003904}
Mike Stump11289f42009-09-09 15:08:12 +00003905
Douglas Gregorebe10102009-08-20 07:17:43 +00003906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003907StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003908TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003909 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003910}
Mike Stump11289f42009-09-09 15:08:12 +00003911
Douglas Gregorebe10102009-08-20 07:17:43 +00003912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003913StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003914TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003915 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003916 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003917 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003918
Mike Stump11289f42009-09-09 15:08:12 +00003919 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003920 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003921 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003922}
Mike Stump11289f42009-09-09 15:08:12 +00003923
Douglas Gregorebe10102009-08-20 07:17:43 +00003924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003925StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003926TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003927 bool DeclChanged = false;
3928 llvm::SmallVector<Decl *, 4> Decls;
3929 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3930 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003931 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3932 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003933 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003934 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregorebe10102009-08-20 07:17:43 +00003936 if (Transformed != *D)
3937 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregorebe10102009-08-20 07:17:43 +00003939 Decls.push_back(Transformed);
3940 }
Mike Stump11289f42009-09-09 15:08:12 +00003941
Douglas Gregorebe10102009-08-20 07:17:43 +00003942 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00003943 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003944
3945 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003946 S->getStartLoc(), S->getEndLoc());
3947}
Mike Stump11289f42009-09-09 15:08:12 +00003948
Douglas Gregorebe10102009-08-20 07:17:43 +00003949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003950StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003951TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003952 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00003953 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003954}
3955
3956template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003957StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003958TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003959
John McCall37ad5512010-08-23 06:44:23 +00003960 ASTOwningVector<Expr*> Constraints(getSema());
3961 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003962 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003963
John McCalldadc5752010-08-24 06:29:42 +00003964 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003965 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003966
3967 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003968
Anders Carlssonaaeef072010-01-24 05:50:09 +00003969 // Go through the outputs.
3970 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003971 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003972
Anders Carlssonaaeef072010-01-24 05:50:09 +00003973 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003974 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003975
Anders Carlssonaaeef072010-01-24 05:50:09 +00003976 // Transform the output expr.
3977 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003978 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003979 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003980 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003981
Anders Carlssonaaeef072010-01-24 05:50:09 +00003982 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003983
John McCallb268a282010-08-23 23:25:46 +00003984 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003985 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003986
Anders Carlssonaaeef072010-01-24 05:50:09 +00003987 // Go through the inputs.
3988 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003989 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003990
Anders Carlssonaaeef072010-01-24 05:50:09 +00003991 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003992 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003993
Anders Carlssonaaeef072010-01-24 05:50:09 +00003994 // Transform the input expr.
3995 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003996 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003997 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003998 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003999
Anders Carlssonaaeef072010-01-24 05:50:09 +00004000 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004001
John McCallb268a282010-08-23 23:25:46 +00004002 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004003 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004004
Anders Carlssonaaeef072010-01-24 05:50:09 +00004005 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004006 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004007
4008 // Go through the clobbers.
4009 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004010 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004011
4012 // No need to transform the asm string literal.
4013 AsmString = SemaRef.Owned(S->getAsmString());
4014
4015 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4016 S->isSimple(),
4017 S->isVolatile(),
4018 S->getNumOutputs(),
4019 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004020 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004021 move_arg(Constraints),
4022 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004023 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004024 move_arg(Clobbers),
4025 S->getRParenLoc(),
4026 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004027}
4028
4029
4030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004031StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004032TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004033 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004034 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004035 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004036 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004037
Douglas Gregor96c79492010-04-23 22:50:49 +00004038 // Transform the @catch statements (if present).
4039 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004040 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004041 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004042 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004043 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004044 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004045 if (Catch.get() != S->getCatchStmt(I))
4046 AnyCatchChanged = true;
4047 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004048 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004049
Douglas Gregor306de2f2010-04-22 23:59:56 +00004050 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004051 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004052 if (S->getFinallyStmt()) {
4053 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4054 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004055 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004056 }
4057
4058 // If nothing changed, just retain this statement.
4059 if (!getDerived().AlwaysRebuild() &&
4060 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004061 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004062 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004063 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004064
Douglas Gregor306de2f2010-04-22 23:59:56 +00004065 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004066 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4067 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004068}
Mike Stump11289f42009-09-09 15:08:12 +00004069
Douglas Gregorebe10102009-08-20 07:17:43 +00004070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004071StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004072TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004073 // Transform the @catch parameter, if there is one.
4074 VarDecl *Var = 0;
4075 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4076 TypeSourceInfo *TSInfo = 0;
4077 if (FromVar->getTypeSourceInfo()) {
4078 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4079 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004080 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004081 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004082
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004083 QualType T;
4084 if (TSInfo)
4085 T = TSInfo->getType();
4086 else {
4087 T = getDerived().TransformType(FromVar->getType());
4088 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004089 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004090 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004091
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004092 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4093 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004094 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004095 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004096
John McCalldadc5752010-08-24 06:29:42 +00004097 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004098 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004099 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004100
4101 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004102 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004103 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004104}
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregorebe10102009-08-20 07:17:43 +00004106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004107StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004108TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004109 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004110 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004111 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004112 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004113
Douglas Gregor306de2f2010-04-22 23:59:56 +00004114 // If nothing changed, just retain this statement.
4115 if (!getDerived().AlwaysRebuild() &&
4116 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004117 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004118
4119 // Build a new statement.
4120 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004121 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004122}
Mike Stump11289f42009-09-09 15:08:12 +00004123
Douglas Gregorebe10102009-08-20 07:17:43 +00004124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004125StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004126TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004127 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004128 if (S->getThrowExpr()) {
4129 Operand = getDerived().TransformExpr(S->getThrowExpr());
4130 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004131 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004132 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004133
Douglas Gregor2900c162010-04-22 21:44:01 +00004134 if (!getDerived().AlwaysRebuild() &&
4135 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004136 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004137
John McCallb268a282010-08-23 23:25:46 +00004138 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004139}
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregorebe10102009-08-20 07:17:43 +00004141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004142StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004143TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004144 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004145 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004146 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004147 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004148 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004149
Douglas Gregor6148de72010-04-22 22:01:21 +00004150 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004151 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004152 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004153 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004154
Douglas Gregor6148de72010-04-22 22:01:21 +00004155 // If nothing change, just retain the current statement.
4156 if (!getDerived().AlwaysRebuild() &&
4157 Object.get() == S->getSynchExpr() &&
4158 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004159 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004160
4161 // Build a new statement.
4162 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004163 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004164}
4165
4166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004167StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004168TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004169 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004170 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004171 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004172 if (Element.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 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004176 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004177 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004178 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004179
Douglas Gregorf68a5082010-04-22 23:10:45 +00004180 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004181 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004182 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004183 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004184
Douglas Gregorf68a5082010-04-22 23:10:45 +00004185 // If nothing changed, just retain this statement.
4186 if (!getDerived().AlwaysRebuild() &&
4187 Element.get() == S->getElement() &&
4188 Collection.get() == S->getCollection() &&
4189 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004190 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004191
Douglas Gregorf68a5082010-04-22 23:10:45 +00004192 // Build a new statement.
4193 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4194 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004195 Element.get(),
4196 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004197 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004198 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004199}
4200
4201
4202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004203StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004204TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4205 // Transform the exception declaration, if any.
4206 VarDecl *Var = 0;
4207 if (S->getExceptionDecl()) {
4208 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004209 TypeSourceInfo *T = getDerived().TransformType(
4210 ExceptionDecl->getTypeSourceInfo());
4211 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004212 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004214 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004215 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004216 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004217 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004218 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004219 }
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregorebe10102009-08-20 07:17:43 +00004221 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004222 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004223 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004224 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregorebe10102009-08-20 07:17:43 +00004226 if (!getDerived().AlwaysRebuild() &&
4227 !Var &&
4228 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004229 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004230
4231 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4232 Var,
John McCallb268a282010-08-23 23:25:46 +00004233 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004234}
Mike Stump11289f42009-09-09 15:08:12 +00004235
Douglas Gregorebe10102009-08-20 07:17:43 +00004236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004237StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004238TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4239 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004240 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004241 = getDerived().TransformCompoundStmt(S->getTryBlock());
4242 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004243 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004244
Douglas Gregorebe10102009-08-20 07:17:43 +00004245 // Transform the handlers.
4246 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004247 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004248 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004249 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004250 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4251 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004252 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004253
Douglas Gregorebe10102009-08-20 07:17:43 +00004254 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4255 Handlers.push_back(Handler.takeAs<Stmt>());
4256 }
Mike Stump11289f42009-09-09 15:08:12 +00004257
Douglas Gregorebe10102009-08-20 07:17:43 +00004258 if (!getDerived().AlwaysRebuild() &&
4259 TryBlock.get() == S->getTryBlock() &&
4260 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004261 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004262
John McCallb268a282010-08-23 23:25:46 +00004263 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004264 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004265}
Mike Stump11289f42009-09-09 15:08:12 +00004266
Douglas Gregorebe10102009-08-20 07:17:43 +00004267//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004268// Expression transformation
4269//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004271ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004272TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004273 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004274}
Mike Stump11289f42009-09-09 15:08:12 +00004275
4276template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004277ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004278TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004279 NestedNameSpecifier *Qualifier = 0;
4280 if (E->getQualifier()) {
4281 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004282 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004283 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004284 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004285 }
John McCallce546572009-12-08 09:08:17 +00004286
4287 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004288 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4289 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004290 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004292
John McCall815039a2010-08-17 21:27:17 +00004293 DeclarationNameInfo NameInfo = E->getNameInfo();
4294 if (NameInfo.getName()) {
4295 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4296 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004297 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004298 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004299
4300 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004301 Qualifier == E->getQualifier() &&
4302 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004303 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004304 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004305
4306 // Mark it referenced in the new context regardless.
4307 // FIXME: this is a bit instantiation-specific.
4308 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4309
John McCallc3007a22010-10-26 07:05:15 +00004310 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004311 }
John McCallce546572009-12-08 09:08:17 +00004312
4313 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004314 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004315 TemplateArgs = &TransArgs;
4316 TransArgs.setLAngleLoc(E->getLAngleLoc());
4317 TransArgs.setRAngleLoc(E->getRAngleLoc());
4318 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4319 TemplateArgumentLoc Loc;
4320 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004321 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004322 TransArgs.addArgument(Loc);
4323 }
4324 }
4325
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004326 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004327 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004328}
Mike Stump11289f42009-09-09 15:08:12 +00004329
Douglas Gregora16548e2009-08-11 05:31:07 +00004330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004331ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004332TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004333 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004334}
Mike Stump11289f42009-09-09 15:08:12 +00004335
Douglas Gregora16548e2009-08-11 05:31:07 +00004336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004337ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004338TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004339 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004340}
Mike Stump11289f42009-09-09 15:08:12 +00004341
Douglas Gregora16548e2009-08-11 05:31:07 +00004342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004343ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004344TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004345 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004346}
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004349ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004350TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004351 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004352}
Mike Stump11289f42009-09-09 15:08:12 +00004353
Douglas Gregora16548e2009-08-11 05:31:07 +00004354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004356TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004357 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004358}
4359
4360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004361ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004362TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004363 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004365 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004368 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004369
John McCallb268a282010-08-23 23:25:46 +00004370 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 E->getRParen());
4372}
4373
Mike Stump11289f42009-09-09 15:08:12 +00004374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004376TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004377 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004378 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004380
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004382 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4385 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004386 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004387}
Mike Stump11289f42009-09-09 15:08:12 +00004388
Douglas Gregora16548e2009-08-11 05:31:07 +00004389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004390ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004391TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4392 // Transform the type.
4393 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4394 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004395 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004396
Douglas Gregor882211c2010-04-28 22:16:22 +00004397 // Transform all of the components into components similar to what the
4398 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004399 // FIXME: It would be slightly more efficient in the non-dependent case to
4400 // just map FieldDecls, rather than requiring the rebuilder to look for
4401 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004402 // template code that we don't care.
4403 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004404 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004405 typedef OffsetOfExpr::OffsetOfNode Node;
4406 llvm::SmallVector<Component, 4> Components;
4407 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4408 const Node &ON = E->getComponent(I);
4409 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004410 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004411 Comp.LocStart = ON.getRange().getBegin();
4412 Comp.LocEnd = ON.getRange().getEnd();
4413 switch (ON.getKind()) {
4414 case Node::Array: {
4415 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004416 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004417 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004418 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004419
Douglas Gregor882211c2010-04-28 22:16:22 +00004420 ExprChanged = ExprChanged || Index.get() != FromIndex;
4421 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004422 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004423 break;
4424 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004425
Douglas Gregor882211c2010-04-28 22:16:22 +00004426 case Node::Field:
4427 case Node::Identifier:
4428 Comp.isBrackets = false;
4429 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004430 if (!Comp.U.IdentInfo)
4431 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004432
Douglas Gregor882211c2010-04-28 22:16:22 +00004433 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004434
Douglas Gregord1702062010-04-29 00:18:15 +00004435 case Node::Base:
4436 // Will be recomputed during the rebuild.
4437 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004438 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004439
Douglas Gregor882211c2010-04-28 22:16:22 +00004440 Components.push_back(Comp);
4441 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004442
Douglas Gregor882211c2010-04-28 22:16:22 +00004443 // If nothing changed, retain the existing expression.
4444 if (!getDerived().AlwaysRebuild() &&
4445 Type == E->getTypeSourceInfo() &&
4446 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004447 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004448
Douglas Gregor882211c2010-04-28 22:16:22 +00004449 // Build a new offsetof expression.
4450 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4451 Components.data(), Components.size(),
4452 E->getRParenLoc());
4453}
4454
4455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004456ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004457TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4458 assert(getDerived().AlreadyTransformed(E->getType()) &&
4459 "opaque value expression requires transformation");
4460 return SemaRef.Owned(E);
4461}
4462
4463template<typename Derived>
4464ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004465TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004466 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004467 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004468
John McCallbcd03502009-12-07 02:54:59 +00004469 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004470 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004471 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004472
John McCall4c98fd82009-11-04 07:28:41 +00004473 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004474 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004475
John McCall4c98fd82009-11-04 07:28:41 +00004476 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004477 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 E->getSourceRange());
4479 }
Mike Stump11289f42009-09-09 15:08:12 +00004480
John McCalldadc5752010-08-24 06:29:42 +00004481 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004482 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004483 // C++0x [expr.sizeof]p1:
4484 // The operand is either an expression, which is an unevaluated operand
4485 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004486 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004487
Douglas Gregora16548e2009-08-11 05:31:07 +00004488 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4489 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004491
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004493 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 }
Mike Stump11289f42009-09-09 15:08:12 +00004495
John McCallb268a282010-08-23 23:25:46 +00004496 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 E->isSizeOf(),
4498 E->getSourceRange());
4499}
Mike Stump11289f42009-09-09 15:08:12 +00004500
Douglas Gregora16548e2009-08-11 05:31:07 +00004501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004502ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004503TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004504 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004505 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004506 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004507
John McCalldadc5752010-08-24 06:29:42 +00004508 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004511
4512
Douglas Gregora16548e2009-08-11 05:31:07 +00004513 if (!getDerived().AlwaysRebuild() &&
4514 LHS.get() == E->getLHS() &&
4515 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004516 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004517
John McCallb268a282010-08-23 23:25:46 +00004518 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004520 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004521 E->getRBracketLoc());
4522}
Mike Stump11289f42009-09-09 15:08:12 +00004523
4524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004526TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004527 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004528 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004530 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004531
4532 // Transform arguments.
4533 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004534 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004536 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004539
Mike Stump11289f42009-09-09 15:08:12 +00004540 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004541 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004542 }
Mike Stump11289f42009-09-09 15:08:12 +00004543
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 if (!getDerived().AlwaysRebuild() &&
4545 Callee.get() == E->getCallee() &&
4546 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004547 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004550 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004551 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004552 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004553 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 E->getRParenLoc());
4555}
Mike Stump11289f42009-09-09 15:08:12 +00004556
4557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004558ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004559TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004560 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004563
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004564 NestedNameSpecifier *Qualifier = 0;
4565 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004566 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004567 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004568 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004569 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004570 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004571 }
Mike Stump11289f42009-09-09 15:08:12 +00004572
Eli Friedman2cfcef62009-12-04 06:40:45 +00004573 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004574 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4575 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004576 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004578
John McCall16df1e52010-03-30 21:47:33 +00004579 NamedDecl *FoundDecl = E->getFoundDecl();
4580 if (FoundDecl == E->getMemberDecl()) {
4581 FoundDecl = Member;
4582 } else {
4583 FoundDecl = cast_or_null<NamedDecl>(
4584 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4585 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004586 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004587 }
4588
Douglas Gregora16548e2009-08-11 05:31:07 +00004589 if (!getDerived().AlwaysRebuild() &&
4590 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004591 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004592 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004593 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004594 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004595
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004596 // Mark it referenced in the new context regardless.
4597 // FIXME: this is a bit instantiation-specific.
4598 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004599 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004600 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004601
John McCall6b51f282009-11-23 01:53:49 +00004602 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004603 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004604 TransArgs.setLAngleLoc(E->getLAngleLoc());
4605 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004606 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004607 TemplateArgumentLoc Loc;
4608 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004609 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004610 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004611 }
4612 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004613
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 // FIXME: Bogus source location for the operator
4615 SourceLocation FakeOperatorLoc
4616 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4617
John McCall38836f02010-01-15 08:34:02 +00004618 // FIXME: to do this check properly, we will need to preserve the
4619 // first-qualifier-in-scope here, just in case we had a dependent
4620 // base (and therefore couldn't do the check) and a
4621 // nested-name-qualifier (and therefore could do the lookup).
4622 NamedDecl *FirstQualifierInScope = 0;
4623
John McCallb268a282010-08-23 23:25:46 +00004624 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004626 Qualifier,
4627 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004628 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004629 Member,
John McCall16df1e52010-03-30 21:47:33 +00004630 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004631 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004632 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004633 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004634}
Mike Stump11289f42009-09-09 15:08:12 +00004635
Douglas Gregora16548e2009-08-11 05:31:07 +00004636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004638TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004639 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004640 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004642
John McCalldadc5752010-08-24 06:29:42 +00004643 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004644 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004646
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 if (!getDerived().AlwaysRebuild() &&
4648 LHS.get() == E->getLHS() &&
4649 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004650 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregora16548e2009-08-11 05:31:07 +00004652 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004653 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004654}
4655
Mike Stump11289f42009-09-09 15:08:12 +00004656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004657ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004658TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004659 CompoundAssignOperator *E) {
4660 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004661}
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregora16548e2009-08-11 05:31:07 +00004663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004665TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004666 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004669
John McCalldadc5752010-08-24 06:29:42 +00004670 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004673
John McCalldadc5752010-08-24 06:29:42 +00004674 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 if (!getDerived().AlwaysRebuild() &&
4679 Cond.get() == E->getCond() &&
4680 LHS.get() == E->getLHS() &&
4681 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004682 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004683
John McCallb268a282010-08-23 23:25:46 +00004684 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004685 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004686 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004687 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004688 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004689}
Mike Stump11289f42009-09-09 15:08:12 +00004690
4691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004692ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004693TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004694 // Implicit casts are eliminated during transformation, since they
4695 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004696 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004697}
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregora16548e2009-08-11 05:31:07 +00004699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004700ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004701TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004702 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4703 if (!Type)
4704 return ExprError();
4705
John McCalldadc5752010-08-24 06:29:42 +00004706 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004707 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004708 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004712 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004714 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004715
John McCall97513962010-01-15 18:39:57 +00004716 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004717 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004719 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004724TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004725 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4726 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4727 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004729
John McCalldadc5752010-08-24 06:29:42 +00004730 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004733
Douglas Gregora16548e2009-08-11 05:31:07 +00004734 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004735 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004737 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004738
John McCall5d7aa7f2010-01-19 22:33:45 +00004739 // Note: the expression type doesn't necessarily match the
4740 // type-as-written, but that's okay, because it should always be
4741 // derivable from the initializer.
4742
John McCalle15bbff2010-01-18 19:35:47 +00004743 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004745 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004746}
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregora16548e2009-08-11 05:31:07 +00004748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004749ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004750TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004751 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 if (!getDerived().AlwaysRebuild() &&
4756 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004757 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004760 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004762 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004763 E->getAccessorLoc(),
4764 E->getAccessor());
4765}
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregora16548e2009-08-11 05:31:07 +00004767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004768ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004769TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004771
John McCall37ad5512010-08-23 06:44:23 +00004772 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004774 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004775 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004779 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 }
Mike Stump11289f42009-09-09 15:08:12 +00004781
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004783 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004786 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004787}
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregora16548e2009-08-11 05:31:07 +00004789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004791TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004793
Douglas Gregorebe10102009-08-20 07:17:43 +00004794 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004795 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004797 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregorebe10102009-08-20 07:17:43 +00004799 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004800 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 bool ExprChanged = false;
4802 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4803 DEnd = E->designators_end();
4804 D != DEnd; ++D) {
4805 if (D->isFieldDesignator()) {
4806 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4807 D->getDotLoc(),
4808 D->getFieldLoc()));
4809 continue;
4810 }
Mike Stump11289f42009-09-09 15:08:12 +00004811
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004813 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004816
4817 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4821 ArrayExprs.push_back(Index.release());
4822 continue;
4823 }
Mike Stump11289f42009-09-09 15:08:12 +00004824
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004826 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4828 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004829 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004830
John McCalldadc5752010-08-24 06:29:42 +00004831 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004832 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004834
4835 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004836 End.get(),
4837 D->getLBracketLoc(),
4838 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4841 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004842
Douglas Gregora16548e2009-08-11 05:31:07 +00004843 ArrayExprs.push_back(Start.release());
4844 ArrayExprs.push_back(End.release());
4845 }
Mike Stump11289f42009-09-09 15:08:12 +00004846
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 if (!getDerived().AlwaysRebuild() &&
4848 Init.get() == E->getInit() &&
4849 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004850 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004851
Douglas Gregora16548e2009-08-11 05:31:07 +00004852 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4853 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004854 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004855}
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregora16548e2009-08-11 05:31:07 +00004857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004858ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004859TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004860 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004861 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004862
Douglas Gregor3da3c062009-10-28 00:29:27 +00004863 // FIXME: Will we ever have proper type location here? Will we actually
4864 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004865 QualType T = getDerived().TransformType(E->getType());
4866 if (T.isNull())
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() &&
4870 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004871 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregora16548e2009-08-11 05:31:07 +00004873 return getDerived().RebuildImplicitValueInitExpr(T);
4874}
Mike Stump11289f42009-09-09 15:08:12 +00004875
Douglas Gregora16548e2009-08-11 05:31:07 +00004876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004878TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004879 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4880 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004882
John McCalldadc5752010-08-24 06:29:42 +00004883 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004884 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004886
Douglas Gregora16548e2009-08-11 05:31:07 +00004887 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004888 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004889 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004890 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004891
John McCallb268a282010-08-23 23:25:46 +00004892 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004893 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004894}
4895
4896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004898TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004900 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004901 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004902 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004905
Douglas Gregora16548e2009-08-11 05:31:07 +00004906 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004907 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004908 }
Mike Stump11289f42009-09-09 15:08:12 +00004909
Douglas Gregora16548e2009-08-11 05:31:07 +00004910 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4911 move_arg(Inits),
4912 E->getRParenLoc());
4913}
Mike Stump11289f42009-09-09 15:08:12 +00004914
Douglas Gregora16548e2009-08-11 05:31:07 +00004915/// \brief Transform an address-of-label expression.
4916///
4917/// By default, the transformation of an address-of-label expression always
4918/// rebuilds the expression, so that the label identifier can be resolved to
4919/// the corresponding label statement by semantic analysis.
4920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004922TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004923 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4924 E->getLabel());
4925}
Mike Stump11289f42009-09-09 15:08:12 +00004926
4927template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004928ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004929TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004930 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004931 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4932 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004934
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 if (!getDerived().AlwaysRebuild() &&
4936 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00004937 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004938
4939 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004940 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004941 E->getRParenLoc());
4942}
Mike Stump11289f42009-09-09 15:08:12 +00004943
Douglas Gregora16548e2009-08-11 05:31:07 +00004944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004946TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004947 TypeSourceInfo *TInfo1;
4948 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004949
4950 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4951 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregor7058c262010-08-10 14:27:00 +00004954 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4955 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004957
4958 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004959 TInfo1 == E->getArgTInfo1() &&
4960 TInfo2 == E->getArgTInfo2())
John McCallc3007a22010-10-26 07:05:15 +00004961 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004962
Douglas Gregora16548e2009-08-11 05:31:07 +00004963 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004964 TInfo1, TInfo2,
4965 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004966}
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregora16548e2009-08-11 05:31:07 +00004968template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004969ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004970TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004971 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004974
John McCalldadc5752010-08-24 06:29:42 +00004975 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004976 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004978
John McCalldadc5752010-08-24 06:29:42 +00004979 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004980 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004982
Douglas Gregora16548e2009-08-11 05:31:07 +00004983 if (!getDerived().AlwaysRebuild() &&
4984 Cond.get() == E->getCond() &&
4985 LHS.get() == E->getLHS() &&
4986 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004987 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004988
Douglas Gregora16548e2009-08-11 05:31:07 +00004989 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004990 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004991 E->getRParenLoc());
4992}
Mike Stump11289f42009-09-09 15:08:12 +00004993
Douglas Gregora16548e2009-08-11 05:31:07 +00004994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004995ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004996TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004997 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004998}
4999
5000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005002TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005003 switch (E->getOperator()) {
5004 case OO_New:
5005 case OO_Delete:
5006 case OO_Array_New:
5007 case OO_Array_Delete:
5008 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005009 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005010
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005011 case OO_Call: {
5012 // This is a call to an object's operator().
5013 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5014
5015 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005016 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005017 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005018 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005019
5020 // FIXME: Poor location information
5021 SourceLocation FakeLParenLoc
5022 = SemaRef.PP.getLocForEndOfToken(
5023 static_cast<Expr *>(Object.get())->getLocEnd());
5024
5025 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005026 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005027 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00005028 if (getDerived().DropCallArgument(E->getArg(I)))
5029 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005030
John McCalldadc5752010-08-24 06:29:42 +00005031 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005032 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005033 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005034
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005035 Args.push_back(Arg.release());
5036 }
5037
John McCallb268a282010-08-23 23:25:46 +00005038 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005039 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005040 E->getLocEnd());
5041 }
5042
5043#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5044 case OO_##Name:
5045#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5046#include "clang/Basic/OperatorKinds.def"
5047 case OO_Subscript:
5048 // Handled below.
5049 break;
5050
5051 case OO_Conditional:
5052 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005053 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005054
5055 case OO_None:
5056 case NUM_OVERLOADED_OPERATORS:
5057 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005058 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005059 }
5060
John McCalldadc5752010-08-24 06:29:42 +00005061 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005063 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005064
John McCalldadc5752010-08-24 06:29:42 +00005065 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005066 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005067 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005068
John McCalldadc5752010-08-24 06:29:42 +00005069 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005070 if (E->getNumArgs() == 2) {
5071 Second = getDerived().TransformExpr(E->getArg(1));
5072 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005073 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005074 }
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 if (!getDerived().AlwaysRebuild() &&
5077 Callee.get() == E->getCallee() &&
5078 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005079 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005080 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5083 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005084 Callee.get(),
5085 First.get(),
5086 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005087}
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregora16548e2009-08-11 05:31:07 +00005089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005091TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5092 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005093}
Mike Stump11289f42009-09-09 15:08:12 +00005094
Douglas Gregora16548e2009-08-11 05:31:07 +00005095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005097TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005098 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5099 if (!Type)
5100 return ExprError();
5101
John McCalldadc5752010-08-24 06:29:42 +00005102 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005103 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005106
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005108 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005110 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005113 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005114 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5115 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5116 SourceLocation FakeRParenLoc
5117 = SemaRef.PP.getLocForEndOfToken(
5118 E->getSubExpr()->getSourceRange().getEnd());
5119 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005120 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005122 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 FakeRAngleLoc,
5124 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005125 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 FakeRParenLoc);
5127}
Mike Stump11289f42009-09-09 15:08:12 +00005128
Douglas Gregora16548e2009-08-11 05:31:07 +00005129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005131TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5132 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005133}
Mike Stump11289f42009-09-09 15:08:12 +00005134
5135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005137TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5138 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005139}
5140
Douglas Gregora16548e2009-08-11 05:31:07 +00005141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005142ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005143TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005144 CXXReinterpretCastExpr *E) {
5145 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005146}
Mike Stump11289f42009-09-09 15:08:12 +00005147
Douglas Gregora16548e2009-08-11 05:31:07 +00005148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005150TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5151 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005152}
Mike Stump11289f42009-09-09 15:08:12 +00005153
Douglas Gregora16548e2009-08-11 05:31:07 +00005154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005155ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005156TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005157 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005158 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5159 if (!Type)
5160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005161
John McCalldadc5752010-08-24 06:29:42 +00005162 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005163 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005165 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005166
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005168 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005170 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005171
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005172 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005174 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005175 E->getRParenLoc());
5176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005180TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005182 TypeSourceInfo *TInfo
5183 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5184 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005186
Douglas Gregora16548e2009-08-11 05:31:07 +00005187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005188 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005189 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregor9da64192010-04-26 22:37:10 +00005191 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5192 E->getLocStart(),
5193 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005194 E->getLocEnd());
5195 }
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregora16548e2009-08-11 05:31:07 +00005197 // We don't know whether the expression is potentially evaluated until
5198 // after we perform semantic analysis, so the expression is potentially
5199 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005200 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005201 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005202
John McCalldadc5752010-08-24 06:29:42 +00005203 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005206
Douglas Gregora16548e2009-08-11 05:31:07 +00005207 if (!getDerived().AlwaysRebuild() &&
5208 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005209 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005210
Douglas Gregor9da64192010-04-26 22:37:10 +00005211 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5212 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005213 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005214 E->getLocEnd());
5215}
5216
5217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005218ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005219TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5220 if (E->isTypeOperand()) {
5221 TypeSourceInfo *TInfo
5222 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5223 if (!TInfo)
5224 return ExprError();
5225
5226 if (!getDerived().AlwaysRebuild() &&
5227 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005228 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005229
5230 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5231 E->getLocStart(),
5232 TInfo,
5233 E->getLocEnd());
5234 }
5235
5236 // We don't know whether the expression is potentially evaluated until
5237 // after we perform semantic analysis, so the expression is potentially
5238 // potentially evaluated.
5239 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5240
5241 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5242 if (SubExpr.isInvalid())
5243 return ExprError();
5244
5245 if (!getDerived().AlwaysRebuild() &&
5246 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005247 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005248
5249 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5250 E->getLocStart(),
5251 SubExpr.get(),
5252 E->getLocEnd());
5253}
5254
5255template<typename Derived>
5256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005257TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005258 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005259}
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregora16548e2009-08-11 05:31:07 +00005261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005262ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005263TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005264 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005265 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005266}
Mike Stump11289f42009-09-09 15:08:12 +00005267
Douglas Gregora16548e2009-08-11 05:31:07 +00005268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005269ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005270TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005271 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5272 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5273 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005274
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005275 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005276 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregorb15af892010-01-07 23:12:05 +00005278 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005279}
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregora16548e2009-08-11 05:31:07 +00005281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005283TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005284 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005285 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005287
Douglas Gregora16548e2009-08-11 05:31:07 +00005288 if (!getDerived().AlwaysRebuild() &&
5289 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005290 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005291
John McCallb268a282010-08-23 23:25:46 +00005292 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005293}
Mike Stump11289f42009-09-09 15:08:12 +00005294
Douglas Gregora16548e2009-08-11 05:31:07 +00005295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005297TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005298 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005299 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5300 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005303
Chandler Carruth794da4c2010-02-08 06:42:49 +00005304 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005305 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005306 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregor033f6752009-12-23 23:03:06 +00005308 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005309}
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregora16548e2009-08-11 05:31:07 +00005311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005312ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005313TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5314 CXXScalarValueInitExpr *E) {
5315 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5316 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005317 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005318
Douglas Gregora16548e2009-08-11 05:31:07 +00005319 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005320 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005321 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005322
Douglas Gregor2b88c112010-09-08 00:15:04 +00005323 return getDerived().RebuildCXXScalarValueInitExpr(T,
5324 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005325 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005326}
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregora16548e2009-08-11 05:31:07 +00005328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005330TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005331 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005332 TypeSourceInfo *AllocTypeInfo
5333 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5334 if (!AllocTypeInfo)
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 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005338 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005339 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005341
Douglas Gregora16548e2009-08-11 05:31:07 +00005342 // Transform the placement arguments (if any).
5343 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005344 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005345 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005346 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5347 ArgumentChanged = true;
5348 break;
5349 }
5350
John McCalldadc5752010-08-24 06:29:42 +00005351 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005352 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005353 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregora16548e2009-08-11 05:31:07 +00005355 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5356 PlacementArgs.push_back(Arg.take());
5357 }
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005360 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005361 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005362 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5363 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005364 break;
John McCall09d13692010-10-05 22:36:42 +00005365 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005366
John McCalldadc5752010-08-24 06:29:42 +00005367 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005368 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005369 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005370
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5372 ConstructorArgs.push_back(Arg.take());
5373 }
Mike Stump11289f42009-09-09 15:08:12 +00005374
Douglas Gregord2d9da02010-02-26 00:38:10 +00005375 // Transform constructor, new operator, and delete operator.
5376 CXXConstructorDecl *Constructor = 0;
5377 if (E->getConstructor()) {
5378 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005379 getDerived().TransformDecl(E->getLocStart(),
5380 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005381 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005382 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005383 }
5384
5385 FunctionDecl *OperatorNew = 0;
5386 if (E->getOperatorNew()) {
5387 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005388 getDerived().TransformDecl(E->getLocStart(),
5389 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005390 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005391 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005392 }
5393
5394 FunctionDecl *OperatorDelete = 0;
5395 if (E->getOperatorDelete()) {
5396 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005397 getDerived().TransformDecl(E->getLocStart(),
5398 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005399 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005400 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005401 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005402
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005404 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005405 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005406 Constructor == E->getConstructor() &&
5407 OperatorNew == E->getOperatorNew() &&
5408 OperatorDelete == E->getOperatorDelete() &&
5409 !ArgumentChanged) {
5410 // Mark any declarations we need as referenced.
5411 // FIXME: instantiation-specific.
5412 if (Constructor)
5413 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5414 if (OperatorNew)
5415 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5416 if (OperatorDelete)
5417 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005418 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005419 }
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregor0744ef62010-09-07 21:49:58 +00005421 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005422 if (!ArraySize.get()) {
5423 // If no array size was specified, but the new expression was
5424 // instantiated with an array type (e.g., "new T" where T is
5425 // instantiated with "int[4]"), extract the outer bound from the
5426 // array type as our array size. We do this with constant and
5427 // dependently-sized array types.
5428 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5429 if (!ArrayT) {
5430 // Do nothing
5431 } else if (const ConstantArrayType *ConsArrayT
5432 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005433 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005434 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5435 ConsArrayT->getSize(),
5436 SemaRef.Context.getSizeType(),
5437 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005438 AllocType = ConsArrayT->getElementType();
5439 } else if (const DependentSizedArrayType *DepArrayT
5440 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5441 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005442 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005443 AllocType = DepArrayT->getElementType();
5444 }
5445 }
5446 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005447
Douglas Gregora16548e2009-08-11 05:31:07 +00005448 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5449 E->isGlobalNew(),
5450 /*FIXME:*/E->getLocStart(),
5451 move_arg(PlacementArgs),
5452 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005453 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005454 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005455 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005456 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 /*FIXME:*/E->getLocStart(),
5458 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005459 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005460}
Mike Stump11289f42009-09-09 15:08:12 +00005461
Douglas Gregora16548e2009-08-11 05:31:07 +00005462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005463ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005464TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005465 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005466 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005468
Douglas Gregord2d9da02010-02-26 00:38:10 +00005469 // Transform the delete operator, if known.
5470 FunctionDecl *OperatorDelete = 0;
5471 if (E->getOperatorDelete()) {
5472 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005473 getDerived().TransformDecl(E->getLocStart(),
5474 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005475 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005477 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005478
Douglas Gregora16548e2009-08-11 05:31:07 +00005479 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005480 Operand.get() == E->getArgument() &&
5481 OperatorDelete == E->getOperatorDelete()) {
5482 // Mark any declarations we need as referenced.
5483 // FIXME: instantiation-specific.
5484 if (OperatorDelete)
5485 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005486
5487 if (!E->getArgument()->isTypeDependent()) {
5488 QualType Destroyed = SemaRef.Context.getBaseElementType(
5489 E->getDestroyedType());
5490 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5491 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5492 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5493 SemaRef.LookupDestructor(Record));
5494 }
5495 }
5496
John McCallc3007a22010-10-26 07:05:15 +00005497 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005498 }
Mike Stump11289f42009-09-09 15:08:12 +00005499
Douglas Gregora16548e2009-08-11 05:31:07 +00005500 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5501 E->isGlobalDelete(),
5502 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005503 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005504}
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregora16548e2009-08-11 05:31:07 +00005506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005507ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005508TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005509 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005510 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005511 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005513
John McCallba7bf592010-08-24 05:47:05 +00005514 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005515 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005516 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005517 E->getOperatorLoc(),
5518 E->isArrow()? tok::arrow : tok::period,
5519 ObjectTypePtr,
5520 MayBePseudoDestructor);
5521 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005523
John McCallba7bf592010-08-24 05:47:05 +00005524 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005525 NestedNameSpecifier *Qualifier = E->getQualifier();
5526 if (Qualifier) {
5527 Qualifier
5528 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5529 E->getQualifierRange(),
5530 ObjectType);
5531 if (!Qualifier)
5532 return ExprError();
5533 }
Mike Stump11289f42009-09-09 15:08:12 +00005534
Douglas Gregor678f90d2010-02-25 01:56:36 +00005535 PseudoDestructorTypeStorage Destroyed;
5536 if (E->getDestroyedTypeInfo()) {
5537 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005538 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5539 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005540 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005542 Destroyed = DestroyedTypeInfo;
5543 } else if (ObjectType->isDependentType()) {
5544 // We aren't likely to be able to resolve the identifier down to a type
5545 // now anyway, so just retain the identifier.
5546 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5547 E->getDestroyedTypeLoc());
5548 } else {
5549 // Look for a destructor known with the given name.
5550 CXXScopeSpec SS;
5551 if (Qualifier) {
5552 SS.setScopeRep(Qualifier);
5553 SS.setRange(E->getQualifierRange());
5554 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005555
John McCallba7bf592010-08-24 05:47:05 +00005556 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005557 *E->getDestroyedTypeIdentifier(),
5558 E->getDestroyedTypeLoc(),
5559 /*Scope=*/0,
5560 SS, ObjectTypePtr,
5561 false);
5562 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005563 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005564
Douglas Gregor678f90d2010-02-25 01:56:36 +00005565 Destroyed
5566 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5567 E->getDestroyedTypeLoc());
5568 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005569
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005570 TypeSourceInfo *ScopeTypeInfo = 0;
5571 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005572 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005573 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005575 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005576
John McCallb268a282010-08-23 23:25:46 +00005577 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005578 E->getOperatorLoc(),
5579 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005580 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005581 E->getQualifierRange(),
5582 ScopeTypeInfo,
5583 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005584 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005585 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005586}
Mike Stump11289f42009-09-09 15:08:12 +00005587
Douglas Gregorad8a3362009-09-04 17:36:40 +00005588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005589ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005590TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005591 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005592 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5593
5594 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5595 Sema::LookupOrdinaryName);
5596
5597 // Transform all the decls.
5598 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5599 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005600 NamedDecl *InstD = static_cast<NamedDecl*>(
5601 getDerived().TransformDecl(Old->getNameLoc(),
5602 *I));
John McCall84d87672009-12-10 09:41:52 +00005603 if (!InstD) {
5604 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5605 // This can happen because of dependent hiding.
5606 if (isa<UsingShadowDecl>(*I))
5607 continue;
5608 else
John McCallfaf5fb42010-08-26 23:41:50 +00005609 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005610 }
John McCalle66edc12009-11-24 19:00:30 +00005611
5612 // Expand using declarations.
5613 if (isa<UsingDecl>(InstD)) {
5614 UsingDecl *UD = cast<UsingDecl>(InstD);
5615 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5616 E = UD->shadow_end(); I != E; ++I)
5617 R.addDecl(*I);
5618 continue;
5619 }
5620
5621 R.addDecl(InstD);
5622 }
5623
5624 // Resolve a kind, but don't do any further analysis. If it's
5625 // ambiguous, the callee needs to deal with it.
5626 R.resolveKind();
5627
5628 // Rebuild the nested-name qualifier, if present.
5629 CXXScopeSpec SS;
5630 NestedNameSpecifier *Qualifier = 0;
5631 if (Old->getQualifier()) {
5632 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005633 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005634 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005635 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005636
John McCalle66edc12009-11-24 19:00:30 +00005637 SS.setScopeRep(Qualifier);
5638 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005639 }
5640
Douglas Gregor9262f472010-04-27 18:19:34 +00005641 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005642 CXXRecordDecl *NamingClass
5643 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5644 Old->getNameLoc(),
5645 Old->getNamingClass()));
5646 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005648
Douglas Gregorda7be082010-04-27 16:10:10 +00005649 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005650 }
5651
5652 // If we have no template arguments, it's a normal declaration name.
5653 if (!Old->hasExplicitTemplateArgs())
5654 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5655
5656 // If we have template arguments, rebuild them, then rebuild the
5657 // templateid expression.
5658 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5659 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5660 TemplateArgumentLoc Loc;
5661 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005662 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005663 TransArgs.addArgument(Loc);
5664 }
5665
5666 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5667 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005668}
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregora16548e2009-08-11 05:31:07 +00005670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005672TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005673 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5674 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005675 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregora16548e2009-08-11 05:31:07 +00005677 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005678 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005679 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005680
Mike Stump11289f42009-09-09 15:08:12 +00005681 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005683 T,
5684 E->getLocEnd());
5685}
Mike Stump11289f42009-09-09 15:08:12 +00005686
Douglas Gregora16548e2009-08-11 05:31:07 +00005687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005688ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005689TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005690 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005692 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005693 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005694 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005696
John McCall31f82722010-11-12 08:19:04 +00005697 // TODO: If this is a conversion-function-id, verify that the
5698 // destination type name (if present) resolves the same way after
5699 // instantiation as it did in the local scope.
5700
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005701 DeclarationNameInfo NameInfo
5702 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5703 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005705
John McCalle66edc12009-11-24 19:00:30 +00005706 if (!E->hasExplicitTemplateArgs()) {
5707 if (!getDerived().AlwaysRebuild() &&
5708 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005709 // Note: it is sufficient to compare the Name component of NameInfo:
5710 // if name has not changed, DNLoc has not changed either.
5711 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005712 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005713
John McCalle66edc12009-11-24 19:00:30 +00005714 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5715 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005716 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005717 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005718 }
John McCall6b51f282009-11-23 01:53:49 +00005719
5720 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005722 TemplateArgumentLoc Loc;
5723 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005724 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005725 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 }
5727
John McCalle66edc12009-11-24 19:00:30 +00005728 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5729 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005730 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005731 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005732}
5733
5734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005736TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005737 // CXXConstructExprs are always implicit, so when we have a
5738 // 1-argument construction we just transform that argument.
5739 if (E->getNumArgs() == 1 ||
5740 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5741 return getDerived().TransformExpr(E->getArg(0));
5742
Douglas Gregora16548e2009-08-11 05:31:07 +00005743 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5744
5745 QualType T = getDerived().TransformType(E->getType());
5746 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005747 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005748
5749 CXXConstructorDecl *Constructor
5750 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005751 getDerived().TransformDecl(E->getLocStart(),
5752 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregora16548e2009-08-11 05:31:07 +00005756 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005757 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005758 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 ArgEnd = E->arg_end();
5760 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005761 if (getDerived().DropCallArgument(*Arg)) {
5762 ArgumentChanged = true;
5763 break;
5764 }
5765
John McCalldadc5752010-08-24 06:29:42 +00005766 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005767 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005769
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005771 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005772 }
5773
5774 if (!getDerived().AlwaysRebuild() &&
5775 T == E->getType() &&
5776 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005777 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005778 // Mark the constructor as referenced.
5779 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005780 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005781 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005782 }
Mike Stump11289f42009-09-09 15:08:12 +00005783
Douglas Gregordb121ba2009-12-14 16:27:04 +00005784 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5785 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005786 move_arg(Args),
5787 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005788 E->getConstructionKind(),
5789 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005790}
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregora16548e2009-08-11 05:31:07 +00005792/// \brief Transform a C++ temporary-binding expression.
5793///
Douglas Gregor363b1512009-12-24 18:51:59 +00005794/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5795/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005798TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005799 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005800}
Mike Stump11289f42009-09-09 15:08:12 +00005801
5802/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005803/// be destroyed after the expression is evaluated.
5804///
Douglas Gregor363b1512009-12-24 18:51:59 +00005805/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5806/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005808ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005809TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005810 CXXExprWithTemporaries *E) {
5811 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005812}
Mike Stump11289f42009-09-09 15:08:12 +00005813
Douglas Gregora16548e2009-08-11 05:31:07 +00005814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005815ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005816TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005817 CXXTemporaryObjectExpr *E) {
5818 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5819 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005821
Douglas Gregora16548e2009-08-11 05:31:07 +00005822 CXXConstructorDecl *Constructor
5823 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005824 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005825 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005826 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005828
Douglas Gregora16548e2009-08-11 05:31:07 +00005829 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005830 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005831 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005832 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005833 ArgEnd = E->arg_end();
5834 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005835 if (getDerived().DropCallArgument(*Arg)) {
5836 ArgumentChanged = true;
5837 break;
5838 }
5839
John McCalldadc5752010-08-24 06:29:42 +00005840 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005842 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005843
Douglas Gregora16548e2009-08-11 05:31:07 +00005844 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5845 Args.push_back((Expr *)TransArg.release());
5846 }
Mike Stump11289f42009-09-09 15:08:12 +00005847
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005849 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005851 !ArgumentChanged) {
5852 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005853 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005854 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005855 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005856
5857 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5858 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005859 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 E->getLocEnd());
5861}
Mike Stump11289f42009-09-09 15:08:12 +00005862
Douglas Gregora16548e2009-08-11 05:31:07 +00005863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005864ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005865TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005866 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005867 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5868 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005869 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005870
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005872 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005873 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5874 ArgEnd = E->arg_end();
5875 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005876 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005879
Douglas Gregora16548e2009-08-11 05:31:07 +00005880 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005881 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005882 }
Mike Stump11289f42009-09-09 15:08:12 +00005883
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005885 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005888
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005890 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 E->getLParenLoc(),
5892 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 E->getRParenLoc());
5894}
Mike Stump11289f42009-09-09 15:08:12 +00005895
Douglas Gregora16548e2009-08-11 05:31:07 +00005896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005897ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005898TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005899 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005900 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005901 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005902 Expr *OldBase;
5903 QualType BaseType;
5904 QualType ObjectType;
5905 if (!E->isImplicitAccess()) {
5906 OldBase = E->getBase();
5907 Base = getDerived().TransformExpr(OldBase);
5908 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005910
John McCall2d74de92009-12-01 22:10:20 +00005911 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005912 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005913 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005914 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005915 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005916 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005917 ObjectTy,
5918 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005919 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005920 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005921
John McCallba7bf592010-08-24 05:47:05 +00005922 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005923 BaseType = ((Expr*) Base.get())->getType();
5924 } else {
5925 OldBase = 0;
5926 BaseType = getDerived().TransformType(E->getBaseType());
5927 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5928 }
Mike Stump11289f42009-09-09 15:08:12 +00005929
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005930 // Transform the first part of the nested-name-specifier that qualifies
5931 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005932 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005933 = getDerived().TransformFirstQualifierInScope(
5934 E->getFirstQualifierFoundInScope(),
5935 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005936
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005937 NestedNameSpecifier *Qualifier = 0;
5938 if (E->getQualifier()) {
5939 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5940 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005941 ObjectType,
5942 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005943 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005944 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005945 }
Mike Stump11289f42009-09-09 15:08:12 +00005946
John McCall31f82722010-11-12 08:19:04 +00005947 // TODO: If this is a conversion-function-id, verify that the
5948 // destination type name (if present) resolves the same way after
5949 // instantiation as it did in the local scope.
5950
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005951 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00005952 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005953 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005954 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005955
John McCall2d74de92009-12-01 22:10:20 +00005956 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005957 // This is a reference to a member without an explicitly-specified
5958 // template argument list. Optimize for this common case.
5959 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005960 Base.get() == OldBase &&
5961 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005962 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005963 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005964 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00005965 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005966
John McCallb268a282010-08-23 23:25:46 +00005967 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005968 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005969 E->isArrow(),
5970 E->getOperatorLoc(),
5971 Qualifier,
5972 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005973 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005974 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005975 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005976 }
5977
John McCall6b51f282009-11-23 01:53:49 +00005978 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005979 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005980 TemplateArgumentLoc Loc;
5981 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005982 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005983 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005984 }
Mike Stump11289f42009-09-09 15:08:12 +00005985
John McCallb268a282010-08-23 23:25:46 +00005986 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005987 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005988 E->isArrow(),
5989 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005990 Qualifier,
5991 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005992 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005993 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005994 &TransArgs);
5995}
5996
5997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005998ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005999TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006000 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006001 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006002 QualType BaseType;
6003 if (!Old->isImplicitAccess()) {
6004 Base = getDerived().TransformExpr(Old->getBase());
6005 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006007 BaseType = ((Expr*) Base.get())->getType();
6008 } else {
6009 BaseType = getDerived().TransformType(Old->getBaseType());
6010 }
John McCall10eae182009-11-30 22:42:35 +00006011
6012 NestedNameSpecifier *Qualifier = 0;
6013 if (Old->getQualifier()) {
6014 Qualifier
6015 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006016 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006017 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006019 }
6020
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006021 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006022 Sema::LookupOrdinaryName);
6023
6024 // Transform all the decls.
6025 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6026 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006027 NamedDecl *InstD = static_cast<NamedDecl*>(
6028 getDerived().TransformDecl(Old->getMemberLoc(),
6029 *I));
John McCall84d87672009-12-10 09:41:52 +00006030 if (!InstD) {
6031 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6032 // This can happen because of dependent hiding.
6033 if (isa<UsingShadowDecl>(*I))
6034 continue;
6035 else
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006037 }
John McCall10eae182009-11-30 22:42:35 +00006038
6039 // Expand using declarations.
6040 if (isa<UsingDecl>(InstD)) {
6041 UsingDecl *UD = cast<UsingDecl>(InstD);
6042 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6043 E = UD->shadow_end(); I != E; ++I)
6044 R.addDecl(*I);
6045 continue;
6046 }
6047
6048 R.addDecl(InstD);
6049 }
6050
6051 R.resolveKind();
6052
Douglas Gregor9262f472010-04-27 18:19:34 +00006053 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006054 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006055 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006056 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006057 Old->getMemberLoc(),
6058 Old->getNamingClass()));
6059 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006060 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006061
Douglas Gregorda7be082010-04-27 16:10:10 +00006062 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006063 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006064
John McCall10eae182009-11-30 22:42:35 +00006065 TemplateArgumentListInfo TransArgs;
6066 if (Old->hasExplicitTemplateArgs()) {
6067 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6068 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6069 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6070 TemplateArgumentLoc Loc;
6071 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6072 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006073 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006074 TransArgs.addArgument(Loc);
6075 }
6076 }
John McCall38836f02010-01-15 08:34:02 +00006077
6078 // FIXME: to do this check properly, we will need to preserve the
6079 // first-qualifier-in-scope here, just in case we had a dependent
6080 // base (and therefore couldn't do the check) and a
6081 // nested-name-qualifier (and therefore could do the lookup).
6082 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006083
John McCallb268a282010-08-23 23:25:46 +00006084 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006085 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006086 Old->getOperatorLoc(),
6087 Old->isArrow(),
6088 Qualifier,
6089 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006090 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006091 R,
6092 (Old->hasExplicitTemplateArgs()
6093 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006094}
6095
6096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006097ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006098TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6099 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6100 if (SubExpr.isInvalid())
6101 return ExprError();
6102
6103 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006104 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006105
6106 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6107}
6108
6109template<typename Derived>
6110ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006111TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006113}
6114
Mike Stump11289f42009-09-09 15:08:12 +00006115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006117TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006118 TypeSourceInfo *EncodedTypeInfo
6119 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6120 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006122
Douglas Gregora16548e2009-08-11 05:31:07 +00006123 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006124 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006125 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006126
6127 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006128 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 E->getRParenLoc());
6130}
Mike Stump11289f42009-09-09 15:08:12 +00006131
Douglas Gregora16548e2009-08-11 05:31:07 +00006132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006135 // Transform arguments.
6136 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006137 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006138 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006139 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006140 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006141 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006142
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006143 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006144 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006145 }
6146
6147 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6148 // Class message: transform the receiver type.
6149 TypeSourceInfo *ReceiverTypeInfo
6150 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6151 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006152 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006153
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006154 // If nothing changed, just retain the existing message send.
6155 if (!getDerived().AlwaysRebuild() &&
6156 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006157 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006158
6159 // Build a new class message send.
6160 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6161 E->getSelector(),
6162 E->getMethodDecl(),
6163 E->getLeftLoc(),
6164 move_arg(Args),
6165 E->getRightLoc());
6166 }
6167
6168 // Instance message: transform the receiver
6169 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6170 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006171 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006172 = getDerived().TransformExpr(E->getInstanceReceiver());
6173 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006174 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006175
6176 // If nothing changed, just retain the existing message send.
6177 if (!getDerived().AlwaysRebuild() &&
6178 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006179 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006180
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006181 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006182 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006183 E->getSelector(),
6184 E->getMethodDecl(),
6185 E->getLeftLoc(),
6186 move_arg(Args),
6187 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006188}
6189
Mike Stump11289f42009-09-09 15:08:12 +00006190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006192TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006193 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006194}
6195
Mike Stump11289f42009-09-09 15:08:12 +00006196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006198TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006199 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006200}
6201
Mike Stump11289f42009-09-09 15:08:12 +00006202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006205 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006206 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006207 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006209
6210 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006211
Douglas Gregord51d90d2010-04-26 20:11:03 +00006212 // If nothing changed, just retain the existing expression.
6213 if (!getDerived().AlwaysRebuild() &&
6214 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006215 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006216
John McCallb268a282010-08-23 23:25:46 +00006217 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006218 E->getLocation(),
6219 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006220}
6221
Mike Stump11289f42009-09-09 15:08:12 +00006222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006224TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006225 // 'super' never changes. Property never changes. Just retain the existing
6226 // expression.
6227 if (E->isSuperReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006228 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006229
Douglas Gregor9faee212010-04-26 20:47:02 +00006230 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006231 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006232 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006233 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006234
Douglas Gregor9faee212010-04-26 20:47:02 +00006235 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006236
Douglas Gregor9faee212010-04-26 20:47:02 +00006237 // If nothing changed, just retain the existing expression.
6238 if (!getDerived().AlwaysRebuild() &&
6239 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006240 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006241
John McCallb268a282010-08-23 23:25:46 +00006242 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006243 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006244}
6245
Mike Stump11289f42009-09-09 15:08:12 +00006246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006247ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006248TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006249 ObjCImplicitSetterGetterRefExpr *E) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006250 // If this implicit setter/getter refers to super, it cannot have any
6251 // dependent parts. Just retain the existing declaration.
6252 if (E->isSuperReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006253 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006254
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006255 // If this implicit setter/getter refers to class methods, it cannot have any
6256 // dependent parts. Just retain the existing declaration.
6257 if (E->getInterfaceDecl())
John McCallc3007a22010-10-26 07:05:15 +00006258 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006259
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006260 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006261 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006262 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006263 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006264
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006265 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006266
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006267 // If nothing changed, just retain the existing expression.
6268 if (!getDerived().AlwaysRebuild() &&
6269 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006270 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006271
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006272 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6273 E->getGetterMethod(),
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006274 E->getType(),
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006275 E->getSetterMethod(),
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006276 E->getLocation(),
6277 Base.get(),
6278 E->getSuperLocation(),
6279 E->getSuperType(),
6280 E->isSuperReceiver());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006281
Douglas Gregora16548e2009-08-11 05:31:07 +00006282}
6283
Mike Stump11289f42009-09-09 15:08:12 +00006284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006286TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006287 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006288 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006289 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006290 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006291
Douglas Gregord51d90d2010-04-26 20:11:03 +00006292 // If nothing changed, just retain the existing expression.
6293 if (!getDerived().AlwaysRebuild() &&
6294 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006295 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006296
John McCallb268a282010-08-23 23:25:46 +00006297 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006298 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006299}
6300
Mike Stump11289f42009-09-09 15:08:12 +00006301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006303TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006304 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006305 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006306 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006307 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006308 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006310
Douglas Gregora16548e2009-08-11 05:31:07 +00006311 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006312 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 }
Mike Stump11289f42009-09-09 15:08:12 +00006314
Douglas Gregora16548e2009-08-11 05:31:07 +00006315 if (!getDerived().AlwaysRebuild() &&
6316 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006317 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006318
Douglas Gregora16548e2009-08-11 05:31:07 +00006319 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6320 move_arg(SubExprs),
6321 E->getRParenLoc());
6322}
6323
Mike Stump11289f42009-09-09 15:08:12 +00006324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006326TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006327 SourceLocation CaretLoc(E->getExprLoc());
6328
6329 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6330 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6331 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6332 llvm::SmallVector<ParmVarDecl*, 4> Params;
6333 llvm::SmallVector<QualType, 4> ParamTypes;
6334
6335 // Parameter substitution.
6336 const BlockDecl *BD = E->getBlockDecl();
6337 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6338 EN = BD->param_end(); P != EN; ++P) {
6339 ParmVarDecl *OldParm = (*P);
6340 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6341 QualType NewType = NewParm->getType();
6342 Params.push_back(NewParm);
6343 ParamTypes.push_back(NewParm->getType());
6344 }
6345
6346 const FunctionType *BExprFunctionType = E->getFunctionType();
6347 QualType BExprResultType = BExprFunctionType->getResultType();
6348 if (!BExprResultType.isNull()) {
6349 if (!BExprResultType->isDependentType())
6350 CurBlock->ReturnType = BExprResultType;
6351 else if (BExprResultType != SemaRef.Context.DependentTy)
6352 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6353 }
6354
6355 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006356 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006357 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006358 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006359 // Set the parameters on the block decl.
6360 if (!Params.empty())
6361 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6362
6363 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6364 CurBlock->ReturnType,
6365 ParamTypes.data(),
6366 ParamTypes.size(),
6367 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006368 0,
6369 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006370
6371 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006372 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006373}
6374
Mike Stump11289f42009-09-09 15:08:12 +00006375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006376ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006377TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006378 NestedNameSpecifier *Qualifier = 0;
6379
6380 ValueDecl *ND
6381 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6382 E->getDecl()));
6383 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006384 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006385
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006386 if (!getDerived().AlwaysRebuild() &&
6387 ND == E->getDecl()) {
6388 // Mark it referenced in the new context regardless.
6389 // FIXME: this is a bit instantiation-specific.
6390 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6391
John McCallc3007a22010-10-26 07:05:15 +00006392 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006393 }
6394
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006395 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006396 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006397 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006398}
Mike Stump11289f42009-09-09 15:08:12 +00006399
Douglas Gregora16548e2009-08-11 05:31:07 +00006400//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006401// Type reconstruction
6402//===----------------------------------------------------------------------===//
6403
Mike Stump11289f42009-09-09 15:08:12 +00006404template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006405QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6406 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006407 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006408 getDerived().getBaseEntity());
6409}
6410
Mike Stump11289f42009-09-09 15:08:12 +00006411template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006412QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6413 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006414 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006415 getDerived().getBaseEntity());
6416}
6417
Mike Stump11289f42009-09-09 15:08:12 +00006418template<typename Derived>
6419QualType
John McCall70dd5f62009-10-30 00:06:24 +00006420TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6421 bool WrittenAsLValue,
6422 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006423 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006424 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006425}
6426
6427template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006428QualType
John McCall70dd5f62009-10-30 00:06:24 +00006429TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6430 QualType ClassType,
6431 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006432 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006433 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006434}
6435
6436template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006437QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6439 ArrayType::ArraySizeModifier SizeMod,
6440 const llvm::APInt *Size,
6441 Expr *SizeExpr,
6442 unsigned IndexTypeQuals,
6443 SourceRange BracketsRange) {
6444 if (SizeExpr || !Size)
6445 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6446 IndexTypeQuals, BracketsRange,
6447 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006448
6449 QualType Types[] = {
6450 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6451 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6452 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006453 };
6454 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6455 QualType SizeType;
6456 for (unsigned I = 0; I != NumTypes; ++I)
6457 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6458 SizeType = Types[I];
6459 break;
6460 }
Mike Stump11289f42009-09-09 15:08:12 +00006461
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006462 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6463 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006464 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006465 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006466 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006467}
Mike Stump11289f42009-09-09 15:08:12 +00006468
Douglas Gregord6ff3322009-08-04 16:50:30 +00006469template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006470QualType
6471TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006472 ArrayType::ArraySizeModifier SizeMod,
6473 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006474 unsigned IndexTypeQuals,
6475 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006476 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006477 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006478}
6479
6480template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006481QualType
Mike Stump11289f42009-09-09 15:08:12 +00006482TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006483 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006484 unsigned IndexTypeQuals,
6485 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006486 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006487 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006488}
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregord6ff3322009-08-04 16:50:30 +00006490template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006491QualType
6492TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006493 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006494 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006495 unsigned IndexTypeQuals,
6496 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006497 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006498 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006499 IndexTypeQuals, BracketsRange);
6500}
6501
6502template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006503QualType
6504TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006505 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006506 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006507 unsigned IndexTypeQuals,
6508 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006509 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006510 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006511 IndexTypeQuals, BracketsRange);
6512}
6513
6514template<typename Derived>
6515QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006516 unsigned NumElements,
6517 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006518 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006519 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006520}
Mike Stump11289f42009-09-09 15:08:12 +00006521
Douglas Gregord6ff3322009-08-04 16:50:30 +00006522template<typename Derived>
6523QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6524 unsigned NumElements,
6525 SourceLocation AttributeLoc) {
6526 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6527 NumElements, true);
6528 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006529 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6530 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006531 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006532}
Mike Stump11289f42009-09-09 15:08:12 +00006533
Douglas Gregord6ff3322009-08-04 16:50:30 +00006534template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006535QualType
6536TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006537 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006538 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006539 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006540}
Mike Stump11289f42009-09-09 15:08:12 +00006541
Douglas Gregord6ff3322009-08-04 16:50:30 +00006542template<typename Derived>
6543QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006544 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006545 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006546 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006547 unsigned Quals,
6548 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006549 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006550 Quals,
6551 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006552 getDerived().getBaseEntity(),
6553 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006554}
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregord6ff3322009-08-04 16:50:30 +00006556template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006557QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6558 return SemaRef.Context.getFunctionNoProtoType(T);
6559}
6560
6561template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006562QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6563 assert(D && "no decl found");
6564 if (D->isInvalidDecl()) return QualType();
6565
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006566 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006567 TypeDecl *Ty;
6568 if (isa<UsingDecl>(D)) {
6569 UsingDecl *Using = cast<UsingDecl>(D);
6570 assert(Using->isTypeName() &&
6571 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6572
6573 // A valid resolved using typename decl points to exactly one type decl.
6574 assert(++Using->shadow_begin() == Using->shadow_end());
6575 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006576
John McCallb96ec562009-12-04 22:46:56 +00006577 } else {
6578 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6579 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6580 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6581 }
6582
6583 return SemaRef.Context.getTypeDeclType(Ty);
6584}
6585
6586template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006587QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6588 SourceLocation Loc) {
6589 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006590}
6591
6592template<typename Derived>
6593QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6594 return SemaRef.Context.getTypeOfType(Underlying);
6595}
6596
6597template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006598QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6599 SourceLocation Loc) {
6600 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006601}
6602
6603template<typename Derived>
6604QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006605 TemplateName Template,
6606 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006607 const TemplateArgumentListInfo &TemplateArgs) {
6608 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006609}
Mike Stump11289f42009-09-09 15:08:12 +00006610
Douglas Gregor1135c352009-08-06 05:28:30 +00006611template<typename Derived>
6612NestedNameSpecifier *
6613TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6614 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006615 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006616 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006617 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006618 CXXScopeSpec SS;
6619 // FIXME: The source location information is all wrong.
6620 SS.setRange(Range);
6621 SS.setScopeRep(Prefix);
6622 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006623 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006624 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006625 ObjectType,
6626 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006627 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006628}
6629
6630template<typename Derived>
6631NestedNameSpecifier *
6632TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6633 SourceRange Range,
6634 NamespaceDecl *NS) {
6635 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6636}
6637
6638template<typename Derived>
6639NestedNameSpecifier *
6640TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6641 SourceRange Range,
6642 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006643 QualType T) {
6644 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006645 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006646 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006647 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6648 T.getTypePtr());
6649 }
Mike Stump11289f42009-09-09 15:08:12 +00006650
Douglas Gregor1135c352009-08-06 05:28:30 +00006651 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6652 return 0;
6653}
Mike Stump11289f42009-09-09 15:08:12 +00006654
Douglas Gregor71dc5092009-08-06 06:41:21 +00006655template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006656TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006657TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6658 bool TemplateKW,
6659 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006660 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006661 Template);
6662}
6663
6664template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006665TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006666TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006667 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006668 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00006669 QualType ObjectType,
6670 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006671 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006672 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006673 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006674 UnqualifiedId Name;
6675 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006676 Sema::TemplateTy Template;
6677 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6678 /*FIXME:*/getDerived().getBaseLocation(),
6679 SS,
6680 Name,
John McCallba7bf592010-08-24 05:47:05 +00006681 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006682 /*EnteringContext=*/false,
6683 Template);
John McCall31f82722010-11-12 08:19:04 +00006684 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006685}
Mike Stump11289f42009-09-09 15:08:12 +00006686
Douglas Gregora16548e2009-08-11 05:31:07 +00006687template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006688TemplateName
6689TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6690 OverloadedOperatorKind Operator,
6691 QualType ObjectType) {
6692 CXXScopeSpec SS;
6693 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6694 SS.setScopeRep(Qualifier);
6695 UnqualifiedId Name;
6696 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6697 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6698 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006699 Sema::TemplateTy Template;
6700 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006701 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006702 SS,
6703 Name,
John McCallba7bf592010-08-24 05:47:05 +00006704 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006705 /*EnteringContext=*/false,
6706 Template);
6707 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006708}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006709
Douglas Gregor71395fa2009-11-04 00:56:37 +00006710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006711ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006712TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6713 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006714 Expr *OrigCallee,
6715 Expr *First,
6716 Expr *Second) {
6717 Expr *Callee = OrigCallee->IgnoreParenCasts();
6718 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006719
Douglas Gregora16548e2009-08-11 05:31:07 +00006720 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006721 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006722 if (!First->getType()->isOverloadableType() &&
6723 !Second->getType()->isOverloadableType())
6724 return getSema().CreateBuiltinArraySubscriptExpr(First,
6725 Callee->getLocStart(),
6726 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006727 } else if (Op == OO_Arrow) {
6728 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006729 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6730 } else if (Second == 0 || isPostIncDec) {
6731 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 // The argument is not of overloadable type, so try to create a
6733 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006734 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006735 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006736
John McCallb268a282010-08-23 23:25:46 +00006737 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006738 }
6739 } else {
John McCallb268a282010-08-23 23:25:46 +00006740 if (!First->getType()->isOverloadableType() &&
6741 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006742 // Neither of the arguments is an overloadable type, so try to
6743 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006744 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006745 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006746 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006747 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006749
Douglas Gregora16548e2009-08-11 05:31:07 +00006750 return move(Result);
6751 }
6752 }
Mike Stump11289f42009-09-09 15:08:12 +00006753
6754 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006755 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006756 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006757
John McCallb268a282010-08-23 23:25:46 +00006758 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006759 assert(ULE->requiresADL());
6760
6761 // FIXME: Do we have to check
6762 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006763 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006764 } else {
John McCallb268a282010-08-23 23:25:46 +00006765 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006766 }
Mike Stump11289f42009-09-09 15:08:12 +00006767
Douglas Gregora16548e2009-08-11 05:31:07 +00006768 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006769 Expr *Args[2] = { First, Second };
6770 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006771
Douglas Gregora16548e2009-08-11 05:31:07 +00006772 // Create the overloaded operator invocation for unary operators.
6773 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006774 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006775 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006776 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006777 }
Mike Stump11289f42009-09-09 15:08:12 +00006778
Sebastian Redladba46e2009-10-29 20:17:01 +00006779 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006780 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006781 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006782 First,
6783 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006784
Douglas Gregora16548e2009-08-11 05:31:07 +00006785 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006786 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006787 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006788 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6789 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006791
Mike Stump11289f42009-09-09 15:08:12 +00006792 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006793}
Mike Stump11289f42009-09-09 15:08:12 +00006794
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006796ExprResult
John McCallb268a282010-08-23 23:25:46 +00006797TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006798 SourceLocation OperatorLoc,
6799 bool isArrow,
6800 NestedNameSpecifier *Qualifier,
6801 SourceRange QualifierRange,
6802 TypeSourceInfo *ScopeType,
6803 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006804 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006805 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006806 CXXScopeSpec SS;
6807 if (Qualifier) {
6808 SS.setRange(QualifierRange);
6809 SS.setScopeRep(Qualifier);
6810 }
6811
John McCallb268a282010-08-23 23:25:46 +00006812 QualType BaseType = Base->getType();
6813 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006814 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006815 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006816 !BaseType->getAs<PointerType>()->getPointeeType()
6817 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006818 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006819 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006820 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006821 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006822 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006823 /*FIXME?*/true);
6824 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006825
Douglas Gregor678f90d2010-02-25 01:56:36 +00006826 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006827 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6828 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6829 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6830 NameInfo.setNamedTypeInfo(DestroyedType);
6831
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006832 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006833
John McCallb268a282010-08-23 23:25:46 +00006834 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006835 OperatorLoc, isArrow,
6836 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006837 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006838 /*TemplateArgs*/ 0);
6839}
6840
Douglas Gregord6ff3322009-08-04 16:50:30 +00006841} // end namespace clang
6842
6843#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H