blob: 89e0b60de07e1d25e926111cb9d30a71b64c43c1 [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
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000016#include "clang/Sema/Sema.h"
17#include "clang/Sema/Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
John McCall8b0666c2010-08-20 18:27:03 +000027#include "clang/Sema/Ownership.h"
28#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000029#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
Douglas Gregora16548e2009-08-11 05:31:07 +000094 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000095 typedef Sema::MultiStmtArg MultiStmtArg;
Alexis Hunta8136cc2010-05-05 15:23:54 +000096
Douglas Gregord6ff3322009-08-04 16:50:30 +000097 /// \brief Initializes a new tree transformer.
98 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000099
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Retrieves a reference to the derived class.
101 Derived &getDerived() { return static_cast<Derived&>(*this); }
102
103 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000104 const Derived &getDerived() const {
105 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000106 }
107
John McCallb268a282010-08-23 23:25:46 +0000108 static inline OwningExprResult Owned(Expr *E) { return E; }
109 static inline OwningStmtResult Owned(Stmt *S) { return S; }
110
Douglas Gregord6ff3322009-08-04 16:50:30 +0000111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
247 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000253 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000262
Douglas Gregord6ff3322009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump11289f42009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregorf816bd72009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000279 DeclarationNameInfo
280 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCallbcd03502009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
John McCall58f10c32010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Alexis Hunta8136cc2010-05-05 15:23:54 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Alexis Hunta8136cc2010-05-05 15:23:54 +0000336 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000339
Douglas Gregorebe10102009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000424 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000435 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner37141f42010-06-23 06:00:24 +0000445 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000461 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000473
John McCall550e0c22009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCallb96ec562009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCallfcc33b02009-09-05 00:15:47 +0000495
Mike Stump11289f42009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000500 QualType RebuildTypeOfExprType(Expr *Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501
Mike Stump11289f42009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump11289f42009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000511 QualType RebuildDecltypeType(Expr *Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000521
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
527 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
528 NestedNameSpecifier *NNS, QualType Named) {
529 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000530 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531
532 /// \brief Build a new typename type that refers to a template-id.
533 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000534 /// By default, builds a new DependentNameType type from the
535 /// nested-name-specifier and the given type. Subclasses may override
536 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000537 QualType RebuildDependentTemplateSpecializationType(
538 ElaboratedTypeKeyword Keyword,
539 NestedNameSpecifier *NNS,
540 const IdentifierInfo *Name,
541 SourceLocation NameLoc,
542 const TemplateArgumentListInfo &Args) {
543 // Rebuild the template name.
544 // TODO: avoid TemplateName abstraction
545 TemplateName InstName =
546 getDerived().RebuildTemplateName(NNS, *Name, QualType());
547
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCallc392f372010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
554 Keyword, NNS, Name, Args);
555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000561
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000562 // NOTE: NNS is already recorded in template specialization type T.
563 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000564 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
566 /// \brief Build a new typename type that refers to an identifier.
567 ///
568 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000571 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000572 NestedNameSpecifier *NNS,
573 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 SourceLocation KeywordLoc,
575 SourceRange NNSRange,
576 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000577 CXXScopeSpec SS;
578 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000579 SS.setRange(NNSRange);
580
Douglas Gregore677daf2010-03-31 22:19:08 +0000581 if (NNS->isDependent()) {
582 // If the name is still dependent, just build a new dependent name type.
583 if (!SemaRef.computeDeclContext(SS))
584 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 }
586
Abramo Bagnara6150c882010-05-11 21:36:43 +0000587 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000588 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
589 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590
591 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
592
Abramo Bagnarad7548482010-05-19 21:37:53 +0000593 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000594 // into a non-dependent elaborated-type-specifier. Find the tag we're
595 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000596 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000597 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
598 if (!DC)
599 return QualType();
600
John McCallbf8c5192010-05-27 06:40:31 +0000601 if (SemaRef.RequireCompleteDeclContext(SS, DC))
602 return QualType();
603
Douglas Gregore677daf2010-03-31 22:19:08 +0000604 TagDecl *Tag = 0;
605 SemaRef.LookupQualifiedName(Result, DC);
606 switch (Result.getResultKind()) {
607 case LookupResult::NotFound:
608 case LookupResult::NotFoundInCurrentInstantiation:
609 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000610
Douglas Gregore677daf2010-03-31 22:19:08 +0000611 case LookupResult::Found:
612 Tag = Result.getAsSingle<TagDecl>();
613 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000614
Douglas Gregore677daf2010-03-31 22:19:08 +0000615 case LookupResult::FoundOverloaded:
616 case LookupResult::FoundUnresolvedValue:
617 llvm_unreachable("Tag lookup cannot find non-tags");
618 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000619
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 case LookupResult::Ambiguous:
621 // Let the LookupResult structure handle ambiguities.
622 return QualType();
623 }
624
625 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000627 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000628 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000629 return QualType();
630 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000631
Abramo Bagnarad7548482010-05-19 21:37:53 +0000632 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
633 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000634 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
635 return QualType();
636 }
637
638 // Build the elaborated-type-specifier type.
639 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000640 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 }
Mike Stump11289f42009-09-09 15:08:12 +0000642
Douglas Gregor1135c352009-08-06 05:28:30 +0000643 /// \brief Build a new nested-name-specifier given the prefix and an
644 /// identifier that names the next step in the nested-name-specifier.
645 ///
646 /// By default, performs semantic analysis when building the new
647 /// nested-name-specifier. Subclasses may override this routine to provide
648 /// different behavior.
649 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
650 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000651 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000652 QualType ObjectType,
653 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000654
655 /// \brief Build a new nested-name-specifier given the prefix and the
656 /// namespace named in the next step in the nested-name-specifier.
657 ///
658 /// By default, performs semantic analysis when building the new
659 /// nested-name-specifier. Subclasses may override this routine to provide
660 /// different behavior.
661 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
662 SourceRange Range,
663 NamespaceDecl *NS);
664
665 /// \brief Build a new nested-name-specifier given the prefix and the
666 /// type named in the next step in the nested-name-specifier.
667 ///
668 /// By default, performs semantic analysis when building the new
669 /// nested-name-specifier. Subclasses may override this routine to provide
670 /// different behavior.
671 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
672 SourceRange Range,
673 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000674 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000675
676 /// \brief Build a new template name given a nested name specifier, a flag
677 /// indicating whether the "template" keyword was provided, and the template
678 /// that the template name refers to.
679 ///
680 /// By default, builds the new template name directly. Subclasses may override
681 /// this routine to provide different behavior.
682 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
683 bool TemplateKW,
684 TemplateDecl *Template);
685
Douglas Gregor71dc5092009-08-06 06:41:21 +0000686 /// \brief Build a new template name given a nested name specifier and the
687 /// name that is referred to as a template.
688 ///
689 /// By default, performs semantic analysis to determine whether the name can
690 /// be resolved to a specific template, then builds the appropriate kind of
691 /// template name. Subclasses may override this routine to provide different
692 /// behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000694 const IdentifierInfo &II,
695 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000696
Douglas Gregor71395fa2009-11-04 00:56:37 +0000697 /// \brief Build a new template name given a nested name specifier and the
698 /// overloaded operator name that is referred to as a template.
699 ///
700 /// By default, performs semantic analysis to determine whether the name can
701 /// be resolved to a specific template, then builds the appropriate kind of
702 /// template name. Subclasses may override this routine to provide different
703 /// behavior.
704 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
705 OverloadedOperatorKind Operator,
706 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000707
Douglas Gregorebe10102009-08-20 07:17:43 +0000708 /// \brief Build a new compound statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
713 MultiStmtArg Statements,
714 SourceLocation RBraceLoc,
715 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000716 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000717 IsStmtExpr);
718 }
719
720 /// \brief Build a new case statement.
721 ///
722 /// By default, performs semantic analysis to build the new statement.
723 /// Subclasses may override this routine to provide different behavior.
724 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000725 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000727 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000729 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000730 ColonLoc);
731 }
Mike Stump11289f42009-09-09 15:08:12 +0000732
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 /// \brief Attach the body to a new case statement.
734 ///
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000737 OwningStmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
738 getSema().ActOnCaseStmtBody(S, Body);
739 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 }
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregorebe10102009-08-20 07:17:43 +0000742 /// \brief Build a new default statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000746 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000748 Stmt *SubStmt) {
749 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000750 /*CurScope=*/0);
751 }
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregorebe10102009-08-20 07:17:43 +0000753 /// \brief Build a new label statement.
754 ///
755 /// By default, performs semantic analysis to build the new statement.
756 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000757 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 IdentifierInfo *Id,
759 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000760 Stmt *SubStmt) {
761 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 }
Mike Stump11289f42009-09-09 15:08:12 +0000763
Douglas Gregorebe10102009-08-20 07:17:43 +0000764 /// \brief Build a new "if" statement.
765 ///
766 /// By default, performs semantic analysis to build the new statement.
767 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000768 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000769 VarDecl *CondVar, Stmt *Then,
770 SourceLocation ElseLoc, Stmt *Else) {
771 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000772 }
Mike Stump11289f42009-09-09 15:08:12 +0000773
Douglas Gregorebe10102009-08-20 07:17:43 +0000774 /// \brief Start building a new switch statement.
775 ///
776 /// By default, performs semantic analysis to build the new statement.
777 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000778 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000779 Expr *Cond, VarDecl *CondVar) {
780 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000781 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 }
Mike Stump11289f42009-09-09 15:08:12 +0000783
Douglas Gregorebe10102009-08-20 07:17:43 +0000784 /// \brief Attach the body to the switch statement.
785 ///
786 /// By default, performs semantic analysis to build the new statement.
787 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000788 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000789 Stmt *Switch, Stmt *Body) {
790 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000791 }
792
793 /// \brief Build a new while statement.
794 ///
795 /// By default, performs semantic analysis to build the new statement.
796 /// Subclasses may override this routine to provide different behavior.
797 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000798 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000799 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000800 Stmt *Body) {
801 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000802 }
Mike Stump11289f42009-09-09 15:08:12 +0000803
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 /// \brief Build a new do-while statement.
805 ///
806 /// By default, performs semantic analysis to build the new statement.
807 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000808 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000809 SourceLocation WhileLoc,
810 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000811 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000812 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000813 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
814 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000815 }
816
817 /// \brief Build a new for statement.
818 ///
819 /// By default, performs semantic analysis to build the new statement.
820 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000821 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000822 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000823 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000824 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000825 SourceLocation RParenLoc, Stmt *Body) {
826 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000827 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000828 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 }
Mike Stump11289f42009-09-09 15:08:12 +0000830
Douglas Gregorebe10102009-08-20 07:17:43 +0000831 /// \brief Build a new goto statement.
832 ///
833 /// By default, performs semantic analysis to build the new statement.
834 /// Subclasses may override this routine to provide different behavior.
835 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
836 SourceLocation LabelLoc,
837 LabelStmt *Label) {
838 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
839 }
840
841 /// \brief Build a new indirect goto statement.
842 ///
843 /// By default, performs semantic analysis to build the new statement.
844 /// Subclasses may override this routine to provide different behavior.
845 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
846 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000847 Expr *Target) {
848 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000849 }
Mike Stump11289f42009-09-09 15:08:12 +0000850
Douglas Gregorebe10102009-08-20 07:17:43 +0000851 /// \brief Build a new return statement.
852 ///
853 /// By default, performs semantic analysis to build the new statement.
854 /// Subclasses may override this routine to provide different behavior.
855 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000856 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000857
John McCallb268a282010-08-23 23:25:46 +0000858 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000859 }
Mike Stump11289f42009-09-09 15:08:12 +0000860
Douglas Gregorebe10102009-08-20 07:17:43 +0000861 /// \brief Build a new declaration statement.
862 ///
863 /// By default, performs semantic analysis to build the new statement.
864 /// Subclasses may override this routine to provide different behavior.
865 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000866 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000867 SourceLocation EndLoc) {
868 return getSema().Owned(
869 new (getSema().Context) DeclStmt(
870 DeclGroupRef::Create(getSema().Context,
871 Decls, NumDecls),
872 StartLoc, EndLoc));
873 }
Mike Stump11289f42009-09-09 15:08:12 +0000874
Anders Carlssonaaeef072010-01-24 05:50:09 +0000875 /// \brief Build a new inline asm statement.
876 ///
877 /// By default, performs semantic analysis to build the new statement.
878 /// Subclasses may override this routine to provide different behavior.
879 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
880 bool IsSimple,
881 bool IsVolatile,
882 unsigned NumOutputs,
883 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000884 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000885 MultiExprArg Constraints,
886 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000887 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000888 MultiExprArg Clobbers,
889 SourceLocation RParenLoc,
890 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000891 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000892 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000893 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000894 RParenLoc, MSAsm);
895 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000896
897 /// \brief Build a new Objective-C @try statement.
898 ///
899 /// By default, performs semantic analysis to build the new statement.
900 /// Subclasses may override this routine to provide different behavior.
901 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000902 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000903 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000904 Stmt *Finally) {
905 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
906 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000907 }
908
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000909 /// \brief Rebuild an Objective-C exception declaration.
910 ///
911 /// By default, performs semantic analysis to build the new declaration.
912 /// Subclasses may override this routine to provide different behavior.
913 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
914 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000915 return getSema().BuildObjCExceptionDecl(TInfo, T,
916 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000917 ExceptionDecl->getLocation());
918 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000919
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000920 /// \brief Build a new Objective-C @catch statement.
921 ///
922 /// By default, performs semantic analysis to build the new statement.
923 /// Subclasses may override this routine to provide different behavior.
924 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
925 SourceLocation RParenLoc,
926 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000927 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000928 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000929 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000930 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000931
Douglas Gregor306de2f2010-04-22 23:59:56 +0000932 /// \brief Build a new Objective-C @finally statement.
933 ///
934 /// By default, performs semantic analysis to build the new statement.
935 /// Subclasses may override this routine to provide different behavior.
936 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000937 Stmt *Body) {
938 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000939 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000940
Douglas Gregor6148de72010-04-22 22:01:21 +0000941 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
945 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000946 Expr *Operand) {
947 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000948 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000949
Douglas Gregor6148de72010-04-22 22:01:21 +0000950 /// \brief Build a new Objective-C @synchronized statement.
951 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000952 /// By default, performs semantic analysis to build the new statement.
953 /// Subclasses may override this routine to provide different behavior.
954 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000955 Expr *Object,
956 Stmt *Body) {
957 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
958 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000959 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000960
961 /// \brief Build a new Objective-C fast enumeration statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
965 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
966 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000967 Stmt *Element,
968 Expr *Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000969 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000970 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000971 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000972 Element,
973 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000974 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000975 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000976 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000977
Douglas Gregorebe10102009-08-20 07:17:43 +0000978 /// \brief Build a new C++ exception declaration.
979 ///
980 /// By default, performs semantic analysis to build the new decaration.
981 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000982 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000983 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 IdentifierInfo *Name,
985 SourceLocation Loc,
986 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000987 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000988 TypeRange);
989 }
990
991 /// \brief Build a new C++ catch statement.
992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
995 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
996 VarDecl *ExceptionDecl,
John McCallb268a282010-08-23 23:25:46 +0000997 Stmt *Handler) {
998 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
999 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 }
Mike Stump11289f42009-09-09 15:08:12 +00001001
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 /// \brief Build a new C++ try statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
1006 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallb268a282010-08-23 23:25:46 +00001007 Stmt *TryBlock,
Douglas Gregorebe10102009-08-20 07:17:43 +00001008 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001009 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001010 }
Mike Stump11289f42009-09-09 15:08:12 +00001011
Douglas Gregora16548e2009-08-11 05:31:07 +00001012 /// \brief Build a new expression that references a declaration.
1013 ///
1014 /// By default, performs semantic analysis to build the new expression.
1015 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001016 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1017 LookupResult &R,
1018 bool RequiresADL) {
1019 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1020 }
1021
1022
1023 /// \brief Build a new expression that references a declaration.
1024 ///
1025 /// By default, performs semantic analysis to build the new expression.
1026 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001027 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1028 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001029 ValueDecl *VD,
1030 const DeclarationNameInfo &NameInfo,
John McCallce546572009-12-08 09:08:17 +00001031 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001032 CXXScopeSpec SS;
1033 SS.setScopeRep(Qualifier);
1034 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001035
1036 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001037
1038 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001042 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 /// By default, performs semantic analysis to build the new expression.
1044 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001045 OwningExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001047 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 }
1049
Douglas Gregorad8a3362009-09-04 17:36:40 +00001050 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001051 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001054 OwningExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001055 SourceLocation OperatorLoc,
1056 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001057 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001058 SourceRange QualifierRange,
1059 TypeSourceInfo *ScopeType,
1060 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001061 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001062 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001063
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001065 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 /// By default, performs semantic analysis to build the new expression.
1067 /// Subclasses may override this routine to provide different behavior.
1068 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1069 UnaryOperator::Opcode Opc,
John McCallb268a282010-08-23 23:25:46 +00001070 Expr *SubExpr) {
1071 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 }
Mike Stump11289f42009-09-09 15:08:12 +00001073
Douglas Gregor882211c2010-04-28 22:16:22 +00001074 /// \brief Build a new builtin offsetof expression.
1075 ///
1076 /// By default, performs semantic analysis to build the new expression.
1077 /// Subclasses may override this routine to provide different behavior.
1078 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1079 TypeSourceInfo *Type,
1080 Action::OffsetOfComponent *Components,
1081 unsigned NumComponents,
1082 SourceLocation RParenLoc) {
1083 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1084 NumComponents, RParenLoc);
1085 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001086
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001091 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001092 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001094 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001095 }
1096
Mike Stump11289f42009-09-09 15:08:12 +00001097 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001099 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001102 OwningExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001104 OwningExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001105 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 if (Result.isInvalid())
1107 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 return move(Result);
1110 }
Mike Stump11289f42009-09-09 15:08:12 +00001111
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001113 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001114 /// By default, performs semantic analysis to build the new expression.
1115 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001116 OwningExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001118 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001120 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1121 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 RBracketLoc);
1123 }
1124
1125 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001126 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 /// By default, performs semantic analysis to build the new expression.
1128 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001129 OwningExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 MultiExprArg Args,
1131 SourceLocation *CommaLocs,
1132 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001133 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 move(Args), CommaLocs, RParenLoc);
1135 }
1136
1137 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001138 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001141 OwningExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001142 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001143 NestedNameSpecifier *Qualifier,
1144 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001145 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001146 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001147 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001148 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001149 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001150 if (!Member->getDeclName()) {
1151 // We have a reference to an unnamed field.
1152 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001153
John McCallb268a282010-08-23 23:25:46 +00001154 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001155 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001156 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001157
Mike Stump11289f42009-09-09 15:08:12 +00001158 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001159 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001160 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001161 cast<FieldDecl>(Member)->getType());
1162 return getSema().Owned(ME);
1163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001165 CXXScopeSpec SS;
1166 if (Qualifier) {
1167 SS.setRange(QualifierRange);
1168 SS.setScopeRep(Qualifier);
1169 }
1170
John McCallb268a282010-08-23 23:25:46 +00001171 getSema().DefaultFunctionArrayConversion(Base);
1172 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001173
John McCall16df1e52010-03-30 21:47:33 +00001174 // FIXME: this involves duplicating earlier analysis in a lot of
1175 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001176 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001177 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001178 R.resolveKind();
1179
John McCallb268a282010-08-23 23:25:46 +00001180 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001181 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001182 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001186 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 /// By default, performs semantic analysis to build the new expression.
1188 /// Subclasses may override this routine to provide different behavior.
1189 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1190 BinaryOperator::Opcode Opc,
John McCallb268a282010-08-23 23:25:46 +00001191 Expr *LHS, Expr *RHS) {
1192 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 }
1194
1195 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001196 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 /// By default, performs semantic analysis to build the new expression.
1198 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001199 OwningExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001201 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001203 Expr *RHS) {
1204 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1205 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 }
1207
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001209 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 /// By default, performs semantic analysis to build the new expression.
1211 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001212 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1213 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001215 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001216 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001217 SubExpr);
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 compound literal 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.
1224 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001225 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001227 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001228 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001229 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001233 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001236 OwningExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 SourceLocation OpLoc,
1238 SourceLocation AccessorLoc,
1239 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001240
John McCall10eae182009-11-30 22:42:35 +00001241 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001242 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001243 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001244 OpLoc, /*IsArrow*/ false,
1245 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001246 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001247 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 }
Mike Stump11289f42009-09-09 15:08:12 +00001249
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001251 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 /// By default, performs semantic analysis to build the new expression.
1253 /// Subclasses may override this routine to provide different behavior.
1254 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1255 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001256 SourceLocation RBraceLoc,
1257 QualType ResultTy) {
1258 OwningExprResult Result
1259 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1260 if (Result.isInvalid() || ResultTy->isDependentType())
1261 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001262
Douglas Gregord3d93062009-11-09 17:16:50 +00001263 // Patch in the result type we were given, which may have been computed
1264 // when the initial InitListExpr was built.
1265 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1266 ILE->setType(ResultTy);
1267 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001271 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 /// By default, performs semantic analysis to build the new expression.
1273 /// Subclasses may override this routine to provide different behavior.
1274 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1275 MultiExprArg ArrayExprs,
1276 SourceLocation EqualOrColonLoc,
1277 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001278 Expr *Init) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 OwningExprResult Result
1280 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001281 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 if (Result.isInvalid())
1283 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001284
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 ArrayExprs.release();
1286 return move(Result);
1287 }
Mike Stump11289f42009-09-09 15:08:12 +00001288
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001290 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 /// By default, builds the implicit value initialization without performing
1292 /// any semantic analysis. Subclasses may override this routine to provide
1293 /// different behavior.
1294 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1295 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1296 }
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001299 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnara27db2392010-08-10 10:06:15 +00001302 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001303 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001304 SourceLocation RParenLoc) {
1305 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001306 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001307 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 }
1309
1310 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1315 MultiExprArg SubExprs,
1316 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001317 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001318 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 }
Mike Stump11289f42009-09-09 15:08:12 +00001320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001322 ///
1323 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// rather than attempting to map the label statement itself.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1327 SourceLocation LabelLoc,
1328 LabelStmt *Label) {
1329 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
1336 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001337 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001339 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new __builtin_types_compatible_p expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001347 TypeSourceInfo *TInfo1,
1348 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001350 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1351 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 RParenLoc);
1353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new __builtin_choose_expr expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
1359 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001360 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 SourceLocation RParenLoc) {
1362 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001363 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 RParenLoc);
1365 }
Mike Stump11289f42009-09-09 15:08:12 +00001366
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 /// \brief Build a new overloaded operator call expression.
1368 ///
1369 /// By default, performs semantic analysis to build the new expression.
1370 /// The semantic analysis provides the behavior of template instantiation,
1371 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001372 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 /// argument-dependent lookup, etc. Subclasses may override this routine to
1374 /// provide different behavior.
1375 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1376 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001377 Expr *Callee,
1378 Expr *First,
1379 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001380
1381 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// reinterpret_cast.
1383 ///
1384 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001385 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// Subclasses may override this routine to provide different behavior.
1387 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1388 Stmt::StmtClass Class,
1389 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001390 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 SourceLocation RAngleLoc,
1392 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001393 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 SourceLocation RParenLoc) {
1395 switch (Class) {
1396 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001397 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001398 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001399 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001400
1401 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001402 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001403 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001404 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001405
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001407 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001408 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001409 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001413 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001414 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001415 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 default:
1418 assert(false && "Invalid C++ named cast");
1419 break;
1420 }
Mike Stump11289f42009-09-09 15:08:12 +00001421
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 return getSema().ExprError();
1423 }
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// \brief Build a new C++ static_cast expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
1429 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1430 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001431 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 SourceLocation RAngleLoc,
1433 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001434 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001436 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001437 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001438 SourceRange(LAngleLoc, RAngleLoc),
1439 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 }
1441
1442 /// \brief Build a new C++ dynamic_cast expression.
1443 ///
1444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
1446 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1447 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001448 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 SourceLocation RAngleLoc,
1450 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001451 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001453 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001454 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001455 SourceRange(LAngleLoc, RAngleLoc),
1456 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new C++ reinterpret_cast expression.
1460 ///
1461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
1463 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1464 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001465 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 SourceLocation RAngleLoc,
1467 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001468 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001470 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001471 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001472 SourceRange(LAngleLoc, RAngleLoc),
1473 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 }
1475
1476 /// \brief Build a new C++ const_cast expression.
1477 ///
1478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
1480 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1481 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001482 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 SourceLocation RAngleLoc,
1484 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001485 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001487 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001488 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001489 SourceRange(LAngleLoc, RAngleLoc),
1490 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 }
Mike Stump11289f42009-09-09 15:08:12 +00001492
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 /// \brief Build a new C++ functional-style cast expression.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
1497 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001498 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001500 Expr *Sub,
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCallba7bf592010-08-24 05:47:05 +00001503 ParsedType::make(TInfo->getType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001505 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001506 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 RParenLoc);
1508 }
Mike Stump11289f42009-09-09 15:08:12 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// \brief Build a new C++ typeid(type) expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001514 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1515 SourceLocation TypeidLoc,
1516 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001518 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001519 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 }
Mike Stump11289f42009-09-09 15:08:12 +00001521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// \brief Build a new C++ typeid(expr) expression.
1523 ///
1524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001526 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1527 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001528 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001530 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001531 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001532 }
1533
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// \brief Build a new C++ "this" expression.
1535 ///
1536 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001537 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001539 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001540 QualType ThisType,
1541 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001542 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001543 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1544 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 }
1546
1547 /// \brief Build a new C++ throw expression.
1548 ///
1549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001551 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
1552 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 }
1554
1555 /// \brief Build a new C++ default-argument expression.
1556 ///
1557 /// By default, builds a new default-argument expression, which does not
1558 /// require any semantic analysis. Subclasses may override this routine to
1559 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001560 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001561 ParmVarDecl *Param) {
1562 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1563 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 }
1565
1566 /// \brief Build a new C++ zero-initialization expression.
1567 ///
1568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor747eb782010-07-08 06:14:04 +00001570 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 SourceLocation LParenLoc,
1572 QualType T,
1573 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001574 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
John McCallba7bf592010-08-24 05:47:05 +00001575 ParsedType::make(T), LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001576 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 0, RParenLoc);
1578 }
Mike Stump11289f42009-09-09 15:08:12 +00001579
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 /// \brief Build a new C++ "new" expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001584 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 bool UseGlobal,
1586 SourceLocation PlacementLParen,
1587 MultiExprArg PlacementArgs,
1588 SourceLocation PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001589 SourceRange TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 QualType AllocType,
1591 SourceLocation TypeLoc,
1592 SourceRange TypeRange,
John McCallb268a282010-08-23 23:25:46 +00001593 Expr *ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 SourceLocation ConstructorLParen,
1595 MultiExprArg ConstructorArgs,
1596 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001597 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 PlacementLParen,
1599 move(PlacementArgs),
1600 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001601 TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 AllocType,
1603 TypeLoc,
1604 TypeRange,
John McCallb268a282010-08-23 23:25:46 +00001605 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 ConstructorLParen,
1607 move(ConstructorArgs),
1608 ConstructorRParen);
1609 }
Mike Stump11289f42009-09-09 15:08:12 +00001610
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 /// \brief Build a new C++ "delete" expression.
1612 ///
1613 /// By default, performs semantic analysis to build the new expression.
1614 /// Subclasses may override this routine to provide different behavior.
1615 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1616 bool IsGlobalDelete,
1617 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001618 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001620 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 }
Mike Stump11289f42009-09-09 15:08:12 +00001622
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 /// \brief Build a new unary type trait expression.
1624 ///
1625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
1627 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1628 SourceLocation StartLoc,
1629 SourceLocation LParenLoc,
1630 QualType T,
1631 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001632 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallba7bf592010-08-24 05:47:05 +00001633 ParsedType::make(T), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 }
1635
Mike Stump11289f42009-09-09 15:08:12 +00001636 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001641 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001643 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001644 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 CXXScopeSpec SS;
1646 SS.setRange(QualifierRange);
1647 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001648
1649 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001650 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001651 *TemplateArgs);
1652
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001653 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 }
1655
1656 /// \brief Build a new template-id expression.
1657 ///
1658 /// By default, performs semantic analysis to build the new expression.
1659 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001660 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1661 LookupResult &R,
1662 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001663 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001664 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
1666
1667 /// \brief Build a new object-construction expression.
1668 ///
1669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
1671 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001672 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 CXXConstructorDecl *Constructor,
1674 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001675 MultiExprArg Args,
1676 bool RequiresZeroInit,
1677 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCall37ad5512010-08-23 06:44:23 +00001678 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001679 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001680 ConvertedArgs))
1681 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001682
Douglas Gregordb121ba2009-12-14 16:27:04 +00001683 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001684 move_arg(ConvertedArgs),
1685 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 }
1687
1688 /// \brief Build a new object-construction expression.
1689 ///
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
1692 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1693 QualType T,
1694 SourceLocation LParenLoc,
1695 MultiExprArg Args,
1696 SourceLocation *Commas,
1697 SourceLocation RParenLoc) {
1698 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
John McCallba7bf592010-08-24 05:47:05 +00001699 ParsedType::make(T),
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 LParenLoc,
1701 move(Args),
1702 Commas,
1703 RParenLoc);
1704 }
1705
1706 /// \brief Build a new object-construction expression.
1707 ///
1708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
1710 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1711 QualType T,
1712 SourceLocation LParenLoc,
1713 MultiExprArg Args,
1714 SourceLocation *Commas,
1715 SourceLocation RParenLoc) {
1716 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1717 /*FIXME*/LParenLoc),
John McCallba7bf592010-08-24 05:47:05 +00001718 ParsedType::make(T),
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 LParenLoc,
1720 move(Args),
1721 Commas,
1722 RParenLoc);
1723 }
Mike Stump11289f42009-09-09 15:08:12 +00001724
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 /// \brief Build a new member reference expression.
1726 ///
1727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001729 OwningExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001730 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 bool IsArrow,
1732 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001733 NestedNameSpecifier *Qualifier,
1734 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001735 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001736 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001737 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001739 SS.setRange(QualifierRange);
1740 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001741
John McCallb268a282010-08-23 23:25:46 +00001742 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001743 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001744 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001745 MemberNameInfo,
1746 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 }
1748
John McCall10eae182009-11-30 22:42:35 +00001749 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001750 ///
1751 /// By default, performs semantic analysis to build the new expression.
1752 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001753 OwningExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001754 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001755 SourceLocation OperatorLoc,
1756 bool IsArrow,
1757 NestedNameSpecifier *Qualifier,
1758 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001759 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001760 LookupResult &R,
1761 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001762 CXXScopeSpec SS;
1763 SS.setRange(QualifierRange);
1764 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001765
John McCallb268a282010-08-23 23:25:46 +00001766 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001767 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001768 SS, FirstQualifierInScope,
1769 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001770 }
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 /// \brief Build a new Objective-C @encode expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
1776 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001777 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001779 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001781 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001782
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001783 /// \brief Build a new Objective-C class message.
1784 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1785 Selector Sel,
1786 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001787 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001788 MultiExprArg Args,
1789 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001790 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1791 ReceiverTypeInfo->getType(),
1792 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001793 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001794 move(Args));
1795 }
1796
1797 /// \brief Build a new Objective-C instance message.
John McCallb268a282010-08-23 23:25:46 +00001798 OwningExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001799 Selector Sel,
1800 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001801 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001802 MultiExprArg Args,
1803 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001804 return SemaRef.BuildInstanceMessage(Receiver,
1805 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001806 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001807 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001808 move(Args));
1809 }
1810
Douglas Gregord51d90d2010-04-26 20:11:03 +00001811 /// \brief Build a new Objective-C ivar reference expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001815 OwningExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001816 SourceLocation IvarLoc,
1817 bool IsArrow, bool IsFreeIvar) {
1818 // FIXME: We lose track of the IsFreeIvar bit.
1819 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001820 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001821 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1822 Sema::LookupMemberName);
1823 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1824 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001825 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001826 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001827 if (Result.isInvalid())
1828 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001829
Douglas Gregord51d90d2010-04-26 20:11:03 +00001830 if (Result.get())
1831 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001832
John McCallb268a282010-08-23 23:25:46 +00001833 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001834 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001835 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001836 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001837 /*TemplateArgs=*/0);
1838 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001839
1840 /// \brief Build a new Objective-C property reference expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001844 OwningExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001845 ObjCPropertyDecl *Property,
1846 SourceLocation PropertyLoc) {
1847 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001848 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001849 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1850 Sema::LookupMemberName);
1851 bool IsArrow = false;
1852 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1853 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001854 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001855 if (Result.isInvalid())
1856 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001857
Douglas Gregor9faee212010-04-26 20:47:02 +00001858 if (Result.get())
1859 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001860
John McCallb268a282010-08-23 23:25:46 +00001861 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001862 /*FIXME:*/PropertyLoc, IsArrow,
1863 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001864 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001865 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001866 /*TemplateArgs=*/0);
1867 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001868
1869 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001870 /// expression.
1871 ///
1872 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001873 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001874 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1875 ObjCMethodDecl *Getter,
1876 QualType T,
1877 ObjCMethodDecl *Setter,
1878 SourceLocation NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001879 Expr *Base) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001880 // Since these expressions can only be value-dependent, we do not need to
1881 // perform semantic analysis again.
John McCallb268a282010-08-23 23:25:46 +00001882 return Owned(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001883 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1884 Setter,
1885 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001886 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001887 }
1888
Douglas Gregord51d90d2010-04-26 20:11:03 +00001889 /// \brief Build a new Objective-C "isa" expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +00001893 OwningExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001894 bool IsArrow) {
1895 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001896 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001897 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1898 Sema::LookupMemberName);
1899 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1900 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001901 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001902 if (Result.isInvalid())
1903 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001904
Douglas Gregord51d90d2010-04-26 20:11:03 +00001905 if (Result.get())
1906 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001907
John McCallb268a282010-08-23 23:25:46 +00001908 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001909 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001910 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001911 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001912 /*TemplateArgs=*/0);
1913 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001914
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 /// \brief Build a new shuffle vector expression.
1916 ///
1917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
1919 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1920 MultiExprArg SubExprs,
1921 SourceLocation RParenLoc) {
1922 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001923 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1925 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1926 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1927 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001928
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 // Build a reference to the __builtin_shufflevector builtin
1930 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001931 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001933 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001935
1936 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 unsigned NumSubExprs = SubExprs.size();
1938 Expr **Subs = (Expr **)SubExprs.release();
1939 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1940 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001941 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 RParenLoc);
1943 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001944
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 // Type-check the __builtin_shufflevector expression.
1946 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1947 if (Result.isInvalid())
1948 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001949
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001951 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001953};
Douglas Gregora16548e2009-08-11 05:31:07 +00001954
Douglas Gregorebe10102009-08-20 07:17:43 +00001955template<typename Derived>
1956Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1957 if (!S)
1958 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001959
Douglas Gregorebe10102009-08-20 07:17:43 +00001960 switch (S->getStmtClass()) {
1961 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregorebe10102009-08-20 07:17:43 +00001963 // Transform individual statement nodes
1964#define STMT(Node, Parent) \
1965 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1966#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001967#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001968
Douglas Gregorebe10102009-08-20 07:17:43 +00001969 // Transform expressions by calling TransformExpr.
1970#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001971#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001972#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001973#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001974 {
1975 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1976 if (E.isInvalid())
1977 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001978
John McCallb268a282010-08-23 23:25:46 +00001979 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00001980 }
Mike Stump11289f42009-09-09 15:08:12 +00001981 }
1982
Douglas Gregorebe10102009-08-20 07:17:43 +00001983 return SemaRef.Owned(S->Retain());
1984}
Mike Stump11289f42009-09-09 15:08:12 +00001985
1986
Douglas Gregore922c772009-08-04 22:27:00 +00001987template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001988Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 if (!E)
1990 return SemaRef.Owned(E);
1991
1992 switch (E->getStmtClass()) {
1993 case Stmt::NoStmtClass: break;
1994#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00001995#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00001996#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001997 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00001998#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001999 }
2000
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002002}
2003
2004template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002005NestedNameSpecifier *
2006TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002007 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002008 QualType ObjectType,
2009 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002010 if (!NNS)
2011 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002012
Douglas Gregorebe10102009-08-20 07:17:43 +00002013 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002014 NestedNameSpecifier *Prefix = NNS->getPrefix();
2015 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002016 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002017 ObjectType,
2018 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002019 if (!Prefix)
2020 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002021
2022 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002023 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002024 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002025 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002026 }
Mike Stump11289f42009-09-09 15:08:12 +00002027
Douglas Gregor1135c352009-08-06 05:28:30 +00002028 switch (NNS->getKind()) {
2029 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002030 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002031 "Identifier nested-name-specifier with no prefix or object type");
2032 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2033 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002034 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002035
2036 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002037 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002038 ObjectType,
2039 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregor1135c352009-08-06 05:28:30 +00002041 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002042 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002043 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002044 getDerived().TransformDecl(Range.getBegin(),
2045 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002046 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002047 Prefix == NNS->getPrefix() &&
2048 NS == NNS->getAsNamespace())
2049 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002050
Douglas Gregor1135c352009-08-06 05:28:30 +00002051 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2052 }
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregor1135c352009-08-06 05:28:30 +00002054 case NestedNameSpecifier::Global:
2055 // There is no meaningful transformation that one could perform on the
2056 // global scope.
2057 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002058
Douglas Gregor1135c352009-08-06 05:28:30 +00002059 case NestedNameSpecifier::TypeSpecWithTemplate:
2060 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002061 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002062 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2063 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002064 if (T.isNull())
2065 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002066
Douglas Gregor1135c352009-08-06 05:28:30 +00002067 if (!getDerived().AlwaysRebuild() &&
2068 Prefix == NNS->getPrefix() &&
2069 T == QualType(NNS->getAsType(), 0))
2070 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002071
2072 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2073 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002074 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002075 }
2076 }
Mike Stump11289f42009-09-09 15:08:12 +00002077
Douglas Gregor1135c352009-08-06 05:28:30 +00002078 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002079 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002080}
2081
2082template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002083DeclarationNameInfo
2084TreeTransform<Derived>
2085::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2086 QualType ObjectType) {
2087 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002088 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002089 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002090
2091 switch (Name.getNameKind()) {
2092 case DeclarationName::Identifier:
2093 case DeclarationName::ObjCZeroArgSelector:
2094 case DeclarationName::ObjCOneArgSelector:
2095 case DeclarationName::ObjCMultiArgSelector:
2096 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002097 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002098 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002099 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002100
Douglas Gregorf816bd72009-09-03 22:13:48 +00002101 case DeclarationName::CXXConstructorName:
2102 case DeclarationName::CXXDestructorName:
2103 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002104 TypeSourceInfo *NewTInfo;
2105 CanQualType NewCanTy;
2106 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2107 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2108 if (!NewTInfo)
2109 return DeclarationNameInfo();
2110 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2111 }
2112 else {
2113 NewTInfo = 0;
2114 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2115 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2116 ObjectType);
2117 if (NewT.isNull())
2118 return DeclarationNameInfo();
2119 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2120 }
Mike Stump11289f42009-09-09 15:08:12 +00002121
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002122 DeclarationName NewName
2123 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2124 NewCanTy);
2125 DeclarationNameInfo NewNameInfo(NameInfo);
2126 NewNameInfo.setName(NewName);
2127 NewNameInfo.setNamedTypeInfo(NewTInfo);
2128 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002129 }
Mike Stump11289f42009-09-09 15:08:12 +00002130 }
2131
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002132 assert(0 && "Unknown name kind.");
2133 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002134}
2135
2136template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002137TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002138TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2139 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002140 SourceLocation Loc = getDerived().getBaseLocation();
2141
Douglas Gregor71dc5092009-08-06 06:41:21 +00002142 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002143 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002144 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002145 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2146 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002147 if (!NNS)
2148 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002149
Douglas Gregor71dc5092009-08-06 06:41:21 +00002150 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002151 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002152 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002153 if (!TransTemplate)
2154 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002155
Douglas Gregor71dc5092009-08-06 06:41:21 +00002156 if (!getDerived().AlwaysRebuild() &&
2157 NNS == QTN->getQualifier() &&
2158 TransTemplate == Template)
2159 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002160
Douglas Gregor71dc5092009-08-06 06:41:21 +00002161 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2162 TransTemplate);
2163 }
Mike Stump11289f42009-09-09 15:08:12 +00002164
John McCalle66edc12009-11-24 19:00:30 +00002165 // These should be getting filtered out before they make it into the AST.
2166 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 }
Mike Stump11289f42009-09-09 15:08:12 +00002168
Douglas Gregor71dc5092009-08-06 06:41:21 +00002169 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002170 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002171 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002172 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2173 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002174 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002175 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002178 NNS == DTN->getQualifier() &&
2179 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002180 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregor71395fa2009-11-04 00:56:37 +00002182 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002183 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002184 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002185
2186 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002187 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002188 }
Mike Stump11289f42009-09-09 15:08:12 +00002189
Douglas Gregor71dc5092009-08-06 06:41:21 +00002190 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002191 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002192 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002193 if (!TransTemplate)
2194 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregor71dc5092009-08-06 06:41:21 +00002196 if (!getDerived().AlwaysRebuild() &&
2197 TransTemplate == Template)
2198 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregor71dc5092009-08-06 06:41:21 +00002200 return TemplateName(TransTemplate);
2201 }
Mike Stump11289f42009-09-09 15:08:12 +00002202
John McCalle66edc12009-11-24 19:00:30 +00002203 // These should be getting filtered out before they reach the AST.
2204 assert(false && "overloaded function decl survived to here");
2205 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002206}
2207
2208template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002209void TreeTransform<Derived>::InventTemplateArgumentLoc(
2210 const TemplateArgument &Arg,
2211 TemplateArgumentLoc &Output) {
2212 SourceLocation Loc = getDerived().getBaseLocation();
2213 switch (Arg.getKind()) {
2214 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002215 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002216 break;
2217
2218 case TemplateArgument::Type:
2219 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002220 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002221
John McCall0ad16662009-10-29 08:12:44 +00002222 break;
2223
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002224 case TemplateArgument::Template:
2225 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2226 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002227
John McCall0ad16662009-10-29 08:12:44 +00002228 case TemplateArgument::Expression:
2229 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2230 break;
2231
2232 case TemplateArgument::Declaration:
2233 case TemplateArgument::Integral:
2234 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002235 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002236 break;
2237 }
2238}
2239
2240template<typename Derived>
2241bool TreeTransform<Derived>::TransformTemplateArgument(
2242 const TemplateArgumentLoc &Input,
2243 TemplateArgumentLoc &Output) {
2244 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002245 switch (Arg.getKind()) {
2246 case TemplateArgument::Null:
2247 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002248 Output = Input;
2249 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002250
Douglas Gregore922c772009-08-04 22:27:00 +00002251 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002252 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002253 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002254 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002255
2256 DI = getDerived().TransformType(DI);
2257 if (!DI) return true;
2258
2259 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2260 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002261 }
Mike Stump11289f42009-09-09 15:08:12 +00002262
Douglas Gregore922c772009-08-04 22:27:00 +00002263 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002264 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002265 DeclarationName Name;
2266 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2267 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002268 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002269 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002270 if (!D) return true;
2271
John McCall0d07eb32009-10-29 18:45:58 +00002272 Expr *SourceExpr = Input.getSourceDeclExpression();
2273 if (SourceExpr) {
2274 EnterExpressionEvaluationContext Unevaluated(getSema(),
2275 Action::Unevaluated);
2276 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002277 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002278 }
2279
2280 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002281 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002282 }
Mike Stump11289f42009-09-09 15:08:12 +00002283
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002284 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002285 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002286 TemplateName Template
2287 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2288 if (Template.isNull())
2289 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002290
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002291 Output = TemplateArgumentLoc(TemplateArgument(Template),
2292 Input.getTemplateQualifierRange(),
2293 Input.getTemplateNameLoc());
2294 return false;
2295 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002296
Douglas Gregore922c772009-08-04 22:27:00 +00002297 case TemplateArgument::Expression: {
2298 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002299 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002300 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002301
John McCall0ad16662009-10-29 08:12:44 +00002302 Expr *InputExpr = Input.getSourceExpression();
2303 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2304
2305 Sema::OwningExprResult E
2306 = getDerived().TransformExpr(InputExpr);
2307 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002308 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002309 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002310 }
Mike Stump11289f42009-09-09 15:08:12 +00002311
Douglas Gregore922c772009-08-04 22:27:00 +00002312 case TemplateArgument::Pack: {
2313 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2314 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002315 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002316 AEnd = Arg.pack_end();
2317 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002318
John McCall0ad16662009-10-29 08:12:44 +00002319 // FIXME: preserve source information here when we start
2320 // caring about parameter packs.
2321
John McCall0d07eb32009-10-29 18:45:58 +00002322 TemplateArgumentLoc InputArg;
2323 TemplateArgumentLoc OutputArg;
2324 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2325 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002326 return true;
2327
John McCall0d07eb32009-10-29 18:45:58 +00002328 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002329 }
2330 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002331 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002332 true);
John McCall0d07eb32009-10-29 18:45:58 +00002333 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002334 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002335 }
2336 }
Mike Stump11289f42009-09-09 15:08:12 +00002337
Douglas Gregore922c772009-08-04 22:27:00 +00002338 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002339 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002340}
2341
Douglas Gregord6ff3322009-08-04 16:50:30 +00002342//===----------------------------------------------------------------------===//
2343// Type transformation
2344//===----------------------------------------------------------------------===//
2345
2346template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002347QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002348 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002349 if (getDerived().AlreadyTransformed(T))
2350 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002351
John McCall550e0c22009-10-21 00:40:46 +00002352 // Temporary workaround. All of these transformations should
2353 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002354 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002355 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002356
Douglas Gregorfe17d252010-02-16 19:09:40 +00002357 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002358
John McCall550e0c22009-10-21 00:40:46 +00002359 if (!NewDI)
2360 return QualType();
2361
2362 return NewDI->getType();
2363}
2364
2365template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002366TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2367 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002368 if (getDerived().AlreadyTransformed(DI->getType()))
2369 return DI;
2370
2371 TypeLocBuilder TLB;
2372
2373 TypeLoc TL = DI->getTypeLoc();
2374 TLB.reserve(TL.getFullDataSize());
2375
Douglas Gregorfe17d252010-02-16 19:09:40 +00002376 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002377 if (Result.isNull())
2378 return 0;
2379
John McCallbcd03502009-12-07 02:54:59 +00002380 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002381}
2382
2383template<typename Derived>
2384QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002385TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2386 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002387 switch (T.getTypeLocClass()) {
2388#define ABSTRACT_TYPELOC(CLASS, PARENT)
2389#define TYPELOC(CLASS, PARENT) \
2390 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002391 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2392 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002393#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002394 }
Mike Stump11289f42009-09-09 15:08:12 +00002395
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002396 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002397 return QualType();
2398}
2399
2400/// FIXME: By default, this routine adds type qualifiers only to types
2401/// that can have qualifiers, and silently suppresses those qualifiers
2402/// that are not permitted (e.g., qualifiers on reference or function
2403/// types). This is the right thing for template instantiation, but
2404/// probably not for other clients.
2405template<typename Derived>
2406QualType
2407TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002408 QualifiedTypeLoc T,
2409 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002410 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002411
Douglas Gregorfe17d252010-02-16 19:09:40 +00002412 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2413 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002414 if (Result.isNull())
2415 return QualType();
2416
2417 // Silently suppress qualifiers if the result type can't be qualified.
2418 // FIXME: this is the right thing for template instantiation, but
2419 // probably not for other clients.
2420 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002421 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002422
John McCallcb0f89a2010-06-05 06:41:15 +00002423 if (!Quals.empty()) {
2424 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2425 TLB.push<QualifiedTypeLoc>(Result);
2426 // No location information to preserve.
2427 }
John McCall550e0c22009-10-21 00:40:46 +00002428
2429 return Result;
2430}
2431
2432template <class TyLoc> static inline
2433QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2434 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2435 NewT.setNameLoc(T.getNameLoc());
2436 return T.getType();
2437}
2438
John McCall550e0c22009-10-21 00:40:46 +00002439template<typename Derived>
2440QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002441 BuiltinTypeLoc T,
2442 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002443 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2444 NewT.setBuiltinLoc(T.getBuiltinLoc());
2445 if (T.needsExtraLocalData())
2446 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2447 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002448}
Mike Stump11289f42009-09-09 15:08:12 +00002449
Douglas Gregord6ff3322009-08-04 16:50:30 +00002450template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002451QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002452 ComplexTypeLoc T,
2453 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002454 // FIXME: recurse?
2455 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002456}
Mike Stump11289f42009-09-09 15:08:12 +00002457
Douglas Gregord6ff3322009-08-04 16:50:30 +00002458template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002459QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002460 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002461 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002462 QualType PointeeType
2463 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002464 if (PointeeType.isNull())
2465 return QualType();
2466
2467 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002468 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002469 // A dependent pointer type 'T *' has is being transformed such
2470 // that an Objective-C class type is being replaced for 'T'. The
2471 // resulting pointer type is an ObjCObjectPointerType, not a
2472 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002473 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002474
John McCall8b07ec22010-05-15 11:32:37 +00002475 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2476 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002477 return Result;
2478 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002479
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002480 if (getDerived().AlwaysRebuild() ||
2481 PointeeType != TL.getPointeeLoc().getType()) {
2482 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2483 if (Result.isNull())
2484 return QualType();
2485 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002486
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002487 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2488 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002489 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002490}
Mike Stump11289f42009-09-09 15:08:12 +00002491
2492template<typename Derived>
2493QualType
John McCall550e0c22009-10-21 00:40:46 +00002494TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002495 BlockPointerTypeLoc TL,
2496 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002497 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002498 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2499 if (PointeeType.isNull())
2500 return QualType();
2501
2502 QualType Result = TL.getType();
2503 if (getDerived().AlwaysRebuild() ||
2504 PointeeType != TL.getPointeeLoc().getType()) {
2505 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002506 TL.getSigilLoc());
2507 if (Result.isNull())
2508 return QualType();
2509 }
2510
Douglas Gregor049211a2010-04-22 16:50:51 +00002511 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002512 NewT.setSigilLoc(TL.getSigilLoc());
2513 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002514}
2515
John McCall70dd5f62009-10-30 00:06:24 +00002516/// Transforms a reference type. Note that somewhat paradoxically we
2517/// don't care whether the type itself is an l-value type or an r-value
2518/// type; we only care if the type was *written* as an l-value type
2519/// or an r-value type.
2520template<typename Derived>
2521QualType
2522TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002523 ReferenceTypeLoc TL,
2524 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002525 const ReferenceType *T = TL.getTypePtr();
2526
2527 // Note that this works with the pointee-as-written.
2528 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2529 if (PointeeType.isNull())
2530 return QualType();
2531
2532 QualType Result = TL.getType();
2533 if (getDerived().AlwaysRebuild() ||
2534 PointeeType != T->getPointeeTypeAsWritten()) {
2535 Result = getDerived().RebuildReferenceType(PointeeType,
2536 T->isSpelledAsLValue(),
2537 TL.getSigilLoc());
2538 if (Result.isNull())
2539 return QualType();
2540 }
2541
2542 // r-value references can be rebuilt as l-value references.
2543 ReferenceTypeLoc NewTL;
2544 if (isa<LValueReferenceType>(Result))
2545 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2546 else
2547 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2548 NewTL.setSigilLoc(TL.getSigilLoc());
2549
2550 return Result;
2551}
2552
Mike Stump11289f42009-09-09 15:08:12 +00002553template<typename Derived>
2554QualType
John McCall550e0c22009-10-21 00:40:46 +00002555TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002556 LValueReferenceTypeLoc TL,
2557 QualType ObjectType) {
2558 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002559}
2560
Mike Stump11289f42009-09-09 15:08:12 +00002561template<typename Derived>
2562QualType
John McCall550e0c22009-10-21 00:40:46 +00002563TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002564 RValueReferenceTypeLoc TL,
2565 QualType ObjectType) {
2566 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002567}
Mike Stump11289f42009-09-09 15:08:12 +00002568
Douglas Gregord6ff3322009-08-04 16:50:30 +00002569template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002570QualType
John McCall550e0c22009-10-21 00:40:46 +00002571TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002572 MemberPointerTypeLoc TL,
2573 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002574 MemberPointerType *T = TL.getTypePtr();
2575
2576 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002577 if (PointeeType.isNull())
2578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002579
John McCall550e0c22009-10-21 00:40:46 +00002580 // TODO: preserve source information for this.
2581 QualType ClassType
2582 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583 if (ClassType.isNull())
2584 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002585
John McCall550e0c22009-10-21 00:40:46 +00002586 QualType Result = TL.getType();
2587 if (getDerived().AlwaysRebuild() ||
2588 PointeeType != T->getPointeeType() ||
2589 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002590 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2591 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002592 if (Result.isNull())
2593 return QualType();
2594 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002595
John McCall550e0c22009-10-21 00:40:46 +00002596 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2597 NewTL.setSigilLoc(TL.getSigilLoc());
2598
2599 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002600}
2601
Mike Stump11289f42009-09-09 15:08:12 +00002602template<typename Derived>
2603QualType
John McCall550e0c22009-10-21 00:40:46 +00002604TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002605 ConstantArrayTypeLoc TL,
2606 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002607 ConstantArrayType *T = TL.getTypePtr();
2608 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002609 if (ElementType.isNull())
2610 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002611
John McCall550e0c22009-10-21 00:40:46 +00002612 QualType Result = TL.getType();
2613 if (getDerived().AlwaysRebuild() ||
2614 ElementType != T->getElementType()) {
2615 Result = getDerived().RebuildConstantArrayType(ElementType,
2616 T->getSizeModifier(),
2617 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002618 T->getIndexTypeCVRQualifiers(),
2619 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002620 if (Result.isNull())
2621 return QualType();
2622 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002623
John McCall550e0c22009-10-21 00:40:46 +00002624 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2625 NewTL.setLBracketLoc(TL.getLBracketLoc());
2626 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002627
John McCall550e0c22009-10-21 00:40:46 +00002628 Expr *Size = TL.getSizeExpr();
2629 if (Size) {
2630 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2631 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2632 }
2633 NewTL.setSizeExpr(Size);
2634
2635 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002636}
Mike Stump11289f42009-09-09 15:08:12 +00002637
Douglas Gregord6ff3322009-08-04 16:50:30 +00002638template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002639QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002640 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002641 IncompleteArrayTypeLoc TL,
2642 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002643 IncompleteArrayType *T = TL.getTypePtr();
2644 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645 if (ElementType.isNull())
2646 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002647
John McCall550e0c22009-10-21 00:40:46 +00002648 QualType Result = TL.getType();
2649 if (getDerived().AlwaysRebuild() ||
2650 ElementType != T->getElementType()) {
2651 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002652 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002653 T->getIndexTypeCVRQualifiers(),
2654 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002655 if (Result.isNull())
2656 return QualType();
2657 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002658
John McCall550e0c22009-10-21 00:40:46 +00002659 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2660 NewTL.setLBracketLoc(TL.getLBracketLoc());
2661 NewTL.setRBracketLoc(TL.getRBracketLoc());
2662 NewTL.setSizeExpr(0);
2663
2664 return Result;
2665}
2666
2667template<typename Derived>
2668QualType
2669TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002670 VariableArrayTypeLoc TL,
2671 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002672 VariableArrayType *T = TL.getTypePtr();
2673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2674 if (ElementType.isNull())
2675 return QualType();
2676
2677 // Array bounds are not potentially evaluated contexts
2678 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2679
2680 Sema::OwningExprResult SizeResult
2681 = getDerived().TransformExpr(T->getSizeExpr());
2682 if (SizeResult.isInvalid())
2683 return QualType();
2684
John McCallb268a282010-08-23 23:25:46 +00002685 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002686
2687 QualType Result = TL.getType();
2688 if (getDerived().AlwaysRebuild() ||
2689 ElementType != T->getElementType() ||
2690 Size != T->getSizeExpr()) {
2691 Result = getDerived().RebuildVariableArrayType(ElementType,
2692 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002693 Size,
John McCall550e0c22009-10-21 00:40:46 +00002694 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002695 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002696 if (Result.isNull())
2697 return QualType();
2698 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002699
John McCall550e0c22009-10-21 00:40:46 +00002700 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2701 NewTL.setLBracketLoc(TL.getLBracketLoc());
2702 NewTL.setRBracketLoc(TL.getRBracketLoc());
2703 NewTL.setSizeExpr(Size);
2704
2705 return Result;
2706}
2707
2708template<typename Derived>
2709QualType
2710TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002711 DependentSizedArrayTypeLoc TL,
2712 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002713 DependentSizedArrayType *T = TL.getTypePtr();
2714 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2715 if (ElementType.isNull())
2716 return QualType();
2717
2718 // Array bounds are not potentially evaluated contexts
2719 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2720
2721 Sema::OwningExprResult SizeResult
2722 = getDerived().TransformExpr(T->getSizeExpr());
2723 if (SizeResult.isInvalid())
2724 return QualType();
2725
2726 Expr *Size = static_cast<Expr*>(SizeResult.get());
2727
2728 QualType Result = TL.getType();
2729 if (getDerived().AlwaysRebuild() ||
2730 ElementType != T->getElementType() ||
2731 Size != T->getSizeExpr()) {
2732 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2733 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002734 Size,
John McCall550e0c22009-10-21 00:40:46 +00002735 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002736 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002737 if (Result.isNull())
2738 return QualType();
2739 }
2740 else SizeResult.take();
2741
2742 // We might have any sort of array type now, but fortunately they
2743 // all have the same location layout.
2744 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2745 NewTL.setLBracketLoc(TL.getLBracketLoc());
2746 NewTL.setRBracketLoc(TL.getRBracketLoc());
2747 NewTL.setSizeExpr(Size);
2748
2749 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750}
Mike Stump11289f42009-09-09 15:08:12 +00002751
2752template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002753QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002754 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002755 DependentSizedExtVectorTypeLoc TL,
2756 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002757 DependentSizedExtVectorType *T = TL.getTypePtr();
2758
2759 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002760 QualType ElementType = getDerived().TransformType(T->getElementType());
2761 if (ElementType.isNull())
2762 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002763
Douglas Gregore922c772009-08-04 22:27:00 +00002764 // Vector sizes are not potentially evaluated contexts
2765 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2766
Douglas Gregord6ff3322009-08-04 16:50:30 +00002767 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2768 if (Size.isInvalid())
2769 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 QualType Result = TL.getType();
2772 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002773 ElementType != T->getElementType() ||
2774 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002775 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002776 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002777 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002778 if (Result.isNull())
2779 return QualType();
2780 }
John McCall550e0c22009-10-21 00:40:46 +00002781
2782 // Result might be dependent or not.
2783 if (isa<DependentSizedExtVectorType>(Result)) {
2784 DependentSizedExtVectorTypeLoc NewTL
2785 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2786 NewTL.setNameLoc(TL.getNameLoc());
2787 } else {
2788 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2789 NewTL.setNameLoc(TL.getNameLoc());
2790 }
2791
2792 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002793}
Mike Stump11289f42009-09-09 15:08:12 +00002794
2795template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002796QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002797 VectorTypeLoc TL,
2798 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002799 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002800 QualType ElementType = getDerived().TransformType(T->getElementType());
2801 if (ElementType.isNull())
2802 return QualType();
2803
John McCall550e0c22009-10-21 00:40:46 +00002804 QualType Result = TL.getType();
2805 if (getDerived().AlwaysRebuild() ||
2806 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002807 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002808 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002809 if (Result.isNull())
2810 return QualType();
2811 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002812
John McCall550e0c22009-10-21 00:40:46 +00002813 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2814 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002815
John McCall550e0c22009-10-21 00:40:46 +00002816 return Result;
2817}
2818
2819template<typename Derived>
2820QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002821 ExtVectorTypeLoc TL,
2822 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002823 VectorType *T = TL.getTypePtr();
2824 QualType ElementType = getDerived().TransformType(T->getElementType());
2825 if (ElementType.isNull())
2826 return QualType();
2827
2828 QualType Result = TL.getType();
2829 if (getDerived().AlwaysRebuild() ||
2830 ElementType != T->getElementType()) {
2831 Result = getDerived().RebuildExtVectorType(ElementType,
2832 T->getNumElements(),
2833 /*FIXME*/ SourceLocation());
2834 if (Result.isNull())
2835 return QualType();
2836 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002837
John McCall550e0c22009-10-21 00:40:46 +00002838 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2839 NewTL.setNameLoc(TL.getNameLoc());
2840
2841 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002842}
Mike Stump11289f42009-09-09 15:08:12 +00002843
2844template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002845ParmVarDecl *
2846TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2847 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2848 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2849 if (!NewDI)
2850 return 0;
2851
2852 if (NewDI == OldDI)
2853 return OldParm;
2854 else
2855 return ParmVarDecl::Create(SemaRef.Context,
2856 OldParm->getDeclContext(),
2857 OldParm->getLocation(),
2858 OldParm->getIdentifier(),
2859 NewDI->getType(),
2860 NewDI,
2861 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002862 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002863 /* DefArg */ NULL);
2864}
2865
2866template<typename Derived>
2867bool TreeTransform<Derived>::
2868 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2869 llvm::SmallVectorImpl<QualType> &PTypes,
2870 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2871 FunctionProtoType *T = TL.getTypePtr();
2872
2873 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2874 ParmVarDecl *OldParm = TL.getArg(i);
2875
2876 QualType NewType;
2877 ParmVarDecl *NewParm;
2878
2879 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002880 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2881 if (!NewParm)
2882 return true;
2883 NewType = NewParm->getType();
2884
2885 // Deal with the possibility that we don't have a parameter
2886 // declaration for this parameter.
2887 } else {
2888 NewParm = 0;
2889
2890 QualType OldType = T->getArgType(i);
2891 NewType = getDerived().TransformType(OldType);
2892 if (NewType.isNull())
2893 return true;
2894 }
2895
2896 PTypes.push_back(NewType);
2897 PVars.push_back(NewParm);
2898 }
2899
2900 return false;
2901}
2902
2903template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002904QualType
John McCall550e0c22009-10-21 00:40:46 +00002905TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002906 FunctionProtoTypeLoc TL,
2907 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002908 // Transform the parameters. We do this first for the benefit of template
2909 // instantiations, so that the ParmVarDecls get/ placed into the template
2910 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002911 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002912 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002913 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2914 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002915
Douglas Gregor14cf7522010-04-30 18:55:50 +00002916 FunctionProtoType *T = TL.getTypePtr();
2917 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2918 if (ResultType.isNull())
2919 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002920
John McCall550e0c22009-10-21 00:40:46 +00002921 QualType Result = TL.getType();
2922 if (getDerived().AlwaysRebuild() ||
2923 ResultType != T->getResultType() ||
2924 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2925 Result = getDerived().RebuildFunctionProtoType(ResultType,
2926 ParamTypes.data(),
2927 ParamTypes.size(),
2928 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002929 T->getTypeQuals(),
2930 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002931 if (Result.isNull())
2932 return QualType();
2933 }
Mike Stump11289f42009-09-09 15:08:12 +00002934
John McCall550e0c22009-10-21 00:40:46 +00002935 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2936 NewTL.setLParenLoc(TL.getLParenLoc());
2937 NewTL.setRParenLoc(TL.getRParenLoc());
2938 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2939 NewTL.setArg(i, ParamDecls[i]);
2940
2941 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002942}
Mike Stump11289f42009-09-09 15:08:12 +00002943
Douglas Gregord6ff3322009-08-04 16:50:30 +00002944template<typename Derived>
2945QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002946 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002947 FunctionNoProtoTypeLoc TL,
2948 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002949 FunctionNoProtoType *T = TL.getTypePtr();
2950 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2951 if (ResultType.isNull())
2952 return QualType();
2953
2954 QualType Result = TL.getType();
2955 if (getDerived().AlwaysRebuild() ||
2956 ResultType != T->getResultType())
2957 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2958
2959 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2960 NewTL.setLParenLoc(TL.getLParenLoc());
2961 NewTL.setRParenLoc(TL.getRParenLoc());
2962
2963 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002964}
Mike Stump11289f42009-09-09 15:08:12 +00002965
John McCallb96ec562009-12-04 22:46:56 +00002966template<typename Derived> QualType
2967TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002968 UnresolvedUsingTypeLoc TL,
2969 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002970 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002971 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002972 if (!D)
2973 return QualType();
2974
2975 QualType Result = TL.getType();
2976 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2977 Result = getDerived().RebuildUnresolvedUsingType(D);
2978 if (Result.isNull())
2979 return QualType();
2980 }
2981
2982 // We might get an arbitrary type spec type back. We should at
2983 // least always get a type spec type, though.
2984 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2985 NewTL.setNameLoc(TL.getNameLoc());
2986
2987 return Result;
2988}
2989
Douglas Gregord6ff3322009-08-04 16:50:30 +00002990template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002991QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002992 TypedefTypeLoc TL,
2993 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002994 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002996 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2997 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002998 if (!Typedef)
2999 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003000
John McCall550e0c22009-10-21 00:40:46 +00003001 QualType Result = TL.getType();
3002 if (getDerived().AlwaysRebuild() ||
3003 Typedef != T->getDecl()) {
3004 Result = getDerived().RebuildTypedefType(Typedef);
3005 if (Result.isNull())
3006 return QualType();
3007 }
Mike Stump11289f42009-09-09 15:08:12 +00003008
John McCall550e0c22009-10-21 00:40:46 +00003009 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3010 NewTL.setNameLoc(TL.getNameLoc());
3011
3012 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013}
Mike Stump11289f42009-09-09 15:08:12 +00003014
Douglas Gregord6ff3322009-08-04 16:50:30 +00003015template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003016QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003017 TypeOfExprTypeLoc TL,
3018 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003019 // typeof expressions are not potentially evaluated contexts
3020 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003021
John McCalle8595032010-01-13 20:03:27 +00003022 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003023 if (E.isInvalid())
3024 return QualType();
3025
John McCall550e0c22009-10-21 00:40:46 +00003026 QualType Result = TL.getType();
3027 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003028 E.get() != TL.getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003029 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003030 if (Result.isNull())
3031 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003032 }
John McCall550e0c22009-10-21 00:40:46 +00003033 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003034
John McCall550e0c22009-10-21 00:40:46 +00003035 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003036 NewTL.setTypeofLoc(TL.getTypeofLoc());
3037 NewTL.setLParenLoc(TL.getLParenLoc());
3038 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003039
3040 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003041}
Mike Stump11289f42009-09-09 15:08:12 +00003042
3043template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003044QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003045 TypeOfTypeLoc TL,
3046 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003047 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3048 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3049 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003050 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003051
John McCall550e0c22009-10-21 00:40:46 +00003052 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003053 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3054 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003055 if (Result.isNull())
3056 return QualType();
3057 }
Mike Stump11289f42009-09-09 15:08:12 +00003058
John McCall550e0c22009-10-21 00:40:46 +00003059 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003060 NewTL.setTypeofLoc(TL.getTypeofLoc());
3061 NewTL.setLParenLoc(TL.getLParenLoc());
3062 NewTL.setRParenLoc(TL.getRParenLoc());
3063 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003064
3065 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003066}
Mike Stump11289f42009-09-09 15:08:12 +00003067
3068template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003069QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003070 DecltypeTypeLoc TL,
3071 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003072 DecltypeType *T = TL.getTypePtr();
3073
Douglas Gregore922c772009-08-04 22:27:00 +00003074 // decltype expressions are not potentially evaluated contexts
3075 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003076
Douglas Gregord6ff3322009-08-04 16:50:30 +00003077 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3078 if (E.isInvalid())
3079 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003080
John McCall550e0c22009-10-21 00:40:46 +00003081 QualType Result = TL.getType();
3082 if (getDerived().AlwaysRebuild() ||
3083 E.get() != T->getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003084 Result = getDerived().RebuildDecltypeType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003085 if (Result.isNull())
3086 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003087 }
John McCall550e0c22009-10-21 00:40:46 +00003088 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003089
John McCall550e0c22009-10-21 00:40:46 +00003090 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3091 NewTL.setNameLoc(TL.getNameLoc());
3092
3093 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003094}
3095
3096template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003097QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003098 RecordTypeLoc TL,
3099 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003100 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003101 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003102 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3103 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003104 if (!Record)
3105 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003106
John McCall550e0c22009-10-21 00:40:46 +00003107 QualType Result = TL.getType();
3108 if (getDerived().AlwaysRebuild() ||
3109 Record != T->getDecl()) {
3110 Result = getDerived().RebuildRecordType(Record);
3111 if (Result.isNull())
3112 return QualType();
3113 }
Mike Stump11289f42009-09-09 15:08:12 +00003114
John McCall550e0c22009-10-21 00:40:46 +00003115 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3116 NewTL.setNameLoc(TL.getNameLoc());
3117
3118 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003119}
Mike Stump11289f42009-09-09 15:08:12 +00003120
3121template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003122QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003123 EnumTypeLoc TL,
3124 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003125 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003126 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003127 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3128 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003129 if (!Enum)
3130 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003131
John McCall550e0c22009-10-21 00:40:46 +00003132 QualType Result = TL.getType();
3133 if (getDerived().AlwaysRebuild() ||
3134 Enum != T->getDecl()) {
3135 Result = getDerived().RebuildEnumType(Enum);
3136 if (Result.isNull())
3137 return QualType();
3138 }
Mike Stump11289f42009-09-09 15:08:12 +00003139
John McCall550e0c22009-10-21 00:40:46 +00003140 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3141 NewTL.setNameLoc(TL.getNameLoc());
3142
3143 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144}
John McCallfcc33b02009-09-05 00:15:47 +00003145
John McCalle78aac42010-03-10 03:28:59 +00003146template<typename Derived>
3147QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3148 TypeLocBuilder &TLB,
3149 InjectedClassNameTypeLoc TL,
3150 QualType ObjectType) {
3151 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3152 TL.getTypePtr()->getDecl());
3153 if (!D) return QualType();
3154
3155 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3156 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3157 return T;
3158}
3159
Mike Stump11289f42009-09-09 15:08:12 +00003160
Douglas Gregord6ff3322009-08-04 16:50:30 +00003161template<typename Derived>
3162QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003163 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003164 TemplateTypeParmTypeLoc TL,
3165 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003166 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003167}
3168
Mike Stump11289f42009-09-09 15:08:12 +00003169template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003170QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003171 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003172 SubstTemplateTypeParmTypeLoc TL,
3173 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003174 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003175}
3176
3177template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003178QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3179 const TemplateSpecializationType *TST,
3180 QualType ObjectType) {
3181 // FIXME: this entire method is a temporary workaround; callers
3182 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003183
John McCall0ad16662009-10-29 08:12:44 +00003184 // Fake up a TemplateSpecializationTypeLoc.
3185 TypeLocBuilder TLB;
3186 TemplateSpecializationTypeLoc TL
3187 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3188
John McCall0d07eb32009-10-29 18:45:58 +00003189 SourceLocation BaseLoc = getDerived().getBaseLocation();
3190
3191 TL.setTemplateNameLoc(BaseLoc);
3192 TL.setLAngleLoc(BaseLoc);
3193 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003194 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3195 const TemplateArgument &TA = TST->getArg(i);
3196 TemplateArgumentLoc TAL;
3197 getDerived().InventTemplateArgumentLoc(TA, TAL);
3198 TL.setArgLocInfo(i, TAL.getLocInfo());
3199 }
3200
3201 TypeLocBuilder IgnoredTLB;
3202 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003203}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003204
Douglas Gregorc59e5612009-10-19 22:04:39 +00003205template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003206QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003207 TypeLocBuilder &TLB,
3208 TemplateSpecializationTypeLoc TL,
3209 QualType ObjectType) {
3210 const TemplateSpecializationType *T = TL.getTypePtr();
3211
Mike Stump11289f42009-09-09 15:08:12 +00003212 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003213 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003214 if (Template.isNull())
3215 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003216
John McCall6b51f282009-11-23 01:53:49 +00003217 TemplateArgumentListInfo NewTemplateArgs;
3218 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3219 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3220
3221 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3222 TemplateArgumentLoc Loc;
3223 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003224 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003225 NewTemplateArgs.addArgument(Loc);
3226 }
Mike Stump11289f42009-09-09 15:08:12 +00003227
John McCall0ad16662009-10-29 08:12:44 +00003228 // FIXME: maybe don't rebuild if all the template arguments are the same.
3229
3230 QualType Result =
3231 getDerived().RebuildTemplateSpecializationType(Template,
3232 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003233 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003234
3235 if (!Result.isNull()) {
3236 TemplateSpecializationTypeLoc NewTL
3237 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3238 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3239 NewTL.setLAngleLoc(TL.getLAngleLoc());
3240 NewTL.setRAngleLoc(TL.getRAngleLoc());
3241 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3242 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003243 }
Mike Stump11289f42009-09-09 15:08:12 +00003244
John McCall0ad16662009-10-29 08:12:44 +00003245 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003246}
Mike Stump11289f42009-09-09 15:08:12 +00003247
3248template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003249QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003250TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3251 ElaboratedTypeLoc TL,
3252 QualType ObjectType) {
3253 ElaboratedType *T = TL.getTypePtr();
3254
3255 NestedNameSpecifier *NNS = 0;
3256 // NOTE: the qualifier in an ElaboratedType is optional.
3257 if (T->getQualifier() != 0) {
3258 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003259 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003260 ObjectType);
3261 if (!NNS)
3262 return QualType();
3263 }
Mike Stump11289f42009-09-09 15:08:12 +00003264
Abramo Bagnarad7548482010-05-19 21:37:53 +00003265 QualType NamedT;
3266 // FIXME: this test is meant to workaround a problem (failing assertion)
3267 // occurring if directly executing the code in the else branch.
3268 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3269 TemplateSpecializationTypeLoc OldNamedTL
3270 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3271 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003272 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003273 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3274 if (NamedT.isNull())
3275 return QualType();
3276 TemplateSpecializationTypeLoc NewNamedTL
3277 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3278 NewNamedTL.copy(OldNamedTL);
3279 }
3280 else {
3281 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3282 if (NamedT.isNull())
3283 return QualType();
3284 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003285
John McCall550e0c22009-10-21 00:40:46 +00003286 QualType Result = TL.getType();
3287 if (getDerived().AlwaysRebuild() ||
3288 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003289 NamedT != T->getNamedType()) {
3290 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003291 if (Result.isNull())
3292 return QualType();
3293 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003294
Abramo Bagnara6150c882010-05-11 21:36:43 +00003295 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003296 NewTL.setKeywordLoc(TL.getKeywordLoc());
3297 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003298
3299 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300}
Mike Stump11289f42009-09-09 15:08:12 +00003301
3302template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003303QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3304 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003305 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003306 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003307
Douglas Gregord6ff3322009-08-04 16:50:30 +00003308 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003309 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3310 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003311 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003312 if (!NNS)
3313 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003314
John McCallc392f372010-06-11 00:33:02 +00003315 QualType Result
3316 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3317 T->getIdentifier(),
3318 TL.getKeywordLoc(),
3319 TL.getQualifierRange(),
3320 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003321 if (Result.isNull())
3322 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323
Abramo Bagnarad7548482010-05-19 21:37:53 +00003324 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3325 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003326 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3327
Abramo Bagnarad7548482010-05-19 21:37:53 +00003328 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3329 NewTL.setKeywordLoc(TL.getKeywordLoc());
3330 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003331 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003332 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3333 NewTL.setKeywordLoc(TL.getKeywordLoc());
3334 NewTL.setQualifierRange(TL.getQualifierRange());
3335 NewTL.setNameLoc(TL.getNameLoc());
3336 }
John McCall550e0c22009-10-21 00:40:46 +00003337 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338}
Mike Stump11289f42009-09-09 15:08:12 +00003339
Douglas Gregord6ff3322009-08-04 16:50:30 +00003340template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003341QualType TreeTransform<Derived>::
3342 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3343 DependentTemplateSpecializationTypeLoc TL,
3344 QualType ObjectType) {
3345 DependentTemplateSpecializationType *T = TL.getTypePtr();
3346
3347 NestedNameSpecifier *NNS
3348 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3349 TL.getQualifierRange(),
3350 ObjectType);
3351 if (!NNS)
3352 return QualType();
3353
3354 TemplateArgumentListInfo NewTemplateArgs;
3355 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3356 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3357
3358 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3359 TemplateArgumentLoc Loc;
3360 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3361 return QualType();
3362 NewTemplateArgs.addArgument(Loc);
3363 }
3364
3365 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3366 T->getKeyword(),
3367 NNS,
3368 T->getIdentifier(),
3369 TL.getNameLoc(),
3370 NewTemplateArgs);
3371 if (Result.isNull())
3372 return QualType();
3373
3374 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3375 QualType NamedT = ElabT->getNamedType();
3376
3377 // Copy information relevant to the template specialization.
3378 TemplateSpecializationTypeLoc NamedTL
3379 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3380 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3381 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3382 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3383 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3384
3385 // Copy information relevant to the elaborated type.
3386 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3387 NewTL.setKeywordLoc(TL.getKeywordLoc());
3388 NewTL.setQualifierRange(TL.getQualifierRange());
3389 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003390 TypeLoc NewTL(Result, TL.getOpaqueData());
3391 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003392 }
3393 return Result;
3394}
3395
3396template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003397QualType
3398TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003399 ObjCInterfaceTypeLoc TL,
3400 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003401 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003402 TLB.pushFullCopy(TL);
3403 return TL.getType();
3404}
3405
3406template<typename Derived>
3407QualType
3408TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3409 ObjCObjectTypeLoc TL,
3410 QualType ObjectType) {
3411 // ObjCObjectType is never dependent.
3412 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003413 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003414}
Mike Stump11289f42009-09-09 15:08:12 +00003415
3416template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003417QualType
3418TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003419 ObjCObjectPointerTypeLoc TL,
3420 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003421 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003422 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003423 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003424}
3425
Douglas Gregord6ff3322009-08-04 16:50:30 +00003426//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003427// Statement transformation
3428//===----------------------------------------------------------------------===//
3429template<typename Derived>
3430Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003431TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3432 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003433}
3434
3435template<typename Derived>
3436Sema::OwningStmtResult
3437TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3438 return getDerived().TransformCompoundStmt(S, false);
3439}
3440
3441template<typename Derived>
3442Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003443TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003444 bool IsStmtExpr) {
3445 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003446 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003447 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3448 B != BEnd; ++B) {
3449 OwningStmtResult Result = getDerived().TransformStmt(*B);
3450 if (Result.isInvalid())
3451 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003452
Douglas Gregorebe10102009-08-20 07:17:43 +00003453 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3454 Statements.push_back(Result.takeAs<Stmt>());
3455 }
Mike Stump11289f42009-09-09 15:08:12 +00003456
Douglas Gregorebe10102009-08-20 07:17:43 +00003457 if (!getDerived().AlwaysRebuild() &&
3458 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003459 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003460
3461 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3462 move_arg(Statements),
3463 S->getRBracLoc(),
3464 IsStmtExpr);
3465}
Mike Stump11289f42009-09-09 15:08:12 +00003466
Douglas Gregorebe10102009-08-20 07:17:43 +00003467template<typename Derived>
3468Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003469TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall37ad5512010-08-23 06:44:23 +00003470 OwningExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003471 {
3472 // The case value expressions are not potentially evaluated.
3473 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003474
Eli Friedman06577382009-11-19 03:14:00 +00003475 // Transform the left-hand case value.
3476 LHS = getDerived().TransformExpr(S->getLHS());
3477 if (LHS.isInvalid())
3478 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003479
Eli Friedman06577382009-11-19 03:14:00 +00003480 // Transform the right-hand case value (for the GNU case-range extension).
3481 RHS = getDerived().TransformExpr(S->getRHS());
3482 if (RHS.isInvalid())
3483 return SemaRef.StmtError();
3484 }
Mike Stump11289f42009-09-09 15:08:12 +00003485
Douglas Gregorebe10102009-08-20 07:17:43 +00003486 // Build the case statement.
3487 // Case statements are always rebuilt so that they will attached to their
3488 // transformed switch statement.
3489 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003490 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003491 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003492 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003493 S->getColonLoc());
3494 if (Case.isInvalid())
3495 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003496
Douglas Gregorebe10102009-08-20 07:17:43 +00003497 // Transform the statement following the case
3498 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3499 if (SubStmt.isInvalid())
3500 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003501
Douglas Gregorebe10102009-08-20 07:17:43 +00003502 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003503 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003504}
3505
3506template<typename Derived>
3507Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003508TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003509 // Transform the statement following the default case
3510 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3511 if (SubStmt.isInvalid())
3512 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003513
Douglas Gregorebe10102009-08-20 07:17:43 +00003514 // Default statements are always rebuilt
3515 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003516 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003517}
Mike Stump11289f42009-09-09 15:08:12 +00003518
Douglas Gregorebe10102009-08-20 07:17:43 +00003519template<typename Derived>
3520Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003521TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003522 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3523 if (SubStmt.isInvalid())
3524 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003525
Douglas Gregorebe10102009-08-20 07:17:43 +00003526 // FIXME: Pass the real colon location in.
3527 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3528 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00003529 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003530}
Mike Stump11289f42009-09-09 15:08:12 +00003531
Douglas Gregorebe10102009-08-20 07:17:43 +00003532template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003533Sema::OwningStmtResult
3534TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003535 // Transform the condition
John McCall37ad5512010-08-23 06:44:23 +00003536 OwningExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003537 VarDecl *ConditionVar = 0;
3538 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003539 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003540 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003541 getDerived().TransformDefinition(
3542 S->getConditionVariable()->getLocation(),
3543 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003544 if (!ConditionVar)
3545 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003546 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003547 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003548
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003549 if (Cond.isInvalid())
3550 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003551
3552 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003553 if (S->getCond()) {
3554 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3555 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003556 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003557 if (CondE.isInvalid())
3558 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003559
John McCallb268a282010-08-23 23:25:46 +00003560 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003561 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003562 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003563
John McCallb268a282010-08-23 23:25:46 +00003564 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3565 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003566 return SemaRef.StmtError();
3567
Douglas Gregorebe10102009-08-20 07:17:43 +00003568 // Transform the "then" branch.
3569 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3570 if (Then.isInvalid())
3571 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003572
Douglas Gregorebe10102009-08-20 07:17:43 +00003573 // Transform the "else" branch.
3574 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3575 if (Else.isInvalid())
3576 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003577
Douglas Gregorebe10102009-08-20 07:17:43 +00003578 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003579 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003580 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003581 Then.get() == S->getThen() &&
3582 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003583 return SemaRef.Owned(S->Retain());
3584
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003585 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003586 Then.get(),
3587 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003588}
3589
3590template<typename Derived>
3591Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003592TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003593 // Transform the condition.
John McCall37ad5512010-08-23 06:44:23 +00003594 OwningExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003595 VarDecl *ConditionVar = 0;
3596 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003597 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003598 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003599 getDerived().TransformDefinition(
3600 S->getConditionVariable()->getLocation(),
3601 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003602 if (!ConditionVar)
3603 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003604 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003605 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003606
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003607 if (Cond.isInvalid())
3608 return SemaRef.StmtError();
3609 }
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003612 OwningStmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003613 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003614 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003615 if (Switch.isInvalid())
3616 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003617
Douglas Gregorebe10102009-08-20 07:17:43 +00003618 // Transform the body of the switch statement.
3619 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3620 if (Body.isInvalid())
3621 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003622
Douglas Gregorebe10102009-08-20 07:17:43 +00003623 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003624 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3625 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003626}
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregorebe10102009-08-20 07:17:43 +00003628template<typename Derived>
3629Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003630TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003631 // Transform the condition
John McCall37ad5512010-08-23 06:44:23 +00003632 OwningExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003633 VarDecl *ConditionVar = 0;
3634 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003635 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003636 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003637 getDerived().TransformDefinition(
3638 S->getConditionVariable()->getLocation(),
3639 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003640 if (!ConditionVar)
3641 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003642 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003643 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003644
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003645 if (Cond.isInvalid())
3646 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003647
3648 if (S->getCond()) {
3649 // Convert the condition to a boolean value.
3650 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003651 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003652 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003653 if (CondE.isInvalid())
3654 return getSema().StmtError();
John McCallb268a282010-08-23 23:25:46 +00003655 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003656 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003657 }
Mike Stump11289f42009-09-09 15:08:12 +00003658
John McCallb268a282010-08-23 23:25:46 +00003659 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3660 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003661 return SemaRef.StmtError();
3662
Douglas Gregorebe10102009-08-20 07:17:43 +00003663 // Transform the body
3664 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3665 if (Body.isInvalid())
3666 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregorebe10102009-08-20 07:17:43 +00003668 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003669 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003670 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003671 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003672 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003674 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003675 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003676}
Mike Stump11289f42009-09-09 15:08:12 +00003677
Douglas Gregorebe10102009-08-20 07:17:43 +00003678template<typename Derived>
3679Sema::OwningStmtResult
3680TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 // Transform the body
3682 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3683 if (Body.isInvalid())
3684 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003685
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003686 // Transform the condition
3687 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3688 if (Cond.isInvalid())
3689 return SemaRef.StmtError();
3690
Douglas Gregorebe10102009-08-20 07:17:43 +00003691 if (!getDerived().AlwaysRebuild() &&
3692 Cond.get() == S->getCond() &&
3693 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003694 return SemaRef.Owned(S->Retain());
3695
John McCallb268a282010-08-23 23:25:46 +00003696 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3697 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003698 S->getRParenLoc());
3699}
Mike Stump11289f42009-09-09 15:08:12 +00003700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701template<typename Derived>
3702Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003703TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 // Transform the initialization statement
3705 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3706 if (Init.isInvalid())
3707 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003708
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 // Transform the condition
John McCall37ad5512010-08-23 06:44:23 +00003710 OwningExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003711 VarDecl *ConditionVar = 0;
3712 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003713 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003714 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003715 getDerived().TransformDefinition(
3716 S->getConditionVariable()->getLocation(),
3717 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003718 if (!ConditionVar)
3719 return SemaRef.StmtError();
3720 } else {
3721 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003722
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003723 if (Cond.isInvalid())
3724 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003725
3726 if (S->getCond()) {
3727 // Convert the condition to a boolean value.
3728 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3729 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003730 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003731 if (CondE.isInvalid())
3732 return getSema().StmtError();
3733
John McCallb268a282010-08-23 23:25:46 +00003734 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003735 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003736 }
Mike Stump11289f42009-09-09 15:08:12 +00003737
John McCallb268a282010-08-23 23:25:46 +00003738 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3739 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003740 return SemaRef.StmtError();
3741
Douglas Gregorebe10102009-08-20 07:17:43 +00003742 // Transform the increment
3743 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3744 if (Inc.isInvalid())
3745 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003746
John McCallb268a282010-08-23 23:25:46 +00003747 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3748 if (S->getInc() && !FullInc.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003749 return SemaRef.StmtError();
3750
Douglas Gregorebe10102009-08-20 07:17:43 +00003751 // Transform the body
3752 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3753 if (Body.isInvalid())
3754 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003755
Douglas Gregorebe10102009-08-20 07:17:43 +00003756 if (!getDerived().AlwaysRebuild() &&
3757 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003758 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003759 Inc.get() == S->getInc() &&
3760 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003761 return SemaRef.Owned(S->Retain());
3762
Douglas Gregorebe10102009-08-20 07:17:43 +00003763 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003764 Init.get(), FullCond, ConditionVar,
3765 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003766}
3767
3768template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003769Sema::OwningStmtResult
3770TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003771 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003772 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003773 S->getLabel());
3774}
3775
3776template<typename Derived>
3777Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003778TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003779 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3780 if (Target.isInvalid())
3781 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003782
Douglas Gregorebe10102009-08-20 07:17:43 +00003783 if (!getDerived().AlwaysRebuild() &&
3784 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003785 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003786
3787 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003788 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003789}
3790
3791template<typename Derived>
3792Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003793TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3794 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003795}
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregorebe10102009-08-20 07:17:43 +00003797template<typename Derived>
3798Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003799TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3800 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003801}
Mike Stump11289f42009-09-09 15:08:12 +00003802
Douglas Gregorebe10102009-08-20 07:17:43 +00003803template<typename Derived>
3804Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003805TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003806 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3807 if (Result.isInvalid())
3808 return SemaRef.StmtError();
3809
Mike Stump11289f42009-09-09 15:08:12 +00003810 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003811 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003812 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003813}
Mike Stump11289f42009-09-09 15:08:12 +00003814
Douglas Gregorebe10102009-08-20 07:17:43 +00003815template<typename Derived>
3816Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003817TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003818 bool DeclChanged = false;
3819 llvm::SmallVector<Decl *, 4> Decls;
3820 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3821 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003822 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3823 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003824 if (!Transformed)
3825 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003826
Douglas Gregorebe10102009-08-20 07:17:43 +00003827 if (Transformed != *D)
3828 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003829
Douglas Gregorebe10102009-08-20 07:17:43 +00003830 Decls.push_back(Transformed);
3831 }
Mike Stump11289f42009-09-09 15:08:12 +00003832
Douglas Gregorebe10102009-08-20 07:17:43 +00003833 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003834 return SemaRef.Owned(S->Retain());
3835
3836 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003837 S->getStartLoc(), S->getEndLoc());
3838}
Mike Stump11289f42009-09-09 15:08:12 +00003839
Douglas Gregorebe10102009-08-20 07:17:43 +00003840template<typename Derived>
3841Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003842TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003843 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003844 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003845}
3846
3847template<typename Derived>
3848Sema::OwningStmtResult
3849TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003850
John McCall37ad5512010-08-23 06:44:23 +00003851 ASTOwningVector<Expr*> Constraints(getSema());
3852 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003853 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003854
John McCall37ad5512010-08-23 06:44:23 +00003855 OwningExprResult AsmString;
3856 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003857
3858 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003859
Anders Carlssonaaeef072010-01-24 05:50:09 +00003860 // Go through the outputs.
3861 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003862 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003863
Anders Carlssonaaeef072010-01-24 05:50:09 +00003864 // No need to transform the constraint literal.
3865 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003866
Anders Carlssonaaeef072010-01-24 05:50:09 +00003867 // Transform the output expr.
3868 Expr *OutputExpr = S->getOutputExpr(I);
3869 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3870 if (Result.isInvalid())
3871 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003872
Anders Carlssonaaeef072010-01-24 05:50:09 +00003873 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003874
John McCallb268a282010-08-23 23:25:46 +00003875 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003876 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003877
Anders Carlssonaaeef072010-01-24 05:50:09 +00003878 // Go through the inputs.
3879 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003880 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003881
Anders Carlssonaaeef072010-01-24 05:50:09 +00003882 // No need to transform the constraint literal.
3883 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003884
Anders Carlssonaaeef072010-01-24 05:50:09 +00003885 // Transform the input expr.
3886 Expr *InputExpr = S->getInputExpr(I);
3887 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3888 if (Result.isInvalid())
3889 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003890
Anders Carlssonaaeef072010-01-24 05:50:09 +00003891 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003892
John McCallb268a282010-08-23 23:25:46 +00003893 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003894 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003895
Anders Carlssonaaeef072010-01-24 05:50:09 +00003896 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3897 return SemaRef.Owned(S->Retain());
3898
3899 // Go through the clobbers.
3900 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3901 Clobbers.push_back(S->getClobber(I)->Retain());
3902
3903 // No need to transform the asm string literal.
3904 AsmString = SemaRef.Owned(S->getAsmString());
3905
3906 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3907 S->isSimple(),
3908 S->isVolatile(),
3909 S->getNumOutputs(),
3910 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003911 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003912 move_arg(Constraints),
3913 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003914 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003915 move_arg(Clobbers),
3916 S->getRParenLoc(),
3917 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003918}
3919
3920
3921template<typename Derived>
3922Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003923TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003924 // Transform the body of the @try.
3925 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3926 if (TryBody.isInvalid())
3927 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003928
Douglas Gregor96c79492010-04-23 22:50:49 +00003929 // Transform the @catch statements (if present).
3930 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003931 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00003932 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3933 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003934 if (Catch.isInvalid())
3935 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003936 if (Catch.get() != S->getCatchStmt(I))
3937 AnyCatchChanged = true;
3938 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003939 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003940
Douglas Gregor306de2f2010-04-22 23:59:56 +00003941 // Transform the @finally statement (if present).
John McCall37ad5512010-08-23 06:44:23 +00003942 OwningStmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00003943 if (S->getFinallyStmt()) {
3944 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3945 if (Finally.isInvalid())
3946 return SemaRef.StmtError();
3947 }
3948
3949 // If nothing changed, just retain this statement.
3950 if (!getDerived().AlwaysRebuild() &&
3951 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003952 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003953 Finally.get() == S->getFinallyStmt())
3954 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003955
Douglas Gregor306de2f2010-04-22 23:59:56 +00003956 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00003957 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3958 move_arg(CatchStmts), Finally.get());
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>
3962Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003963TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003964 // Transform the @catch parameter, if there is one.
3965 VarDecl *Var = 0;
3966 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3967 TypeSourceInfo *TSInfo = 0;
3968 if (FromVar->getTypeSourceInfo()) {
3969 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3970 if (!TSInfo)
3971 return SemaRef.StmtError();
3972 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003973
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003974 QualType T;
3975 if (TSInfo)
3976 T = TSInfo->getType();
3977 else {
3978 T = getDerived().TransformType(FromVar->getType());
3979 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003980 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003981 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003982
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003983 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3984 if (!Var)
3985 return SemaRef.StmtError();
3986 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003987
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003988 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3989 if (Body.isInvalid())
3990 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003991
3992 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003993 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003994 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003995}
Mike Stump11289f42009-09-09 15:08:12 +00003996
Douglas Gregorebe10102009-08-20 07:17:43 +00003997template<typename Derived>
3998Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003999TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004000 // Transform the body.
4001 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4002 if (Body.isInvalid())
4003 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004004
Douglas Gregor306de2f2010-04-22 23:59:56 +00004005 // If nothing changed, just retain this statement.
4006 if (!getDerived().AlwaysRebuild() &&
4007 Body.get() == S->getFinallyBody())
4008 return SemaRef.Owned(S->Retain());
4009
4010 // Build a new statement.
4011 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004012 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004013}
Mike Stump11289f42009-09-09 15:08:12 +00004014
Douglas Gregorebe10102009-08-20 07:17:43 +00004015template<typename Derived>
4016Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004017TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall37ad5512010-08-23 06:44:23 +00004018 OwningExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004019 if (S->getThrowExpr()) {
4020 Operand = getDerived().TransformExpr(S->getThrowExpr());
4021 if (Operand.isInvalid())
4022 return getSema().StmtError();
4023 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004024
Douglas Gregor2900c162010-04-22 21:44:01 +00004025 if (!getDerived().AlwaysRebuild() &&
4026 Operand.get() == S->getThrowExpr())
4027 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004028
John McCallb268a282010-08-23 23:25:46 +00004029 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004030}
Mike Stump11289f42009-09-09 15:08:12 +00004031
Douglas Gregorebe10102009-08-20 07:17:43 +00004032template<typename Derived>
4033Sema::OwningStmtResult
4034TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004035 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004036 // Transform the object we are locking.
4037 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4038 if (Object.isInvalid())
4039 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004040
Douglas Gregor6148de72010-04-22 22:01:21 +00004041 // Transform the body.
4042 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4043 if (Body.isInvalid())
4044 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004045
Douglas Gregor6148de72010-04-22 22:01:21 +00004046 // If nothing change, just retain the current statement.
4047 if (!getDerived().AlwaysRebuild() &&
4048 Object.get() == S->getSynchExpr() &&
4049 Body.get() == S->getSynchBody())
4050 return SemaRef.Owned(S->Retain());
4051
4052 // Build a new statement.
4053 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004054 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004055}
4056
4057template<typename Derived>
4058Sema::OwningStmtResult
4059TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004060 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004061 // Transform the element statement.
4062 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4063 if (Element.isInvalid())
4064 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004065
Douglas Gregorf68a5082010-04-22 23:10:45 +00004066 // Transform the collection expression.
4067 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4068 if (Collection.isInvalid())
4069 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004070
Douglas Gregorf68a5082010-04-22 23:10:45 +00004071 // Transform the body.
4072 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4073 if (Body.isInvalid())
4074 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004075
Douglas Gregorf68a5082010-04-22 23:10:45 +00004076 // If nothing changed, just retain this statement.
4077 if (!getDerived().AlwaysRebuild() &&
4078 Element.get() == S->getElement() &&
4079 Collection.get() == S->getCollection() &&
4080 Body.get() == S->getBody())
4081 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004082
Douglas Gregorf68a5082010-04-22 23:10:45 +00004083 // Build a new statement.
4084 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4085 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004086 Element.get(),
4087 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004088 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004089 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004090}
4091
4092
4093template<typename Derived>
4094Sema::OwningStmtResult
4095TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4096 // Transform the exception declaration, if any.
4097 VarDecl *Var = 0;
4098 if (S->getExceptionDecl()) {
4099 VarDecl *ExceptionDecl = S->getExceptionDecl();
4100 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4101 ExceptionDecl->getDeclName());
4102
4103 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4104 if (T.isNull())
4105 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004106
Douglas Gregorebe10102009-08-20 07:17:43 +00004107 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4108 T,
John McCallbcd03502009-12-07 02:54:59 +00004109 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004110 ExceptionDecl->getIdentifier(),
4111 ExceptionDecl->getLocation(),
4112 /*FIXME: Inaccurate*/
4113 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004114 if (!Var || Var->isInvalidDecl())
Douglas Gregorebe10102009-08-20 07:17:43 +00004115 return SemaRef.StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004116 }
Mike Stump11289f42009-09-09 15:08:12 +00004117
Douglas Gregorebe10102009-08-20 07:17:43 +00004118 // Transform the actual exception handler.
4119 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004120 if (Handler.isInvalid())
Douglas Gregorebe10102009-08-20 07:17:43 +00004121 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004122
Douglas Gregorebe10102009-08-20 07:17:43 +00004123 if (!getDerived().AlwaysRebuild() &&
4124 !Var &&
4125 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004126 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004127
4128 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4129 Var,
John McCallb268a282010-08-23 23:25:46 +00004130 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004131}
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregorebe10102009-08-20 07:17:43 +00004133template<typename Derived>
4134Sema::OwningStmtResult
4135TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4136 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004137 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004138 = getDerived().TransformCompoundStmt(S->getTryBlock());
4139 if (TryBlock.isInvalid())
4140 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004141
Douglas Gregorebe10102009-08-20 07:17:43 +00004142 // Transform the handlers.
4143 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004144 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004145 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004146 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004147 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4148 if (Handler.isInvalid())
4149 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004150
Douglas Gregorebe10102009-08-20 07:17:43 +00004151 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4152 Handlers.push_back(Handler.takeAs<Stmt>());
4153 }
Mike Stump11289f42009-09-09 15:08:12 +00004154
Douglas Gregorebe10102009-08-20 07:17:43 +00004155 if (!getDerived().AlwaysRebuild() &&
4156 TryBlock.get() == S->getTryBlock() &&
4157 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004158 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004159
John McCallb268a282010-08-23 23:25:46 +00004160 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004161 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004162}
Mike Stump11289f42009-09-09 15:08:12 +00004163
Douglas Gregorebe10102009-08-20 07:17:43 +00004164//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004165// Expression transformation
4166//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004167template<typename Derived>
4168Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004169TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004170 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004171}
Mike Stump11289f42009-09-09 15:08:12 +00004172
4173template<typename Derived>
4174Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004175TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004176 NestedNameSpecifier *Qualifier = 0;
4177 if (E->getQualifier()) {
4178 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004179 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004180 if (!Qualifier)
4181 return SemaRef.ExprError();
4182 }
John McCallce546572009-12-08 09:08:17 +00004183
4184 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004185 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4186 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004187 if (!ND)
4188 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004189
John McCall815039a2010-08-17 21:27:17 +00004190 DeclarationNameInfo NameInfo = E->getNameInfo();
4191 if (NameInfo.getName()) {
4192 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4193 if (!NameInfo.getName())
4194 return SemaRef.ExprError();
4195 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004196
4197 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004198 Qualifier == E->getQualifier() &&
4199 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004200 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004201 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004202
4203 // Mark it referenced in the new context regardless.
4204 // FIXME: this is a bit instantiation-specific.
4205 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4206
Mike Stump11289f42009-09-09 15:08:12 +00004207 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004208 }
John McCallce546572009-12-08 09:08:17 +00004209
4210 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004211 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004212 TemplateArgs = &TransArgs;
4213 TransArgs.setLAngleLoc(E->getLAngleLoc());
4214 TransArgs.setRAngleLoc(E->getRAngleLoc());
4215 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4216 TemplateArgumentLoc Loc;
4217 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4218 return SemaRef.ExprError();
4219 TransArgs.addArgument(Loc);
4220 }
4221 }
4222
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004223 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004224 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004225}
Mike Stump11289f42009-09-09 15:08:12 +00004226
Douglas Gregora16548e2009-08-11 05:31:07 +00004227template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004228Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004229TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004230 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
Douglas Gregora16548e2009-08-11 05:31:07 +00004233template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004234Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004235TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004236 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004237}
Mike Stump11289f42009-09-09 15:08:12 +00004238
Douglas Gregora16548e2009-08-11 05:31:07 +00004239template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004240Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004241TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004242 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004243}
Mike Stump11289f42009-09-09 15:08:12 +00004244
Douglas Gregora16548e2009-08-11 05:31:07 +00004245template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004246Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004247TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004248 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004249}
Mike Stump11289f42009-09-09 15:08:12 +00004250
Douglas Gregora16548e2009-08-11 05:31:07 +00004251template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004252Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004253TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004254 return SemaRef.Owned(E->Retain());
4255}
4256
4257template<typename Derived>
4258Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004259TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004260 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4261 if (SubExpr.isInvalid())
4262 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004263
Douglas Gregora16548e2009-08-11 05:31:07 +00004264 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004265 return SemaRef.Owned(E->Retain());
4266
John McCallb268a282010-08-23 23:25:46 +00004267 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004268 E->getRParen());
4269}
4270
Mike Stump11289f42009-09-09 15:08:12 +00004271template<typename Derived>
4272Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004273TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4274 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004275 if (SubExpr.isInvalid())
4276 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004277
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004279 return SemaRef.Owned(E->Retain());
4280
Douglas Gregora16548e2009-08-11 05:31:07 +00004281 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4282 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004283 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004284}
Mike Stump11289f42009-09-09 15:08:12 +00004285
Douglas Gregora16548e2009-08-11 05:31:07 +00004286template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004287Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004288TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4289 // Transform the type.
4290 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4291 if (!Type)
4292 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004293
Douglas Gregor882211c2010-04-28 22:16:22 +00004294 // Transform all of the components into components similar to what the
4295 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004296 // FIXME: It would be slightly more efficient in the non-dependent case to
4297 // just map FieldDecls, rather than requiring the rebuilder to look for
4298 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004299 // template code that we don't care.
4300 bool ExprChanged = false;
4301 typedef Action::OffsetOfComponent Component;
4302 typedef OffsetOfExpr::OffsetOfNode Node;
4303 llvm::SmallVector<Component, 4> Components;
4304 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4305 const Node &ON = E->getComponent(I);
4306 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004307 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004308 Comp.LocStart = ON.getRange().getBegin();
4309 Comp.LocEnd = ON.getRange().getEnd();
4310 switch (ON.getKind()) {
4311 case Node::Array: {
4312 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4313 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4314 if (Index.isInvalid())
4315 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004316
Douglas Gregor882211c2010-04-28 22:16:22 +00004317 ExprChanged = ExprChanged || Index.get() != FromIndex;
4318 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004319 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004320 break;
4321 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004322
Douglas Gregor882211c2010-04-28 22:16:22 +00004323 case Node::Field:
4324 case Node::Identifier:
4325 Comp.isBrackets = false;
4326 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004327 if (!Comp.U.IdentInfo)
4328 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004329
Douglas Gregor882211c2010-04-28 22:16:22 +00004330 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004331
Douglas Gregord1702062010-04-29 00:18:15 +00004332 case Node::Base:
4333 // Will be recomputed during the rebuild.
4334 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004335 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004336
Douglas Gregor882211c2010-04-28 22:16:22 +00004337 Components.push_back(Comp);
4338 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004339
Douglas Gregor882211c2010-04-28 22:16:22 +00004340 // If nothing changed, retain the existing expression.
4341 if (!getDerived().AlwaysRebuild() &&
4342 Type == E->getTypeSourceInfo() &&
4343 !ExprChanged)
4344 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004345
Douglas Gregor882211c2010-04-28 22:16:22 +00004346 // Build a new offsetof expression.
4347 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4348 Components.data(), Components.size(),
4349 E->getRParenLoc());
4350}
4351
4352template<typename Derived>
4353Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004354TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004356 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004357
John McCallbcd03502009-12-07 02:54:59 +00004358 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004359 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004360 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004361
John McCall4c98fd82009-11-04 07:28:41 +00004362 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004363 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004364
John McCall4c98fd82009-11-04 07:28:41 +00004365 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004366 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 E->getSourceRange());
4368 }
Mike Stump11289f42009-09-09 15:08:12 +00004369
John McCall37ad5512010-08-23 06:44:23 +00004370 Sema::OwningExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004371 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 // C++0x [expr.sizeof]p1:
4373 // The operand is either an expression, which is an unevaluated operand
4374 // [...]
4375 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4378 if (SubExpr.isInvalid())
4379 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004380
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4382 return SemaRef.Owned(E->Retain());
4383 }
Mike Stump11289f42009-09-09 15:08:12 +00004384
John McCallb268a282010-08-23 23:25:46 +00004385 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 E->isSizeOf(),
4387 E->getSourceRange());
4388}
Mike Stump11289f42009-09-09 15:08:12 +00004389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004391Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004392TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4394 if (LHS.isInvalid())
4395 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4398 if (RHS.isInvalid())
4399 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004400
4401
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 if (!getDerived().AlwaysRebuild() &&
4403 LHS.get() == E->getLHS() &&
4404 RHS.get() == E->getRHS())
4405 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004406
John McCallb268a282010-08-23 23:25:46 +00004407 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004409 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004410 E->getRBracketLoc());
4411}
Mike Stump11289f42009-09-09 15:08:12 +00004412
4413template<typename Derived>
4414Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004415TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 // Transform the callee.
4417 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4418 if (Callee.isInvalid())
4419 return SemaRef.ExprError();
4420
4421 // Transform arguments.
4422 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004423 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004424 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4425 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4426 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4427 if (Arg.isInvalid())
4428 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 // FIXME: Wrong source location information for the ','.
4431 FakeCommaLocs.push_back(
4432 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004433
4434 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004435 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 }
Mike Stump11289f42009-09-09 15:08:12 +00004437
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 if (!getDerived().AlwaysRebuild() &&
4439 Callee.get() == E->getCallee() &&
4440 !ArgChanged)
4441 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004444 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004446 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004447 move_arg(Args),
4448 FakeCommaLocs.data(),
4449 E->getRParenLoc());
4450}
Mike Stump11289f42009-09-09 15:08:12 +00004451
4452template<typename Derived>
4453Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004454TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4456 if (Base.isInvalid())
4457 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004458
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004459 NestedNameSpecifier *Qualifier = 0;
4460 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004461 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004462 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004463 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004464 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004465 return SemaRef.ExprError();
4466 }
Mike Stump11289f42009-09-09 15:08:12 +00004467
Eli Friedman2cfcef62009-12-04 06:40:45 +00004468 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004469 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4470 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 if (!Member)
4472 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004473
John McCall16df1e52010-03-30 21:47:33 +00004474 NamedDecl *FoundDecl = E->getFoundDecl();
4475 if (FoundDecl == E->getMemberDecl()) {
4476 FoundDecl = Member;
4477 } else {
4478 FoundDecl = cast_or_null<NamedDecl>(
4479 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4480 if (!FoundDecl)
4481 return SemaRef.ExprError();
4482 }
4483
Douglas Gregora16548e2009-08-11 05:31:07 +00004484 if (!getDerived().AlwaysRebuild() &&
4485 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004486 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004487 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004488 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004489 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004490
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004491 // Mark it referenced in the new context regardless.
4492 // FIXME: this is a bit instantiation-specific.
4493 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004494 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004495 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004496
John McCall6b51f282009-11-23 01:53:49 +00004497 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004498 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004499 TransArgs.setLAngleLoc(E->getLAngleLoc());
4500 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004501 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004502 TemplateArgumentLoc Loc;
4503 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004504 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004505 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004506 }
4507 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004508
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 // FIXME: Bogus source location for the operator
4510 SourceLocation FakeOperatorLoc
4511 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4512
John McCall38836f02010-01-15 08:34:02 +00004513 // FIXME: to do this check properly, we will need to preserve the
4514 // first-qualifier-in-scope here, just in case we had a dependent
4515 // base (and therefore couldn't do the check) and a
4516 // nested-name-qualifier (and therefore could do the lookup).
4517 NamedDecl *FirstQualifierInScope = 0;
4518
John McCallb268a282010-08-23 23:25:46 +00004519 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004521 Qualifier,
4522 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004523 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004524 Member,
John McCall16df1e52010-03-30 21:47:33 +00004525 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004526 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004527 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004528 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004529}
Mike Stump11289f42009-09-09 15:08:12 +00004530
Douglas Gregora16548e2009-08-11 05:31:07 +00004531template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004532Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004533TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4535 if (LHS.isInvalid())
4536 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004537
Douglas Gregora16548e2009-08-11 05:31:07 +00004538 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4539 if (RHS.isInvalid())
4540 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregora16548e2009-08-11 05:31:07 +00004542 if (!getDerived().AlwaysRebuild() &&
4543 LHS.get() == E->getLHS() &&
4544 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004545 return SemaRef.Owned(E->Retain());
4546
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004548 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004549}
4550
Mike Stump11289f42009-09-09 15:08:12 +00004551template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004552Sema::OwningExprResult
4553TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004554 CompoundAssignOperator *E) {
4555 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004556}
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004559Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004560TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4562 if (Cond.isInvalid())
4563 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregora16548e2009-08-11 05:31:07 +00004565 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4566 if (LHS.isInvalid())
4567 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004568
Douglas Gregora16548e2009-08-11 05:31:07 +00004569 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4570 if (RHS.isInvalid())
4571 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004572
Douglas Gregora16548e2009-08-11 05:31:07 +00004573 if (!getDerived().AlwaysRebuild() &&
4574 Cond.get() == E->getCond() &&
4575 LHS.get() == E->getLHS() &&
4576 RHS.get() == E->getRHS())
4577 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004578
John McCallb268a282010-08-23 23:25:46 +00004579 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004580 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004581 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004582 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004583 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004584}
Mike Stump11289f42009-09-09 15:08:12 +00004585
4586template<typename Derived>
4587Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004588TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004589 // Implicit casts are eliminated during transformation, since they
4590 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004591 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004592}
Mike Stump11289f42009-09-09 15:08:12 +00004593
Douglas Gregora16548e2009-08-11 05:31:07 +00004594template<typename Derived>
4595Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004596TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004597 TypeSourceInfo *OldT;
4598 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004599 {
4600 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004601 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004602 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4603 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004604
John McCall97513962010-01-15 18:39:57 +00004605 OldT = E->getTypeInfoAsWritten();
4606 NewT = getDerived().TransformType(OldT);
4607 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004608 return SemaRef.ExprError();
4609 }
Mike Stump11289f42009-09-09 15:08:12 +00004610
Douglas Gregor6131b442009-12-12 18:16:41 +00004611 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004612 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004613 if (SubExpr.isInvalid())
4614 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004617 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004618 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004619 return SemaRef.Owned(E->Retain());
4620
John McCall97513962010-01-15 18:39:57 +00004621 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4622 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004624 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004625}
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregora16548e2009-08-11 05:31:07 +00004627template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004628Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004629TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004630 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4631 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4632 if (!NewT)
4633 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004634
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4636 if (Init.isInvalid())
4637 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004640 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004642 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004643
John McCall5d7aa7f2010-01-19 22:33:45 +00004644 // Note: the expression type doesn't necessarily match the
4645 // type-as-written, but that's okay, because it should always be
4646 // derivable from the initializer.
4647
John McCalle15bbff2010-01-18 19:35:47 +00004648 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004649 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004650 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004651}
Mike Stump11289f42009-09-09 15:08:12 +00004652
Douglas Gregora16548e2009-08-11 05:31:07 +00004653template<typename Derived>
4654Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004655TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004656 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4657 if (Base.isInvalid())
4658 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 if (!getDerived().AlwaysRebuild() &&
4661 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004662 return SemaRef.Owned(E->Retain());
4663
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004665 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004667 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 E->getAccessorLoc(),
4669 E->getAccessor());
4670}
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregora16548e2009-08-11 05:31:07 +00004672template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004673Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004674TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004676
John McCall37ad5512010-08-23 06:44:23 +00004677 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4679 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4680 if (Init.isInvalid())
4681 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004682
Douglas Gregora16548e2009-08-11 05:31:07 +00004683 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004684 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 }
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregora16548e2009-08-11 05:31:07 +00004687 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004688 return SemaRef.Owned(E->Retain());
4689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004691 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004692}
Mike Stump11289f42009-09-09 15:08:12 +00004693
Douglas Gregora16548e2009-08-11 05:31:07 +00004694template<typename Derived>
4695Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004696TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregorebe10102009-08-20 07:17:43 +00004699 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4701 if (Init.isInvalid())
4702 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregorebe10102009-08-20 07:17:43 +00004704 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004705 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 bool ExprChanged = false;
4707 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4708 DEnd = E->designators_end();
4709 D != DEnd; ++D) {
4710 if (D->isFieldDesignator()) {
4711 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4712 D->getDotLoc(),
4713 D->getFieldLoc()));
4714 continue;
4715 }
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 if (D->isArrayDesignator()) {
4718 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4719 if (Index.isInvalid())
4720 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004721
4722 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4726 ArrayExprs.push_back(Index.release());
4727 continue;
4728 }
Mike Stump11289f42009-09-09 15:08:12 +00004729
Douglas Gregora16548e2009-08-11 05:31:07 +00004730 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004731 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4733 if (Start.isInvalid())
4734 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004735
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4737 if (End.isInvalid())
4738 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004739
4740 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 End.get(),
4742 D->getLBracketLoc(),
4743 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004744
Douglas Gregora16548e2009-08-11 05:31:07 +00004745 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4746 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 ArrayExprs.push_back(Start.release());
4749 ArrayExprs.push_back(End.release());
4750 }
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 if (!getDerived().AlwaysRebuild() &&
4753 Init.get() == E->getInit() &&
4754 !ExprChanged)
4755 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004756
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4758 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004759 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004760}
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004763Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004764TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004765 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004766 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004767
Douglas Gregor3da3c062009-10-28 00:29:27 +00004768 // FIXME: Will we ever have proper type location here? Will we actually
4769 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 QualType T = getDerived().TransformType(E->getType());
4771 if (T.isNull())
4772 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregora16548e2009-08-11 05:31:07 +00004774 if (!getDerived().AlwaysRebuild() &&
4775 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004776 return SemaRef.Owned(E->Retain());
4777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 return getDerived().RebuildImplicitValueInitExpr(T);
4779}
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregora16548e2009-08-11 05:31:07 +00004781template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004782Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004783TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004784 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4785 if (!TInfo)
4786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4789 if (SubExpr.isInvalid())
4790 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004793 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 SubExpr.get() == E->getSubExpr())
4795 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004796
John McCallb268a282010-08-23 23:25:46 +00004797 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004798 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004799}
4800
4801template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004802Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004803TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004805 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4807 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4808 if (Init.isInvalid())
4809 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004812 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004813 }
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregora16548e2009-08-11 05:31:07 +00004815 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4816 move_arg(Inits),
4817 E->getRParenLoc());
4818}
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820/// \brief Transform an address-of-label expression.
4821///
4822/// By default, the transformation of an address-of-label expression always
4823/// rebuilds the expression, so that the label identifier can be resolved to
4824/// the corresponding label statement by semantic analysis.
4825template<typename Derived>
4826Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004827TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004828 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4829 E->getLabel());
4830}
Mike Stump11289f42009-09-09 15:08:12 +00004831
4832template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004833Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004834TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004835 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004836 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4837 if (SubStmt.isInvalid())
4838 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840 if (!getDerived().AlwaysRebuild() &&
4841 SubStmt.get() == E->getSubStmt())
4842 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004843
4844 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004845 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004846 E->getRParenLoc());
4847}
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregora16548e2009-08-11 05:31:07 +00004849template<typename Derived>
4850Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004851TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004852 TypeSourceInfo *TInfo1;
4853 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004854
4855 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4856 if (!TInfo1)
4857 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004858
Douglas Gregor7058c262010-08-10 14:27:00 +00004859 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4860 if (!TInfo2)
4861 return SemaRef.ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004862
4863 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004864 TInfo1 == E->getArgTInfo1() &&
4865 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004866 return SemaRef.Owned(E->Retain());
4867
Douglas Gregora16548e2009-08-11 05:31:07 +00004868 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004869 TInfo1, TInfo2,
4870 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004871}
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregora16548e2009-08-11 05:31:07 +00004873template<typename Derived>
4874Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004875TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004876 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4877 if (Cond.isInvalid())
4878 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004879
Douglas Gregora16548e2009-08-11 05:31:07 +00004880 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4881 if (LHS.isInvalid())
4882 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004883
Douglas Gregora16548e2009-08-11 05:31:07 +00004884 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4885 if (RHS.isInvalid())
4886 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004887
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 if (!getDerived().AlwaysRebuild() &&
4889 Cond.get() == E->getCond() &&
4890 LHS.get() == E->getLHS() &&
4891 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004892 return SemaRef.Owned(E->Retain());
4893
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004895 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 E->getRParenLoc());
4897}
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregora16548e2009-08-11 05:31:07 +00004899template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004900Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004901TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004902 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004903}
4904
4905template<typename Derived>
4906Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004907TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004908 switch (E->getOperator()) {
4909 case OO_New:
4910 case OO_Delete:
4911 case OO_Array_New:
4912 case OO_Array_Delete:
4913 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4914 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004915
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004916 case OO_Call: {
4917 // This is a call to an object's operator().
4918 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4919
4920 // Transform the object itself.
4921 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4922 if (Object.isInvalid())
4923 return SemaRef.ExprError();
4924
4925 // FIXME: Poor location information
4926 SourceLocation FakeLParenLoc
4927 = SemaRef.PP.getLocForEndOfToken(
4928 static_cast<Expr *>(Object.get())->getLocEnd());
4929
4930 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004931 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004932 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4933 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004934 if (getDerived().DropCallArgument(E->getArg(I)))
4935 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004936
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004937 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4938 if (Arg.isInvalid())
4939 return SemaRef.ExprError();
4940
4941 // FIXME: Poor source location information.
4942 SourceLocation FakeCommaLoc
4943 = SemaRef.PP.getLocForEndOfToken(
4944 static_cast<Expr *>(Arg.get())->getLocEnd());
4945 FakeCommaLocs.push_back(FakeCommaLoc);
4946 Args.push_back(Arg.release());
4947 }
4948
John McCallb268a282010-08-23 23:25:46 +00004949 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004950 move_arg(Args),
4951 FakeCommaLocs.data(),
4952 E->getLocEnd());
4953 }
4954
4955#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4956 case OO_##Name:
4957#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4958#include "clang/Basic/OperatorKinds.def"
4959 case OO_Subscript:
4960 // Handled below.
4961 break;
4962
4963 case OO_Conditional:
4964 llvm_unreachable("conditional operator is not actually overloadable");
4965 return SemaRef.ExprError();
4966
4967 case OO_None:
4968 case NUM_OVERLOADED_OPERATORS:
4969 llvm_unreachable("not an overloaded operator?");
4970 return SemaRef.ExprError();
4971 }
4972
Douglas Gregora16548e2009-08-11 05:31:07 +00004973 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4974 if (Callee.isInvalid())
4975 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004976
John McCall47f29ea2009-12-08 09:21:05 +00004977 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004978 if (First.isInvalid())
4979 return SemaRef.ExprError();
4980
John McCall37ad5512010-08-23 06:44:23 +00004981 OwningExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 if (E->getNumArgs() == 2) {
4983 Second = getDerived().TransformExpr(E->getArg(1));
4984 if (Second.isInvalid())
4985 return SemaRef.ExprError();
4986 }
Mike Stump11289f42009-09-09 15:08:12 +00004987
Douglas Gregora16548e2009-08-11 05:31:07 +00004988 if (!getDerived().AlwaysRebuild() &&
4989 Callee.get() == E->getCallee() &&
4990 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004991 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4992 return SemaRef.Owned(E->Retain());
4993
Douglas Gregora16548e2009-08-11 05:31:07 +00004994 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4995 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00004996 Callee.get(),
4997 First.get(),
4998 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004999}
Mike Stump11289f42009-09-09 15:08:12 +00005000
Douglas Gregora16548e2009-08-11 05:31:07 +00005001template<typename Derived>
5002Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005003TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5004 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005005}
Mike Stump11289f42009-09-09 15:08:12 +00005006
Douglas Gregora16548e2009-08-11 05:31:07 +00005007template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005008Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005009TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005010 TypeSourceInfo *OldT;
5011 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005012 {
5013 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005014 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5016 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005017
John McCall97513962010-01-15 18:39:57 +00005018 OldT = E->getTypeInfoAsWritten();
5019 NewT = getDerived().TransformType(OldT);
5020 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 return SemaRef.ExprError();
5022 }
Mike Stump11289f42009-09-09 15:08:12 +00005023
Douglas Gregor6131b442009-12-12 18:16:41 +00005024 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005025 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 if (SubExpr.isInvalid())
5027 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005028
Douglas Gregora16548e2009-08-11 05:31:07 +00005029 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005030 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005032 return SemaRef.Owned(E->Retain());
5033
Douglas Gregora16548e2009-08-11 05:31:07 +00005034 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005035 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005036 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5037 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5038 SourceLocation FakeRParenLoc
5039 = SemaRef.PP.getLocForEndOfToken(
5040 E->getSubExpr()->getSourceRange().getEnd());
5041 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005042 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005044 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 FakeRAngleLoc,
5046 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005047 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005048 FakeRParenLoc);
5049}
Mike Stump11289f42009-09-09 15:08:12 +00005050
Douglas Gregora16548e2009-08-11 05:31:07 +00005051template<typename Derived>
5052Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005053TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5054 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005055}
Mike Stump11289f42009-09-09 15:08:12 +00005056
5057template<typename Derived>
5058Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005059TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5060 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005061}
5062
Douglas Gregora16548e2009-08-11 05:31:07 +00005063template<typename Derived>
5064Sema::OwningExprResult
5065TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005066 CXXReinterpretCastExpr *E) {
5067 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005068}
Mike Stump11289f42009-09-09 15:08:12 +00005069
Douglas Gregora16548e2009-08-11 05:31:07 +00005070template<typename Derived>
5071Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005072TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5073 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005074}
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregora16548e2009-08-11 05:31:07 +00005076template<typename Derived>
5077Sema::OwningExprResult
5078TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005079 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005080 TypeSourceInfo *OldT;
5081 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005082 {
5083 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005084
John McCall97513962010-01-15 18:39:57 +00005085 OldT = E->getTypeInfoAsWritten();
5086 NewT = getDerived().TransformType(OldT);
5087 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005088 return SemaRef.ExprError();
5089 }
Mike Stump11289f42009-09-09 15:08:12 +00005090
Douglas Gregor6131b442009-12-12 18:16:41 +00005091 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005092 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005093 if (SubExpr.isInvalid())
5094 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregora16548e2009-08-11 05:31:07 +00005096 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005097 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005099 return SemaRef.Owned(E->Retain());
5100
Douglas Gregora16548e2009-08-11 05:31:07 +00005101 // FIXME: The end of the type's source range is wrong
5102 return getDerived().RebuildCXXFunctionalCastExpr(
5103 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005104 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005106 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 E->getRParenLoc());
5108}
Mike Stump11289f42009-09-09 15:08:12 +00005109
Douglas Gregora16548e2009-08-11 05:31:07 +00005110template<typename Derived>
5111Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005112TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005114 TypeSourceInfo *TInfo
5115 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5116 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005118
Douglas Gregora16548e2009-08-11 05:31:07 +00005119 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005120 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregor9da64192010-04-26 22:37:10 +00005123 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5124 E->getLocStart(),
5125 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 E->getLocEnd());
5127 }
Mike Stump11289f42009-09-09 15:08:12 +00005128
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 // We don't know whether the expression is potentially evaluated until
5130 // after we perform semantic analysis, so the expression is potentially
5131 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005132 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5136 if (SubExpr.isInvalid())
5137 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 if (!getDerived().AlwaysRebuild() &&
5140 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005141 return SemaRef.Owned(E->Retain());
5142
Douglas Gregor9da64192010-04-26 22:37:10 +00005143 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5144 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005145 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 E->getLocEnd());
5147}
5148
5149template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005150Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005151TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005152 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005153}
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregora16548e2009-08-11 05:31:07 +00005155template<typename Derived>
5156Sema::OwningExprResult
5157TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005158 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005159 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005160}
Mike Stump11289f42009-09-09 15:08:12 +00005161
Douglas Gregora16548e2009-08-11 05:31:07 +00005162template<typename Derived>
5163Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005164TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005166
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 QualType T = getDerived().TransformType(E->getType());
5168 if (T.isNull())
5169 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005170
Douglas Gregora16548e2009-08-11 05:31:07 +00005171 if (!getDerived().AlwaysRebuild() &&
5172 T == E->getType())
5173 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005174
Douglas Gregorb15af892010-01-07 23:12:05 +00005175 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178template<typename Derived>
5179Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005180TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5182 if (SubExpr.isInvalid())
5183 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005184
Douglas Gregora16548e2009-08-11 05:31:07 +00005185 if (!getDerived().AlwaysRebuild() &&
5186 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005187 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005188
John McCallb268a282010-08-23 23:25:46 +00005189 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005190}
Mike Stump11289f42009-09-09 15:08:12 +00005191
Douglas Gregora16548e2009-08-11 05:31:07 +00005192template<typename Derived>
5193Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005194TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005195 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005196 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5197 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005198 if (!Param)
5199 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005200
Chandler Carruth794da4c2010-02-08 06:42:49 +00005201 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005202 Param == E->getParam())
5203 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005204
Douglas Gregor033f6752009-12-23 23:03:06 +00005205 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005206}
Mike Stump11289f42009-09-09 15:08:12 +00005207
Douglas Gregora16548e2009-08-11 05:31:07 +00005208template<typename Derived>
5209Sema::OwningExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005210TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005211 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5212
5213 QualType T = getDerived().TransformType(E->getType());
5214 if (T.isNull())
5215 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregora16548e2009-08-11 05:31:07 +00005217 if (!getDerived().AlwaysRebuild() &&
5218 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005219 return SemaRef.Owned(E->Retain());
5220
Douglas Gregor747eb782010-07-08 06:14:04 +00005221 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5222 /*FIXME:*/E->getTypeBeginLoc(),
5223 T,
5224 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005225}
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregora16548e2009-08-11 05:31:07 +00005227template<typename Derived>
5228Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005229TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005230 // Transform the type that we're allocating
5231 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5232 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5233 if (AllocType.isNull())
5234 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005235
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 // Transform the size of the array we're allocating (if any).
5237 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5238 if (ArraySize.isInvalid())
5239 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005240
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 // Transform the placement arguments (if any).
5242 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005243 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5245 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5246 if (Arg.isInvalid())
5247 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005248
Douglas Gregora16548e2009-08-11 05:31:07 +00005249 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5250 PlacementArgs.push_back(Arg.take());
5251 }
Mike Stump11289f42009-09-09 15:08:12 +00005252
Douglas Gregorebe10102009-08-20 07:17:43 +00005253 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005254 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005255 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005256 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5257 break;
5258
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5260 if (Arg.isInvalid())
5261 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregora16548e2009-08-11 05:31:07 +00005263 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5264 ConstructorArgs.push_back(Arg.take());
5265 }
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregord2d9da02010-02-26 00:38:10 +00005267 // Transform constructor, new operator, and delete operator.
5268 CXXConstructorDecl *Constructor = 0;
5269 if (E->getConstructor()) {
5270 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005271 getDerived().TransformDecl(E->getLocStart(),
5272 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005273 if (!Constructor)
5274 return SemaRef.ExprError();
5275 }
5276
5277 FunctionDecl *OperatorNew = 0;
5278 if (E->getOperatorNew()) {
5279 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005280 getDerived().TransformDecl(E->getLocStart(),
5281 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005282 if (!OperatorNew)
5283 return SemaRef.ExprError();
5284 }
5285
5286 FunctionDecl *OperatorDelete = 0;
5287 if (E->getOperatorDelete()) {
5288 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005289 getDerived().TransformDecl(E->getLocStart(),
5290 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005291 if (!OperatorDelete)
5292 return SemaRef.ExprError();
5293 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005294
Douglas Gregora16548e2009-08-11 05:31:07 +00005295 if (!getDerived().AlwaysRebuild() &&
5296 AllocType == E->getAllocatedType() &&
5297 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005298 Constructor == E->getConstructor() &&
5299 OperatorNew == E->getOperatorNew() &&
5300 OperatorDelete == E->getOperatorDelete() &&
5301 !ArgumentChanged) {
5302 // Mark any declarations we need as referenced.
5303 // FIXME: instantiation-specific.
5304 if (Constructor)
5305 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5306 if (OperatorNew)
5307 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5308 if (OperatorDelete)
5309 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005310 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005311 }
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005313 if (!ArraySize.get()) {
5314 // If no array size was specified, but the new expression was
5315 // instantiated with an array type (e.g., "new T" where T is
5316 // instantiated with "int[4]"), extract the outer bound from the
5317 // array type as our array size. We do this with constant and
5318 // dependently-sized array types.
5319 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5320 if (!ArrayT) {
5321 // Do nothing
5322 } else if (const ConstantArrayType *ConsArrayT
5323 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005324 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005325 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005326 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005327 SemaRef.Context.getSizeType(),
5328 /*FIXME:*/E->getLocStart()));
5329 AllocType = ConsArrayT->getElementType();
5330 } else if (const DependentSizedArrayType *DepArrayT
5331 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5332 if (DepArrayT->getSizeExpr()) {
5333 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5334 AllocType = DepArrayT->getElementType();
5335 }
5336 }
5337 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005338 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5339 E->isGlobalNew(),
5340 /*FIXME:*/E->getLocStart(),
5341 move_arg(PlacementArgs),
5342 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005343 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005344 AllocType,
5345 /*FIXME:*/E->getLocStart(),
5346 /*FIXME:*/SourceRange(),
John McCallb268a282010-08-23 23:25:46 +00005347 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005348 /*FIXME:*/E->getLocStart(),
5349 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005350 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005351}
Mike Stump11289f42009-09-09 15:08:12 +00005352
Douglas Gregora16548e2009-08-11 05:31:07 +00005353template<typename Derived>
5354Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005355TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005356 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5357 if (Operand.isInvalid())
5358 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005359
Douglas Gregord2d9da02010-02-26 00:38:10 +00005360 // Transform the delete operator, if known.
5361 FunctionDecl *OperatorDelete = 0;
5362 if (E->getOperatorDelete()) {
5363 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005364 getDerived().TransformDecl(E->getLocStart(),
5365 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005366 if (!OperatorDelete)
5367 return SemaRef.ExprError();
5368 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005369
Douglas Gregora16548e2009-08-11 05:31:07 +00005370 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005371 Operand.get() == E->getArgument() &&
5372 OperatorDelete == E->getOperatorDelete()) {
5373 // Mark any declarations we need as referenced.
5374 // FIXME: instantiation-specific.
5375 if (OperatorDelete)
5376 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005377 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005378 }
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregora16548e2009-08-11 05:31:07 +00005380 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5381 E->isGlobalDelete(),
5382 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005383 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005384}
Mike Stump11289f42009-09-09 15:08:12 +00005385
Douglas Gregora16548e2009-08-11 05:31:07 +00005386template<typename Derived>
5387Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005388TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005389 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005390 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5391 if (Base.isInvalid())
5392 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005393
John McCallba7bf592010-08-24 05:47:05 +00005394 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005395 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005396 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005397 E->getOperatorLoc(),
5398 E->isArrow()? tok::arrow : tok::period,
5399 ObjectTypePtr,
5400 MayBePseudoDestructor);
5401 if (Base.isInvalid())
5402 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005403
John McCallba7bf592010-08-24 05:47:05 +00005404 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005405 NestedNameSpecifier *Qualifier
5406 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005407 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005408 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005409 if (E->getQualifier() && !Qualifier)
5410 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005411
Douglas Gregor678f90d2010-02-25 01:56:36 +00005412 PseudoDestructorTypeStorage Destroyed;
5413 if (E->getDestroyedTypeInfo()) {
5414 TypeSourceInfo *DestroyedTypeInfo
5415 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5416 if (!DestroyedTypeInfo)
5417 return SemaRef.ExprError();
5418 Destroyed = DestroyedTypeInfo;
5419 } else if (ObjectType->isDependentType()) {
5420 // We aren't likely to be able to resolve the identifier down to a type
5421 // now anyway, so just retain the identifier.
5422 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5423 E->getDestroyedTypeLoc());
5424 } else {
5425 // Look for a destructor known with the given name.
5426 CXXScopeSpec SS;
5427 if (Qualifier) {
5428 SS.setScopeRep(Qualifier);
5429 SS.setRange(E->getQualifierRange());
5430 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005431
John McCallba7bf592010-08-24 05:47:05 +00005432 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005433 *E->getDestroyedTypeIdentifier(),
5434 E->getDestroyedTypeLoc(),
5435 /*Scope=*/0,
5436 SS, ObjectTypePtr,
5437 false);
5438 if (!T)
5439 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005440
Douglas Gregor678f90d2010-02-25 01:56:36 +00005441 Destroyed
5442 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5443 E->getDestroyedTypeLoc());
5444 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005445
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005446 TypeSourceInfo *ScopeTypeInfo = 0;
5447 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005448 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005449 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005450 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005451 return SemaRef.ExprError();
5452 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005453
John McCallb268a282010-08-23 23:25:46 +00005454 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005455 E->getOperatorLoc(),
5456 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005457 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005458 E->getQualifierRange(),
5459 ScopeTypeInfo,
5460 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005461 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005462 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005463}
Mike Stump11289f42009-09-09 15:08:12 +00005464
Douglas Gregorad8a3362009-09-04 17:36:40 +00005465template<typename Derived>
5466Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005467TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005468 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005469 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5470
5471 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5472 Sema::LookupOrdinaryName);
5473
5474 // Transform all the decls.
5475 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5476 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005477 NamedDecl *InstD = static_cast<NamedDecl*>(
5478 getDerived().TransformDecl(Old->getNameLoc(),
5479 *I));
John McCall84d87672009-12-10 09:41:52 +00005480 if (!InstD) {
5481 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5482 // This can happen because of dependent hiding.
5483 if (isa<UsingShadowDecl>(*I))
5484 continue;
5485 else
5486 return SemaRef.ExprError();
5487 }
John McCalle66edc12009-11-24 19:00:30 +00005488
5489 // Expand using declarations.
5490 if (isa<UsingDecl>(InstD)) {
5491 UsingDecl *UD = cast<UsingDecl>(InstD);
5492 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5493 E = UD->shadow_end(); I != E; ++I)
5494 R.addDecl(*I);
5495 continue;
5496 }
5497
5498 R.addDecl(InstD);
5499 }
5500
5501 // Resolve a kind, but don't do any further analysis. If it's
5502 // ambiguous, the callee needs to deal with it.
5503 R.resolveKind();
5504
5505 // Rebuild the nested-name qualifier, if present.
5506 CXXScopeSpec SS;
5507 NestedNameSpecifier *Qualifier = 0;
5508 if (Old->getQualifier()) {
5509 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005510 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005511 if (!Qualifier)
5512 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005513
John McCalle66edc12009-11-24 19:00:30 +00005514 SS.setScopeRep(Qualifier);
5515 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005516 }
5517
Douglas Gregor9262f472010-04-27 18:19:34 +00005518 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005519 CXXRecordDecl *NamingClass
5520 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5521 Old->getNameLoc(),
5522 Old->getNamingClass()));
5523 if (!NamingClass)
5524 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005525
Douglas Gregorda7be082010-04-27 16:10:10 +00005526 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005527 }
5528
5529 // If we have no template arguments, it's a normal declaration name.
5530 if (!Old->hasExplicitTemplateArgs())
5531 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5532
5533 // If we have template arguments, rebuild them, then rebuild the
5534 // templateid expression.
5535 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5536 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5537 TemplateArgumentLoc Loc;
5538 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5539 return SemaRef.ExprError();
5540 TransArgs.addArgument(Loc);
5541 }
5542
5543 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5544 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005545}
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregora16548e2009-08-11 05:31:07 +00005547template<typename Derived>
5548Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005549TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005550 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 QualType T = getDerived().TransformType(E->getQueriedType());
5553 if (T.isNull())
5554 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005555
Douglas Gregora16548e2009-08-11 05:31:07 +00005556 if (!getDerived().AlwaysRebuild() &&
5557 T == E->getQueriedType())
5558 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 // FIXME: Bad location information
5561 SourceLocation FakeLParenLoc
5562 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005563
5564 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005565 E->getLocStart(),
5566 /*FIXME:*/FakeLParenLoc,
5567 T,
5568 E->getLocEnd());
5569}
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregora16548e2009-08-11 05:31:07 +00005571template<typename Derived>
5572Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005573TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005574 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005576 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005577 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005578 if (!NNS)
5579 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005580
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005581 DeclarationNameInfo NameInfo
5582 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5583 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005584 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005585
John McCalle66edc12009-11-24 19:00:30 +00005586 if (!E->hasExplicitTemplateArgs()) {
5587 if (!getDerived().AlwaysRebuild() &&
5588 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005589 // Note: it is sufficient to compare the Name component of NameInfo:
5590 // if name has not changed, DNLoc has not changed either.
5591 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005592 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005593
John McCalle66edc12009-11-24 19:00:30 +00005594 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5595 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005596 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005597 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005598 }
John McCall6b51f282009-11-23 01:53:49 +00005599
5600 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005602 TemplateArgumentLoc Loc;
5603 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005605 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 }
5607
John McCalle66edc12009-11-24 19:00:30 +00005608 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5609 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005610 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005611 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005612}
5613
5614template<typename Derived>
5615Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005616TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005617 // CXXConstructExprs are always implicit, so when we have a
5618 // 1-argument construction we just transform that argument.
5619 if (E->getNumArgs() == 1 ||
5620 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5621 return getDerived().TransformExpr(E->getArg(0));
5622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5624
5625 QualType T = getDerived().TransformType(E->getType());
5626 if (T.isNull())
5627 return SemaRef.ExprError();
5628
5629 CXXConstructorDecl *Constructor
5630 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005631 getDerived().TransformDecl(E->getLocStart(),
5632 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 if (!Constructor)
5634 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005637 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005638 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 ArgEnd = E->arg_end();
5640 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005641 if (getDerived().DropCallArgument(*Arg)) {
5642 ArgumentChanged = true;
5643 break;
5644 }
5645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5647 if (TransArg.isInvalid())
5648 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005651 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 }
5653
5654 if (!getDerived().AlwaysRebuild() &&
5655 T == E->getType() &&
5656 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005657 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005658 // Mark the constructor as referenced.
5659 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005660 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005661 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005662 }
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregordb121ba2009-12-14 16:27:04 +00005664 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5665 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005666 move_arg(Args),
5667 E->requiresZeroInitialization(),
5668 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005669}
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregora16548e2009-08-11 05:31:07 +00005671/// \brief Transform a C++ temporary-binding expression.
5672///
Douglas Gregor363b1512009-12-24 18:51:59 +00005673/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5674/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005675template<typename Derived>
5676Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005677TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005678 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005679}
Mike Stump11289f42009-09-09 15:08:12 +00005680
Anders Carlssonba6c4372010-01-29 02:39:32 +00005681/// \brief Transform a C++ reference-binding expression.
5682///
5683/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5684/// transform the subexpression and return that.
5685template<typename Derived>
5686Sema::OwningExprResult
5687TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5688 return getDerived().TransformExpr(E->getSubExpr());
5689}
5690
Mike Stump11289f42009-09-09 15:08:12 +00005691/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005692/// be destroyed after the expression is evaluated.
5693///
Douglas Gregor363b1512009-12-24 18:51:59 +00005694/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5695/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005696template<typename Derived>
5697Sema::OwningExprResult
5698TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005699 CXXExprWithTemporaries *E) {
5700 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005701}
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregora16548e2009-08-11 05:31:07 +00005703template<typename Derived>
5704Sema::OwningExprResult
5705TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005706 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5708 QualType T = getDerived().TransformType(E->getType());
5709 if (T.isNull())
5710 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712 CXXConstructorDecl *Constructor
5713 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005714 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005715 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005716 if (!Constructor)
5717 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005718
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005720 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005722 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 ArgEnd = E->arg_end();
5724 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005725 if (getDerived().DropCallArgument(*Arg)) {
5726 ArgumentChanged = true;
5727 break;
5728 }
5729
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5731 if (TransArg.isInvalid())
5732 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5735 Args.push_back((Expr *)TransArg.release());
5736 }
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregora16548e2009-08-11 05:31:07 +00005738 if (!getDerived().AlwaysRebuild() &&
5739 T == E->getType() &&
5740 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005741 !ArgumentChanged) {
5742 // FIXME: Instantiation-specific
5743 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005744 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005745 }
Mike Stump11289f42009-09-09 15:08:12 +00005746
Douglas Gregora16548e2009-08-11 05:31:07 +00005747 // FIXME: Bogus location information
5748 SourceLocation CommaLoc;
5749 if (Args.size() > 1) {
5750 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005751 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005752 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5753 }
5754 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5755 T,
5756 /*FIXME:*/E->getTypeBeginLoc(),
5757 move_arg(Args),
5758 &CommaLoc,
5759 E->getLocEnd());
5760}
Mike Stump11289f42009-09-09 15:08:12 +00005761
Douglas Gregora16548e2009-08-11 05:31:07 +00005762template<typename Derived>
5763Sema::OwningExprResult
5764TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005765 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005766 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5767 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5768 if (T.isNull())
5769 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005770
Douglas Gregora16548e2009-08-11 05:31:07 +00005771 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005772 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5774 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5775 ArgEnd = E->arg_end();
5776 Arg != ArgEnd; ++Arg) {
5777 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5778 if (TransArg.isInvalid())
5779 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005780
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5782 FakeCommaLocs.push_back(
5783 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
John McCallb268a282010-08-23 23:25:46 +00005784 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005785 }
Mike Stump11289f42009-09-09 15:08:12 +00005786
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 if (!getDerived().AlwaysRebuild() &&
5788 T == E->getTypeAsWritten() &&
5789 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005790 return SemaRef.Owned(E->Retain());
5791
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 // FIXME: we're faking the locations of the commas
5793 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5794 T,
5795 E->getLParenLoc(),
5796 move_arg(Args),
5797 FakeCommaLocs.data(),
5798 E->getRParenLoc());
5799}
Mike Stump11289f42009-09-09 15:08:12 +00005800
Douglas Gregora16548e2009-08-11 05:31:07 +00005801template<typename Derived>
5802Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005803TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005804 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 // Transform the base of the expression.
John McCall37ad5512010-08-23 06:44:23 +00005806 OwningExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005807 Expr *OldBase;
5808 QualType BaseType;
5809 QualType ObjectType;
5810 if (!E->isImplicitAccess()) {
5811 OldBase = E->getBase();
5812 Base = getDerived().TransformExpr(OldBase);
5813 if (Base.isInvalid())
5814 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005815
John McCall2d74de92009-12-01 22:10:20 +00005816 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005817 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005818 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005819 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005820 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005821 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005822 ObjectTy,
5823 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005824 if (Base.isInvalid())
5825 return SemaRef.ExprError();
5826
John McCallba7bf592010-08-24 05:47:05 +00005827 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005828 BaseType = ((Expr*) Base.get())->getType();
5829 } else {
5830 OldBase = 0;
5831 BaseType = getDerived().TransformType(E->getBaseType());
5832 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5833 }
Mike Stump11289f42009-09-09 15:08:12 +00005834
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005835 // Transform the first part of the nested-name-specifier that qualifies
5836 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005837 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005838 = getDerived().TransformFirstQualifierInScope(
5839 E->getFirstQualifierFoundInScope(),
5840 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005841
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005842 NestedNameSpecifier *Qualifier = 0;
5843 if (E->getQualifier()) {
5844 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5845 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005846 ObjectType,
5847 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005848 if (!Qualifier)
5849 return SemaRef.ExprError();
5850 }
Mike Stump11289f42009-09-09 15:08:12 +00005851
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005852 DeclarationNameInfo NameInfo
5853 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5854 ObjectType);
5855 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005856 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005857
John McCall2d74de92009-12-01 22:10:20 +00005858 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005859 // This is a reference to a member without an explicitly-specified
5860 // template argument list. Optimize for this common case.
5861 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005862 Base.get() == OldBase &&
5863 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005864 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005865 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005866 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005867 return SemaRef.Owned(E->Retain());
5868
John McCallb268a282010-08-23 23:25:46 +00005869 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005870 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005871 E->isArrow(),
5872 E->getOperatorLoc(),
5873 Qualifier,
5874 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005875 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005876 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005877 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005878 }
5879
John McCall6b51f282009-11-23 01:53:49 +00005880 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005881 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005882 TemplateArgumentLoc Loc;
5883 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005884 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005885 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005886 }
Mike Stump11289f42009-09-09 15:08:12 +00005887
John McCallb268a282010-08-23 23:25:46 +00005888 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005889 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005890 E->isArrow(),
5891 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005892 Qualifier,
5893 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005894 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005895 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005896 &TransArgs);
5897}
5898
5899template<typename Derived>
5900Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005901TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005902 // Transform the base of the expression.
John McCall37ad5512010-08-23 06:44:23 +00005903 OwningExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005904 QualType BaseType;
5905 if (!Old->isImplicitAccess()) {
5906 Base = getDerived().TransformExpr(Old->getBase());
5907 if (Base.isInvalid())
5908 return SemaRef.ExprError();
5909 BaseType = ((Expr*) Base.get())->getType();
5910 } else {
5911 BaseType = getDerived().TransformType(Old->getBaseType());
5912 }
John McCall10eae182009-11-30 22:42:35 +00005913
5914 NestedNameSpecifier *Qualifier = 0;
5915 if (Old->getQualifier()) {
5916 Qualifier
5917 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005918 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005919 if (Qualifier == 0)
5920 return SemaRef.ExprError();
5921 }
5922
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005923 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005924 Sema::LookupOrdinaryName);
5925
5926 // Transform all the decls.
5927 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5928 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005929 NamedDecl *InstD = static_cast<NamedDecl*>(
5930 getDerived().TransformDecl(Old->getMemberLoc(),
5931 *I));
John McCall84d87672009-12-10 09:41:52 +00005932 if (!InstD) {
5933 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5934 // This can happen because of dependent hiding.
5935 if (isa<UsingShadowDecl>(*I))
5936 continue;
5937 else
5938 return SemaRef.ExprError();
5939 }
John McCall10eae182009-11-30 22:42:35 +00005940
5941 // Expand using declarations.
5942 if (isa<UsingDecl>(InstD)) {
5943 UsingDecl *UD = cast<UsingDecl>(InstD);
5944 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5945 E = UD->shadow_end(); I != E; ++I)
5946 R.addDecl(*I);
5947 continue;
5948 }
5949
5950 R.addDecl(InstD);
5951 }
5952
5953 R.resolveKind();
5954
Douglas Gregor9262f472010-04-27 18:19:34 +00005955 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005956 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005957 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005958 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005959 Old->getMemberLoc(),
5960 Old->getNamingClass()));
5961 if (!NamingClass)
5962 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005963
Douglas Gregorda7be082010-04-27 16:10:10 +00005964 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005965 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005966
John McCall10eae182009-11-30 22:42:35 +00005967 TemplateArgumentListInfo TransArgs;
5968 if (Old->hasExplicitTemplateArgs()) {
5969 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5970 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5971 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5972 TemplateArgumentLoc Loc;
5973 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5974 Loc))
5975 return SemaRef.ExprError();
5976 TransArgs.addArgument(Loc);
5977 }
5978 }
John McCall38836f02010-01-15 08:34:02 +00005979
5980 // FIXME: to do this check properly, we will need to preserve the
5981 // first-qualifier-in-scope here, just in case we had a dependent
5982 // base (and therefore couldn't do the check) and a
5983 // nested-name-qualifier (and therefore could do the lookup).
5984 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005985
John McCallb268a282010-08-23 23:25:46 +00005986 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005987 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005988 Old->getOperatorLoc(),
5989 Old->isArrow(),
5990 Qualifier,
5991 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005992 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005993 R,
5994 (Old->hasExplicitTemplateArgs()
5995 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005996}
5997
5998template<typename Derived>
5999Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006000TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006001 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006002}
6003
Mike Stump11289f42009-09-09 15:08:12 +00006004template<typename Derived>
6005Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006006TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006007 TypeSourceInfo *EncodedTypeInfo
6008 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6009 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006011
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006013 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006014 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006015
6016 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006017 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006018 E->getRParenLoc());
6019}
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregora16548e2009-08-11 05:31:07 +00006021template<typename Derived>
6022Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006023TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006024 // Transform arguments.
6025 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006026 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006027 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6028 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6029 if (Arg.isInvalid())
6030 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006031
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006032 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006033 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006034 }
6035
6036 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6037 // Class message: transform the receiver type.
6038 TypeSourceInfo *ReceiverTypeInfo
6039 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6040 if (!ReceiverTypeInfo)
6041 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006042
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006043 // If nothing changed, just retain the existing message send.
6044 if (!getDerived().AlwaysRebuild() &&
6045 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6046 return SemaRef.Owned(E->Retain());
6047
6048 // Build a new class message send.
6049 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6050 E->getSelector(),
6051 E->getMethodDecl(),
6052 E->getLeftLoc(),
6053 move_arg(Args),
6054 E->getRightLoc());
6055 }
6056
6057 // Instance message: transform the receiver
6058 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6059 "Only class and instance messages may be instantiated");
6060 OwningExprResult Receiver
6061 = getDerived().TransformExpr(E->getInstanceReceiver());
6062 if (Receiver.isInvalid())
6063 return SemaRef.ExprError();
6064
6065 // If nothing changed, just retain the existing message send.
6066 if (!getDerived().AlwaysRebuild() &&
6067 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6068 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006069
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006070 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006071 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006072 E->getSelector(),
6073 E->getMethodDecl(),
6074 E->getLeftLoc(),
6075 move_arg(Args),
6076 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006077}
6078
Mike Stump11289f42009-09-09 15:08:12 +00006079template<typename Derived>
6080Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006081TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006082 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006083}
6084
Mike Stump11289f42009-09-09 15:08:12 +00006085template<typename Derived>
6086Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006088 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006089}
6090
Mike Stump11289f42009-09-09 15:08:12 +00006091template<typename Derived>
6092Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006093TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006094 // Transform the base expression.
6095 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6096 if (Base.isInvalid())
6097 return SemaRef.ExprError();
6098
6099 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006100
Douglas Gregord51d90d2010-04-26 20:11:03 +00006101 // If nothing changed, just retain the existing expression.
6102 if (!getDerived().AlwaysRebuild() &&
6103 Base.get() == E->getBase())
6104 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006105
John McCallb268a282010-08-23 23:25:46 +00006106 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006107 E->getLocation(),
6108 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006109}
6110
Mike Stump11289f42009-09-09 15:08:12 +00006111template<typename Derived>
6112Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006113TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006114 // Transform the base expression.
6115 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6116 if (Base.isInvalid())
6117 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006118
Douglas Gregor9faee212010-04-26 20:47:02 +00006119 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006120
Douglas Gregor9faee212010-04-26 20:47:02 +00006121 // If nothing changed, just retain the existing expression.
6122 if (!getDerived().AlwaysRebuild() &&
6123 Base.get() == E->getBase())
6124 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006125
John McCallb268a282010-08-23 23:25:46 +00006126 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006127 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006128}
6129
Mike Stump11289f42009-09-09 15:08:12 +00006130template<typename Derived>
6131Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006132TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006133 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006134 // If this implicit setter/getter refers to class methods, it cannot have any
6135 // dependent parts. Just retain the existing declaration.
6136 if (E->getInterfaceDecl())
6137 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006138
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006139 // Transform the base expression.
6140 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6141 if (Base.isInvalid())
6142 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006143
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006144 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006145
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006146 // If nothing changed, just retain the existing expression.
6147 if (!getDerived().AlwaysRebuild() &&
6148 Base.get() == E->getBase())
6149 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006150
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006151 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6152 E->getGetterMethod(),
6153 E->getType(),
6154 E->getSetterMethod(),
6155 E->getLocation(),
John McCallb268a282010-08-23 23:25:46 +00006156 Base.get());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006157
Douglas Gregora16548e2009-08-11 05:31:07 +00006158}
6159
Mike Stump11289f42009-09-09 15:08:12 +00006160template<typename Derived>
6161Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006162TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006163 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006164 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006165}
6166
Mike Stump11289f42009-09-09 15:08:12 +00006167template<typename Derived>
6168Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006170 // Transform the base expression.
6171 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6172 if (Base.isInvalid())
6173 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006174
Douglas Gregord51d90d2010-04-26 20:11:03 +00006175 // If nothing changed, just retain the existing expression.
6176 if (!getDerived().AlwaysRebuild() &&
6177 Base.get() == E->getBase())
6178 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006179
John McCallb268a282010-08-23 23:25:46 +00006180 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006181 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006182}
6183
Mike Stump11289f42009-09-09 15:08:12 +00006184template<typename Derived>
6185Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006186TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006188 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006189 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6190 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6191 if (SubExpr.isInvalid())
6192 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006193
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006195 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 }
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 if (!getDerived().AlwaysRebuild() &&
6199 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006200 return SemaRef.Owned(E->Retain());
6201
Douglas Gregora16548e2009-08-11 05:31:07 +00006202 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6203 move_arg(SubExprs),
6204 E->getRParenLoc());
6205}
6206
Mike Stump11289f42009-09-09 15:08:12 +00006207template<typename Derived>
6208Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006209TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006210 SourceLocation CaretLoc(E->getExprLoc());
6211
6212 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6213 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6214 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6215 llvm::SmallVector<ParmVarDecl*, 4> Params;
6216 llvm::SmallVector<QualType, 4> ParamTypes;
6217
6218 // Parameter substitution.
6219 const BlockDecl *BD = E->getBlockDecl();
6220 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6221 EN = BD->param_end(); P != EN; ++P) {
6222 ParmVarDecl *OldParm = (*P);
6223 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6224 QualType NewType = NewParm->getType();
6225 Params.push_back(NewParm);
6226 ParamTypes.push_back(NewParm->getType());
6227 }
6228
6229 const FunctionType *BExprFunctionType = E->getFunctionType();
6230 QualType BExprResultType = BExprFunctionType->getResultType();
6231 if (!BExprResultType.isNull()) {
6232 if (!BExprResultType->isDependentType())
6233 CurBlock->ReturnType = BExprResultType;
6234 else if (BExprResultType != SemaRef.Context.DependentTy)
6235 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6236 }
6237
6238 // Transform the body
6239 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6240 if (Body.isInvalid())
6241 return SemaRef.ExprError();
6242 // Set the parameters on the block decl.
6243 if (!Params.empty())
6244 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6245
6246 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6247 CurBlock->ReturnType,
6248 ParamTypes.data(),
6249 ParamTypes.size(),
6250 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006251 0,
6252 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006253
6254 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006255 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006256}
6257
Mike Stump11289f42009-09-09 15:08:12 +00006258template<typename Derived>
6259Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006260TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006261 NestedNameSpecifier *Qualifier = 0;
6262
6263 ValueDecl *ND
6264 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6265 E->getDecl()));
6266 if (!ND)
6267 return SemaRef.ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006268
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006269 if (!getDerived().AlwaysRebuild() &&
6270 ND == E->getDecl()) {
6271 // Mark it referenced in the new context regardless.
6272 // FIXME: this is a bit instantiation-specific.
6273 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6274
6275 return SemaRef.Owned(E->Retain());
6276 }
6277
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006278 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006279 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006280 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006281}
Mike Stump11289f42009-09-09 15:08:12 +00006282
Douglas Gregora16548e2009-08-11 05:31:07 +00006283//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006284// Type reconstruction
6285//===----------------------------------------------------------------------===//
6286
Mike Stump11289f42009-09-09 15:08:12 +00006287template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006288QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6289 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006290 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006291 getDerived().getBaseEntity());
6292}
6293
Mike Stump11289f42009-09-09 15:08:12 +00006294template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006295QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6296 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006297 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006298 getDerived().getBaseEntity());
6299}
6300
Mike Stump11289f42009-09-09 15:08:12 +00006301template<typename Derived>
6302QualType
John McCall70dd5f62009-10-30 00:06:24 +00006303TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6304 bool WrittenAsLValue,
6305 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006306 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006307 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006308}
6309
6310template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006311QualType
John McCall70dd5f62009-10-30 00:06:24 +00006312TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6313 QualType ClassType,
6314 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006315 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006316 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006317}
6318
6319template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006320QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006321TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6322 ArrayType::ArraySizeModifier SizeMod,
6323 const llvm::APInt *Size,
6324 Expr *SizeExpr,
6325 unsigned IndexTypeQuals,
6326 SourceRange BracketsRange) {
6327 if (SizeExpr || !Size)
6328 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6329 IndexTypeQuals, BracketsRange,
6330 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006331
6332 QualType Types[] = {
6333 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6334 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6335 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006336 };
6337 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6338 QualType SizeType;
6339 for (unsigned I = 0; I != NumTypes; ++I)
6340 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6341 SizeType = Types[I];
6342 break;
6343 }
Mike Stump11289f42009-09-09 15:08:12 +00006344
Douglas Gregord6ff3322009-08-04 16:50:30 +00006345 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006346 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006347 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006348 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006349}
Mike Stump11289f42009-09-09 15:08:12 +00006350
Douglas Gregord6ff3322009-08-04 16:50:30 +00006351template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006352QualType
6353TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006354 ArrayType::ArraySizeModifier SizeMod,
6355 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006356 unsigned IndexTypeQuals,
6357 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006358 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006359 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006360}
6361
6362template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006363QualType
Mike Stump11289f42009-09-09 15:08:12 +00006364TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006365 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006366 unsigned IndexTypeQuals,
6367 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006368 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006369 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006370}
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregord6ff3322009-08-04 16:50:30 +00006372template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006373QualType
6374TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006375 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006376 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006377 unsigned IndexTypeQuals,
6378 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006379 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006380 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006381 IndexTypeQuals, BracketsRange);
6382}
6383
6384template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006385QualType
6386TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006387 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006388 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006389 unsigned IndexTypeQuals,
6390 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006391 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006392 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006393 IndexTypeQuals, BracketsRange);
6394}
6395
6396template<typename Derived>
6397QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006398 unsigned NumElements,
6399 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006400 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006401 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006402}
Mike Stump11289f42009-09-09 15:08:12 +00006403
Douglas Gregord6ff3322009-08-04 16:50:30 +00006404template<typename Derived>
6405QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6406 unsigned NumElements,
6407 SourceLocation AttributeLoc) {
6408 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6409 NumElements, true);
6410 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006411 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006412 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006413 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414}
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregord6ff3322009-08-04 16:50:30 +00006416template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006417QualType
6418TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006419 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006420 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006421 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006422}
Mike Stump11289f42009-09-09 15:08:12 +00006423
Douglas Gregord6ff3322009-08-04 16:50:30 +00006424template<typename Derived>
6425QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006426 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006427 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006428 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006429 unsigned Quals,
6430 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006431 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006432 Quals,
6433 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006434 getDerived().getBaseEntity(),
6435 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006436}
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006439QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6440 return SemaRef.Context.getFunctionNoProtoType(T);
6441}
6442
6443template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006444QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6445 assert(D && "no decl found");
6446 if (D->isInvalidDecl()) return QualType();
6447
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006448 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006449 TypeDecl *Ty;
6450 if (isa<UsingDecl>(D)) {
6451 UsingDecl *Using = cast<UsingDecl>(D);
6452 assert(Using->isTypeName() &&
6453 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6454
6455 // A valid resolved using typename decl points to exactly one type decl.
6456 assert(++Using->shadow_begin() == Using->shadow_end());
6457 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006458
John McCallb96ec562009-12-04 22:46:56 +00006459 } else {
6460 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6461 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6462 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6463 }
6464
6465 return SemaRef.Context.getTypeDeclType(Ty);
6466}
6467
6468template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006469QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6470 return SemaRef.BuildTypeofExprType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006471}
6472
6473template<typename Derived>
6474QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6475 return SemaRef.Context.getTypeOfType(Underlying);
6476}
6477
6478template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006479QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6480 return SemaRef.BuildDecltypeType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006481}
6482
6483template<typename Derived>
6484QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006485 TemplateName Template,
6486 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006487 const TemplateArgumentListInfo &TemplateArgs) {
6488 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006489}
Mike Stump11289f42009-09-09 15:08:12 +00006490
Douglas Gregor1135c352009-08-06 05:28:30 +00006491template<typename Derived>
6492NestedNameSpecifier *
6493TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6494 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006495 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006496 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006497 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006498 CXXScopeSpec SS;
6499 // FIXME: The source location information is all wrong.
6500 SS.setRange(Range);
6501 SS.setScopeRep(Prefix);
6502 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006503 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006504 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006505 ObjectType,
6506 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006507 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006508}
6509
6510template<typename Derived>
6511NestedNameSpecifier *
6512TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6513 SourceRange Range,
6514 NamespaceDecl *NS) {
6515 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6516}
6517
6518template<typename Derived>
6519NestedNameSpecifier *
6520TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6521 SourceRange Range,
6522 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006523 QualType T) {
6524 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006525 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006526 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006527 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6528 T.getTypePtr());
6529 }
Mike Stump11289f42009-09-09 15:08:12 +00006530
Douglas Gregor1135c352009-08-06 05:28:30 +00006531 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6532 return 0;
6533}
Mike Stump11289f42009-09-09 15:08:12 +00006534
Douglas Gregor71dc5092009-08-06 06:41:21 +00006535template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006536TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006537TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6538 bool TemplateKW,
6539 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006540 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006541 Template);
6542}
6543
6544template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006545TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006546TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006547 const IdentifierInfo &II,
6548 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006549 CXXScopeSpec SS;
6550 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006551 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006552 UnqualifiedId Name;
6553 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006554 Sema::TemplateTy Template;
6555 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6556 /*FIXME:*/getDerived().getBaseLocation(),
6557 SS,
6558 Name,
John McCallba7bf592010-08-24 05:47:05 +00006559 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006560 /*EnteringContext=*/false,
6561 Template);
6562 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006563}
Mike Stump11289f42009-09-09 15:08:12 +00006564
Douglas Gregora16548e2009-08-11 05:31:07 +00006565template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006566TemplateName
6567TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6568 OverloadedOperatorKind Operator,
6569 QualType ObjectType) {
6570 CXXScopeSpec SS;
6571 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6572 SS.setScopeRep(Qualifier);
6573 UnqualifiedId Name;
6574 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6575 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6576 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006577 Sema::TemplateTy Template;
6578 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006579 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006580 SS,
6581 Name,
John McCallba7bf592010-08-24 05:47:05 +00006582 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006583 /*EnteringContext=*/false,
6584 Template);
6585 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006586}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006587
Douglas Gregor71395fa2009-11-04 00:56:37 +00006588template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006589Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006590TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6591 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006592 Expr *OrigCallee,
6593 Expr *First,
6594 Expr *Second) {
6595 Expr *Callee = OrigCallee->IgnoreParenCasts();
6596 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006597
Douglas Gregora16548e2009-08-11 05:31:07 +00006598 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006599 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006600 if (!First->getType()->isOverloadableType() &&
6601 !Second->getType()->isOverloadableType())
6602 return getSema().CreateBuiltinArraySubscriptExpr(First,
6603 Callee->getLocStart(),
6604 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006605 } else if (Op == OO_Arrow) {
6606 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006607 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6608 } else if (Second == 0 || isPostIncDec) {
6609 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006610 // The argument is not of overloadable type, so try to create a
6611 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006612 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006613 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006614
John McCallb268a282010-08-23 23:25:46 +00006615 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006616 }
6617 } else {
John McCallb268a282010-08-23 23:25:46 +00006618 if (!First->getType()->isOverloadableType() &&
6619 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006620 // Neither of the arguments is an overloadable type, so try to
6621 // create a built-in binary operation.
6622 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006623 OwningExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006624 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006625 if (Result.isInvalid())
6626 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006627
Douglas Gregora16548e2009-08-11 05:31:07 +00006628 return move(Result);
6629 }
6630 }
Mike Stump11289f42009-09-09 15:08:12 +00006631
6632 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006633 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006634 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006635
John McCallb268a282010-08-23 23:25:46 +00006636 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006637 assert(ULE->requiresADL());
6638
6639 // FIXME: Do we have to check
6640 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006641 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006642 } else {
John McCallb268a282010-08-23 23:25:46 +00006643 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006644 }
Mike Stump11289f42009-09-09 15:08:12 +00006645
Douglas Gregora16548e2009-08-11 05:31:07 +00006646 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006647 Expr *Args[2] = { First, Second };
6648 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006649
Douglas Gregora16548e2009-08-11 05:31:07 +00006650 // Create the overloaded operator invocation for unary operators.
6651 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006652 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006653 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006654 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006655 }
Mike Stump11289f42009-09-09 15:08:12 +00006656
Sebastian Redladba46e2009-10-29 20:17:01 +00006657 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006658 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006659 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006660 First,
6661 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006662
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006664 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006666 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006667 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6668 if (Result.isInvalid())
6669 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006670
Mike Stump11289f42009-09-09 15:08:12 +00006671 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006672}
Mike Stump11289f42009-09-09 15:08:12 +00006673
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006674template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006675Sema::OwningExprResult
John McCallb268a282010-08-23 23:25:46 +00006676TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006677 SourceLocation OperatorLoc,
6678 bool isArrow,
6679 NestedNameSpecifier *Qualifier,
6680 SourceRange QualifierRange,
6681 TypeSourceInfo *ScopeType,
6682 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006683 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006684 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006685 CXXScopeSpec SS;
6686 if (Qualifier) {
6687 SS.setRange(QualifierRange);
6688 SS.setScopeRep(Qualifier);
6689 }
6690
John McCallb268a282010-08-23 23:25:46 +00006691 QualType BaseType = Base->getType();
6692 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006693 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006694 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006695 !BaseType->getAs<PointerType>()->getPointeeType()
6696 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006697 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006698 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006699 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006700 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006701 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006702 /*FIXME?*/true);
6703 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006704
Douglas Gregor678f90d2010-02-25 01:56:36 +00006705 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006706 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6707 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6708 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6709 NameInfo.setNamedTypeInfo(DestroyedType);
6710
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006711 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006712
John McCallb268a282010-08-23 23:25:46 +00006713 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006714 OperatorLoc, isArrow,
6715 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006716 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006717 /*TemplateArgs*/ 0);
6718}
6719
Douglas Gregord6ff3322009-08-04 16:50:30 +00006720} // end namespace clang
6721
6722#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H