blob: bd471cea13afada077e1cbfd865f130b7eb04abe [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000028#include "clang/Sema/Ownership.h"
29#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000030#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000031#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000032#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000036using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000037
Douglas Gregord6ff3322009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump11289f42009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump11289f42009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000093
94public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000097
Douglas Gregord6ff3322009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000104 }
105
John McCalldadc5752010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000119
Douglas Gregord6ff3322009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump11289f42009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregora16548e2009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000141
Douglas Gregora16548e2009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregora16548e2009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Douglas Gregora16548e2009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump11289f42009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregord196a582009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000182
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCall550e0c22009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000192 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000193
John McCall550e0c22009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 ///
John McCall550e0c22009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000203
204 /// \brief Transform the given type-with-location into a new
205 /// type, collecting location information in the given builder
206 /// as necessary.
207 ///
John McCall31f82722010-11-12 08:19:04 +0000208 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000209
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000210 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000211 ///
Mike Stump11289f42009-09-09 15:08:12 +0000212 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000213 /// appropriate TransformXXXStmt function to transform a specific kind of
214 /// statement or the TransformExpr() function to transform an expression.
215 /// Subclasses may override this function to transform statements using some
216 /// other mechanism.
217 ///
218 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000219 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000220
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000221 /// \brief Transform the given expression.
222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 /// By default, this routine transforms an expression by delegating to the
224 /// appropriate TransformXXXExpr function to build a new expression.
225 /// Subclasses may override this function to transform expressions using some
226 /// other mechanism.
227 ///
228 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000229 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000230
Douglas Gregord6ff3322009-08-04 16:50:30 +0000231 /// \brief Transform the given declaration, which is referenced from a type
232 /// or expression.
233 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000234 /// By default, acts as the identity function on declarations. Subclasses
235 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000236 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000237
238 /// \brief Transform the definition of the given declaration.
239 ///
Mike Stump11289f42009-09-09 15:08:12 +0000240 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000241 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000242 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
243 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000244 }
Mike Stump11289f42009-09-09 15:08:12 +0000245
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000249 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000257 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000258
Douglas Gregord6ff3322009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregorf816bd72009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000275 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000276 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000277
Douglas Gregord6ff3322009-08-04 16:50:30 +0000278 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000279 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000280 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000281 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000282 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000283 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000284 QualType ObjectType = QualType(),
285 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000286
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump11289f42009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
Douglas Gregor62e06f22010-12-20 17:31:10 +0000298 /// \brief Transform the given set of template arguments.
299 ///
300 /// By default, this operation transforms all of the template arguments
301 /// in the input set using \c TransformTemplateArgument(), and appends
302 /// the transformed arguments to the output list.
303 ///
304 /// \param Inputs The set of template arguments to be transformed.
305 ///
306 /// \param NumInputs The number of template arguments in \p Inputs.
307 ///
308 /// \param Outputs The set of transformed template arguments output by this
309 /// routine.
310 ///
311 /// Returns true if an error occurred.
312 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
313 unsigned NumInputs,
314 TemplateArgumentListInfo &Outputs);
315
John McCall0ad16662009-10-29 08:12:44 +0000316 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
317 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
318 TemplateArgumentLoc &ArgLoc);
319
John McCallbcd03502009-12-07 02:54:59 +0000320 /// \brief Fakes up a TypeSourceInfo for a type.
321 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
322 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000323 getDerived().getBaseLocation());
324 }
Mike Stump11289f42009-09-09 15:08:12 +0000325
John McCall550e0c22009-10-21 00:40:46 +0000326#define ABSTRACT_TYPELOC(CLASS, PARENT)
327#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000328 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000329#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000330
John McCall31f82722010-11-12 08:19:04 +0000331 QualType
332 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
333 TemplateSpecializationTypeLoc TL,
334 TemplateName Template);
335
336 QualType
337 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
338 DependentTemplateSpecializationTypeLoc TL,
339 NestedNameSpecifier *Prefix);
340
John McCall58f10c32010-03-11 09:03:00 +0000341 /// \brief Transforms the parameters of a function type into the
342 /// given vectors.
343 ///
344 /// The result vectors should be kept in sync; null entries in the
345 /// variables vector are acceptable.
346 ///
347 /// Return true on error.
348 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
349 llvm::SmallVectorImpl<QualType> &PTypes,
350 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
351
352 /// \brief Transforms a single function-type parameter. Return null
353 /// on error.
354 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
355
John McCall31f82722010-11-12 08:19:04 +0000356 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000357
John McCalldadc5752010-08-24 06:29:42 +0000358 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
359 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Douglas Gregorebe10102009-08-20 07:17:43 +0000361#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000362 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000363#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000364 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000365#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000366#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000367
Douglas Gregord6ff3322009-08-04 16:50:30 +0000368 /// \brief Build a new pointer type given its pointee type.
369 ///
370 /// By default, performs semantic analysis when building the pointer type.
371 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000372 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000373
374 /// \brief Build a new block pointer type given its pointee type.
375 ///
Mike Stump11289f42009-09-09 15:08:12 +0000376 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000378 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000379
John McCall70dd5f62009-10-30 00:06:24 +0000380 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000381 ///
John McCall70dd5f62009-10-30 00:06:24 +0000382 /// By default, performs semantic analysis when building the
383 /// reference type. Subclasses may override this routine to provide
384 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000385 ///
John McCall70dd5f62009-10-30 00:06:24 +0000386 /// \param LValue whether the type was written with an lvalue sigil
387 /// or an rvalue sigil.
388 QualType RebuildReferenceType(QualType ReferentType,
389 bool LValue,
390 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000391
Douglas Gregord6ff3322009-08-04 16:50:30 +0000392 /// \brief Build a new member pointer type given the pointee type and the
393 /// class type it refers into.
394 ///
395 /// By default, performs semantic analysis when building the member pointer
396 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000397 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
398 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000399
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 /// \brief Build a new array type given the element type, size
401 /// modifier, size of the array (if known), size expression, and index type
402 /// qualifiers.
403 ///
404 /// By default, performs semantic analysis when building the array type.
405 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000406 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 QualType RebuildArrayType(QualType ElementType,
408 ArrayType::ArraySizeModifier SizeMod,
409 const llvm::APInt *Size,
410 Expr *SizeExpr,
411 unsigned IndexTypeQuals,
412 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000413
Douglas Gregord6ff3322009-08-04 16:50:30 +0000414 /// \brief Build a new constant array type given the element type, size
415 /// modifier, (known) size of the array, and index type qualifiers.
416 ///
417 /// By default, performs semantic analysis when building the array type.
418 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000419 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000420 ArrayType::ArraySizeModifier SizeMod,
421 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000422 unsigned IndexTypeQuals,
423 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 /// \brief Build a new incomplete array type given the element type, size
426 /// modifier, and index type qualifiers.
427 ///
428 /// By default, performs semantic analysis when building the array type.
429 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000430 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000431 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000432 unsigned IndexTypeQuals,
433 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434
Mike Stump11289f42009-09-09 15:08:12 +0000435 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 /// size modifier, size expression, and index type qualifiers.
437 ///
438 /// By default, performs semantic analysis when building the array type.
439 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000440 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000441 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000442 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000443 unsigned IndexTypeQuals,
444 SourceRange BracketsRange);
445
Mike Stump11289f42009-09-09 15:08:12 +0000446 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// size modifier, size expression, and index type qualifiers.
448 ///
449 /// By default, performs semantic analysis when building the array type.
450 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000451 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000452 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000453 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000454 unsigned IndexTypeQuals,
455 SourceRange BracketsRange);
456
457 /// \brief Build a new vector type given the element type and
458 /// number of elements.
459 ///
460 /// By default, performs semantic analysis when building the vector type.
461 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000462 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000463 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000464
Douglas Gregord6ff3322009-08-04 16:50:30 +0000465 /// \brief Build a new extended vector type given the element type and
466 /// number of elements.
467 ///
468 /// By default, performs semantic analysis when building the vector type.
469 /// Subclasses may override this routine to provide different behavior.
470 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
471 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000472
473 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000474 /// given the element type and number of elements.
475 ///
476 /// By default, performs semantic analysis when building the vector type.
477 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000478 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000479 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000481
Douglas Gregord6ff3322009-08-04 16:50:30 +0000482 /// \brief Build a new function type.
483 ///
484 /// By default, performs semantic analysis when building the function type.
485 /// Subclasses may override this routine to provide different behavior.
486 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000487 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000488 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000489 bool Variadic, unsigned Quals,
490 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000491
John McCall550e0c22009-10-21 00:40:46 +0000492 /// \brief Build a new unprototyped function type.
493 QualType RebuildFunctionNoProtoType(QualType ResultType);
494
John McCallb96ec562009-12-04 22:46:56 +0000495 /// \brief Rebuild an unresolved typename type, given the decl that
496 /// the UnresolvedUsingTypenameDecl was transformed to.
497 QualType RebuildUnresolvedUsingType(Decl *D);
498
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499 /// \brief Build a new typedef type.
500 QualType RebuildTypedefType(TypedefDecl *Typedef) {
501 return SemaRef.Context.getTypeDeclType(Typedef);
502 }
503
504 /// \brief Build a new class/struct/union type.
505 QualType RebuildRecordType(RecordDecl *Record) {
506 return SemaRef.Context.getTypeDeclType(Record);
507 }
508
509 /// \brief Build a new Enum type.
510 QualType RebuildEnumType(EnumDecl *Enum) {
511 return SemaRef.Context.getTypeDeclType(Enum);
512 }
John McCallfcc33b02009-09-05 00:15:47 +0000513
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000515 ///
516 /// By default, performs semantic analysis when building the typeof type.
517 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000518 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000519
Mike Stump11289f42009-09-09 15:08:12 +0000520 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 ///
522 /// By default, builds a new TypeOfType with the given underlying type.
523 QualType RebuildTypeOfType(QualType Underlying);
524
Mike Stump11289f42009-09-09 15:08:12 +0000525 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 ///
527 /// By default, performs semantic analysis when building the decltype type.
528 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000529 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 /// \brief Build a new template specialization type.
532 ///
533 /// By default, performs semantic analysis when building the template
534 /// specialization type. Subclasses may override this routine to provide
535 /// different behavior.
536 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000537 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000538 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000540 /// \brief Build a new parenthesized type.
541 ///
542 /// By default, builds a new ParenType type from the inner type.
543 /// Subclasses may override this routine to provide different behavior.
544 QualType RebuildParenType(QualType InnerType) {
545 return SemaRef.Context.getParenType(InnerType);
546 }
547
Douglas Gregord6ff3322009-08-04 16:50:30 +0000548 /// \brief Build a new qualified name type.
549 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000550 /// By default, builds a new ElaboratedType type from the keyword,
551 /// the nested-name-specifier and the named type.
552 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000553 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
554 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000555 NestedNameSpecifier *NNS, QualType Named) {
556 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000557 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
559 /// \brief Build a new typename type that refers to a template-id.
560 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000561 /// By default, builds a new DependentNameType type from the
562 /// nested-name-specifier and the given type. Subclasses may override
563 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000564 QualType RebuildDependentTemplateSpecializationType(
565 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000566 NestedNameSpecifier *Qualifier,
567 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000568 const IdentifierInfo *Name,
569 SourceLocation NameLoc,
570 const TemplateArgumentListInfo &Args) {
571 // Rebuild the template name.
572 // TODO: avoid TemplateName abstraction
573 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000574 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000575 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000576
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000577 if (InstName.isNull())
578 return QualType();
579
John McCallc392f372010-06-11 00:33:02 +0000580 // If it's still dependent, make a dependent specialization.
581 if (InstName.getAsDependentTemplateName())
582 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000583 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000584
585 // Otherwise, make an elaborated type wrapping a non-dependent
586 // specialization.
587 QualType T =
588 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
589 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000591 // NOTE: NNS is already recorded in template specialization type T.
592 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000593 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594
595 /// \brief Build a new typename type that refers to an identifier.
596 ///
597 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000598 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000600 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000601 NestedNameSpecifier *NNS,
602 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000603 SourceLocation KeywordLoc,
604 SourceRange NNSRange,
605 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000606 CXXScopeSpec SS;
607 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000608 SS.setRange(NNSRange);
609
Douglas Gregore677daf2010-03-31 22:19:08 +0000610 if (NNS->isDependent()) {
611 // If the name is still dependent, just build a new dependent name type.
612 if (!SemaRef.computeDeclContext(SS))
613 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
614 }
615
Abramo Bagnara6150c882010-05-11 21:36:43 +0000616 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000617 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
618 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000619
620 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
621
Abramo Bagnarad7548482010-05-19 21:37:53 +0000622 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000623 // into a non-dependent elaborated-type-specifier. Find the tag we're
624 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000625 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000626 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
627 if (!DC)
628 return QualType();
629
John McCallbf8c5192010-05-27 06:40:31 +0000630 if (SemaRef.RequireCompleteDeclContext(SS, DC))
631 return QualType();
632
Douglas Gregore677daf2010-03-31 22:19:08 +0000633 TagDecl *Tag = 0;
634 SemaRef.LookupQualifiedName(Result, DC);
635 switch (Result.getResultKind()) {
636 case LookupResult::NotFound:
637 case LookupResult::NotFoundInCurrentInstantiation:
638 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000639
Douglas Gregore677daf2010-03-31 22:19:08 +0000640 case LookupResult::Found:
641 Tag = Result.getAsSingle<TagDecl>();
642 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000643
Douglas Gregore677daf2010-03-31 22:19:08 +0000644 case LookupResult::FoundOverloaded:
645 case LookupResult::FoundUnresolvedValue:
646 llvm_unreachable("Tag lookup cannot find non-tags");
647 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000648
Douglas Gregore677daf2010-03-31 22:19:08 +0000649 case LookupResult::Ambiguous:
650 // Let the LookupResult structure handle ambiguities.
651 return QualType();
652 }
653
654 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000655 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000656 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000657 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000658 return QualType();
659 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000660
Abramo Bagnarad7548482010-05-19 21:37:53 +0000661 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
662 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000663 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
664 return QualType();
665 }
666
667 // Build the elaborated-type-specifier type.
668 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000669 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000670 }
Mike Stump11289f42009-09-09 15:08:12 +0000671
Douglas Gregor1135c352009-08-06 05:28:30 +0000672 /// \brief Build a new nested-name-specifier given the prefix and an
673 /// identifier that names the next step in the nested-name-specifier.
674 ///
675 /// By default, performs semantic analysis when building the new
676 /// nested-name-specifier. Subclasses may override this routine to provide
677 /// different behavior.
678 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
679 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000680 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000681 QualType ObjectType,
682 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000683
684 /// \brief Build a new nested-name-specifier given the prefix and the
685 /// namespace named in the next step in the nested-name-specifier.
686 ///
687 /// By default, performs semantic analysis when building the new
688 /// nested-name-specifier. Subclasses may override this routine to provide
689 /// different behavior.
690 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
691 SourceRange Range,
692 NamespaceDecl *NS);
693
694 /// \brief Build a new nested-name-specifier given the prefix and the
695 /// type named in the next step in the nested-name-specifier.
696 ///
697 /// By default, performs semantic analysis when building the new
698 /// nested-name-specifier. Subclasses may override this routine to provide
699 /// different behavior.
700 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
701 SourceRange Range,
702 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000703 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000704
705 /// \brief Build a new template name given a nested name specifier, a flag
706 /// indicating whether the "template" keyword was provided, and the template
707 /// that the template name refers to.
708 ///
709 /// By default, builds the new template name directly. Subclasses may override
710 /// this routine to provide different behavior.
711 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
712 bool TemplateKW,
713 TemplateDecl *Template);
714
Douglas Gregor71dc5092009-08-06 06:41:21 +0000715 /// \brief Build a new template name given a nested name specifier and the
716 /// name that is referred to as a template.
717 ///
718 /// By default, performs semantic analysis to determine whether the name can
719 /// be resolved to a specific template, then builds the appropriate kind of
720 /// template name. Subclasses may override this routine to provide different
721 /// behavior.
722 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000723 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000724 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000725 QualType ObjectType,
726 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregor71395fa2009-11-04 00:56:37 +0000728 /// \brief Build a new template name given a nested name specifier and the
729 /// overloaded operator name that is referred to as a template.
730 ///
731 /// By default, performs semantic analysis to determine whether the name can
732 /// be resolved to a specific template, then builds the appropriate kind of
733 /// template name. Subclasses may override this routine to provide different
734 /// behavior.
735 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
736 OverloadedOperatorKind Operator,
737 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000738
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 /// \brief Build a new compound statement.
740 ///
741 /// By default, performs semantic analysis to build the new statement.
742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000743 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000744 MultiStmtArg Statements,
745 SourceLocation RBraceLoc,
746 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000747 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000748 IsStmtExpr);
749 }
750
751 /// \brief Build a new case statement.
752 ///
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000755 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000756 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000758 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000759 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000760 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000761 ColonLoc);
762 }
Mike Stump11289f42009-09-09 15:08:12 +0000763
Douglas Gregorebe10102009-08-20 07:17:43 +0000764 /// \brief Attach the body to a new case statement.
765 ///
766 /// By default, performs semantic analysis to build the new statement.
767 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000768 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000769 getSema().ActOnCaseStmtBody(S, Body);
770 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000771 }
Mike Stump11289f42009-09-09 15:08:12 +0000772
Douglas Gregorebe10102009-08-20 07:17:43 +0000773 /// \brief Build a new default statement.
774 ///
775 /// By default, performs semantic analysis to build the new statement.
776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000777 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000779 Stmt *SubStmt) {
780 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000781 /*CurScope=*/0);
782 }
Mike Stump11289f42009-09-09 15:08:12 +0000783
Douglas Gregorebe10102009-08-20 07:17:43 +0000784 /// \brief Build a new label statement.
785 ///
786 /// By default, performs semantic analysis to build the new statement.
787 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000788 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 IdentifierInfo *Id,
790 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000791 Stmt *SubStmt, bool HasUnusedAttr) {
792 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
793 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000794 }
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregorebe10102009-08-20 07:17:43 +0000796 /// \brief Build a new "if" statement.
797 ///
798 /// By default, performs semantic analysis to build the new statement.
799 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000800 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000801 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000802 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000803 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 }
Mike Stump11289f42009-09-09 15:08:12 +0000805
Douglas Gregorebe10102009-08-20 07:17:43 +0000806 /// \brief Start building a new switch statement.
807 ///
808 /// By default, performs semantic analysis to build the new statement.
809 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000810 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000811 Expr *Cond, VarDecl *CondVar) {
812 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000813 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 }
Mike Stump11289f42009-09-09 15:08:12 +0000815
Douglas Gregorebe10102009-08-20 07:17:43 +0000816 /// \brief Attach the body to the switch statement.
817 ///
818 /// By default, performs semantic analysis to build the new statement.
819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000820 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000821 Stmt *Switch, Stmt *Body) {
822 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000823 }
824
825 /// \brief Build a new while statement.
826 ///
827 /// By default, performs semantic analysis to build the new statement.
828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000829 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000830 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000831 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000832 Stmt *Body) {
833 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 }
Mike Stump11289f42009-09-09 15:08:12 +0000835
Douglas Gregorebe10102009-08-20 07:17:43 +0000836 /// \brief Build a new do-while statement.
837 ///
838 /// By default, performs semantic analysis to build the new statement.
839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000840 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000841 SourceLocation WhileLoc,
842 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000843 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000845 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
846 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 }
848
849 /// \brief Build a new for statement.
850 ///
851 /// By default, performs semantic analysis to build the new statement.
852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000853 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000854 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000855 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000856 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000857 SourceLocation RParenLoc, Stmt *Body) {
858 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000859 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000860 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000861 }
Mike Stump11289f42009-09-09 15:08:12 +0000862
Douglas Gregorebe10102009-08-20 07:17:43 +0000863 /// \brief Build a new goto statement.
864 ///
865 /// By default, performs semantic analysis to build the new statement.
866 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000867 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000868 SourceLocation LabelLoc,
869 LabelStmt *Label) {
870 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
871 }
872
873 /// \brief Build a new indirect goto statement.
874 ///
875 /// By default, performs semantic analysis to build the new statement.
876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000877 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000878 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000879 Expr *Target) {
880 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000881 }
Mike Stump11289f42009-09-09 15:08:12 +0000882
Douglas Gregorebe10102009-08-20 07:17:43 +0000883 /// \brief Build a new return statement.
884 ///
885 /// By default, performs semantic analysis to build the new statement.
886 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000887 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000888 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000889
John McCallb268a282010-08-23 23:25:46 +0000890 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000891 }
Mike Stump11289f42009-09-09 15:08:12 +0000892
Douglas Gregorebe10102009-08-20 07:17:43 +0000893 /// \brief Build a new declaration statement.
894 ///
895 /// By default, performs semantic analysis to build the new statement.
896 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000897 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000898 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000899 SourceLocation EndLoc) {
900 return getSema().Owned(
901 new (getSema().Context) DeclStmt(
902 DeclGroupRef::Create(getSema().Context,
903 Decls, NumDecls),
904 StartLoc, EndLoc));
905 }
Mike Stump11289f42009-09-09 15:08:12 +0000906
Anders Carlssonaaeef072010-01-24 05:50:09 +0000907 /// \brief Build a new inline asm statement.
908 ///
909 /// By default, performs semantic analysis to build the new statement.
910 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000911 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000912 bool IsSimple,
913 bool IsVolatile,
914 unsigned NumOutputs,
915 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000916 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000917 MultiExprArg Constraints,
918 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000919 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000920 MultiExprArg Clobbers,
921 SourceLocation RParenLoc,
922 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000923 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000924 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000925 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000926 RParenLoc, MSAsm);
927 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000928
929 /// \brief Build a new Objective-C @try statement.
930 ///
931 /// By default, performs semantic analysis to build the new statement.
932 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000933 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000934 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000935 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000936 Stmt *Finally) {
937 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
938 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000939 }
940
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000941 /// \brief Rebuild an Objective-C exception declaration.
942 ///
943 /// By default, performs semantic analysis to build the new declaration.
944 /// Subclasses may override this routine to provide different behavior.
945 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
946 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000947 return getSema().BuildObjCExceptionDecl(TInfo, T,
948 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000949 ExceptionDecl->getLocation());
950 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000951
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000952 /// \brief Build a new Objective-C @catch statement.
953 ///
954 /// By default, performs semantic analysis to build the new statement.
955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000956 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000957 SourceLocation RParenLoc,
958 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000959 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000960 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000961 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000962 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000963
Douglas Gregor306de2f2010-04-22 23:59:56 +0000964 /// \brief Build a new Objective-C @finally statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000968 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000969 Stmt *Body) {
970 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000971 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000972
Douglas Gregor6148de72010-04-22 22:01:21 +0000973 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Expr *Operand) {
979 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000980 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000981
Douglas Gregor6148de72010-04-22 22:01:21 +0000982 /// \brief Build a new Objective-C @synchronized statement.
983 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000984 /// By default, performs semantic analysis to build the new statement.
985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000986 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000987 Expr *Object,
988 Stmt *Body) {
989 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
990 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000991 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000992
993 /// \brief Build a new Objective-C fast enumeration statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000997 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000998 SourceLocation LParenLoc,
999 Stmt *Element,
1000 Expr *Collection,
1001 SourceLocation RParenLoc,
1002 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001003 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001004 Element,
1005 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001006 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001007 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001008 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001009
Douglas Gregorebe10102009-08-20 07:17:43 +00001010 /// \brief Build a new C++ exception declaration.
1011 ///
1012 /// By default, performs semantic analysis to build the new decaration.
1013 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001014 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001015 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001016 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001017 SourceLocation Loc) {
1018 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001019 }
1020
1021 /// \brief Build a new C++ catch statement.
1022 ///
1023 /// By default, performs semantic analysis to build the new statement.
1024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001025 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001026 VarDecl *ExceptionDecl,
1027 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001028 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1029 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001030 }
Mike Stump11289f42009-09-09 15:08:12 +00001031
Douglas Gregorebe10102009-08-20 07:17:43 +00001032 /// \brief Build a new C++ try statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001036 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001037 Stmt *TryBlock,
1038 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001039 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001040 }
Mike Stump11289f42009-09-09 15:08:12 +00001041
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 /// \brief Build a new expression that references a declaration.
1043 ///
1044 /// By default, performs semantic analysis to build the new expression.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001047 LookupResult &R,
1048 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001049 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1050 }
1051
1052
1053 /// \brief Build a new expression that references a declaration.
1054 ///
1055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001058 SourceRange QualifierRange,
1059 ValueDecl *VD,
1060 const DeclarationNameInfo &NameInfo,
1061 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001062 CXXScopeSpec SS;
1063 SS.setScopeRep(Qualifier);
1064 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001065
1066 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001067
1068 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001069 }
Mike Stump11289f42009-09-09 15:08:12 +00001070
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001072 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 /// By default, performs semantic analysis to build the new expression.
1074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001075 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001077 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 }
1079
Douglas Gregorad8a3362009-09-04 17:36:40 +00001080 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001081 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001082 /// By default, performs semantic analysis to build the new expression.
1083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001084 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001085 SourceLocation OperatorLoc,
1086 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001087 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001088 SourceRange QualifierRange,
1089 TypeSourceInfo *ScopeType,
1090 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001091 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001092 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001093
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001095 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 /// By default, performs semantic analysis to build the new expression.
1097 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001098 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001099 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001100 Expr *SubExpr) {
1101 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 }
Mike Stump11289f42009-09-09 15:08:12 +00001103
Douglas Gregor882211c2010-04-28 22:16:22 +00001104 /// \brief Build a new builtin offsetof expression.
1105 ///
1106 /// By default, performs semantic analysis to build the new expression.
1107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001108 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001109 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001110 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001111 unsigned NumComponents,
1112 SourceLocation RParenLoc) {
1113 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1114 NumComponents, RParenLoc);
1115 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001116
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001118 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 /// By default, performs semantic analysis to build the new expression.
1120 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001121 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001122 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001124 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 }
1126
Mike Stump11289f42009-09-09 15:08:12 +00001127 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001129 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 /// By default, performs semantic analysis to build the new expression.
1131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001132 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001134 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001135 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001136 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001138
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 return move(Result);
1140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001143 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001144 /// By default, performs semantic analysis to build the new expression.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001147 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001148 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001149 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1151 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001152 RBracketLoc);
1153 }
1154
1155 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001156 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001157 /// By default, performs semantic analysis to build the new expression.
1158 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001159 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001160 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001161 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001162 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001163 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001164 }
1165
1166 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001167 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001168 /// By default, performs semantic analysis to build the new expression.
1169 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001170 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001171 bool isArrow,
1172 NestedNameSpecifier *Qualifier,
1173 SourceRange QualifierRange,
1174 const DeclarationNameInfo &MemberNameInfo,
1175 ValueDecl *Member,
1176 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001177 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001178 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001179 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001180 // We have a reference to an unnamed field. This is always the
1181 // base of an anonymous struct/union member access, i.e. the
1182 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001183 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001184 assert(Member->getType()->isRecordType() &&
1185 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001186
John McCallb268a282010-08-23 23:25:46 +00001187 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001188 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001189 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001190
John McCall7decc9e2010-11-18 06:31:45 +00001191 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001192 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001193 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001194 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001195 cast<FieldDecl>(Member)->getType(),
1196 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001197 return getSema().Owned(ME);
1198 }
Mike Stump11289f42009-09-09 15:08:12 +00001199
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001200 CXXScopeSpec SS;
1201 if (Qualifier) {
1202 SS.setRange(QualifierRange);
1203 SS.setScopeRep(Qualifier);
1204 }
1205
John McCallb268a282010-08-23 23:25:46 +00001206 getSema().DefaultFunctionArrayConversion(Base);
1207 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001208
John McCall16df1e52010-03-30 21:47:33 +00001209 // FIXME: this involves duplicating earlier analysis in a lot of
1210 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001211 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001212 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001213 R.resolveKind();
1214
John McCallb268a282010-08-23 23:25:46 +00001215 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001216 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001217 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001224 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001225 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001226 Expr *LHS, Expr *RHS) {
1227 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 }
1229
1230 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001231 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001236 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Expr *RHS) {
1239 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1240 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 }
1242
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001244 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 /// By default, performs semantic analysis to build the new expression.
1246 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001247 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001248 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001250 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001251 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001252 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 }
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001256 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 /// By default, performs semantic analysis to build the new expression.
1258 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001259 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001260 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001262 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001263 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001264 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 }
Mike Stump11289f42009-09-09 15:08:12 +00001266
Douglas Gregora16548e2009-08-11 05:31:07 +00001267 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001268 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001271 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 SourceLocation OpLoc,
1273 SourceLocation AccessorLoc,
1274 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001275
John McCall10eae182009-11-30 22:42:35 +00001276 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001277 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001278 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001279 OpLoc, /*IsArrow*/ false,
1280 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001281 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001282 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 }
Mike Stump11289f42009-09-09 15:08:12 +00001284
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001286 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001289 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001291 SourceLocation RBraceLoc,
1292 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001293 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001294 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1295 if (Result.isInvalid() || ResultTy->isDependentType())
1296 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001297
Douglas Gregord3d93062009-11-09 17:16:50 +00001298 // Patch in the result type we were given, which may have been computed
1299 // when the initial InitListExpr was built.
1300 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1301 ILE->setType(ResultTy);
1302 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 }
Mike Stump11289f42009-09-09 15:08:12 +00001304
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001306 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 /// By default, performs semantic analysis to build the new expression.
1308 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001309 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 MultiExprArg ArrayExprs,
1311 SourceLocation EqualOrColonLoc,
1312 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001313 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001314 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001316 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001318 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001319
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 ArrayExprs.release();
1321 return move(Result);
1322 }
Mike Stump11289f42009-09-09 15:08:12 +00001323
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001325 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// By default, builds the implicit value initialization without performing
1327 /// any semantic analysis. Subclasses may override this routine to provide
1328 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001329 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1331 }
Mike Stump11289f42009-09-09 15:08:12 +00001332
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001334 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// By default, performs semantic analysis to build the new expression.
1336 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001337 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001338 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001339 SourceLocation RParenLoc) {
1340 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001341 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001342 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 }
1344
1345 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001346 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001349 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 MultiExprArg SubExprs,
1351 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001352 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001353 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 }
Mike Stump11289f42009-09-09 15:08:12 +00001355
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001357 ///
1358 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 /// rather than attempting to map the label statement itself.
1360 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001361 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 SourceLocation LabelLoc,
1363 LabelStmt *Label) {
1364 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1365 }
Mike Stump11289f42009-09-09 15:08:12 +00001366
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001368 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 /// By default, performs semantic analysis to build the new expression.
1370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001371 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001372 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001374 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 }
Mike Stump11289f42009-09-09 15:08:12 +00001376
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// \brief Build a new __builtin_choose_expr expression.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001381 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001382 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 SourceLocation RParenLoc) {
1384 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001385 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 RParenLoc);
1387 }
Mike Stump11289f42009-09-09 15:08:12 +00001388
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 /// \brief Build a new overloaded operator call expression.
1390 ///
1391 /// By default, performs semantic analysis to build the new expression.
1392 /// The semantic analysis provides the behavior of template instantiation,
1393 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001394 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// argument-dependent lookup, etc. Subclasses may override this routine to
1396 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001397 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001399 Expr *Callee,
1400 Expr *First,
1401 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001402
1403 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 /// reinterpret_cast.
1405 ///
1406 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001407 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001409 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 Stmt::StmtClass Class,
1411 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001412 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 SourceLocation RAngleLoc,
1414 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001415 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 SourceLocation RParenLoc) {
1417 switch (Class) {
1418 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001419 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001420 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001421 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001422
1423 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001424 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001425 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001426 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001427
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001429 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001430 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001431 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001435 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001436 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001437 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001438
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 default:
1440 assert(false && "Invalid C++ named cast");
1441 break;
1442 }
Mike Stump11289f42009-09-09 15:08:12 +00001443
John McCallfaf5fb42010-08-26 23:41:50 +00001444 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 }
Mike Stump11289f42009-09-09 15:08:12 +00001446
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 /// \brief Build a new C++ static_cast expression.
1448 ///
1449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001453 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 SourceLocation RAngleLoc,
1455 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001456 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001458 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001459 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001460 SourceRange(LAngleLoc, RAngleLoc),
1461 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 }
1463
1464 /// \brief Build a new C++ dynamic_cast expression.
1465 ///
1466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001468 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001470 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 SourceLocation RAngleLoc,
1472 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001473 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001475 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001476 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001477 SourceRange(LAngleLoc, RAngleLoc),
1478 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 }
1480
1481 /// \brief Build a new C++ reinterpret_cast expression.
1482 ///
1483 /// By default, performs semantic analysis to build the new expression.
1484 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001485 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001487 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 SourceLocation RAngleLoc,
1489 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001490 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001492 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001493 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001494 SourceRange(LAngleLoc, RAngleLoc),
1495 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 }
1497
1498 /// \brief Build a new C++ const_cast expression.
1499 ///
1500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001502 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001504 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 SourceLocation RAngleLoc,
1506 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001507 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001509 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001510 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001511 SourceRange(LAngleLoc, RAngleLoc),
1512 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 }
Mike Stump11289f42009-09-09 15:08:12 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new C++ functional-style cast expression.
1516 ///
1517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001519 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1520 SourceLocation LParenLoc,
1521 Expr *Sub,
1522 SourceLocation RParenLoc) {
1523 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001524 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 RParenLoc);
1526 }
Mike Stump11289f42009-09-09 15:08:12 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new C++ typeid(type) 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,
1534 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001536 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001537 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 }
Mike Stump11289f42009-09-09 15:08:12 +00001539
Francois Pichet9f4f2072010-09-08 12:20:18 +00001540
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 /// \brief Build a new C++ typeid(expr) expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001545 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001546 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001547 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001549 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001550 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001551 }
1552
Francois Pichet9f4f2072010-09-08 12:20:18 +00001553 /// \brief Build a new C++ __uuidof(type) expression.
1554 ///
1555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
1557 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1558 SourceLocation TypeidLoc,
1559 TypeSourceInfo *Operand,
1560 SourceLocation RParenLoc) {
1561 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1562 RParenLoc);
1563 }
1564
1565 /// \brief Build a new C++ __uuidof(expr) expression.
1566 ///
1567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
1569 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1570 SourceLocation TypeidLoc,
1571 Expr *Operand,
1572 SourceLocation RParenLoc) {
1573 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1574 RParenLoc);
1575 }
1576
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 /// \brief Build a new C++ "this" expression.
1578 ///
1579 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001580 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001582 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001583 QualType ThisType,
1584 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001586 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1587 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 }
1589
1590 /// \brief Build a new C++ throw expression.
1591 ///
1592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001594 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001595 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 }
1597
1598 /// \brief Build a new C++ default-argument expression.
1599 ///
1600 /// By default, builds a new default-argument expression, which does not
1601 /// require any semantic analysis. Subclasses may override this routine to
1602 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001603 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001604 ParmVarDecl *Param) {
1605 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1606 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 }
1608
1609 /// \brief Build a new C++ zero-initialization expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001613 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1614 SourceLocation LParenLoc,
1615 SourceLocation RParenLoc) {
1616 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001617 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001618 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 }
Mike Stump11289f42009-09-09 15:08:12 +00001620
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 /// \brief Build a new C++ "new" expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001625 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001626 bool UseGlobal,
1627 SourceLocation PlacementLParen,
1628 MultiExprArg PlacementArgs,
1629 SourceLocation PlacementRParen,
1630 SourceRange TypeIdParens,
1631 QualType AllocatedType,
1632 TypeSourceInfo *AllocatedTypeInfo,
1633 Expr *ArraySize,
1634 SourceLocation ConstructorLParen,
1635 MultiExprArg ConstructorArgs,
1636 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001637 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 PlacementLParen,
1639 move(PlacementArgs),
1640 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001641 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001642 AllocatedType,
1643 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001644 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 ConstructorLParen,
1646 move(ConstructorArgs),
1647 ConstructorRParen);
1648 }
Mike Stump11289f42009-09-09 15:08:12 +00001649
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 /// \brief Build a new C++ "delete" expression.
1651 ///
1652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001654 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 bool IsGlobalDelete,
1656 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001657 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001659 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 }
Mike Stump11289f42009-09-09 15:08:12 +00001661
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 /// \brief Build a new unary type trait expression.
1663 ///
1664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001666 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001667 SourceLocation StartLoc,
1668 TypeSourceInfo *T,
1669 SourceLocation RParenLoc) {
1670 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 }
1672
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001673 /// \brief Build a new binary type trait expression.
1674 ///
1675 /// By default, performs semantic analysis to build the new expression.
1676 /// Subclasses may override this routine to provide different behavior.
1677 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1678 SourceLocation StartLoc,
1679 TypeSourceInfo *LhsT,
1680 TypeSourceInfo *RhsT,
1681 SourceLocation RParenLoc) {
1682 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1683 }
1684
Mike Stump11289f42009-09-09 15:08:12 +00001685 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 /// expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001690 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001692 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001693 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 CXXScopeSpec SS;
1695 SS.setRange(QualifierRange);
1696 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001697
1698 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001699 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001700 *TemplateArgs);
1701
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001702 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 }
1704
1705 /// \brief Build a new template-id expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001709 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001710 LookupResult &R,
1711 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001712 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001713 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 }
1715
1716 /// \brief Build a new object-construction expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001720 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001721 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 CXXConstructorDecl *Constructor,
1723 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001724 MultiExprArg Args,
1725 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001726 CXXConstructExpr::ConstructionKind ConstructKind,
1727 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001728 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001729 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001730 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001731 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001732
Douglas Gregordb121ba2009-12-14 16:27:04 +00001733 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001734 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001735 RequiresZeroInit, ConstructKind,
1736 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
1738
1739 /// \brief Build a new object-construction expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001743 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1744 SourceLocation LParenLoc,
1745 MultiExprArg Args,
1746 SourceLocation RParenLoc) {
1747 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 LParenLoc,
1749 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 RParenLoc);
1751 }
1752
1753 /// \brief Build a new object-construction expression.
1754 ///
1755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001757 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1758 SourceLocation LParenLoc,
1759 MultiExprArg Args,
1760 SourceLocation RParenLoc) {
1761 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 LParenLoc,
1763 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 RParenLoc);
1765 }
Mike Stump11289f42009-09-09 15:08:12 +00001766
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 /// \brief Build a new member reference expression.
1768 ///
1769 /// By default, performs semantic analysis to build the new expression.
1770 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001771 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001772 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 bool IsArrow,
1774 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001775 NestedNameSpecifier *Qualifier,
1776 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001777 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001778 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001779 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001781 SS.setRange(QualifierRange);
1782 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001783
John McCallb268a282010-08-23 23:25:46 +00001784 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001785 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001786 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001787 MemberNameInfo,
1788 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 }
1790
John McCall10eae182009-11-30 22:42:35 +00001791 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001792 ///
1793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001795 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001796 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001797 SourceLocation OperatorLoc,
1798 bool IsArrow,
1799 NestedNameSpecifier *Qualifier,
1800 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001801 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001802 LookupResult &R,
1803 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001804 CXXScopeSpec SS;
1805 SS.setRange(QualifierRange);
1806 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001807
John McCallb268a282010-08-23 23:25:46 +00001808 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001809 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001810 SS, FirstQualifierInScope,
1811 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001812 }
Mike Stump11289f42009-09-09 15:08:12 +00001813
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001814 /// \brief Build a new noexcept expression.
1815 ///
1816 /// By default, performs semantic analysis to build the new expression.
1817 /// Subclasses may override this routine to provide different behavior.
1818 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1819 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1820 }
1821
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// \brief Build a new Objective-C @encode expression.
1823 ///
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001826 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001827 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001829 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001831 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001832
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001833 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001834 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001835 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001836 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001837 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001838 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001839 MultiExprArg Args,
1840 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001841 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1842 ReceiverTypeInfo->getType(),
1843 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001844 Sel, Method, LBracLoc, SelectorLoc,
1845 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001846 }
1847
1848 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001849 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001850 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001851 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001852 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001853 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001854 MultiExprArg Args,
1855 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001856 return SemaRef.BuildInstanceMessage(Receiver,
1857 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001858 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001859 Sel, Method, LBracLoc, SelectorLoc,
1860 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001861 }
1862
Douglas Gregord51d90d2010-04-26 20:11:03 +00001863 /// \brief Build a new Objective-C ivar reference expression.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001867 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001868 SourceLocation IvarLoc,
1869 bool IsArrow, bool IsFreeIvar) {
1870 // FIXME: We lose track of the IsFreeIvar bit.
1871 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001872 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001873 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1874 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001875 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001876 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001877 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001878 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001879 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001880 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001881
Douglas Gregord51d90d2010-04-26 20:11:03 +00001882 if (Result.get())
1883 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001884
John McCallb268a282010-08-23 23:25:46 +00001885 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001886 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001887 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001888 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001889 /*TemplateArgs=*/0);
1890 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001891
1892 /// \brief Build a new Objective-C property reference expression.
1893 ///
1894 /// By default, performs semantic analysis to build the new expression.
1895 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001897 ObjCPropertyDecl *Property,
1898 SourceLocation PropertyLoc) {
1899 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001900 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001901 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1902 Sema::LookupMemberName);
1903 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001904 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001905 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001906 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001907 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001908 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001909
Douglas Gregor9faee212010-04-26 20:47:02 +00001910 if (Result.get())
1911 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001912
John McCallb268a282010-08-23 23:25:46 +00001913 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001914 /*FIXME:*/PropertyLoc, IsArrow,
1915 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001916 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001917 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001918 /*TemplateArgs=*/0);
1919 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001920
John McCallb7bd14f2010-12-02 01:19:52 +00001921 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001922 ///
1923 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00001924 /// Subclasses may override this routine to provide different behavior.
1925 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1926 ObjCMethodDecl *Getter,
1927 ObjCMethodDecl *Setter,
1928 SourceLocation PropertyLoc) {
1929 // Since these expressions can only be value-dependent, we do not
1930 // need to perform semantic analysis again.
1931 return Owned(
1932 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
1933 VK_LValue, OK_ObjCProperty,
1934 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001935 }
1936
Douglas Gregord51d90d2010-04-26 20:11:03 +00001937 /// \brief Build a new Objective-C "isa" expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001942 bool IsArrow) {
1943 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001944 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001945 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1946 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001947 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001948 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001949 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001950 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001951 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001952
Douglas Gregord51d90d2010-04-26 20:11:03 +00001953 if (Result.get())
1954 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001955
John McCallb268a282010-08-23 23:25:46 +00001956 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001957 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001958 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001959 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001960 /*TemplateArgs=*/0);
1961 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001962
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 /// \brief Build a new shuffle vector expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001967 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001968 MultiExprArg SubExprs,
1969 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001971 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1973 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1974 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1975 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 // Build a reference to the __builtin_shufflevector builtin
1978 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001979 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00001981 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001983
1984 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 unsigned NumSubExprs = SubExprs.size();
1986 Expr **Subs = (Expr **)SubExprs.release();
1987 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1988 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001989 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00001990 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001992 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001993
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001995 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001997 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001998
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002000 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 }
John McCall31f82722010-11-12 08:19:04 +00002002
2003private:
2004 QualType TransformTypeInObjectScope(QualType T,
2005 QualType ObjectType,
2006 NamedDecl *FirstQualifierInScope,
2007 NestedNameSpecifier *Prefix);
2008
2009 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2010 QualType ObjectType,
2011 NamedDecl *FirstQualifierInScope,
2012 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002013};
Douglas Gregora16548e2009-08-11 05:31:07 +00002014
Douglas Gregorebe10102009-08-20 07:17:43 +00002015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002016StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002017 if (!S)
2018 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregorebe10102009-08-20 07:17:43 +00002020 switch (S->getStmtClass()) {
2021 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregorebe10102009-08-20 07:17:43 +00002023 // Transform individual statement nodes
2024#define STMT(Node, Parent) \
2025 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2026#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002027#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002028
Douglas Gregorebe10102009-08-20 07:17:43 +00002029 // Transform expressions by calling TransformExpr.
2030#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002031#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002032#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002033#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002034 {
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002036 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002037 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002038
John McCallb268a282010-08-23 23:25:46 +00002039 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002040 }
Mike Stump11289f42009-09-09 15:08:12 +00002041 }
2042
John McCallc3007a22010-10-26 07:05:15 +00002043 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002044}
Mike Stump11289f42009-09-09 15:08:12 +00002045
2046
Douglas Gregore922c772009-08-04 22:27:00 +00002047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002048ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 if (!E)
2050 return SemaRef.Owned(E);
2051
2052 switch (E->getStmtClass()) {
2053 case Stmt::NoStmtClass: break;
2054#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002055#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002056#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002057 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002058#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002059 }
2060
John McCallc3007a22010-10-26 07:05:15 +00002061 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002062}
2063
2064template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002065NestedNameSpecifier *
2066TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002067 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002068 QualType ObjectType,
2069 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002070 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002071
Douglas Gregorebe10102009-08-20 07:17:43 +00002072 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002073 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002074 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002075 ObjectType,
2076 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002077 if (!Prefix)
2078 return 0;
2079 }
Mike Stump11289f42009-09-09 15:08:12 +00002080
Douglas Gregor1135c352009-08-06 05:28:30 +00002081 switch (NNS->getKind()) {
2082 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002083 if (Prefix) {
2084 // The object type and qualifier-in-scope really apply to the
2085 // leftmost entity.
2086 ObjectType = QualType();
2087 FirstQualifierInScope = 0;
2088 }
2089
Mike Stump11289f42009-09-09 15:08:12 +00002090 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002091 "Identifier nested-name-specifier with no prefix or object type");
2092 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2093 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002094 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002095
2096 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002097 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002098 ObjectType,
2099 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002100
Douglas Gregor1135c352009-08-06 05:28:30 +00002101 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002102 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002103 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002104 getDerived().TransformDecl(Range.getBegin(),
2105 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002106 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002107 Prefix == NNS->getPrefix() &&
2108 NS == NNS->getAsNamespace())
2109 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002110
Douglas Gregor1135c352009-08-06 05:28:30 +00002111 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2112 }
Mike Stump11289f42009-09-09 15:08:12 +00002113
Douglas Gregor1135c352009-08-06 05:28:30 +00002114 case NestedNameSpecifier::Global:
2115 // There is no meaningful transformation that one could perform on the
2116 // global scope.
2117 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002118
Douglas Gregor1135c352009-08-06 05:28:30 +00002119 case NestedNameSpecifier::TypeSpecWithTemplate:
2120 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002121 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002122 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2123 ObjectType,
2124 FirstQualifierInScope,
2125 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002126 if (T.isNull())
2127 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002128
Douglas Gregor1135c352009-08-06 05:28:30 +00002129 if (!getDerived().AlwaysRebuild() &&
2130 Prefix == NNS->getPrefix() &&
2131 T == QualType(NNS->getAsType(), 0))
2132 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002133
2134 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2135 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002136 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002137 }
2138 }
Mike Stump11289f42009-09-09 15:08:12 +00002139
Douglas Gregor1135c352009-08-06 05:28:30 +00002140 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002141 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002142}
2143
2144template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002145DeclarationNameInfo
2146TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002147::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002148 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002149 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002150 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002151
2152 switch (Name.getNameKind()) {
2153 case DeclarationName::Identifier:
2154 case DeclarationName::ObjCZeroArgSelector:
2155 case DeclarationName::ObjCOneArgSelector:
2156 case DeclarationName::ObjCMultiArgSelector:
2157 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002158 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002159 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002160 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002161
Douglas Gregorf816bd72009-09-03 22:13:48 +00002162 case DeclarationName::CXXConstructorName:
2163 case DeclarationName::CXXDestructorName:
2164 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002165 TypeSourceInfo *NewTInfo;
2166 CanQualType NewCanTy;
2167 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002168 NewTInfo = getDerived().TransformType(OldTInfo);
2169 if (!NewTInfo)
2170 return DeclarationNameInfo();
2171 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002172 }
2173 else {
2174 NewTInfo = 0;
2175 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002176 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002177 if (NewT.isNull())
2178 return DeclarationNameInfo();
2179 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2180 }
Mike Stump11289f42009-09-09 15:08:12 +00002181
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002182 DeclarationName NewName
2183 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2184 NewCanTy);
2185 DeclarationNameInfo NewNameInfo(NameInfo);
2186 NewNameInfo.setName(NewName);
2187 NewNameInfo.setNamedTypeInfo(NewTInfo);
2188 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002189 }
Mike Stump11289f42009-09-09 15:08:12 +00002190 }
2191
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002192 assert(0 && "Unknown name kind.");
2193 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002194}
2195
2196template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002197TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002198TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002199 QualType ObjectType,
2200 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002201 SourceLocation Loc = getDerived().getBaseLocation();
2202
Douglas Gregor71dc5092009-08-06 06:41:21 +00002203 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002204 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002205 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002206 /*FIXME*/ SourceRange(Loc),
2207 ObjectType,
2208 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002209 if (!NNS)
2210 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002211
Douglas Gregor71dc5092009-08-06 06:41:21 +00002212 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002213 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002214 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002215 if (!TransTemplate)
2216 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002217
Douglas Gregor71dc5092009-08-06 06:41:21 +00002218 if (!getDerived().AlwaysRebuild() &&
2219 NNS == QTN->getQualifier() &&
2220 TransTemplate == Template)
2221 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregor71dc5092009-08-06 06:41:21 +00002223 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2224 TransTemplate);
2225 }
Mike Stump11289f42009-09-09 15:08:12 +00002226
John McCalle66edc12009-11-24 19:00:30 +00002227 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002228 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002229 }
Mike Stump11289f42009-09-09 15:08:12 +00002230
Douglas Gregor71dc5092009-08-06 06:41:21 +00002231 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002232 NestedNameSpecifier *NNS = DTN->getQualifier();
2233 if (NNS) {
2234 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2235 /*FIXME:*/SourceRange(Loc),
2236 ObjectType,
2237 FirstQualifierInScope);
2238 if (!NNS) return TemplateName();
2239
2240 // These apply to the scope specifier, not the template.
2241 ObjectType = QualType();
2242 FirstQualifierInScope = 0;
2243 }
Mike Stump11289f42009-09-09 15:08:12 +00002244
Douglas Gregor71dc5092009-08-06 06:41:21 +00002245 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002246 NNS == DTN->getQualifier() &&
2247 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002248 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002249
Douglas Gregora5614c52010-09-08 23:56:00 +00002250 if (DTN->isIdentifier()) {
2251 // FIXME: Bad range
2252 SourceRange QualifierRange(getDerived().getBaseLocation());
2253 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2254 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002255 ObjectType,
2256 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002257 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002258
2259 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002260 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002261 }
Mike Stump11289f42009-09-09 15:08:12 +00002262
Douglas Gregor71dc5092009-08-06 06:41:21 +00002263 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002264 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002265 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002266 if (!TransTemplate)
2267 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregor71dc5092009-08-06 06:41:21 +00002269 if (!getDerived().AlwaysRebuild() &&
2270 TransTemplate == Template)
2271 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregor71dc5092009-08-06 06:41:21 +00002273 return TemplateName(TransTemplate);
2274 }
Mike Stump11289f42009-09-09 15:08:12 +00002275
John McCalle66edc12009-11-24 19:00:30 +00002276 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002277 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002278 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002279}
2280
2281template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002282void TreeTransform<Derived>::InventTemplateArgumentLoc(
2283 const TemplateArgument &Arg,
2284 TemplateArgumentLoc &Output) {
2285 SourceLocation Loc = getDerived().getBaseLocation();
2286 switch (Arg.getKind()) {
2287 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002288 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002289 break;
2290
2291 case TemplateArgument::Type:
2292 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002293 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002294
John McCall0ad16662009-10-29 08:12:44 +00002295 break;
2296
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002297 case TemplateArgument::Template:
2298 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2299 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002300
John McCall0ad16662009-10-29 08:12:44 +00002301 case TemplateArgument::Expression:
2302 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2303 break;
2304
2305 case TemplateArgument::Declaration:
2306 case TemplateArgument::Integral:
2307 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002308 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002309 break;
2310 }
2311}
2312
2313template<typename Derived>
2314bool TreeTransform<Derived>::TransformTemplateArgument(
2315 const TemplateArgumentLoc &Input,
2316 TemplateArgumentLoc &Output) {
2317 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002318 switch (Arg.getKind()) {
2319 case TemplateArgument::Null:
2320 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002321 Output = Input;
2322 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002323
Douglas Gregore922c772009-08-04 22:27:00 +00002324 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002325 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002326 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002327 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002328
2329 DI = getDerived().TransformType(DI);
2330 if (!DI) return true;
2331
2332 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2333 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002334 }
Mike Stump11289f42009-09-09 15:08:12 +00002335
Douglas Gregore922c772009-08-04 22:27:00 +00002336 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002337 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002338 DeclarationName Name;
2339 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2340 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002341 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002342 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002343 if (!D) return true;
2344
John McCall0d07eb32009-10-29 18:45:58 +00002345 Expr *SourceExpr = Input.getSourceDeclExpression();
2346 if (SourceExpr) {
2347 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002348 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002349 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002350 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002351 }
2352
2353 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002354 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002355 }
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002357 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002358 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002359 TemplateName Template
2360 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2361 if (Template.isNull())
2362 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002363
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002364 Output = TemplateArgumentLoc(TemplateArgument(Template),
2365 Input.getTemplateQualifierRange(),
2366 Input.getTemplateNameLoc());
2367 return false;
2368 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002369
Douglas Gregore922c772009-08-04 22:27:00 +00002370 case TemplateArgument::Expression: {
2371 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002372 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002373 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002374
John McCall0ad16662009-10-29 08:12:44 +00002375 Expr *InputExpr = Input.getSourceExpression();
2376 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2377
John McCalldadc5752010-08-24 06:29:42 +00002378 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002379 = getDerived().TransformExpr(InputExpr);
2380 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002381 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002382 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002383 }
Mike Stump11289f42009-09-09 15:08:12 +00002384
Douglas Gregore922c772009-08-04 22:27:00 +00002385 case TemplateArgument::Pack: {
2386 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2387 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002388 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002389 AEnd = Arg.pack_end();
2390 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002391
John McCall0ad16662009-10-29 08:12:44 +00002392 // FIXME: preserve source information here when we start
2393 // caring about parameter packs.
2394
John McCall0d07eb32009-10-29 18:45:58 +00002395 TemplateArgumentLoc InputArg;
2396 TemplateArgumentLoc OutputArg;
2397 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2398 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002399 return true;
2400
John McCall0d07eb32009-10-29 18:45:58 +00002401 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002402 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002403
2404 TemplateArgument *TransformedArgsPtr
2405 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2406 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2407 TransformedArgsPtr);
2408 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2409 TransformedArgs.size()),
2410 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002411 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002412 }
2413 }
Mike Stump11289f42009-09-09 15:08:12 +00002414
Douglas Gregore922c772009-08-04 22:27:00 +00002415 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002416 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002417}
2418
Douglas Gregor62e06f22010-12-20 17:31:10 +00002419template<typename Derived>
2420bool TreeTransform<Derived>::TransformTemplateArguments(
2421 const TemplateArgumentLoc *Inputs,
2422 unsigned NumInputs,
2423 TemplateArgumentListInfo &Outputs) {
2424 for (unsigned I = 0; I != NumInputs; ++I) {
2425 TemplateArgumentLoc Out;
2426 if (getDerived().TransformTemplateArgument(Inputs[I], Out))
2427 return true;
2428
2429 Outputs.addArgument(Out);
2430 }
2431
2432 return false;
2433}
2434
Douglas Gregord6ff3322009-08-04 16:50:30 +00002435//===----------------------------------------------------------------------===//
2436// Type transformation
2437//===----------------------------------------------------------------------===//
2438
2439template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002440QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002441 if (getDerived().AlreadyTransformed(T))
2442 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002443
John McCall550e0c22009-10-21 00:40:46 +00002444 // Temporary workaround. All of these transformations should
2445 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002446 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002447 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002448
John McCall31f82722010-11-12 08:19:04 +00002449 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002450
John McCall550e0c22009-10-21 00:40:46 +00002451 if (!NewDI)
2452 return QualType();
2453
2454 return NewDI->getType();
2455}
2456
2457template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002458TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002459 if (getDerived().AlreadyTransformed(DI->getType()))
2460 return DI;
2461
2462 TypeLocBuilder TLB;
2463
2464 TypeLoc TL = DI->getTypeLoc();
2465 TLB.reserve(TL.getFullDataSize());
2466
John McCall31f82722010-11-12 08:19:04 +00002467 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002468 if (Result.isNull())
2469 return 0;
2470
John McCallbcd03502009-12-07 02:54:59 +00002471 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002472}
2473
2474template<typename Derived>
2475QualType
John McCall31f82722010-11-12 08:19:04 +00002476TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002477 switch (T.getTypeLocClass()) {
2478#define ABSTRACT_TYPELOC(CLASS, PARENT)
2479#define TYPELOC(CLASS, PARENT) \
2480 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002481 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002482#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002483 }
Mike Stump11289f42009-09-09 15:08:12 +00002484
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002485 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002486 return QualType();
2487}
2488
2489/// FIXME: By default, this routine adds type qualifiers only to types
2490/// that can have qualifiers, and silently suppresses those qualifiers
2491/// that are not permitted (e.g., qualifiers on reference or function
2492/// types). This is the right thing for template instantiation, but
2493/// probably not for other clients.
2494template<typename Derived>
2495QualType
2496TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002497 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002498 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002499
John McCall31f82722010-11-12 08:19:04 +00002500 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002501 if (Result.isNull())
2502 return QualType();
2503
2504 // Silently suppress qualifiers if the result type can't be qualified.
2505 // FIXME: this is the right thing for template instantiation, but
2506 // probably not for other clients.
2507 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002508 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002509
John McCallcb0f89a2010-06-05 06:41:15 +00002510 if (!Quals.empty()) {
2511 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2512 TLB.push<QualifiedTypeLoc>(Result);
2513 // No location information to preserve.
2514 }
John McCall550e0c22009-10-21 00:40:46 +00002515
2516 return Result;
2517}
2518
John McCall31f82722010-11-12 08:19:04 +00002519/// \brief Transforms a type that was written in a scope specifier,
2520/// given an object type, the results of unqualified lookup, and
2521/// an already-instantiated prefix.
2522///
2523/// The object type is provided iff the scope specifier qualifies the
2524/// member of a dependent member-access expression. The prefix is
2525/// provided iff the the scope specifier in which this appears has a
2526/// prefix.
2527///
2528/// This is private to TreeTransform.
2529template<typename Derived>
2530QualType
2531TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2532 QualType ObjectType,
2533 NamedDecl *UnqualLookup,
2534 NestedNameSpecifier *Prefix) {
2535 if (getDerived().AlreadyTransformed(T))
2536 return T;
2537
2538 TypeSourceInfo *TSI =
2539 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2540
2541 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2542 UnqualLookup, Prefix);
2543 if (!TSI) return QualType();
2544 return TSI->getType();
2545}
2546
2547template<typename Derived>
2548TypeSourceInfo *
2549TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2550 QualType ObjectType,
2551 NamedDecl *UnqualLookup,
2552 NestedNameSpecifier *Prefix) {
2553 // TODO: in some cases, we might be some verification to do here.
2554 if (ObjectType.isNull())
2555 return getDerived().TransformType(TSI);
2556
2557 QualType T = TSI->getType();
2558 if (getDerived().AlreadyTransformed(T))
2559 return TSI;
2560
2561 TypeLocBuilder TLB;
2562 QualType Result;
2563
2564 if (isa<TemplateSpecializationType>(T)) {
2565 TemplateSpecializationTypeLoc TL
2566 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2567
2568 TemplateName Template =
2569 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2570 ObjectType, UnqualLookup);
2571 if (Template.isNull()) return 0;
2572
2573 Result = getDerived()
2574 .TransformTemplateSpecializationType(TLB, TL, Template);
2575 } else if (isa<DependentTemplateSpecializationType>(T)) {
2576 DependentTemplateSpecializationTypeLoc TL
2577 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2578
2579 Result = getDerived()
2580 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2581 } else {
2582 // Nothing special needs to be done for these.
2583 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2584 }
2585
2586 if (Result.isNull()) return 0;
2587 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2588}
2589
John McCall550e0c22009-10-21 00:40:46 +00002590template <class TyLoc> static inline
2591QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2592 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2593 NewT.setNameLoc(T.getNameLoc());
2594 return T.getType();
2595}
2596
John McCall550e0c22009-10-21 00:40:46 +00002597template<typename Derived>
2598QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002599 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002600 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2601 NewT.setBuiltinLoc(T.getBuiltinLoc());
2602 if (T.needsExtraLocalData())
2603 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2604 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002605}
Mike Stump11289f42009-09-09 15:08:12 +00002606
Douglas Gregord6ff3322009-08-04 16:50:30 +00002607template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002608QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002609 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002610 // FIXME: recurse?
2611 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002612}
Mike Stump11289f42009-09-09 15:08:12 +00002613
Douglas Gregord6ff3322009-08-04 16:50:30 +00002614template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002615QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002616 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002617 QualType PointeeType
2618 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002619 if (PointeeType.isNull())
2620 return QualType();
2621
2622 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002623 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002624 // A dependent pointer type 'T *' has is being transformed such
2625 // that an Objective-C class type is being replaced for 'T'. The
2626 // resulting pointer type is an ObjCObjectPointerType, not a
2627 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002628 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002629
John McCall8b07ec22010-05-15 11:32:37 +00002630 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2631 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002632 return Result;
2633 }
John McCall31f82722010-11-12 08:19:04 +00002634
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002635 if (getDerived().AlwaysRebuild() ||
2636 PointeeType != TL.getPointeeLoc().getType()) {
2637 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2638 if (Result.isNull())
2639 return QualType();
2640 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002641
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002642 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2643 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002644 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645}
Mike Stump11289f42009-09-09 15:08:12 +00002646
2647template<typename Derived>
2648QualType
John McCall550e0c22009-10-21 00:40:46 +00002649TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002650 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002651 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002652 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2653 if (PointeeType.isNull())
2654 return QualType();
2655
2656 QualType Result = TL.getType();
2657 if (getDerived().AlwaysRebuild() ||
2658 PointeeType != TL.getPointeeLoc().getType()) {
2659 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002660 TL.getSigilLoc());
2661 if (Result.isNull())
2662 return QualType();
2663 }
2664
Douglas Gregor049211a2010-04-22 16:50:51 +00002665 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002666 NewT.setSigilLoc(TL.getSigilLoc());
2667 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002668}
2669
John McCall70dd5f62009-10-30 00:06:24 +00002670/// Transforms a reference type. Note that somewhat paradoxically we
2671/// don't care whether the type itself is an l-value type or an r-value
2672/// type; we only care if the type was *written* as an l-value type
2673/// or an r-value type.
2674template<typename Derived>
2675QualType
2676TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002677 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002678 const ReferenceType *T = TL.getTypePtr();
2679
2680 // Note that this works with the pointee-as-written.
2681 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2682 if (PointeeType.isNull())
2683 return QualType();
2684
2685 QualType Result = TL.getType();
2686 if (getDerived().AlwaysRebuild() ||
2687 PointeeType != T->getPointeeTypeAsWritten()) {
2688 Result = getDerived().RebuildReferenceType(PointeeType,
2689 T->isSpelledAsLValue(),
2690 TL.getSigilLoc());
2691 if (Result.isNull())
2692 return QualType();
2693 }
2694
2695 // r-value references can be rebuilt as l-value references.
2696 ReferenceTypeLoc NewTL;
2697 if (isa<LValueReferenceType>(Result))
2698 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2699 else
2700 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2701 NewTL.setSigilLoc(TL.getSigilLoc());
2702
2703 return Result;
2704}
2705
Mike Stump11289f42009-09-09 15:08:12 +00002706template<typename Derived>
2707QualType
John McCall550e0c22009-10-21 00:40:46 +00002708TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002709 LValueReferenceTypeLoc TL) {
2710 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002711}
2712
Mike Stump11289f42009-09-09 15:08:12 +00002713template<typename Derived>
2714QualType
John McCall550e0c22009-10-21 00:40:46 +00002715TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002716 RValueReferenceTypeLoc TL) {
2717 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002718}
Mike Stump11289f42009-09-09 15:08:12 +00002719
Douglas Gregord6ff3322009-08-04 16:50:30 +00002720template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002721QualType
John McCall550e0c22009-10-21 00:40:46 +00002722TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002723 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002724 MemberPointerType *T = TL.getTypePtr();
2725
2726 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002727 if (PointeeType.isNull())
2728 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002729
John McCall550e0c22009-10-21 00:40:46 +00002730 // TODO: preserve source information for this.
2731 QualType ClassType
2732 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002733 if (ClassType.isNull())
2734 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002735
John McCall550e0c22009-10-21 00:40:46 +00002736 QualType Result = TL.getType();
2737 if (getDerived().AlwaysRebuild() ||
2738 PointeeType != T->getPointeeType() ||
2739 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002740 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2741 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002742 if (Result.isNull())
2743 return QualType();
2744 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002745
John McCall550e0c22009-10-21 00:40:46 +00002746 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2747 NewTL.setSigilLoc(TL.getSigilLoc());
2748
2749 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750}
2751
Mike Stump11289f42009-09-09 15:08:12 +00002752template<typename Derived>
2753QualType
John McCall550e0c22009-10-21 00:40:46 +00002754TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002755 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002756 ConstantArrayType *T = TL.getTypePtr();
2757 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758 if (ElementType.isNull())
2759 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002760
John McCall550e0c22009-10-21 00:40:46 +00002761 QualType Result = TL.getType();
2762 if (getDerived().AlwaysRebuild() ||
2763 ElementType != T->getElementType()) {
2764 Result = getDerived().RebuildConstantArrayType(ElementType,
2765 T->getSizeModifier(),
2766 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002767 T->getIndexTypeCVRQualifiers(),
2768 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002769 if (Result.isNull())
2770 return QualType();
2771 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002772
John McCall550e0c22009-10-21 00:40:46 +00002773 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2774 NewTL.setLBracketLoc(TL.getLBracketLoc());
2775 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002776
John McCall550e0c22009-10-21 00:40:46 +00002777 Expr *Size = TL.getSizeExpr();
2778 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002779 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002780 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2781 }
2782 NewTL.setSizeExpr(Size);
2783
2784 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002785}
Mike Stump11289f42009-09-09 15:08:12 +00002786
Douglas Gregord6ff3322009-08-04 16:50:30 +00002787template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002788QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002789 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002790 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002791 IncompleteArrayType *T = TL.getTypePtr();
2792 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002793 if (ElementType.isNull())
2794 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002795
John McCall550e0c22009-10-21 00:40:46 +00002796 QualType Result = TL.getType();
2797 if (getDerived().AlwaysRebuild() ||
2798 ElementType != T->getElementType()) {
2799 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002800 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002801 T->getIndexTypeCVRQualifiers(),
2802 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002803 if (Result.isNull())
2804 return QualType();
2805 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002806
John McCall550e0c22009-10-21 00:40:46 +00002807 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2808 NewTL.setLBracketLoc(TL.getLBracketLoc());
2809 NewTL.setRBracketLoc(TL.getRBracketLoc());
2810 NewTL.setSizeExpr(0);
2811
2812 return Result;
2813}
2814
2815template<typename Derived>
2816QualType
2817TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002818 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002819 VariableArrayType *T = TL.getTypePtr();
2820 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2821 if (ElementType.isNull())
2822 return QualType();
2823
2824 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002825 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002826
John McCalldadc5752010-08-24 06:29:42 +00002827 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002828 = getDerived().TransformExpr(T->getSizeExpr());
2829 if (SizeResult.isInvalid())
2830 return QualType();
2831
John McCallb268a282010-08-23 23:25:46 +00002832 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002833
2834 QualType Result = TL.getType();
2835 if (getDerived().AlwaysRebuild() ||
2836 ElementType != T->getElementType() ||
2837 Size != T->getSizeExpr()) {
2838 Result = getDerived().RebuildVariableArrayType(ElementType,
2839 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002840 Size,
John McCall550e0c22009-10-21 00:40:46 +00002841 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002842 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002843 if (Result.isNull())
2844 return QualType();
2845 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002846
John McCall550e0c22009-10-21 00:40:46 +00002847 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2848 NewTL.setLBracketLoc(TL.getLBracketLoc());
2849 NewTL.setRBracketLoc(TL.getRBracketLoc());
2850 NewTL.setSizeExpr(Size);
2851
2852 return Result;
2853}
2854
2855template<typename Derived>
2856QualType
2857TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002858 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002859 DependentSizedArrayType *T = TL.getTypePtr();
2860 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2861 if (ElementType.isNull())
2862 return QualType();
2863
2864 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002865 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002866
John McCalldadc5752010-08-24 06:29:42 +00002867 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002868 = getDerived().TransformExpr(T->getSizeExpr());
2869 if (SizeResult.isInvalid())
2870 return QualType();
2871
2872 Expr *Size = static_cast<Expr*>(SizeResult.get());
2873
2874 QualType Result = TL.getType();
2875 if (getDerived().AlwaysRebuild() ||
2876 ElementType != T->getElementType() ||
2877 Size != T->getSizeExpr()) {
2878 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2879 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002880 Size,
John McCall550e0c22009-10-21 00:40:46 +00002881 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002882 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002883 if (Result.isNull())
2884 return QualType();
2885 }
2886 else SizeResult.take();
2887
2888 // We might have any sort of array type now, but fortunately they
2889 // all have the same location layout.
2890 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2891 NewTL.setLBracketLoc(TL.getLBracketLoc());
2892 NewTL.setRBracketLoc(TL.getRBracketLoc());
2893 NewTL.setSizeExpr(Size);
2894
2895 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002896}
Mike Stump11289f42009-09-09 15:08:12 +00002897
2898template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002900 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002901 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002902 DependentSizedExtVectorType *T = TL.getTypePtr();
2903
2904 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002905 QualType ElementType = getDerived().TransformType(T->getElementType());
2906 if (ElementType.isNull())
2907 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002908
Douglas Gregore922c772009-08-04 22:27:00 +00002909 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002910 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002911
John McCalldadc5752010-08-24 06:29:42 +00002912 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002913 if (Size.isInvalid())
2914 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002915
John McCall550e0c22009-10-21 00:40:46 +00002916 QualType Result = TL.getType();
2917 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002918 ElementType != T->getElementType() ||
2919 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002920 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002921 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002922 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002923 if (Result.isNull())
2924 return QualType();
2925 }
John McCall550e0c22009-10-21 00:40:46 +00002926
2927 // Result might be dependent or not.
2928 if (isa<DependentSizedExtVectorType>(Result)) {
2929 DependentSizedExtVectorTypeLoc NewTL
2930 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2931 NewTL.setNameLoc(TL.getNameLoc());
2932 } else {
2933 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2934 NewTL.setNameLoc(TL.getNameLoc());
2935 }
2936
2937 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002938}
Mike Stump11289f42009-09-09 15:08:12 +00002939
2940template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002941QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002942 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002943 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002944 QualType ElementType = getDerived().TransformType(T->getElementType());
2945 if (ElementType.isNull())
2946 return QualType();
2947
John McCall550e0c22009-10-21 00:40:46 +00002948 QualType Result = TL.getType();
2949 if (getDerived().AlwaysRebuild() ||
2950 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002951 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00002952 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00002953 if (Result.isNull())
2954 return QualType();
2955 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002956
John McCall550e0c22009-10-21 00:40:46 +00002957 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2958 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002959
John McCall550e0c22009-10-21 00:40:46 +00002960 return Result;
2961}
2962
2963template<typename Derived>
2964QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002965 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002966 VectorType *T = TL.getTypePtr();
2967 QualType ElementType = getDerived().TransformType(T->getElementType());
2968 if (ElementType.isNull())
2969 return QualType();
2970
2971 QualType Result = TL.getType();
2972 if (getDerived().AlwaysRebuild() ||
2973 ElementType != T->getElementType()) {
2974 Result = getDerived().RebuildExtVectorType(ElementType,
2975 T->getNumElements(),
2976 /*FIXME*/ SourceLocation());
2977 if (Result.isNull())
2978 return QualType();
2979 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002980
John McCall550e0c22009-10-21 00:40:46 +00002981 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2982 NewTL.setNameLoc(TL.getNameLoc());
2983
2984 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002985}
Mike Stump11289f42009-09-09 15:08:12 +00002986
2987template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002988ParmVarDecl *
2989TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2990 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2991 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2992 if (!NewDI)
2993 return 0;
2994
2995 if (NewDI == OldDI)
2996 return OldParm;
2997 else
2998 return ParmVarDecl::Create(SemaRef.Context,
2999 OldParm->getDeclContext(),
3000 OldParm->getLocation(),
3001 OldParm->getIdentifier(),
3002 NewDI->getType(),
3003 NewDI,
3004 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003005 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003006 /* DefArg */ NULL);
3007}
3008
3009template<typename Derived>
3010bool TreeTransform<Derived>::
3011 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3012 llvm::SmallVectorImpl<QualType> &PTypes,
3013 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3014 FunctionProtoType *T = TL.getTypePtr();
3015
3016 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3017 ParmVarDecl *OldParm = TL.getArg(i);
3018
3019 QualType NewType;
3020 ParmVarDecl *NewParm;
3021
3022 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00003023 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3024 if (!NewParm)
3025 return true;
3026 NewType = NewParm->getType();
3027
3028 // Deal with the possibility that we don't have a parameter
3029 // declaration for this parameter.
3030 } else {
3031 NewParm = 0;
3032
3033 QualType OldType = T->getArgType(i);
3034 NewType = getDerived().TransformType(OldType);
3035 if (NewType.isNull())
3036 return true;
3037 }
3038
3039 PTypes.push_back(NewType);
3040 PVars.push_back(NewParm);
3041 }
3042
3043 return false;
3044}
3045
3046template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003047QualType
John McCall550e0c22009-10-21 00:40:46 +00003048TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003049 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003050 // Transform the parameters and return type.
3051 //
3052 // We instantiate in source order, with the return type first followed by
3053 // the parameters, because users tend to expect this (even if they shouldn't
3054 // rely on it!).
3055 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003056 // When the function has a trailing return type, we instantiate the
3057 // parameters before the return type, since the return type can then refer
3058 // to the parameters themselves (via decltype, sizeof, etc.).
3059 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003060 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003061 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003062 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003063
Douglas Gregor7fb25412010-10-01 18:44:50 +00003064 QualType ResultType;
3065
3066 if (TL.getTrailingReturn()) {
3067 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3068 return QualType();
3069
3070 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3071 if (ResultType.isNull())
3072 return QualType();
3073 }
3074 else {
3075 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3076 if (ResultType.isNull())
3077 return QualType();
3078
3079 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3080 return QualType();
3081 }
3082
John McCall550e0c22009-10-21 00:40:46 +00003083 QualType Result = TL.getType();
3084 if (getDerived().AlwaysRebuild() ||
3085 ResultType != T->getResultType() ||
3086 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3087 Result = getDerived().RebuildFunctionProtoType(ResultType,
3088 ParamTypes.data(),
3089 ParamTypes.size(),
3090 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003091 T->getTypeQuals(),
3092 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003093 if (Result.isNull())
3094 return QualType();
3095 }
Mike Stump11289f42009-09-09 15:08:12 +00003096
John McCall550e0c22009-10-21 00:40:46 +00003097 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3098 NewTL.setLParenLoc(TL.getLParenLoc());
3099 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003100 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003101 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3102 NewTL.setArg(i, ParamDecls[i]);
3103
3104 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105}
Mike Stump11289f42009-09-09 15:08:12 +00003106
Douglas Gregord6ff3322009-08-04 16:50:30 +00003107template<typename Derived>
3108QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003109 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003110 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003111 FunctionNoProtoType *T = TL.getTypePtr();
3112 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3113 if (ResultType.isNull())
3114 return QualType();
3115
3116 QualType Result = TL.getType();
3117 if (getDerived().AlwaysRebuild() ||
3118 ResultType != T->getResultType())
3119 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3120
3121 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3122 NewTL.setLParenLoc(TL.getLParenLoc());
3123 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003124 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003125
3126 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127}
Mike Stump11289f42009-09-09 15:08:12 +00003128
John McCallb96ec562009-12-04 22:46:56 +00003129template<typename Derived> QualType
3130TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003131 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003132 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003133 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003134 if (!D)
3135 return QualType();
3136
3137 QualType Result = TL.getType();
3138 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3139 Result = getDerived().RebuildUnresolvedUsingType(D);
3140 if (Result.isNull())
3141 return QualType();
3142 }
3143
3144 // We might get an arbitrary type spec type back. We should at
3145 // least always get a type spec type, though.
3146 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3147 NewTL.setNameLoc(TL.getNameLoc());
3148
3149 return Result;
3150}
3151
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003153QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003154 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003155 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003156 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003157 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3158 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003159 if (!Typedef)
3160 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003161
John McCall550e0c22009-10-21 00:40:46 +00003162 QualType Result = TL.getType();
3163 if (getDerived().AlwaysRebuild() ||
3164 Typedef != T->getDecl()) {
3165 Result = getDerived().RebuildTypedefType(Typedef);
3166 if (Result.isNull())
3167 return QualType();
3168 }
Mike Stump11289f42009-09-09 15:08:12 +00003169
John McCall550e0c22009-10-21 00:40:46 +00003170 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3171 NewTL.setNameLoc(TL.getNameLoc());
3172
3173 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003174}
Mike Stump11289f42009-09-09 15:08:12 +00003175
Douglas Gregord6ff3322009-08-04 16:50:30 +00003176template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003177QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003178 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003179 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003180 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003181
John McCalldadc5752010-08-24 06:29:42 +00003182 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003183 if (E.isInvalid())
3184 return QualType();
3185
John McCall550e0c22009-10-21 00:40:46 +00003186 QualType Result = TL.getType();
3187 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003188 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003189 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003190 if (Result.isNull())
3191 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003192 }
John McCall550e0c22009-10-21 00:40:46 +00003193 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003194
John McCall550e0c22009-10-21 00:40:46 +00003195 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003196 NewTL.setTypeofLoc(TL.getTypeofLoc());
3197 NewTL.setLParenLoc(TL.getLParenLoc());
3198 NewTL.setRParenLoc(TL.getRParenLoc());
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>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003205 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003206 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3207 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3208 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003209 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003210
John McCall550e0c22009-10-21 00:40:46 +00003211 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003212 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3213 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003214 if (Result.isNull())
3215 return QualType();
3216 }
Mike Stump11289f42009-09-09 15:08:12 +00003217
John McCall550e0c22009-10-21 00:40:46 +00003218 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003219 NewTL.setTypeofLoc(TL.getTypeofLoc());
3220 NewTL.setLParenLoc(TL.getLParenLoc());
3221 NewTL.setRParenLoc(TL.getRParenLoc());
3222 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003223
3224 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003225}
Mike Stump11289f42009-09-09 15:08:12 +00003226
3227template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003228QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003229 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003230 DecltypeType *T = TL.getTypePtr();
3231
Douglas Gregore922c772009-08-04 22:27:00 +00003232 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003233 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003234
John McCalldadc5752010-08-24 06:29:42 +00003235 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003236 if (E.isInvalid())
3237 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003238
John McCall550e0c22009-10-21 00:40:46 +00003239 QualType Result = TL.getType();
3240 if (getDerived().AlwaysRebuild() ||
3241 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003242 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003243 if (Result.isNull())
3244 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003245 }
John McCall550e0c22009-10-21 00:40:46 +00003246 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003247
John McCall550e0c22009-10-21 00:40:46 +00003248 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3249 NewTL.setNameLoc(TL.getNameLoc());
3250
3251 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003252}
3253
3254template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003255QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003256 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003257 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003258 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003259 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3260 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003261 if (!Record)
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 Record != T->getDecl()) {
3267 Result = getDerived().RebuildRecordType(Record);
3268 if (Result.isNull())
3269 return QualType();
3270 }
Mike Stump11289f42009-09-09 15:08:12 +00003271
John McCall550e0c22009-10-21 00:40:46 +00003272 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3273 NewTL.setNameLoc(TL.getNameLoc());
3274
3275 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003276}
Mike Stump11289f42009-09-09 15:08:12 +00003277
3278template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003279QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003280 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003281 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003283 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3284 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285 if (!Enum)
3286 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003287
John McCall550e0c22009-10-21 00:40:46 +00003288 QualType Result = TL.getType();
3289 if (getDerived().AlwaysRebuild() ||
3290 Enum != T->getDecl()) {
3291 Result = getDerived().RebuildEnumType(Enum);
3292 if (Result.isNull())
3293 return QualType();
3294 }
Mike Stump11289f42009-09-09 15:08:12 +00003295
John McCall550e0c22009-10-21 00:40:46 +00003296 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3297 NewTL.setNameLoc(TL.getNameLoc());
3298
3299 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300}
John McCallfcc33b02009-09-05 00:15:47 +00003301
John McCalle78aac42010-03-10 03:28:59 +00003302template<typename Derived>
3303QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3304 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003305 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003306 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3307 TL.getTypePtr()->getDecl());
3308 if (!D) return QualType();
3309
3310 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3311 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3312 return T;
3313}
3314
Mike Stump11289f42009-09-09 15:08:12 +00003315
Douglas Gregord6ff3322009-08-04 16:50:30 +00003316template<typename Derived>
3317QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003318 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003319 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003320 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003321}
3322
Mike Stump11289f42009-09-09 15:08:12 +00003323template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003324QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003325 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003326 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003327 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003328}
3329
3330template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003331QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003332 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003333 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003334 const TemplateSpecializationType *T = TL.getTypePtr();
3335
Mike Stump11289f42009-09-09 15:08:12 +00003336 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003337 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338 if (Template.isNull())
3339 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003340
John McCall31f82722010-11-12 08:19:04 +00003341 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3342}
3343
3344template <typename Derived>
3345QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3346 TypeLocBuilder &TLB,
3347 TemplateSpecializationTypeLoc TL,
3348 TemplateName Template) {
3349 const TemplateSpecializationType *T = TL.getTypePtr();
3350
John McCall6b51f282009-11-23 01:53:49 +00003351 TemplateArgumentListInfo NewTemplateArgs;
3352 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3353 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3354
3355 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3356 TemplateArgumentLoc Loc;
3357 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003358 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003359 NewTemplateArgs.addArgument(Loc);
3360 }
Mike Stump11289f42009-09-09 15:08:12 +00003361
John McCall0ad16662009-10-29 08:12:44 +00003362 // FIXME: maybe don't rebuild if all the template arguments are the same.
3363
3364 QualType Result =
3365 getDerived().RebuildTemplateSpecializationType(Template,
3366 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003367 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003368
3369 if (!Result.isNull()) {
3370 TemplateSpecializationTypeLoc NewTL
3371 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3372 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3373 NewTL.setLAngleLoc(TL.getLAngleLoc());
3374 NewTL.setRAngleLoc(TL.getRAngleLoc());
3375 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3376 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003377 }
Mike Stump11289f42009-09-09 15:08:12 +00003378
John McCall0ad16662009-10-29 08:12:44 +00003379 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003380}
Mike Stump11289f42009-09-09 15:08:12 +00003381
3382template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003383QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003384TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003385 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003386 ElaboratedType *T = TL.getTypePtr();
3387
3388 NestedNameSpecifier *NNS = 0;
3389 // NOTE: the qualifier in an ElaboratedType is optional.
3390 if (T->getQualifier() != 0) {
3391 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003392 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003393 if (!NNS)
3394 return QualType();
3395 }
Mike Stump11289f42009-09-09 15:08:12 +00003396
John McCall31f82722010-11-12 08:19:04 +00003397 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3398 if (NamedT.isNull())
3399 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003400
John McCall550e0c22009-10-21 00:40:46 +00003401 QualType Result = TL.getType();
3402 if (getDerived().AlwaysRebuild() ||
3403 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003404 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003405 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3406 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003407 if (Result.isNull())
3408 return QualType();
3409 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003410
Abramo Bagnara6150c882010-05-11 21:36:43 +00003411 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003412 NewTL.setKeywordLoc(TL.getKeywordLoc());
3413 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003414
3415 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003416}
Mike Stump11289f42009-09-09 15:08:12 +00003417
3418template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00003419QualType
3420TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3421 ParenTypeLoc TL) {
3422 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3423 if (Inner.isNull())
3424 return QualType();
3425
3426 QualType Result = TL.getType();
3427 if (getDerived().AlwaysRebuild() ||
3428 Inner != TL.getInnerLoc().getType()) {
3429 Result = getDerived().RebuildParenType(Inner);
3430 if (Result.isNull())
3431 return QualType();
3432 }
3433
3434 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3435 NewTL.setLParenLoc(TL.getLParenLoc());
3436 NewTL.setRParenLoc(TL.getRParenLoc());
3437 return Result;
3438}
3439
3440template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003441QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003442 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003443 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003444
Douglas Gregord6ff3322009-08-04 16:50:30 +00003445 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003446 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003447 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003448 if (!NNS)
3449 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003450
John McCallc392f372010-06-11 00:33:02 +00003451 QualType Result
3452 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3453 T->getIdentifier(),
3454 TL.getKeywordLoc(),
3455 TL.getQualifierRange(),
3456 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003457 if (Result.isNull())
3458 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003459
Abramo Bagnarad7548482010-05-19 21:37:53 +00003460 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3461 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003462 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3463
Abramo Bagnarad7548482010-05-19 21:37:53 +00003464 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3465 NewTL.setKeywordLoc(TL.getKeywordLoc());
3466 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003467 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003468 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3469 NewTL.setKeywordLoc(TL.getKeywordLoc());
3470 NewTL.setQualifierRange(TL.getQualifierRange());
3471 NewTL.setNameLoc(TL.getNameLoc());
3472 }
John McCall550e0c22009-10-21 00:40:46 +00003473 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003474}
Mike Stump11289f42009-09-09 15:08:12 +00003475
Douglas Gregord6ff3322009-08-04 16:50:30 +00003476template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003477QualType TreeTransform<Derived>::
3478 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003479 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003480 DependentTemplateSpecializationType *T = TL.getTypePtr();
3481
3482 NestedNameSpecifier *NNS
3483 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003484 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003485 if (!NNS)
3486 return QualType();
3487
John McCall31f82722010-11-12 08:19:04 +00003488 return getDerived()
3489 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3490}
3491
3492template<typename Derived>
3493QualType TreeTransform<Derived>::
3494 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3495 DependentTemplateSpecializationTypeLoc TL,
3496 NestedNameSpecifier *NNS) {
3497 DependentTemplateSpecializationType *T = TL.getTypePtr();
3498
John McCallc392f372010-06-11 00:33:02 +00003499 TemplateArgumentListInfo NewTemplateArgs;
3500 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3501 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3502
3503 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3504 TemplateArgumentLoc Loc;
3505 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3506 return QualType();
3507 NewTemplateArgs.addArgument(Loc);
3508 }
3509
Douglas Gregora5614c52010-09-08 23:56:00 +00003510 QualType Result
3511 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3512 NNS,
3513 TL.getQualifierRange(),
3514 T->getIdentifier(),
3515 TL.getNameLoc(),
3516 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003517 if (Result.isNull())
3518 return QualType();
3519
3520 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3521 QualType NamedT = ElabT->getNamedType();
3522
3523 // Copy information relevant to the template specialization.
3524 TemplateSpecializationTypeLoc NamedTL
3525 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3526 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3527 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3528 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3529 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3530
3531 // Copy information relevant to the elaborated type.
3532 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3533 NewTL.setKeywordLoc(TL.getKeywordLoc());
3534 NewTL.setQualifierRange(TL.getQualifierRange());
3535 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003536 TypeLoc NewTL(Result, TL.getOpaqueData());
3537 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003538 }
3539 return Result;
3540}
3541
3542template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00003543QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3544 PackExpansionTypeLoc TL) {
3545 // FIXME: Implement!
3546 getSema().Diag(TL.getEllipsisLoc(),
3547 diag::err_pack_expansion_instantiation_unsupported);
3548 return QualType();
3549}
3550
3551template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003552QualType
3553TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003554 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003555 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003556 TLB.pushFullCopy(TL);
3557 return TL.getType();
3558}
3559
3560template<typename Derived>
3561QualType
3562TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003563 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003564 // ObjCObjectType is never dependent.
3565 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003566 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003567}
Mike Stump11289f42009-09-09 15:08:12 +00003568
3569template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003570QualType
3571TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003572 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003573 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003574 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003575 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003576}
3577
Douglas Gregord6ff3322009-08-04 16:50:30 +00003578//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003579// Statement transformation
3580//===----------------------------------------------------------------------===//
3581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003582StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003583TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003584 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003585}
3586
3587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003588StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003589TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3590 return getDerived().TransformCompoundStmt(S, false);
3591}
3592
3593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003594StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003595TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003596 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003597 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003598 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003599 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003600 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3601 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003602 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003603 if (Result.isInvalid()) {
3604 // Immediately fail if this was a DeclStmt, since it's very
3605 // likely that this will cause problems for future statements.
3606 if (isa<DeclStmt>(*B))
3607 return StmtError();
3608
3609 // Otherwise, just keep processing substatements and fail later.
3610 SubStmtInvalid = true;
3611 continue;
3612 }
Mike Stump11289f42009-09-09 15:08:12 +00003613
Douglas Gregorebe10102009-08-20 07:17:43 +00003614 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3615 Statements.push_back(Result.takeAs<Stmt>());
3616 }
Mike Stump11289f42009-09-09 15:08:12 +00003617
John McCall1ababa62010-08-27 19:56:05 +00003618 if (SubStmtInvalid)
3619 return StmtError();
3620
Douglas Gregorebe10102009-08-20 07:17:43 +00003621 if (!getDerived().AlwaysRebuild() &&
3622 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003623 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003624
3625 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3626 move_arg(Statements),
3627 S->getRBracLoc(),
3628 IsStmtExpr);
3629}
Mike Stump11289f42009-09-09 15:08:12 +00003630
Douglas Gregorebe10102009-08-20 07:17:43 +00003631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003632StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003633TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003634 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003635 {
3636 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003637 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003638
Eli Friedman06577382009-11-19 03:14:00 +00003639 // Transform the left-hand case value.
3640 LHS = getDerived().TransformExpr(S->getLHS());
3641 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003642 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003643
Eli Friedman06577382009-11-19 03:14:00 +00003644 // Transform the right-hand case value (for the GNU case-range extension).
3645 RHS = getDerived().TransformExpr(S->getRHS());
3646 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003647 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003648 }
Mike Stump11289f42009-09-09 15:08:12 +00003649
Douglas Gregorebe10102009-08-20 07:17:43 +00003650 // Build the case statement.
3651 // Case statements are always rebuilt so that they will attached to their
3652 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003653 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003654 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003655 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003656 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003657 S->getColonLoc());
3658 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003659 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003660
Douglas Gregorebe10102009-08-20 07:17:43 +00003661 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003662 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003663 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003664 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003665
Douglas Gregorebe10102009-08-20 07:17:43 +00003666 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003667 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003668}
3669
3670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003671StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003672TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003673 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003674 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003675 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003676 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003677
Douglas Gregorebe10102009-08-20 07:17:43 +00003678 // Default statements are always rebuilt
3679 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003680 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003681}
Mike Stump11289f42009-09-09 15:08:12 +00003682
Douglas Gregorebe10102009-08-20 07:17:43 +00003683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003684StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003685TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003686 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003687 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003688 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003689
Douglas Gregorebe10102009-08-20 07:17:43 +00003690 // FIXME: Pass the real colon location in.
3691 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3692 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003693 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003694}
Mike Stump11289f42009-09-09 15:08:12 +00003695
Douglas Gregorebe10102009-08-20 07:17:43 +00003696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003697StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003698TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003699 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003700 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003701 VarDecl *ConditionVar = 0;
3702 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003703 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003704 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003705 getDerived().TransformDefinition(
3706 S->getConditionVariable()->getLocation(),
3707 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003708 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003709 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003710 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003711 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003712
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003713 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003714 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003715
3716 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003717 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003718 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003719 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003720 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003721 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003722 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003723
John McCallb268a282010-08-23 23:25:46 +00003724 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003725 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003726 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003727
John McCallb268a282010-08-23 23:25:46 +00003728 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3729 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003730 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003731
Douglas Gregorebe10102009-08-20 07:17:43 +00003732 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003733 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003734 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003735 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregorebe10102009-08-20 07:17:43 +00003737 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003738 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003739 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003740 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003741
Douglas Gregorebe10102009-08-20 07:17:43 +00003742 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003743 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003744 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003745 Then.get() == S->getThen() &&
3746 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003747 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003748
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003749 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00003750 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00003751 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003752}
3753
3754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003755StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003756TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003757 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003758 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003759 VarDecl *ConditionVar = 0;
3760 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003761 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003762 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003763 getDerived().TransformDefinition(
3764 S->getConditionVariable()->getLocation(),
3765 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003766 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003767 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003768 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003769 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003770
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003771 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003772 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003773 }
Mike Stump11289f42009-09-09 15:08:12 +00003774
Douglas Gregorebe10102009-08-20 07:17:43 +00003775 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003776 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003777 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003778 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003779 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003780 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003781
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003783 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003784 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003785 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003786
Douglas Gregorebe10102009-08-20 07:17:43 +00003787 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003788 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3789 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003790}
Mike Stump11289f42009-09-09 15:08:12 +00003791
Douglas Gregorebe10102009-08-20 07:17:43 +00003792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003793StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003794TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003795 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003796 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003797 VarDecl *ConditionVar = 0;
3798 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003799 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003800 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003801 getDerived().TransformDefinition(
3802 S->getConditionVariable()->getLocation(),
3803 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003804 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003805 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003806 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003807 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003808
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003809 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003810 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003811
3812 if (S->getCond()) {
3813 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003814 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003815 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003816 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003817 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003818 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003819 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003820 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003821 }
Mike Stump11289f42009-09-09 15:08:12 +00003822
John McCallb268a282010-08-23 23:25:46 +00003823 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3824 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003825 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003826
Douglas Gregorebe10102009-08-20 07:17:43 +00003827 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003828 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003829 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003830 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregorebe10102009-08-20 07:17:43 +00003832 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003833 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003834 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003835 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003836 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003838 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003839 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003840}
Mike Stump11289f42009-09-09 15:08:12 +00003841
Douglas Gregorebe10102009-08-20 07:17:43 +00003842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003843StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003844TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003845 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003846 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003847 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003848 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003849
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003850 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003851 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003852 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003853 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003854
Douglas Gregorebe10102009-08-20 07:17:43 +00003855 if (!getDerived().AlwaysRebuild() &&
3856 Cond.get() == S->getCond() &&
3857 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003858 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003859
John McCallb268a282010-08-23 23:25:46 +00003860 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3861 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003862 S->getRParenLoc());
3863}
Mike Stump11289f42009-09-09 15:08:12 +00003864
Douglas Gregorebe10102009-08-20 07:17:43 +00003865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003866StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003867TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003868 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003869 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003870 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003871 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003872
Douglas Gregorebe10102009-08-20 07:17:43 +00003873 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003874 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003875 VarDecl *ConditionVar = 0;
3876 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003877 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003878 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003879 getDerived().TransformDefinition(
3880 S->getConditionVariable()->getLocation(),
3881 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003882 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003883 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003884 } else {
3885 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003886
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003887 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003888 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003889
3890 if (S->getCond()) {
3891 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003892 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003893 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003894 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003895 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003896 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003897
John McCallb268a282010-08-23 23:25:46 +00003898 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003899 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003900 }
Mike Stump11289f42009-09-09 15:08:12 +00003901
John McCallb268a282010-08-23 23:25:46 +00003902 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3903 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003904 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003905
Douglas Gregorebe10102009-08-20 07:17:43 +00003906 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003907 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003908 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003909 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003910
John McCallb268a282010-08-23 23:25:46 +00003911 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3912 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003913 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003914
Douglas Gregorebe10102009-08-20 07:17:43 +00003915 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003916 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003917 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003918 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003919
Douglas Gregorebe10102009-08-20 07:17:43 +00003920 if (!getDerived().AlwaysRebuild() &&
3921 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003922 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003923 Inc.get() == S->getInc() &&
3924 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003925 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003926
Douglas Gregorebe10102009-08-20 07:17:43 +00003927 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003928 Init.get(), FullCond, ConditionVar,
3929 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003930}
3931
3932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003933StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003934TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003935 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003936 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003937 S->getLabel());
3938}
3939
3940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003941StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003942TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003943 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003944 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003945 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregorebe10102009-08-20 07:17:43 +00003947 if (!getDerived().AlwaysRebuild() &&
3948 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003949 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003950
3951 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003952 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003953}
3954
3955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003956StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003957TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003958 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003959}
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregorebe10102009-08-20 07:17:43 +00003961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003962StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003963TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003964 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003965}
Mike Stump11289f42009-09-09 15:08:12 +00003966
Douglas Gregorebe10102009-08-20 07:17:43 +00003967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003968StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003969TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003970 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003971 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003972 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003973
Mike Stump11289f42009-09-09 15:08:12 +00003974 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003975 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003976 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003977}
Mike Stump11289f42009-09-09 15:08:12 +00003978
Douglas Gregorebe10102009-08-20 07:17:43 +00003979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003980StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003981TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003982 bool DeclChanged = false;
3983 llvm::SmallVector<Decl *, 4> Decls;
3984 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3985 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003986 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3987 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003988 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003989 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregorebe10102009-08-20 07:17:43 +00003991 if (Transformed != *D)
3992 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003993
Douglas Gregorebe10102009-08-20 07:17:43 +00003994 Decls.push_back(Transformed);
3995 }
Mike Stump11289f42009-09-09 15:08:12 +00003996
Douglas Gregorebe10102009-08-20 07:17:43 +00003997 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00003998 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003999
4000 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004001 S->getStartLoc(), S->getEndLoc());
4002}
Mike Stump11289f42009-09-09 15:08:12 +00004003
Douglas Gregorebe10102009-08-20 07:17:43 +00004004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004005StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004006TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004007 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004008 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004009}
4010
4011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004012StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004013TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004014
John McCall37ad5512010-08-23 06:44:23 +00004015 ASTOwningVector<Expr*> Constraints(getSema());
4016 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004017 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004018
John McCalldadc5752010-08-24 06:29:42 +00004019 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004020 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004021
4022 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004023
Anders Carlssonaaeef072010-01-24 05:50:09 +00004024 // Go through the outputs.
4025 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004026 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004027
Anders Carlssonaaeef072010-01-24 05:50:09 +00004028 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004029 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004030
Anders Carlssonaaeef072010-01-24 05:50:09 +00004031 // Transform the output expr.
4032 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004033 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004034 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004035 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004036
Anders Carlssonaaeef072010-01-24 05:50:09 +00004037 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004038
John McCallb268a282010-08-23 23:25:46 +00004039 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004040 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004041
Anders Carlssonaaeef072010-01-24 05:50:09 +00004042 // Go through the inputs.
4043 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004044 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004045
Anders Carlssonaaeef072010-01-24 05:50:09 +00004046 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004047 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004048
Anders Carlssonaaeef072010-01-24 05:50:09 +00004049 // Transform the input expr.
4050 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004051 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004052 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004053 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004054
Anders Carlssonaaeef072010-01-24 05:50:09 +00004055 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004056
John McCallb268a282010-08-23 23:25:46 +00004057 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004058 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004059
Anders Carlssonaaeef072010-01-24 05:50:09 +00004060 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004061 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004062
4063 // Go through the clobbers.
4064 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004065 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004066
4067 // No need to transform the asm string literal.
4068 AsmString = SemaRef.Owned(S->getAsmString());
4069
4070 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4071 S->isSimple(),
4072 S->isVolatile(),
4073 S->getNumOutputs(),
4074 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004075 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004076 move_arg(Constraints),
4077 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004078 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004079 move_arg(Clobbers),
4080 S->getRParenLoc(),
4081 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004082}
4083
4084
4085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004086StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004087TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004088 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004089 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004090 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004091 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004092
Douglas Gregor96c79492010-04-23 22:50:49 +00004093 // Transform the @catch statements (if present).
4094 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004095 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004096 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004097 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004098 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004099 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004100 if (Catch.get() != S->getCatchStmt(I))
4101 AnyCatchChanged = true;
4102 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004103 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004104
Douglas Gregor306de2f2010-04-22 23:59:56 +00004105 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004106 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004107 if (S->getFinallyStmt()) {
4108 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4109 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004110 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004111 }
4112
4113 // If nothing changed, just retain this statement.
4114 if (!getDerived().AlwaysRebuild() &&
4115 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004116 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004117 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004118 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004119
Douglas Gregor306de2f2010-04-22 23:59:56 +00004120 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004121 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4122 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004123}
Mike Stump11289f42009-09-09 15:08:12 +00004124
Douglas Gregorebe10102009-08-20 07:17:43 +00004125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004126StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004127TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004128 // Transform the @catch parameter, if there is one.
4129 VarDecl *Var = 0;
4130 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4131 TypeSourceInfo *TSInfo = 0;
4132 if (FromVar->getTypeSourceInfo()) {
4133 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4134 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004135 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004136 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004137
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004138 QualType T;
4139 if (TSInfo)
4140 T = TSInfo->getType();
4141 else {
4142 T = getDerived().TransformType(FromVar->getType());
4143 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004144 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004145 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004146
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004147 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4148 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004149 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004150 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004151
John McCalldadc5752010-08-24 06:29:42 +00004152 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004153 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004154 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004155
4156 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004157 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004158 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004159}
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregorebe10102009-08-20 07:17:43 +00004161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004162StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004163TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004164 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004165 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004166 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004167 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004168
Douglas Gregor306de2f2010-04-22 23:59:56 +00004169 // If nothing changed, just retain this statement.
4170 if (!getDerived().AlwaysRebuild() &&
4171 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004172 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004173
4174 // Build a new statement.
4175 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004176 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004177}
Mike Stump11289f42009-09-09 15:08:12 +00004178
Douglas Gregorebe10102009-08-20 07:17:43 +00004179template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004180StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004181TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004182 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004183 if (S->getThrowExpr()) {
4184 Operand = getDerived().TransformExpr(S->getThrowExpr());
4185 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004186 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004187 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004188
Douglas Gregor2900c162010-04-22 21:44:01 +00004189 if (!getDerived().AlwaysRebuild() &&
4190 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004191 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004192
John McCallb268a282010-08-23 23:25:46 +00004193 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004194}
Mike Stump11289f42009-09-09 15:08:12 +00004195
Douglas Gregorebe10102009-08-20 07:17:43 +00004196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004197StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004198TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004199 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004200 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004201 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004202 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004203 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004204
Douglas Gregor6148de72010-04-22 22:01:21 +00004205 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004206 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004207 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004208 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004209
Douglas Gregor6148de72010-04-22 22:01:21 +00004210 // If nothing change, just retain the current statement.
4211 if (!getDerived().AlwaysRebuild() &&
4212 Object.get() == S->getSynchExpr() &&
4213 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004214 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004215
4216 // Build a new statement.
4217 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004218 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004219}
4220
4221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004222StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004223TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004224 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004225 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004226 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004227 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004228 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004229
Douglas Gregorf68a5082010-04-22 23:10:45 +00004230 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004231 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004232 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004233 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004234
Douglas Gregorf68a5082010-04-22 23:10:45 +00004235 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004236 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004237 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004238 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004239
Douglas Gregorf68a5082010-04-22 23:10:45 +00004240 // If nothing changed, just retain this statement.
4241 if (!getDerived().AlwaysRebuild() &&
4242 Element.get() == S->getElement() &&
4243 Collection.get() == S->getCollection() &&
4244 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004245 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004246
Douglas Gregorf68a5082010-04-22 23:10:45 +00004247 // Build a new statement.
4248 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4249 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004250 Element.get(),
4251 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004252 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004253 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004254}
4255
4256
4257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004258StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004259TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4260 // Transform the exception declaration, if any.
4261 VarDecl *Var = 0;
4262 if (S->getExceptionDecl()) {
4263 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004264 TypeSourceInfo *T = getDerived().TransformType(
4265 ExceptionDecl->getTypeSourceInfo());
4266 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004267 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004268
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004269 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004270 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004271 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004272 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004273 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004274 }
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregorebe10102009-08-20 07:17:43 +00004276 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004277 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004278 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004279 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004280
Douglas Gregorebe10102009-08-20 07:17:43 +00004281 if (!getDerived().AlwaysRebuild() &&
4282 !Var &&
4283 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004284 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004285
4286 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4287 Var,
John McCallb268a282010-08-23 23:25:46 +00004288 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004289}
Mike Stump11289f42009-09-09 15:08:12 +00004290
Douglas Gregorebe10102009-08-20 07:17:43 +00004291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004292StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004293TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4294 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004295 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004296 = getDerived().TransformCompoundStmt(S->getTryBlock());
4297 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004298 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004299
Douglas Gregorebe10102009-08-20 07:17:43 +00004300 // Transform the handlers.
4301 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004302 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004303 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004304 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004305 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4306 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004307 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregorebe10102009-08-20 07:17:43 +00004309 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4310 Handlers.push_back(Handler.takeAs<Stmt>());
4311 }
Mike Stump11289f42009-09-09 15:08:12 +00004312
Douglas Gregorebe10102009-08-20 07:17:43 +00004313 if (!getDerived().AlwaysRebuild() &&
4314 TryBlock.get() == S->getTryBlock() &&
4315 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004316 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004317
John McCallb268a282010-08-23 23:25:46 +00004318 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004319 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004320}
Mike Stump11289f42009-09-09 15:08:12 +00004321
Douglas Gregorebe10102009-08-20 07:17:43 +00004322//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004323// Expression transformation
4324//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004326ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004327TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004328 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004329}
Mike Stump11289f42009-09-09 15:08:12 +00004330
4331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004332ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004333TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004334 NestedNameSpecifier *Qualifier = 0;
4335 if (E->getQualifier()) {
4336 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004337 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004338 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004339 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004340 }
John McCallce546572009-12-08 09:08:17 +00004341
4342 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004343 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4344 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004345 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004347
John McCall815039a2010-08-17 21:27:17 +00004348 DeclarationNameInfo NameInfo = E->getNameInfo();
4349 if (NameInfo.getName()) {
4350 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4351 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004352 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004353 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004354
4355 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004356 Qualifier == E->getQualifier() &&
4357 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004358 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004359 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004360
4361 // Mark it referenced in the new context regardless.
4362 // FIXME: this is a bit instantiation-specific.
4363 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4364
John McCallc3007a22010-10-26 07:05:15 +00004365 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004366 }
John McCallce546572009-12-08 09:08:17 +00004367
4368 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004369 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004370 TemplateArgs = &TransArgs;
4371 TransArgs.setLAngleLoc(E->getLAngleLoc());
4372 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004373 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4374 E->getNumTemplateArgs(),
4375 TransArgs))
4376 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004377 }
4378
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004379 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004380 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004381}
Mike Stump11289f42009-09-09 15:08:12 +00004382
Douglas Gregora16548e2009-08-11 05:31:07 +00004383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004384ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004385TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004386 return SemaRef.Owned(E);
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
John McCall47f29ea2009-12-08 09:21:05 +00004391TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004392 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004393}
Mike Stump11289f42009-09-09 15:08:12 +00004394
Douglas Gregora16548e2009-08-11 05:31:07 +00004395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004397TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004398 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004399}
Mike Stump11289f42009-09-09 15:08:12 +00004400
Douglas Gregora16548e2009-08-11 05:31:07 +00004401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004402ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004403TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004404 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004405}
Mike Stump11289f42009-09-09 15:08:12 +00004406
Douglas Gregora16548e2009-08-11 05:31:07 +00004407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004408ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004409TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004410 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004411}
4412
4413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004415TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004416 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004418 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004421 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004422
John McCallb268a282010-08-23 23:25:46 +00004423 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004424 E->getRParen());
4425}
4426
Mike Stump11289f42009-09-09 15:08:12 +00004427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004429TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004430 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004433
Douglas Gregora16548e2009-08-11 05:31:07 +00004434 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004435 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4438 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004439 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004440}
Mike Stump11289f42009-09-09 15:08:12 +00004441
Douglas Gregora16548e2009-08-11 05:31:07 +00004442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004443ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004444TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4445 // Transform the type.
4446 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4447 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004448 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004449
Douglas Gregor882211c2010-04-28 22:16:22 +00004450 // Transform all of the components into components similar to what the
4451 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004452 // FIXME: It would be slightly more efficient in the non-dependent case to
4453 // just map FieldDecls, rather than requiring the rebuilder to look for
4454 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004455 // template code that we don't care.
4456 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004457 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004458 typedef OffsetOfExpr::OffsetOfNode Node;
4459 llvm::SmallVector<Component, 4> Components;
4460 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4461 const Node &ON = E->getComponent(I);
4462 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004463 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004464 Comp.LocStart = ON.getRange().getBegin();
4465 Comp.LocEnd = ON.getRange().getEnd();
4466 switch (ON.getKind()) {
4467 case Node::Array: {
4468 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004469 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004470 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004471 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004472
Douglas Gregor882211c2010-04-28 22:16:22 +00004473 ExprChanged = ExprChanged || Index.get() != FromIndex;
4474 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004475 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004476 break;
4477 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004478
Douglas Gregor882211c2010-04-28 22:16:22 +00004479 case Node::Field:
4480 case Node::Identifier:
4481 Comp.isBrackets = false;
4482 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004483 if (!Comp.U.IdentInfo)
4484 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004485
Douglas Gregor882211c2010-04-28 22:16:22 +00004486 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004487
Douglas Gregord1702062010-04-29 00:18:15 +00004488 case Node::Base:
4489 // Will be recomputed during the rebuild.
4490 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004491 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004492
Douglas Gregor882211c2010-04-28 22:16:22 +00004493 Components.push_back(Comp);
4494 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004495
Douglas Gregor882211c2010-04-28 22:16:22 +00004496 // If nothing changed, retain the existing expression.
4497 if (!getDerived().AlwaysRebuild() &&
4498 Type == E->getTypeSourceInfo() &&
4499 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004500 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004501
Douglas Gregor882211c2010-04-28 22:16:22 +00004502 // Build a new offsetof expression.
4503 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4504 Components.data(), Components.size(),
4505 E->getRParenLoc());
4506}
4507
4508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004509ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004510TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4511 assert(getDerived().AlreadyTransformed(E->getType()) &&
4512 "opaque value expression requires transformation");
4513 return SemaRef.Owned(E);
4514}
4515
4516template<typename Derived>
4517ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004518TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004520 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004521
John McCallbcd03502009-12-07 02:54:59 +00004522 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004523 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004525
John McCall4c98fd82009-11-04 07:28:41 +00004526 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004527 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004528
John McCall4c98fd82009-11-04 07:28:41 +00004529 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004530 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 E->getSourceRange());
4532 }
Mike Stump11289f42009-09-09 15:08:12 +00004533
John McCalldadc5752010-08-24 06:29:42 +00004534 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004535 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 // C++0x [expr.sizeof]p1:
4537 // The operand is either an expression, which is an unevaluated operand
4538 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004539 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregora16548e2009-08-11 05:31:07 +00004541 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4542 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004543 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004544
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004546 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 }
Mike Stump11289f42009-09-09 15:08:12 +00004548
John McCallb268a282010-08-23 23:25:46 +00004549 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004550 E->isSizeOf(),
4551 E->getSourceRange());
4552}
Mike Stump11289f42009-09-09 15:08:12 +00004553
Douglas Gregora16548e2009-08-11 05:31:07 +00004554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004556TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004557 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004559 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004560
John McCalldadc5752010-08-24 06:29:42 +00004561 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004563 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004564
4565
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 if (!getDerived().AlwaysRebuild() &&
4567 LHS.get() == E->getLHS() &&
4568 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004569 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004570
John McCallb268a282010-08-23 23:25:46 +00004571 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004573 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 E->getRBracketLoc());
4575}
Mike Stump11289f42009-09-09 15:08:12 +00004576
4577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004579TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004580 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004581 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004583 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004584
4585 // Transform arguments.
4586 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004587 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004588 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004589 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004592
Mike Stump11289f42009-09-09 15:08:12 +00004593 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004594 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 }
Mike Stump11289f42009-09-09 15:08:12 +00004596
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 if (!getDerived().AlwaysRebuild() &&
4598 Callee.get() == E->getCallee() &&
4599 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004600 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregora16548e2009-08-11 05:31:07 +00004602 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004603 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004604 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004605 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004606 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 E->getRParenLoc());
4608}
Mike Stump11289f42009-09-09 15:08:12 +00004609
4610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004611ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004612TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004613 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004615 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004616
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004617 NestedNameSpecifier *Qualifier = 0;
4618 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004619 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004620 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004621 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004622 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004623 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004624 }
Mike Stump11289f42009-09-09 15:08:12 +00004625
Eli Friedman2cfcef62009-12-04 06:40:45 +00004626 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004627 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4628 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004629 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004630 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004631
John McCall16df1e52010-03-30 21:47:33 +00004632 NamedDecl *FoundDecl = E->getFoundDecl();
4633 if (FoundDecl == E->getMemberDecl()) {
4634 FoundDecl = Member;
4635 } else {
4636 FoundDecl = cast_or_null<NamedDecl>(
4637 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4638 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004639 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004640 }
4641
Douglas Gregora16548e2009-08-11 05:31:07 +00004642 if (!getDerived().AlwaysRebuild() &&
4643 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004644 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004645 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004646 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004647 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004648
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004649 // Mark it referenced in the new context regardless.
4650 // FIXME: this is a bit instantiation-specific.
4651 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004652 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004653 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004654
John McCall6b51f282009-11-23 01:53:49 +00004655 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004656 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004657 TransArgs.setLAngleLoc(E->getLAngleLoc());
4658 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004659 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4660 E->getNumTemplateArgs(),
4661 TransArgs))
4662 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004663 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004664
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 // FIXME: Bogus source location for the operator
4666 SourceLocation FakeOperatorLoc
4667 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4668
John McCall38836f02010-01-15 08:34:02 +00004669 // FIXME: to do this check properly, we will need to preserve the
4670 // first-qualifier-in-scope here, just in case we had a dependent
4671 // base (and therefore couldn't do the check) and a
4672 // nested-name-qualifier (and therefore could do the lookup).
4673 NamedDecl *FirstQualifierInScope = 0;
4674
John McCallb268a282010-08-23 23:25:46 +00004675 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004677 Qualifier,
4678 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004679 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004680 Member,
John McCall16df1e52010-03-30 21:47:33 +00004681 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004682 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004683 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004684 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004685}
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregora16548e2009-08-11 05:31:07 +00004687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004688ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004689TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004690 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004691 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004693
John McCalldadc5752010-08-24 06:29:42 +00004694 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregora16548e2009-08-11 05:31:07 +00004698 if (!getDerived().AlwaysRebuild() &&
4699 LHS.get() == E->getLHS() &&
4700 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004701 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregora16548e2009-08-11 05:31:07 +00004703 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004704 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004705}
4706
Mike Stump11289f42009-09-09 15:08:12 +00004707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004708ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004709TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004710 CompoundAssignOperator *E) {
4711 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004712}
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004715ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004716TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004717 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004720
John McCalldadc5752010-08-24 06:29:42 +00004721 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004723 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004724
John McCalldadc5752010-08-24 06:29:42 +00004725 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 if (!getDerived().AlwaysRebuild() &&
4730 Cond.get() == E->getCond() &&
4731 LHS.get() == E->getLHS() &&
4732 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004733 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004734
John McCallb268a282010-08-23 23:25:46 +00004735 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004736 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004737 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004738 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004739 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004740}
Mike Stump11289f42009-09-09 15:08:12 +00004741
4742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004743ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004744TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004745 // Implicit casts are eliminated during transformation, since they
4746 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004747 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004748}
Mike Stump11289f42009-09-09 15:08:12 +00004749
Douglas Gregora16548e2009-08-11 05:31:07 +00004750template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004751ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004752TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004753 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4754 if (!Type)
4755 return ExprError();
4756
John McCalldadc5752010-08-24 06:29:42 +00004757 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004758 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004760 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004763 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004765 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004766
John McCall97513962010-01-15 18:39:57 +00004767 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004768 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004770 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004771}
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregora16548e2009-08-11 05:31:07 +00004773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004774ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004775TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004776 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4777 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4778 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004780
John McCalldadc5752010-08-24 06:29:42 +00004781 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004783 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004786 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004788 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004789
John McCall5d7aa7f2010-01-19 22:33:45 +00004790 // Note: the expression type doesn't necessarily match the
4791 // type-as-written, but that's okay, because it should always be
4792 // derivable from the initializer.
4793
John McCalle15bbff2010-01-18 19:35:47 +00004794 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004796 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004797}
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004800ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004801TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004802 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 if (!getDerived().AlwaysRebuild() &&
4807 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004808 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004809
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004811 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004813 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 E->getAccessorLoc(),
4815 E->getAccessor());
4816}
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregora16548e2009-08-11 05:31:07 +00004818template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004819ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004820TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004821 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004822
John McCall37ad5512010-08-23 06:44:23 +00004823 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004825 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004826 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004828
Douglas Gregora16548e2009-08-11 05:31:07 +00004829 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004830 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 }
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004834 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregora16548e2009-08-11 05:31:07 +00004836 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004837 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004838}
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004842TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004843 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregorebe10102009-08-20 07:17:43 +00004845 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004846 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregorebe10102009-08-20 07:17:43 +00004850 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004851 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004852 bool ExprChanged = false;
4853 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4854 DEnd = E->designators_end();
4855 D != DEnd; ++D) {
4856 if (D->isFieldDesignator()) {
4857 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4858 D->getDotLoc(),
4859 D->getFieldLoc()));
4860 continue;
4861 }
Mike Stump11289f42009-09-09 15:08:12 +00004862
Douglas Gregora16548e2009-08-11 05:31:07 +00004863 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004864 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004865 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004866 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004867
4868 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004869 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4872 ArrayExprs.push_back(Index.release());
4873 continue;
4874 }
Mike Stump11289f42009-09-09 15:08:12 +00004875
Douglas Gregora16548e2009-08-11 05:31:07 +00004876 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004877 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4879 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004880 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004881
John McCalldadc5752010-08-24 06:29:42 +00004882 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004883 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004884 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004885
4886 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004887 End.get(),
4888 D->getLBracketLoc(),
4889 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004890
Douglas Gregora16548e2009-08-11 05:31:07 +00004891 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4892 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004893
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 ArrayExprs.push_back(Start.release());
4895 ArrayExprs.push_back(End.release());
4896 }
Mike Stump11289f42009-09-09 15:08:12 +00004897
Douglas Gregora16548e2009-08-11 05:31:07 +00004898 if (!getDerived().AlwaysRebuild() &&
4899 Init.get() == E->getInit() &&
4900 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004901 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4904 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004905 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004906}
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregora16548e2009-08-11 05:31:07 +00004908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004909ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004910TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004911 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004912 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004913
Douglas Gregor3da3c062009-10-28 00:29:27 +00004914 // FIXME: Will we ever have proper type location here? Will we actually
4915 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004916 QualType T = getDerived().TransformType(E->getType());
4917 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004919
Douglas Gregora16548e2009-08-11 05:31:07 +00004920 if (!getDerived().AlwaysRebuild() &&
4921 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004922 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004923
Douglas Gregora16548e2009-08-11 05:31:07 +00004924 return getDerived().RebuildImplicitValueInitExpr(T);
4925}
Mike Stump11289f42009-09-09 15:08:12 +00004926
Douglas Gregora16548e2009-08-11 05:31:07 +00004927template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004928ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004929TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004930 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4931 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004932 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004933
John McCalldadc5752010-08-24 06:29:42 +00004934 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004939 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004940 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004941 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004942
John McCallb268a282010-08-23 23:25:46 +00004943 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004944 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004945}
4946
4947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004948ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004949TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004950 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004951 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004952 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004953 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004954 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004956
Douglas Gregora16548e2009-08-11 05:31:07 +00004957 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004958 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004959 }
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregora16548e2009-08-11 05:31:07 +00004961 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4962 move_arg(Inits),
4963 E->getRParenLoc());
4964}
Mike Stump11289f42009-09-09 15:08:12 +00004965
Douglas Gregora16548e2009-08-11 05:31:07 +00004966/// \brief Transform an address-of-label expression.
4967///
4968/// By default, the transformation of an address-of-label expression always
4969/// rebuilds the expression, so that the label identifier can be resolved to
4970/// the corresponding label statement by semantic analysis.
4971template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004972ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004973TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004974 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4975 E->getLabel());
4976}
Mike Stump11289f42009-09-09 15:08:12 +00004977
4978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004979ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004980TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004981 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4983 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004984 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004985
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 if (!getDerived().AlwaysRebuild() &&
4987 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00004988 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004989
4990 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004991 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 E->getRParenLoc());
4993}
Mike Stump11289f42009-09-09 15:08:12 +00004994
Douglas Gregora16548e2009-08-11 05:31:07 +00004995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004996ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004997TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004998 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005000 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005001
John McCalldadc5752010-08-24 06:29:42 +00005002 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005003 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005005
John McCalldadc5752010-08-24 06:29:42 +00005006 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005007 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005008 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005009
Douglas Gregora16548e2009-08-11 05:31:07 +00005010 if (!getDerived().AlwaysRebuild() &&
5011 Cond.get() == E->getCond() &&
5012 LHS.get() == E->getLHS() &&
5013 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005014 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005015
Douglas Gregora16548e2009-08-11 05:31:07 +00005016 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005017 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005018 E->getRParenLoc());
5019}
Mike Stump11289f42009-09-09 15:08:12 +00005020
Douglas Gregora16548e2009-08-11 05:31:07 +00005021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005023TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005024 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005025}
5026
5027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005028ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005029TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005030 switch (E->getOperator()) {
5031 case OO_New:
5032 case OO_Delete:
5033 case OO_Array_New:
5034 case OO_Array_Delete:
5035 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005036 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005037
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005038 case OO_Call: {
5039 // This is a call to an object's operator().
5040 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5041
5042 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005043 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005044 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005045 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005046
5047 // FIXME: Poor location information
5048 SourceLocation FakeLParenLoc
5049 = SemaRef.PP.getLocForEndOfToken(
5050 static_cast<Expr *>(Object.get())->getLocEnd());
5051
5052 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005053 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005054 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00005055 if (getDerived().DropCallArgument(E->getArg(I)))
5056 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005057
John McCalldadc5752010-08-24 06:29:42 +00005058 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005059 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005060 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005061
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005062 Args.push_back(Arg.release());
5063 }
5064
John McCallb268a282010-08-23 23:25:46 +00005065 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005066 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005067 E->getLocEnd());
5068 }
5069
5070#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5071 case OO_##Name:
5072#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5073#include "clang/Basic/OperatorKinds.def"
5074 case OO_Subscript:
5075 // Handled below.
5076 break;
5077
5078 case OO_Conditional:
5079 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005080 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005081
5082 case OO_None:
5083 case NUM_OVERLOADED_OPERATORS:
5084 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005085 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005086 }
5087
John McCalldadc5752010-08-24 06:29:42 +00005088 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005091
John McCalldadc5752010-08-24 06:29:42 +00005092 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005093 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005094 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005095
John McCalldadc5752010-08-24 06:29:42 +00005096 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005097 if (E->getNumArgs() == 2) {
5098 Second = getDerived().TransformExpr(E->getArg(1));
5099 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005100 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005101 }
Mike Stump11289f42009-09-09 15:08:12 +00005102
Douglas Gregora16548e2009-08-11 05:31:07 +00005103 if (!getDerived().AlwaysRebuild() &&
5104 Callee.get() == E->getCallee() &&
5105 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005106 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005107 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005108
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5110 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005111 Callee.get(),
5112 First.get(),
5113 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005114}
Mike Stump11289f42009-09-09 15:08:12 +00005115
Douglas Gregora16548e2009-08-11 05:31:07 +00005116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005118TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5119 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005120}
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregora16548e2009-08-11 05:31:07 +00005122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005124TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005125 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5126 if (!Type)
5127 return ExprError();
5128
John McCalldadc5752010-08-24 06:29:42 +00005129 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005130 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregora16548e2009-08-11 05:31:07 +00005134 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005135 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005136 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005137 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005140 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005141 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5142 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5143 SourceLocation FakeRParenLoc
5144 = SemaRef.PP.getLocForEndOfToken(
5145 E->getSubExpr()->getSourceRange().getEnd());
5146 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005147 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005149 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005150 FakeRAngleLoc,
5151 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005152 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 FakeRParenLoc);
5154}
Mike Stump11289f42009-09-09 15:08:12 +00005155
Douglas Gregora16548e2009-08-11 05:31:07 +00005156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005157ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005158TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5159 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005160}
Mike Stump11289f42009-09-09 15:08:12 +00005161
5162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005164TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5165 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005166}
5167
Douglas Gregora16548e2009-08-11 05:31:07 +00005168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005169ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005170TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005171 CXXReinterpretCastExpr *E) {
5172 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005173}
Mike Stump11289f42009-09-09 15:08:12 +00005174
Douglas Gregora16548e2009-08-11 05:31:07 +00005175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005177TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5178 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005179}
Mike Stump11289f42009-09-09 15:08:12 +00005180
Douglas Gregora16548e2009-08-11 05:31:07 +00005181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005182ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005183TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005184 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005185 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5186 if (!Type)
5187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005188
John McCalldadc5752010-08-24 06:29:42 +00005189 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005190 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005191 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005192 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005193
Douglas Gregora16548e2009-08-11 05:31:07 +00005194 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005195 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005196 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005197 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005198
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005199 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005201 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005202 E->getRParenLoc());
5203}
Mike Stump11289f42009-09-09 15:08:12 +00005204
Douglas Gregora16548e2009-08-11 05:31:07 +00005205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005207TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005208 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005209 TypeSourceInfo *TInfo
5210 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5211 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregora16548e2009-08-11 05:31:07 +00005214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005215 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005216 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005217
Douglas Gregor9da64192010-04-26 22:37:10 +00005218 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5219 E->getLocStart(),
5220 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005221 E->getLocEnd());
5222 }
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregora16548e2009-08-11 05:31:07 +00005224 // We don't know whether the expression is potentially evaluated until
5225 // after we perform semantic analysis, so the expression is potentially
5226 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005227 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005228 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005229
John McCalldadc5752010-08-24 06:29:42 +00005230 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005231 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005232 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005233
Douglas Gregora16548e2009-08-11 05:31:07 +00005234 if (!getDerived().AlwaysRebuild() &&
5235 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005236 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005237
Douglas Gregor9da64192010-04-26 22:37:10 +00005238 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5239 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005240 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 E->getLocEnd());
5242}
5243
5244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005245ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005246TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5247 if (E->isTypeOperand()) {
5248 TypeSourceInfo *TInfo
5249 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5250 if (!TInfo)
5251 return ExprError();
5252
5253 if (!getDerived().AlwaysRebuild() &&
5254 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005255 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005256
5257 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5258 E->getLocStart(),
5259 TInfo,
5260 E->getLocEnd());
5261 }
5262
5263 // We don't know whether the expression is potentially evaluated until
5264 // after we perform semantic analysis, so the expression is potentially
5265 // potentially evaluated.
5266 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5267
5268 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5269 if (SubExpr.isInvalid())
5270 return ExprError();
5271
5272 if (!getDerived().AlwaysRebuild() &&
5273 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005274 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005275
5276 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5277 E->getLocStart(),
5278 SubExpr.get(),
5279 E->getLocEnd());
5280}
5281
5282template<typename Derived>
5283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005284TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005285 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005286}
Mike Stump11289f42009-09-09 15:08:12 +00005287
Douglas Gregora16548e2009-08-11 05:31:07 +00005288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005289ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005290TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005291 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005292 return SemaRef.Owned(E);
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>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005298 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5299 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5300 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005301
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005302 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005303 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregorb15af892010-01-07 23:12:05 +00005305 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005306}
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregora16548e2009-08-11 05:31:07 +00005308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005309ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005310TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005311 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005312 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005313 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005314
Douglas Gregora16548e2009-08-11 05:31:07 +00005315 if (!getDerived().AlwaysRebuild() &&
5316 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005317 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005318
John McCallb268a282010-08-23 23:25:46 +00005319 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005320}
Mike Stump11289f42009-09-09 15:08:12 +00005321
Douglas Gregora16548e2009-08-11 05:31:07 +00005322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005323ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005324TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005325 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005326 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5327 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005328 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005329 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005330
Chandler Carruth794da4c2010-02-08 06:42:49 +00005331 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005332 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005333 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005334
Douglas Gregor033f6752009-12-23 23:03:06 +00005335 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005336}
Mike Stump11289f42009-09-09 15:08:12 +00005337
Douglas Gregora16548e2009-08-11 05:31:07 +00005338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005339ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005340TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5341 CXXScalarValueInitExpr *E) {
5342 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5343 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005344 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005345
Douglas Gregora16548e2009-08-11 05:31:07 +00005346 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005347 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005348 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005349
Douglas Gregor2b88c112010-09-08 00:15:04 +00005350 return getDerived().RebuildCXXScalarValueInitExpr(T,
5351 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005352 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005353}
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregora16548e2009-08-11 05:31:07 +00005355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005356ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005357TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005359 TypeSourceInfo *AllocTypeInfo
5360 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5361 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005363
Douglas Gregora16548e2009-08-11 05:31:07 +00005364 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005365 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005366 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005368
Douglas Gregora16548e2009-08-11 05:31:07 +00005369 // Transform the placement arguments (if any).
5370 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005371 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005372 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005373 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5374 ArgumentChanged = true;
5375 break;
5376 }
5377
John McCalldadc5752010-08-24 06:29:42 +00005378 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005379 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5383 PlacementArgs.push_back(Arg.take());
5384 }
Mike Stump11289f42009-09-09 15:08:12 +00005385
Douglas Gregorebe10102009-08-20 07:17:43 +00005386 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005387 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005388 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005389 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5390 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005391 break;
John McCall09d13692010-10-05 22:36:42 +00005392 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005393
John McCalldadc5752010-08-24 06:29:42 +00005394 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005395 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005396 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005397
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5399 ConstructorArgs.push_back(Arg.take());
5400 }
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregord2d9da02010-02-26 00:38:10 +00005402 // Transform constructor, new operator, and delete operator.
5403 CXXConstructorDecl *Constructor = 0;
5404 if (E->getConstructor()) {
5405 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005406 getDerived().TransformDecl(E->getLocStart(),
5407 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005408 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005409 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005410 }
5411
5412 FunctionDecl *OperatorNew = 0;
5413 if (E->getOperatorNew()) {
5414 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005415 getDerived().TransformDecl(E->getLocStart(),
5416 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005417 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005419 }
5420
5421 FunctionDecl *OperatorDelete = 0;
5422 if (E->getOperatorDelete()) {
5423 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005424 getDerived().TransformDecl(E->getLocStart(),
5425 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005426 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005427 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005428 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005429
Douglas Gregora16548e2009-08-11 05:31:07 +00005430 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005431 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005432 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005433 Constructor == E->getConstructor() &&
5434 OperatorNew == E->getOperatorNew() &&
5435 OperatorDelete == E->getOperatorDelete() &&
5436 !ArgumentChanged) {
5437 // Mark any declarations we need as referenced.
5438 // FIXME: instantiation-specific.
5439 if (Constructor)
5440 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5441 if (OperatorNew)
5442 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5443 if (OperatorDelete)
5444 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005445 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005446 }
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregor0744ef62010-09-07 21:49:58 +00005448 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005449 if (!ArraySize.get()) {
5450 // If no array size was specified, but the new expression was
5451 // instantiated with an array type (e.g., "new T" where T is
5452 // instantiated with "int[4]"), extract the outer bound from the
5453 // array type as our array size. We do this with constant and
5454 // dependently-sized array types.
5455 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5456 if (!ArrayT) {
5457 // Do nothing
5458 } else if (const ConstantArrayType *ConsArrayT
5459 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005460 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005461 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5462 ConsArrayT->getSize(),
5463 SemaRef.Context.getSizeType(),
5464 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005465 AllocType = ConsArrayT->getElementType();
5466 } else if (const DependentSizedArrayType *DepArrayT
5467 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5468 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005469 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005470 AllocType = DepArrayT->getElementType();
5471 }
5472 }
5473 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005474
Douglas Gregora16548e2009-08-11 05:31:07 +00005475 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5476 E->isGlobalNew(),
5477 /*FIXME:*/E->getLocStart(),
5478 move_arg(PlacementArgs),
5479 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005480 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005481 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005482 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005483 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005484 /*FIXME:*/E->getLocStart(),
5485 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005486 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005487}
Mike Stump11289f42009-09-09 15:08:12 +00005488
Douglas Gregora16548e2009-08-11 05:31:07 +00005489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005491TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005492 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005493 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005494 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005495
Douglas Gregord2d9da02010-02-26 00:38:10 +00005496 // Transform the delete operator, if known.
5497 FunctionDecl *OperatorDelete = 0;
5498 if (E->getOperatorDelete()) {
5499 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005500 getDerived().TransformDecl(E->getLocStart(),
5501 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005502 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005503 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005504 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005505
Douglas Gregora16548e2009-08-11 05:31:07 +00005506 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005507 Operand.get() == E->getArgument() &&
5508 OperatorDelete == E->getOperatorDelete()) {
5509 // Mark any declarations we need as referenced.
5510 // FIXME: instantiation-specific.
5511 if (OperatorDelete)
5512 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005513
5514 if (!E->getArgument()->isTypeDependent()) {
5515 QualType Destroyed = SemaRef.Context.getBaseElementType(
5516 E->getDestroyedType());
5517 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5518 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5519 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5520 SemaRef.LookupDestructor(Record));
5521 }
5522 }
5523
John McCallc3007a22010-10-26 07:05:15 +00005524 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005525 }
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5528 E->isGlobalDelete(),
5529 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005530 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005531}
Mike Stump11289f42009-09-09 15:08:12 +00005532
Douglas Gregora16548e2009-08-11 05:31:07 +00005533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005534ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005535TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005536 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005537 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005538 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005540
John McCallba7bf592010-08-24 05:47:05 +00005541 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005542 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005543 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005544 E->getOperatorLoc(),
5545 E->isArrow()? tok::arrow : tok::period,
5546 ObjectTypePtr,
5547 MayBePseudoDestructor);
5548 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005550
John McCallba7bf592010-08-24 05:47:05 +00005551 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005552 NestedNameSpecifier *Qualifier = E->getQualifier();
5553 if (Qualifier) {
5554 Qualifier
5555 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5556 E->getQualifierRange(),
5557 ObjectType);
5558 if (!Qualifier)
5559 return ExprError();
5560 }
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregor678f90d2010-02-25 01:56:36 +00005562 PseudoDestructorTypeStorage Destroyed;
5563 if (E->getDestroyedTypeInfo()) {
5564 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005565 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5566 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005567 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005568 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005569 Destroyed = DestroyedTypeInfo;
5570 } else if (ObjectType->isDependentType()) {
5571 // We aren't likely to be able to resolve the identifier down to a type
5572 // now anyway, so just retain the identifier.
5573 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5574 E->getDestroyedTypeLoc());
5575 } else {
5576 // Look for a destructor known with the given name.
5577 CXXScopeSpec SS;
5578 if (Qualifier) {
5579 SS.setScopeRep(Qualifier);
5580 SS.setRange(E->getQualifierRange());
5581 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005582
John McCallba7bf592010-08-24 05:47:05 +00005583 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005584 *E->getDestroyedTypeIdentifier(),
5585 E->getDestroyedTypeLoc(),
5586 /*Scope=*/0,
5587 SS, ObjectTypePtr,
5588 false);
5589 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005591
Douglas Gregor678f90d2010-02-25 01:56:36 +00005592 Destroyed
5593 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5594 E->getDestroyedTypeLoc());
5595 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005596
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005597 TypeSourceInfo *ScopeTypeInfo = 0;
5598 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005599 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005600 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005601 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005602 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005603
John McCallb268a282010-08-23 23:25:46 +00005604 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005605 E->getOperatorLoc(),
5606 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005607 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005608 E->getQualifierRange(),
5609 ScopeTypeInfo,
5610 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005611 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005612 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005613}
Mike Stump11289f42009-09-09 15:08:12 +00005614
Douglas Gregorad8a3362009-09-04 17:36:40 +00005615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005616ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005617TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005618 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005619 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5620
5621 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5622 Sema::LookupOrdinaryName);
5623
5624 // Transform all the decls.
5625 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5626 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005627 NamedDecl *InstD = static_cast<NamedDecl*>(
5628 getDerived().TransformDecl(Old->getNameLoc(),
5629 *I));
John McCall84d87672009-12-10 09:41:52 +00005630 if (!InstD) {
5631 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5632 // This can happen because of dependent hiding.
5633 if (isa<UsingShadowDecl>(*I))
5634 continue;
5635 else
John McCallfaf5fb42010-08-26 23:41:50 +00005636 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005637 }
John McCalle66edc12009-11-24 19:00:30 +00005638
5639 // Expand using declarations.
5640 if (isa<UsingDecl>(InstD)) {
5641 UsingDecl *UD = cast<UsingDecl>(InstD);
5642 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5643 E = UD->shadow_end(); I != E; ++I)
5644 R.addDecl(*I);
5645 continue;
5646 }
5647
5648 R.addDecl(InstD);
5649 }
5650
5651 // Resolve a kind, but don't do any further analysis. If it's
5652 // ambiguous, the callee needs to deal with it.
5653 R.resolveKind();
5654
5655 // Rebuild the nested-name qualifier, if present.
5656 CXXScopeSpec SS;
5657 NestedNameSpecifier *Qualifier = 0;
5658 if (Old->getQualifier()) {
5659 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005660 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005661 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005662 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005663
John McCalle66edc12009-11-24 19:00:30 +00005664 SS.setScopeRep(Qualifier);
5665 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005666 }
5667
Douglas Gregor9262f472010-04-27 18:19:34 +00005668 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005669 CXXRecordDecl *NamingClass
5670 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5671 Old->getNameLoc(),
5672 Old->getNamingClass()));
5673 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005675
Douglas Gregorda7be082010-04-27 16:10:10 +00005676 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005677 }
5678
5679 // If we have no template arguments, it's a normal declaration name.
5680 if (!Old->hasExplicitTemplateArgs())
5681 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5682
5683 // If we have template arguments, rebuild them, then rebuild the
5684 // templateid expression.
5685 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005686 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
5687 Old->getNumTemplateArgs(),
5688 TransArgs))
5689 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005690
5691 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5692 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005693}
Mike Stump11289f42009-09-09 15:08:12 +00005694
Douglas Gregora16548e2009-08-11 05:31:07 +00005695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005696ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005697TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005698 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5699 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005701
Douglas Gregora16548e2009-08-11 05:31:07 +00005702 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005703 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005704 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005705
Mike Stump11289f42009-09-09 15:08:12 +00005706 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 T,
5709 E->getLocEnd());
5710}
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005713ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00005714TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
5715 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
5716 if (!LhsT)
5717 return ExprError();
5718
5719 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
5720 if (!RhsT)
5721 return ExprError();
5722
5723 if (!getDerived().AlwaysRebuild() &&
5724 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
5725 return SemaRef.Owned(E);
5726
5727 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
5728 E->getLocStart(),
5729 LhsT, RhsT,
5730 E->getLocEnd());
5731}
5732
5733template<typename Derived>
5734ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005735TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005736 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005738 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005739 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005741 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005742
John McCall31f82722010-11-12 08:19:04 +00005743 // TODO: If this is a conversion-function-id, verify that the
5744 // destination type name (if present) resolves the same way after
5745 // instantiation as it did in the local scope.
5746
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005747 DeclarationNameInfo NameInfo
5748 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5749 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005751
John McCalle66edc12009-11-24 19:00:30 +00005752 if (!E->hasExplicitTemplateArgs()) {
5753 if (!getDerived().AlwaysRebuild() &&
5754 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005755 // Note: it is sufficient to compare the Name component of NameInfo:
5756 // if name has not changed, DNLoc has not changed either.
5757 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005758 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005759
John McCalle66edc12009-11-24 19:00:30 +00005760 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5761 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005762 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005763 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005764 }
John McCall6b51f282009-11-23 01:53:49 +00005765
5766 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005767 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5768 E->getNumTemplateArgs(),
5769 TransArgs))
5770 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005771
John McCalle66edc12009-11-24 19:00:30 +00005772 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5773 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005774 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005775 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005776}
5777
5778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005780TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005781 // CXXConstructExprs are always implicit, so when we have a
5782 // 1-argument construction we just transform that argument.
5783 if (E->getNumArgs() == 1 ||
5784 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5785 return getDerived().TransformExpr(E->getArg(0));
5786
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5788
5789 QualType T = getDerived().TransformType(E->getType());
5790 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005791 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005792
5793 CXXConstructorDecl *Constructor
5794 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005795 getDerived().TransformDecl(E->getLocStart(),
5796 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005799
Douglas Gregora16548e2009-08-11 05:31:07 +00005800 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005801 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005802 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005803 ArgEnd = E->arg_end();
5804 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005805 if (getDerived().DropCallArgument(*Arg)) {
5806 ArgumentChanged = true;
5807 break;
5808 }
5809
John McCalldadc5752010-08-24 06:29:42 +00005810 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005811 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005813
Douglas Gregora16548e2009-08-11 05:31:07 +00005814 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005815 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005816 }
5817
5818 if (!getDerived().AlwaysRebuild() &&
5819 T == E->getType() &&
5820 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005821 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005822 // Mark the constructor as referenced.
5823 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005824 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005825 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005826 }
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregordb121ba2009-12-14 16:27:04 +00005828 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5829 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005830 move_arg(Args),
5831 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005832 E->getConstructionKind(),
5833 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005834}
Mike Stump11289f42009-09-09 15:08:12 +00005835
Douglas Gregora16548e2009-08-11 05:31:07 +00005836/// \brief Transform a C++ temporary-binding expression.
5837///
Douglas Gregor363b1512009-12-24 18:51:59 +00005838/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5839/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005842TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005843 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005844}
Mike Stump11289f42009-09-09 15:08:12 +00005845
John McCall5d413782010-12-06 08:20:24 +00005846/// \brief Transform a C++ expression that contains cleanups that should
5847/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00005848///
John McCall5d413782010-12-06 08:20:24 +00005849/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00005850/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005852ExprResult
John McCall5d413782010-12-06 08:20:24 +00005853TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005854 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005855}
Mike Stump11289f42009-09-09 15:08:12 +00005856
Douglas Gregora16548e2009-08-11 05:31:07 +00005857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005858ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005859TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005860 CXXTemporaryObjectExpr *E) {
5861 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5862 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005864
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 CXXConstructorDecl *Constructor
5866 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005867 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005868 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005869 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005871
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005873 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005875 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005876 ArgEnd = E->arg_end();
5877 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005878 if (getDerived().DropCallArgument(*Arg)) {
5879 ArgumentChanged = true;
5880 break;
5881 }
5882
John McCalldadc5752010-08-24 06:29:42 +00005883 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005886
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5888 Args.push_back((Expr *)TransArg.release());
5889 }
Mike Stump11289f42009-09-09 15:08:12 +00005890
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005892 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005894 !ArgumentChanged) {
5895 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005896 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005897 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005898 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005899
5900 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5901 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005902 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 E->getLocEnd());
5904}
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregora16548e2009-08-11 05:31:07 +00005906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005907ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005908TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005909 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005910 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5911 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005912 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005913
Douglas Gregora16548e2009-08-11 05:31:07 +00005914 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005915 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5917 ArgEnd = E->arg_end();
5918 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005919 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005924 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005925 }
Mike Stump11289f42009-09-09 15:08:12 +00005926
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005928 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005929 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005930 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005931
Douglas Gregora16548e2009-08-11 05:31:07 +00005932 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005933 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005934 E->getLParenLoc(),
5935 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 E->getRParenLoc());
5937}
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregora16548e2009-08-11 05:31:07 +00005939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005940ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005941TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005942 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005943 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005944 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005945 Expr *OldBase;
5946 QualType BaseType;
5947 QualType ObjectType;
5948 if (!E->isImplicitAccess()) {
5949 OldBase = E->getBase();
5950 Base = getDerived().TransformExpr(OldBase);
5951 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005953
John McCall2d74de92009-12-01 22:10:20 +00005954 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005955 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005956 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005957 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005958 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005959 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005960 ObjectTy,
5961 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005962 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005964
John McCallba7bf592010-08-24 05:47:05 +00005965 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005966 BaseType = ((Expr*) Base.get())->getType();
5967 } else {
5968 OldBase = 0;
5969 BaseType = getDerived().TransformType(E->getBaseType());
5970 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5971 }
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005973 // Transform the first part of the nested-name-specifier that qualifies
5974 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005975 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005976 = getDerived().TransformFirstQualifierInScope(
5977 E->getFirstQualifierFoundInScope(),
5978 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005979
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005980 NestedNameSpecifier *Qualifier = 0;
5981 if (E->getQualifier()) {
5982 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5983 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005984 ObjectType,
5985 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005986 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005987 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005988 }
Mike Stump11289f42009-09-09 15:08:12 +00005989
John McCall31f82722010-11-12 08:19:04 +00005990 // TODO: If this is a conversion-function-id, verify that the
5991 // destination type name (if present) resolves the same way after
5992 // instantiation as it did in the local scope.
5993
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005994 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00005995 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005996 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005997 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005998
John McCall2d74de92009-12-01 22:10:20 +00005999 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006000 // This is a reference to a member without an explicitly-specified
6001 // template argument list. Optimize for this common case.
6002 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006003 Base.get() == OldBase &&
6004 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006005 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006006 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006007 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006008 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006009
John McCallb268a282010-08-23 23:25:46 +00006010 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006011 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006012 E->isArrow(),
6013 E->getOperatorLoc(),
6014 Qualifier,
6015 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006016 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006017 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006018 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006019 }
6020
John McCall6b51f282009-11-23 01:53:49 +00006021 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006022 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6023 E->getNumTemplateArgs(),
6024 TransArgs))
6025 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006026
John McCallb268a282010-08-23 23:25:46 +00006027 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006028 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 E->isArrow(),
6030 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006031 Qualifier,
6032 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006033 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006034 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006035 &TransArgs);
6036}
6037
6038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006039ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006040TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006041 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006042 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006043 QualType BaseType;
6044 if (!Old->isImplicitAccess()) {
6045 Base = getDerived().TransformExpr(Old->getBase());
6046 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006047 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006048 BaseType = ((Expr*) Base.get())->getType();
6049 } else {
6050 BaseType = getDerived().TransformType(Old->getBaseType());
6051 }
John McCall10eae182009-11-30 22:42:35 +00006052
6053 NestedNameSpecifier *Qualifier = 0;
6054 if (Old->getQualifier()) {
6055 Qualifier
6056 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006057 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006058 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006059 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006060 }
6061
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006062 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006063 Sema::LookupOrdinaryName);
6064
6065 // Transform all the decls.
6066 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6067 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006068 NamedDecl *InstD = static_cast<NamedDecl*>(
6069 getDerived().TransformDecl(Old->getMemberLoc(),
6070 *I));
John McCall84d87672009-12-10 09:41:52 +00006071 if (!InstD) {
6072 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6073 // This can happen because of dependent hiding.
6074 if (isa<UsingShadowDecl>(*I))
6075 continue;
6076 else
John McCallfaf5fb42010-08-26 23:41:50 +00006077 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006078 }
John McCall10eae182009-11-30 22:42:35 +00006079
6080 // Expand using declarations.
6081 if (isa<UsingDecl>(InstD)) {
6082 UsingDecl *UD = cast<UsingDecl>(InstD);
6083 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6084 E = UD->shadow_end(); I != E; ++I)
6085 R.addDecl(*I);
6086 continue;
6087 }
6088
6089 R.addDecl(InstD);
6090 }
6091
6092 R.resolveKind();
6093
Douglas Gregor9262f472010-04-27 18:19:34 +00006094 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006095 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006096 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006097 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006098 Old->getMemberLoc(),
6099 Old->getNamingClass()));
6100 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006101 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006102
Douglas Gregorda7be082010-04-27 16:10:10 +00006103 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006104 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006105
John McCall10eae182009-11-30 22:42:35 +00006106 TemplateArgumentListInfo TransArgs;
6107 if (Old->hasExplicitTemplateArgs()) {
6108 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6109 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006110 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6111 Old->getNumTemplateArgs(),
6112 TransArgs))
6113 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006114 }
John McCall38836f02010-01-15 08:34:02 +00006115
6116 // FIXME: to do this check properly, we will need to preserve the
6117 // first-qualifier-in-scope here, just in case we had a dependent
6118 // base (and therefore couldn't do the check) and a
6119 // nested-name-qualifier (and therefore could do the lookup).
6120 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006121
John McCallb268a282010-08-23 23:25:46 +00006122 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006123 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006124 Old->getOperatorLoc(),
6125 Old->isArrow(),
6126 Qualifier,
6127 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006128 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006129 R,
6130 (Old->hasExplicitTemplateArgs()
6131 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006132}
6133
6134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006135ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006136TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6137 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6138 if (SubExpr.isInvalid())
6139 return ExprError();
6140
6141 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006142 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006143
6144 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6145}
6146
6147template<typename Derived>
6148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006149TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006150 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006151}
6152
Mike Stump11289f42009-09-09 15:08:12 +00006153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006155TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006156 TypeSourceInfo *EncodedTypeInfo
6157 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6158 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006159 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006160
Douglas Gregora16548e2009-08-11 05:31:07 +00006161 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006162 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006163 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006164
6165 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006166 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006167 E->getRParenLoc());
6168}
Mike Stump11289f42009-09-09 15:08:12 +00006169
Douglas Gregora16548e2009-08-11 05:31:07 +00006170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006171ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006172TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006173 // Transform arguments.
6174 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006175 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006176 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006177 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006178 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006179 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006180
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006181 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006182 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006183 }
6184
6185 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6186 // Class message: transform the receiver type.
6187 TypeSourceInfo *ReceiverTypeInfo
6188 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6189 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006190 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006191
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006192 // If nothing changed, just retain the existing message send.
6193 if (!getDerived().AlwaysRebuild() &&
6194 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006195 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006196
6197 // Build a new class message send.
6198 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6199 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006200 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006201 E->getMethodDecl(),
6202 E->getLeftLoc(),
6203 move_arg(Args),
6204 E->getRightLoc());
6205 }
6206
6207 // Instance message: transform the receiver
6208 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6209 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006210 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006211 = getDerived().TransformExpr(E->getInstanceReceiver());
6212 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006214
6215 // If nothing changed, just retain the existing message send.
6216 if (!getDerived().AlwaysRebuild() &&
6217 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006219
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006220 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006221 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006222 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006223 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006224 E->getMethodDecl(),
6225 E->getLeftLoc(),
6226 move_arg(Args),
6227 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006228}
6229
Mike Stump11289f42009-09-09 15:08:12 +00006230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006232TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006233 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006234}
6235
Mike Stump11289f42009-09-09 15:08:12 +00006236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006238TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006239 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006240}
6241
Mike Stump11289f42009-09-09 15:08:12 +00006242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006244TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006245 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006246 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006247 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006248 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006249
6250 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006251
Douglas Gregord51d90d2010-04-26 20:11:03 +00006252 // If nothing changed, just retain the existing expression.
6253 if (!getDerived().AlwaysRebuild() &&
6254 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006255 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006256
John McCallb268a282010-08-23 23:25:46 +00006257 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006258 E->getLocation(),
6259 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006260}
6261
Mike Stump11289f42009-09-09 15:08:12 +00006262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006263ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006264TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006265 // 'super' and types never change. Property never changes. Just
6266 // retain the existing expression.
6267 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006268 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006269
Douglas Gregor9faee212010-04-26 20:47:02 +00006270 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006271 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006272 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006273 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006274
Douglas Gregor9faee212010-04-26 20:47:02 +00006275 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006276
Douglas Gregor9faee212010-04-26 20:47:02 +00006277 // If nothing changed, just retain the existing expression.
6278 if (!getDerived().AlwaysRebuild() &&
6279 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006280 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006281
John McCallb7bd14f2010-12-02 01:19:52 +00006282 if (E->isExplicitProperty())
6283 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6284 E->getExplicitProperty(),
6285 E->getLocation());
6286
6287 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6288 E->getType(),
6289 E->getImplicitPropertyGetter(),
6290 E->getImplicitPropertySetter(),
6291 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006292}
6293
Mike Stump11289f42009-09-09 15:08:12 +00006294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006295ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006296TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006297 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006298 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006299 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006300 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006301
Douglas Gregord51d90d2010-04-26 20:11:03 +00006302 // If nothing changed, just retain the existing expression.
6303 if (!getDerived().AlwaysRebuild() &&
6304 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006306
John McCallb268a282010-08-23 23:25:46 +00006307 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006308 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006309}
6310
Mike Stump11289f42009-09-09 15:08:12 +00006311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006313TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006314 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006315 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006316 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006317 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006318 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006320
Douglas Gregora16548e2009-08-11 05:31:07 +00006321 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006322 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006323 }
Mike Stump11289f42009-09-09 15:08:12 +00006324
Douglas Gregora16548e2009-08-11 05:31:07 +00006325 if (!getDerived().AlwaysRebuild() &&
6326 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006327 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006328
Douglas Gregora16548e2009-08-11 05:31:07 +00006329 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6330 move_arg(SubExprs),
6331 E->getRParenLoc());
6332}
6333
Mike Stump11289f42009-09-09 15:08:12 +00006334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006336TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006337 SourceLocation CaretLoc(E->getExprLoc());
6338
6339 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6340 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6341 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6342 llvm::SmallVector<ParmVarDecl*, 4> Params;
6343 llvm::SmallVector<QualType, 4> ParamTypes;
6344
6345 // Parameter substitution.
6346 const BlockDecl *BD = E->getBlockDecl();
6347 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6348 EN = BD->param_end(); P != EN; ++P) {
6349 ParmVarDecl *OldParm = (*P);
6350 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6351 QualType NewType = NewParm->getType();
6352 Params.push_back(NewParm);
6353 ParamTypes.push_back(NewParm->getType());
6354 }
6355
6356 const FunctionType *BExprFunctionType = E->getFunctionType();
6357 QualType BExprResultType = BExprFunctionType->getResultType();
6358 if (!BExprResultType.isNull()) {
6359 if (!BExprResultType->isDependentType())
6360 CurBlock->ReturnType = BExprResultType;
6361 else if (BExprResultType != SemaRef.Context.DependentTy)
6362 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6363 }
6364
6365 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006366 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006367 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006368 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006369 // Set the parameters on the block decl.
6370 if (!Params.empty())
6371 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6372
6373 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6374 CurBlock->ReturnType,
6375 ParamTypes.data(),
6376 ParamTypes.size(),
6377 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006378 0,
6379 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006380
6381 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006382 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006383}
6384
Mike Stump11289f42009-09-09 15:08:12 +00006385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006386ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006387TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006388 NestedNameSpecifier *Qualifier = 0;
6389
6390 ValueDecl *ND
6391 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6392 E->getDecl()));
6393 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006394 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006395
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006396 if (!getDerived().AlwaysRebuild() &&
6397 ND == E->getDecl()) {
6398 // Mark it referenced in the new context regardless.
6399 // FIXME: this is a bit instantiation-specific.
6400 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6401
John McCallc3007a22010-10-26 07:05:15 +00006402 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006403 }
6404
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006405 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006406 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006407 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006408}
Mike Stump11289f42009-09-09 15:08:12 +00006409
Douglas Gregora16548e2009-08-11 05:31:07 +00006410//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006411// Type reconstruction
6412//===----------------------------------------------------------------------===//
6413
Mike Stump11289f42009-09-09 15:08:12 +00006414template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006415QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6416 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006417 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006418 getDerived().getBaseEntity());
6419}
6420
Mike Stump11289f42009-09-09 15:08:12 +00006421template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006422QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6423 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006424 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006425 getDerived().getBaseEntity());
6426}
6427
Mike Stump11289f42009-09-09 15:08:12 +00006428template<typename Derived>
6429QualType
John McCall70dd5f62009-10-30 00:06:24 +00006430TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6431 bool WrittenAsLValue,
6432 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006433 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006434 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006435}
6436
6437template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006438QualType
John McCall70dd5f62009-10-30 00:06:24 +00006439TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6440 QualType ClassType,
6441 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006442 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006443 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006444}
6445
6446template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006447QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006448TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6449 ArrayType::ArraySizeModifier SizeMod,
6450 const llvm::APInt *Size,
6451 Expr *SizeExpr,
6452 unsigned IndexTypeQuals,
6453 SourceRange BracketsRange) {
6454 if (SizeExpr || !Size)
6455 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6456 IndexTypeQuals, BracketsRange,
6457 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006458
6459 QualType Types[] = {
6460 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6461 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6462 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006463 };
6464 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6465 QualType SizeType;
6466 for (unsigned I = 0; I != NumTypes; ++I)
6467 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6468 SizeType = Types[I];
6469 break;
6470 }
Mike Stump11289f42009-09-09 15:08:12 +00006471
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006472 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6473 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006474 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006475 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006476 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006477}
Mike Stump11289f42009-09-09 15:08:12 +00006478
Douglas Gregord6ff3322009-08-04 16:50:30 +00006479template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006480QualType
6481TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006482 ArrayType::ArraySizeModifier SizeMod,
6483 const llvm::APInt &Size,
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, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006487 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006488}
6489
6490template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006491QualType
Mike Stump11289f42009-09-09 15:08:12 +00006492TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006493 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006494 unsigned IndexTypeQuals,
6495 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006496 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006497 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006498}
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregord6ff3322009-08-04 16:50:30 +00006500template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006501QualType
6502TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006503 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006504 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006505 unsigned IndexTypeQuals,
6506 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006507 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006508 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006509 IndexTypeQuals, BracketsRange);
6510}
6511
6512template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006513QualType
6514TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006515 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006516 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006517 unsigned IndexTypeQuals,
6518 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006519 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006520 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006521 IndexTypeQuals, BracketsRange);
6522}
6523
6524template<typename Derived>
6525QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006526 unsigned NumElements,
6527 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006528 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006529 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006530}
Mike Stump11289f42009-09-09 15:08:12 +00006531
Douglas Gregord6ff3322009-08-04 16:50:30 +00006532template<typename Derived>
6533QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6534 unsigned NumElements,
6535 SourceLocation AttributeLoc) {
6536 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6537 NumElements, true);
6538 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006539 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6540 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006541 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006542}
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregord6ff3322009-08-04 16:50:30 +00006544template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006545QualType
6546TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006547 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006548 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006549 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006550}
Mike Stump11289f42009-09-09 15:08:12 +00006551
Douglas Gregord6ff3322009-08-04 16:50:30 +00006552template<typename Derived>
6553QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006554 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006555 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006556 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006557 unsigned Quals,
6558 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006559 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006560 Quals,
6561 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006562 getDerived().getBaseEntity(),
6563 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006564}
Mike Stump11289f42009-09-09 15:08:12 +00006565
Douglas Gregord6ff3322009-08-04 16:50:30 +00006566template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006567QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6568 return SemaRef.Context.getFunctionNoProtoType(T);
6569}
6570
6571template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006572QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6573 assert(D && "no decl found");
6574 if (D->isInvalidDecl()) return QualType();
6575
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006576 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006577 TypeDecl *Ty;
6578 if (isa<UsingDecl>(D)) {
6579 UsingDecl *Using = cast<UsingDecl>(D);
6580 assert(Using->isTypeName() &&
6581 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6582
6583 // A valid resolved using typename decl points to exactly one type decl.
6584 assert(++Using->shadow_begin() == Using->shadow_end());
6585 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006586
John McCallb96ec562009-12-04 22:46:56 +00006587 } else {
6588 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6589 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6590 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6591 }
6592
6593 return SemaRef.Context.getTypeDeclType(Ty);
6594}
6595
6596template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006597QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6598 SourceLocation Loc) {
6599 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006600}
6601
6602template<typename Derived>
6603QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6604 return SemaRef.Context.getTypeOfType(Underlying);
6605}
6606
6607template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006608QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6609 SourceLocation Loc) {
6610 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006611}
6612
6613template<typename Derived>
6614QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006615 TemplateName Template,
6616 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006617 const TemplateArgumentListInfo &TemplateArgs) {
6618 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006619}
Mike Stump11289f42009-09-09 15:08:12 +00006620
Douglas Gregor1135c352009-08-06 05:28:30 +00006621template<typename Derived>
6622NestedNameSpecifier *
6623TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6624 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006625 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006626 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006627 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006628 CXXScopeSpec SS;
6629 // FIXME: The source location information is all wrong.
6630 SS.setRange(Range);
6631 SS.setScopeRep(Prefix);
6632 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006633 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006634 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006635 ObjectType,
6636 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006637 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006638}
6639
6640template<typename Derived>
6641NestedNameSpecifier *
6642TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6643 SourceRange Range,
6644 NamespaceDecl *NS) {
6645 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6646}
6647
6648template<typename Derived>
6649NestedNameSpecifier *
6650TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6651 SourceRange Range,
6652 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006653 QualType T) {
6654 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006655 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006656 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006657 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6658 T.getTypePtr());
6659 }
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregor1135c352009-08-06 05:28:30 +00006661 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6662 return 0;
6663}
Mike Stump11289f42009-09-09 15:08:12 +00006664
Douglas Gregor71dc5092009-08-06 06:41:21 +00006665template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006666TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006667TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6668 bool TemplateKW,
6669 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006670 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006671 Template);
6672}
6673
6674template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006675TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006676TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006677 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006678 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00006679 QualType ObjectType,
6680 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006681 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006682 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006683 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006684 UnqualifiedId Name;
6685 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006686 Sema::TemplateTy Template;
6687 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6688 /*FIXME:*/getDerived().getBaseLocation(),
6689 SS,
6690 Name,
John McCallba7bf592010-08-24 05:47:05 +00006691 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006692 /*EnteringContext=*/false,
6693 Template);
John McCall31f82722010-11-12 08:19:04 +00006694 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006695}
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006698TemplateName
6699TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6700 OverloadedOperatorKind Operator,
6701 QualType ObjectType) {
6702 CXXScopeSpec SS;
6703 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6704 SS.setScopeRep(Qualifier);
6705 UnqualifiedId Name;
6706 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6707 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6708 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006709 Sema::TemplateTy Template;
6710 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006711 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006712 SS,
6713 Name,
John McCallba7bf592010-08-24 05:47:05 +00006714 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006715 /*EnteringContext=*/false,
6716 Template);
6717 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006718}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006719
Douglas Gregor71395fa2009-11-04 00:56:37 +00006720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006721ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006722TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6723 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006724 Expr *OrigCallee,
6725 Expr *First,
6726 Expr *Second) {
6727 Expr *Callee = OrigCallee->IgnoreParenCasts();
6728 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006729
Douglas Gregora16548e2009-08-11 05:31:07 +00006730 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006731 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006732 if (!First->getType()->isOverloadableType() &&
6733 !Second->getType()->isOverloadableType())
6734 return getSema().CreateBuiltinArraySubscriptExpr(First,
6735 Callee->getLocStart(),
6736 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006737 } else if (Op == OO_Arrow) {
6738 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006739 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6740 } else if (Second == 0 || isPostIncDec) {
6741 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006742 // The argument is not of overloadable type, so try to create a
6743 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006744 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006745 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006746
John McCallb268a282010-08-23 23:25:46 +00006747 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006748 }
6749 } else {
John McCallb268a282010-08-23 23:25:46 +00006750 if (!First->getType()->isOverloadableType() &&
6751 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006752 // Neither of the arguments is an overloadable type, so try to
6753 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006754 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006755 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006756 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006757 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006759
Douglas Gregora16548e2009-08-11 05:31:07 +00006760 return move(Result);
6761 }
6762 }
Mike Stump11289f42009-09-09 15:08:12 +00006763
6764 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006765 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006766 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006767
John McCallb268a282010-08-23 23:25:46 +00006768 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006769 assert(ULE->requiresADL());
6770
6771 // FIXME: Do we have to check
6772 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006773 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006774 } else {
John McCallb268a282010-08-23 23:25:46 +00006775 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006776 }
Mike Stump11289f42009-09-09 15:08:12 +00006777
Douglas Gregora16548e2009-08-11 05:31:07 +00006778 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006779 Expr *Args[2] = { First, Second };
6780 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006781
Douglas Gregora16548e2009-08-11 05:31:07 +00006782 // Create the overloaded operator invocation for unary operators.
6783 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006784 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006785 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006786 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006787 }
Mike Stump11289f42009-09-09 15:08:12 +00006788
Sebastian Redladba46e2009-10-29 20:17:01 +00006789 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006790 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006791 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006792 First,
6793 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006794
Douglas Gregora16548e2009-08-11 05:31:07 +00006795 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006796 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006797 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006798 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6799 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006800 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006801
Mike Stump11289f42009-09-09 15:08:12 +00006802 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006803}
Mike Stump11289f42009-09-09 15:08:12 +00006804
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006806ExprResult
John McCallb268a282010-08-23 23:25:46 +00006807TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006808 SourceLocation OperatorLoc,
6809 bool isArrow,
6810 NestedNameSpecifier *Qualifier,
6811 SourceRange QualifierRange,
6812 TypeSourceInfo *ScopeType,
6813 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006814 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006815 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006816 CXXScopeSpec SS;
6817 if (Qualifier) {
6818 SS.setRange(QualifierRange);
6819 SS.setScopeRep(Qualifier);
6820 }
6821
John McCallb268a282010-08-23 23:25:46 +00006822 QualType BaseType = Base->getType();
6823 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006824 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006825 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006826 !BaseType->getAs<PointerType>()->getPointeeType()
6827 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006828 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006829 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006830 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006831 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006832 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006833 /*FIXME?*/true);
6834 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006835
Douglas Gregor678f90d2010-02-25 01:56:36 +00006836 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006837 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6838 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6839 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6840 NameInfo.setNamedTypeInfo(DestroyedType);
6841
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006842 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006843
John McCallb268a282010-08-23 23:25:46 +00006844 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006845 OperatorLoc, isArrow,
6846 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006847 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006848 /*TemplateArgs*/ 0);
6849}
6850
Douglas Gregord6ff3322009-08-04 16:50:30 +00006851} // end namespace clang
6852
6853#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H