blob: 16114f2ca399ac9fb02b44aa7ca5d87f3a582f02 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000028#include "clang/AST/TypeLocBuilder.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000036using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000037
Douglas Gregord6ff3322009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump11289f42009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump11289f42009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000093
94public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000097
Douglas Gregord6ff3322009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000104 }
105
John McCalldadc5752010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000119
Douglas Gregord6ff3322009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump11289f42009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregora16548e2009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000141
Douglas Gregora16548e2009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregora16548e2009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Douglas Gregora16548e2009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump11289f42009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregord196a582009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000182
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCall550e0c22009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000192 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000193
John McCall550e0c22009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 ///
John McCall550e0c22009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000203 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000204
205 /// \brief Transform the given type-with-location into a new
206 /// type, collecting location information in the given builder
207 /// as necessary.
208 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000209 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000210 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000211
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000213 ///
Mike Stump11289f42009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000221 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000222
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000231 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000232
Douglas Gregord6ff3322009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000238 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump11289f42009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000244 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
245 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 }
Mike Stump11289f42009-09-09 15:08:12 +0000247
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000251 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000259 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000260
Douglas Gregord6ff3322009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump11289f42009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000270
Douglas Gregorf816bd72009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000277 DeclarationNameInfo
278 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
279 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000280
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000282 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000288
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump11289f42009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCallbcd03502009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump11289f42009-09-09 15:08:12 +0000309
John McCall550e0c22009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000314#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000315
John McCall58f10c32010-03-11 09:03:00 +0000316 /// \brief Transforms the parameters of a function type into the
317 /// given vectors.
318 ///
319 /// The result vectors should be kept in sync; null entries in the
320 /// variables vector are acceptable.
321 ///
322 /// Return true on error.
323 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
324 llvm::SmallVectorImpl<QualType> &PTypes,
325 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
326
327 /// \brief Transforms a single function-type parameter. Return null
328 /// on error.
329 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
330
Alexis Hunta8136cc2010-05-05 15:23:54 +0000331 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000332 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000333
Alexis Hunta8136cc2010-05-05 15:23:54 +0000334 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000335 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
336 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000337
John McCalldadc5752010-08-24 06:29:42 +0000338 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
339 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000340
Douglas Gregorebe10102009-08-20 07:17:43 +0000341#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000342 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000343#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000344 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000345#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000346#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000347
Douglas Gregord6ff3322009-08-04 16:50:30 +0000348 /// \brief Build a new pointer type given its pointee type.
349 ///
350 /// By default, performs semantic analysis when building the pointer type.
351 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000352 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000353
354 /// \brief Build a new block pointer type given its pointee type.
355 ///
Mike Stump11289f42009-09-09 15:08:12 +0000356 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000357 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000358 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359
John McCall70dd5f62009-10-30 00:06:24 +0000360 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361 ///
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// By default, performs semantic analysis when building the
363 /// reference type. Subclasses may override this routine to provide
364 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000365 ///
John McCall70dd5f62009-10-30 00:06:24 +0000366 /// \param LValue whether the type was written with an lvalue sigil
367 /// or an rvalue sigil.
368 QualType RebuildReferenceType(QualType ReferentType,
369 bool LValue,
370 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000371
Douglas Gregord6ff3322009-08-04 16:50:30 +0000372 /// \brief Build a new member pointer type given the pointee type and the
373 /// class type it refers into.
374 ///
375 /// By default, performs semantic analysis when building the member pointer
376 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000377 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
378 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000379
Douglas Gregord6ff3322009-08-04 16:50:30 +0000380 /// \brief Build a new array type given the element type, size
381 /// modifier, size of the array (if known), size expression, and index type
382 /// qualifiers.
383 ///
384 /// By default, performs semantic analysis when building the array type.
385 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000386 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000387 QualType RebuildArrayType(QualType ElementType,
388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt *Size,
390 Expr *SizeExpr,
391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Build a new constant array type given the element type, size
395 /// modifier, (known) size of the array, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000399 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
401 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// \brief Build a new incomplete array type given the element type, size
406 /// modifier, and index type qualifiers.
407 ///
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000410 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000414
Mike Stump11289f42009-09-09 15:08:12 +0000415 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000420 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000422 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
Mike Stump11289f42009-09-09 15:08:12 +0000426 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000427 /// size modifier, size expression, and index type qualifiers.
428 ///
429 /// By default, performs semantic analysis when building the array type.
430 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000431 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000433 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 unsigned IndexTypeQuals,
435 SourceRange BracketsRange);
436
437 /// \brief Build a new vector type given the element type and
438 /// number of elements.
439 ///
440 /// By default, performs semantic analysis when building the vector type.
441 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000442 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner37141f42010-06-23 06:00:24 +0000443 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump11289f42009-09-09 15:08:12 +0000444
Douglas Gregord6ff3322009-08-04 16:50:30 +0000445 /// \brief Build a new extended vector type given the element type and
446 /// number of elements.
447 ///
448 /// By default, performs semantic analysis when building the vector type.
449 /// Subclasses may override this routine to provide different behavior.
450 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
451 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000452
453 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000454 /// given the element type and number of elements.
455 ///
456 /// By default, performs semantic analysis when building the vector type.
457 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000458 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000459 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000460 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000461
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 /// \brief Build a new function type.
463 ///
464 /// By default, performs semantic analysis when building the function type.
465 /// Subclasses may override this routine to provide different behavior.
466 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000467 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000468 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000469 bool Variadic, unsigned Quals,
470 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000471
John McCall550e0c22009-10-21 00:40:46 +0000472 /// \brief Build a new unprototyped function type.
473 QualType RebuildFunctionNoProtoType(QualType ResultType);
474
John McCallb96ec562009-12-04 22:46:56 +0000475 /// \brief Rebuild an unresolved typename type, given the decl that
476 /// the UnresolvedUsingTypenameDecl was transformed to.
477 QualType RebuildUnresolvedUsingType(Decl *D);
478
Douglas Gregord6ff3322009-08-04 16:50:30 +0000479 /// \brief Build a new typedef type.
480 QualType RebuildTypedefType(TypedefDecl *Typedef) {
481 return SemaRef.Context.getTypeDeclType(Typedef);
482 }
483
484 /// \brief Build a new class/struct/union type.
485 QualType RebuildRecordType(RecordDecl *Record) {
486 return SemaRef.Context.getTypeDeclType(Record);
487 }
488
489 /// \brief Build a new Enum type.
490 QualType RebuildEnumType(EnumDecl *Enum) {
491 return SemaRef.Context.getTypeDeclType(Enum);
492 }
John McCallfcc33b02009-09-05 00:15:47 +0000493
Mike Stump11289f42009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000495 ///
496 /// By default, performs semantic analysis when building the typeof type.
497 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, builds a new TypeOfType with the given underlying type.
503 QualType RebuildTypeOfType(QualType Underlying);
504
Mike Stump11289f42009-09-09 15:08:12 +0000505 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 ///
507 /// By default, performs semantic analysis when building the decltype type.
508 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000509 QualType RebuildDecltypeType(Expr *Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000510
Douglas Gregord6ff3322009-08-04 16:50:30 +0000511 /// \brief Build a new template specialization type.
512 ///
513 /// By default, performs semantic analysis when building the template
514 /// specialization type. Subclasses may override this routine to provide
515 /// different behavior.
516 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000517 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000518 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000519
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 /// \brief Build a new qualified name type.
521 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000522 /// By default, builds a new ElaboratedType type from the keyword,
523 /// the nested-name-specifier and the named type.
524 /// Subclasses may override this routine to provide different behavior.
525 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
526 NestedNameSpecifier *NNS, QualType Named) {
527 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000528 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529
530 /// \brief Build a new typename type that refers to a template-id.
531 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000532 /// By default, builds a new DependentNameType type from the
533 /// nested-name-specifier and the given type. Subclasses may override
534 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000535 QualType RebuildDependentTemplateSpecializationType(
536 ElaboratedTypeKeyword Keyword,
537 NestedNameSpecifier *NNS,
538 const IdentifierInfo *Name,
539 SourceLocation NameLoc,
540 const TemplateArgumentListInfo &Args) {
541 // Rebuild the template name.
542 // TODO: avoid TemplateName abstraction
543 TemplateName InstName =
544 getDerived().RebuildTemplateName(NNS, *Name, QualType());
545
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000546 if (InstName.isNull())
547 return QualType();
548
John McCallc392f372010-06-11 00:33:02 +0000549 // If it's still dependent, make a dependent specialization.
550 if (InstName.getAsDependentTemplateName())
551 return SemaRef.Context.getDependentTemplateSpecializationType(
552 Keyword, NNS, Name, Args);
553
554 // Otherwise, make an elaborated type wrapping a non-dependent
555 // specialization.
556 QualType T =
557 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
558 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000559
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000560 // NOTE: NNS is already recorded in template specialization type T.
561 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000562 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563
564 /// \brief Build a new typename type that refers to an identifier.
565 ///
566 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000567 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000570 NestedNameSpecifier *NNS,
571 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 SourceLocation KeywordLoc,
573 SourceRange NNSRange,
574 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000575 CXXScopeSpec SS;
576 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000577 SS.setRange(NNSRange);
578
Douglas Gregore677daf2010-03-31 22:19:08 +0000579 if (NNS->isDependent()) {
580 // If the name is still dependent, just build a new dependent name type.
581 if (!SemaRef.computeDeclContext(SS))
582 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
583 }
584
Abramo Bagnara6150c882010-05-11 21:36:43 +0000585 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000586 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
587 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000588
589 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
590
Abramo Bagnarad7548482010-05-19 21:37:53 +0000591 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000592 // into a non-dependent elaborated-type-specifier. Find the tag we're
593 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000594 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000595 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
596 if (!DC)
597 return QualType();
598
John McCallbf8c5192010-05-27 06:40:31 +0000599 if (SemaRef.RequireCompleteDeclContext(SS, DC))
600 return QualType();
601
Douglas Gregore677daf2010-03-31 22:19:08 +0000602 TagDecl *Tag = 0;
603 SemaRef.LookupQualifiedName(Result, DC);
604 switch (Result.getResultKind()) {
605 case LookupResult::NotFound:
606 case LookupResult::NotFoundInCurrentInstantiation:
607 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000608
Douglas Gregore677daf2010-03-31 22:19:08 +0000609 case LookupResult::Found:
610 Tag = Result.getAsSingle<TagDecl>();
611 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000612
Douglas Gregore677daf2010-03-31 22:19:08 +0000613 case LookupResult::FoundOverloaded:
614 case LookupResult::FoundUnresolvedValue:
615 llvm_unreachable("Tag lookup cannot find non-tags");
616 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000617
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 case LookupResult::Ambiguous:
619 // Let the LookupResult structure handle ambiguities.
620 return QualType();
621 }
622
623 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000624 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000625 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000627 return QualType();
628 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000629
Abramo Bagnarad7548482010-05-19 21:37:53 +0000630 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
631 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000632 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
633 return QualType();
634 }
635
636 // Build the elaborated-type-specifier type.
637 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000638 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000639 }
Mike Stump11289f42009-09-09 15:08:12 +0000640
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 /// \brief Build a new nested-name-specifier given the prefix and an
642 /// identifier that names the next step in the nested-name-specifier.
643 ///
644 /// By default, performs semantic analysis when building the new
645 /// nested-name-specifier. Subclasses may override this routine to provide
646 /// different behavior.
647 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
648 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000649 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000650 QualType ObjectType,
651 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000652
653 /// \brief Build a new nested-name-specifier given the prefix and the
654 /// namespace named in the next step in the nested-name-specifier.
655 ///
656 /// By default, performs semantic analysis when building the new
657 /// nested-name-specifier. Subclasses may override this routine to provide
658 /// different behavior.
659 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
660 SourceRange Range,
661 NamespaceDecl *NS);
662
663 /// \brief Build a new nested-name-specifier given the prefix and the
664 /// type named in the next step in the nested-name-specifier.
665 ///
666 /// By default, performs semantic analysis when building the new
667 /// nested-name-specifier. Subclasses may override this routine to provide
668 /// different behavior.
669 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
670 SourceRange Range,
671 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000672 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000673
674 /// \brief Build a new template name given a nested name specifier, a flag
675 /// indicating whether the "template" keyword was provided, and the template
676 /// that the template name refers to.
677 ///
678 /// By default, builds the new template name directly. Subclasses may override
679 /// this routine to provide different behavior.
680 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
681 bool TemplateKW,
682 TemplateDecl *Template);
683
Douglas Gregor71dc5092009-08-06 06:41:21 +0000684 /// \brief Build a new template name given a nested name specifier and the
685 /// name that is referred to as a template.
686 ///
687 /// By default, performs semantic analysis to determine whether the name can
688 /// be resolved to a specific template, then builds the appropriate kind of
689 /// template name. Subclasses may override this routine to provide different
690 /// behavior.
691 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000692 const IdentifierInfo &II,
693 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Douglas Gregor71395fa2009-11-04 00:56:37 +0000695 /// \brief Build a new template name given a nested name specifier and the
696 /// overloaded operator name that is referred to as a template.
697 ///
698 /// By default, performs semantic analysis to determine whether the name can
699 /// be resolved to a specific template, then builds the appropriate kind of
700 /// template name. Subclasses may override this routine to provide different
701 /// behavior.
702 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
703 OverloadedOperatorKind Operator,
704 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000705
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 /// \brief Build a new compound statement.
707 ///
708 /// By default, performs semantic analysis to build the new statement.
709 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000710 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000711 MultiStmtArg Statements,
712 SourceLocation RBraceLoc,
713 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000714 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000715 IsStmtExpr);
716 }
717
718 /// \brief Build a new case statement.
719 ///
720 /// By default, performs semantic analysis to build the new statement.
721 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000722 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000723 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000725 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000727 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 ColonLoc);
729 }
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 /// \brief Attach the body to a new case statement.
732 ///
733 /// By default, performs semantic analysis to build the new statement.
734 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000735 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000736 getSema().ActOnCaseStmtBody(S, Body);
737 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000738 }
Mike Stump11289f42009-09-09 15:08:12 +0000739
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 /// \brief Build a new default statement.
741 ///
742 /// By default, performs semantic analysis to build the new statement.
743 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000744 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000746 Stmt *SubStmt) {
747 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000748 /*CurScope=*/0);
749 }
Mike Stump11289f42009-09-09 15:08:12 +0000750
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 /// \brief Build a new label statement.
752 ///
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000755 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000756 IdentifierInfo *Id,
757 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000758 Stmt *SubStmt) {
759 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000760 }
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 /// \brief Build a new "if" statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000766 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000767 VarDecl *CondVar, Stmt *Then,
768 SourceLocation ElseLoc, Stmt *Else) {
769 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 }
Mike Stump11289f42009-09-09 15:08:12 +0000771
Douglas Gregorebe10102009-08-20 07:17:43 +0000772 /// \brief Start building a new switch statement.
773 ///
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000776 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000777 Expr *Cond, VarDecl *CondVar) {
778 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000779 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000780 }
Mike Stump11289f42009-09-09 15:08:12 +0000781
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 /// \brief Attach the body to the switch statement.
783 ///
784 /// By default, performs semantic analysis to build the new statement.
785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000786 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000787 Stmt *Switch, Stmt *Body) {
788 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 }
790
791 /// \brief Build a new while statement.
792 ///
793 /// By default, performs semantic analysis to build the new statement.
794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000795 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000796 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000797 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000798 Stmt *Body) {
799 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000800 }
Mike Stump11289f42009-09-09 15:08:12 +0000801
Douglas Gregorebe10102009-08-20 07:17:43 +0000802 /// \brief Build a new do-while statement.
803 ///
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000806 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 SourceLocation WhileLoc,
808 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000809 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000811 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
812 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000813 }
814
815 /// \brief Build a new for statement.
816 ///
817 /// By default, performs semantic analysis to build the new statement.
818 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000819 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000820 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000821 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000822 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000823 SourceLocation RParenLoc, Stmt *Body) {
824 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000825 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000826 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 }
Mike Stump11289f42009-09-09 15:08:12 +0000828
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 /// \brief Build a new goto statement.
830 ///
831 /// By default, performs semantic analysis to build the new statement.
832 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000833 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 SourceLocation LabelLoc,
835 LabelStmt *Label) {
836 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
837 }
838
839 /// \brief Build a new indirect goto statement.
840 ///
841 /// By default, performs semantic analysis to build the new statement.
842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000843 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000845 Expr *Target) {
846 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 }
Mike Stump11289f42009-09-09 15:08:12 +0000848
Douglas Gregorebe10102009-08-20 07:17:43 +0000849 /// \brief Build a new return statement.
850 ///
851 /// By default, performs semantic analysis to build the new statement.
852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000853 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000854 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000855
John McCallb268a282010-08-23 23:25:46 +0000856 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 }
Mike Stump11289f42009-09-09 15:08:12 +0000858
Douglas Gregorebe10102009-08-20 07:17:43 +0000859 /// \brief Build a new declaration statement.
860 ///
861 /// By default, performs semantic analysis to build the new statement.
862 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000863 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000864 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 SourceLocation EndLoc) {
866 return getSema().Owned(
867 new (getSema().Context) DeclStmt(
868 DeclGroupRef::Create(getSema().Context,
869 Decls, NumDecls),
870 StartLoc, EndLoc));
871 }
Mike Stump11289f42009-09-09 15:08:12 +0000872
Anders Carlssonaaeef072010-01-24 05:50:09 +0000873 /// \brief Build a new inline asm statement.
874 ///
875 /// By default, performs semantic analysis to build the new statement.
876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000877 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000878 bool IsSimple,
879 bool IsVolatile,
880 unsigned NumOutputs,
881 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000882 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000883 MultiExprArg Constraints,
884 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000885 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000886 MultiExprArg Clobbers,
887 SourceLocation RParenLoc,
888 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000889 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000890 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000891 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000892 RParenLoc, MSAsm);
893 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000894
895 /// \brief Build a new Objective-C @try statement.
896 ///
897 /// By default, performs semantic analysis to build the new statement.
898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000899 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000900 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000901 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000902 Stmt *Finally) {
903 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
904 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000905 }
906
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000907 /// \brief Rebuild an Objective-C exception declaration.
908 ///
909 /// By default, performs semantic analysis to build the new declaration.
910 /// Subclasses may override this routine to provide different behavior.
911 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
912 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000913 return getSema().BuildObjCExceptionDecl(TInfo, T,
914 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000915 ExceptionDecl->getLocation());
916 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000917
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000918 /// \brief Build a new Objective-C @catch statement.
919 ///
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000922 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 SourceLocation RParenLoc,
924 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000925 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000926 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000927 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000928 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000929
Douglas Gregor306de2f2010-04-22 23:59:56 +0000930 /// \brief Build a new Objective-C @finally statement.
931 ///
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000934 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000935 Stmt *Body) {
936 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000937 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000938
Douglas Gregor6148de72010-04-22 22:01:21 +0000939 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000940 ///
941 /// By default, performs semantic analysis to build the new statement.
942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000943 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000944 Expr *Operand) {
945 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000946 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000947
Douglas Gregor6148de72010-04-22 22:01:21 +0000948 /// \brief Build a new Objective-C @synchronized statement.
949 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000950 /// By default, performs semantic analysis to build the new statement.
951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000952 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000953 Expr *Object,
954 Stmt *Body) {
955 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
956 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000957 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000958
959 /// \brief Build a new Objective-C fast enumeration statement.
960 ///
961 /// By default, performs semantic analysis to build the new statement.
962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000963 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000964 SourceLocation LParenLoc,
965 Stmt *Element,
966 Expr *Collection,
967 SourceLocation RParenLoc,
968 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000969 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000970 Element,
971 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000972 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000973 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000974 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000975
Douglas Gregorebe10102009-08-20 07:17:43 +0000976 /// \brief Build a new C++ exception declaration.
977 ///
978 /// By default, performs semantic analysis to build the new decaration.
979 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000980 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000981 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 IdentifierInfo *Name,
983 SourceLocation Loc,
984 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000985 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 TypeRange);
987 }
988
989 /// \brief Build a new C++ catch statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000993 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000994 VarDecl *ExceptionDecl,
995 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +0000996 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
997 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +0000998 }
Mike Stump11289f42009-09-09 15:08:12 +0000999
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 /// \brief Build a new C++ try statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001004 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001005 Stmt *TryBlock,
1006 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001007 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001008 }
Mike Stump11289f42009-09-09 15:08:12 +00001009
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 /// \brief Build a new expression that references a declaration.
1011 ///
1012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001014 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001015 LookupResult &R,
1016 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001017 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1018 }
1019
1020
1021 /// \brief Build a new expression that references a declaration.
1022 ///
1023 /// By default, performs semantic analysis to build the new expression.
1024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001025 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001026 SourceRange QualifierRange,
1027 ValueDecl *VD,
1028 const DeclarationNameInfo &NameInfo,
1029 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001030 CXXScopeSpec SS;
1031 SS.setScopeRep(Qualifier);
1032 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001033
1034 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001035
1036 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 }
Mike Stump11289f42009-09-09 15:08:12 +00001038
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001040 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// By default, performs semantic analysis to build the new expression.
1042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001043 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001045 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 }
1047
Douglas Gregorad8a3362009-09-04 17:36:40 +00001048 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001049 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001052 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001053 SourceLocation OperatorLoc,
1054 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001055 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001056 SourceRange QualifierRange,
1057 TypeSourceInfo *ScopeType,
1058 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001059 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001060 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001061
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001063 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001066 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001067 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001068 Expr *SubExpr) {
1069 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor882211c2010-04-28 22:16:22 +00001072 /// \brief Build a new builtin offsetof expression.
1073 ///
1074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001077 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001078 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001079 unsigned NumComponents,
1080 SourceLocation RParenLoc) {
1081 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1082 NumComponents, RParenLoc);
1083 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001084
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001086 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// By default, performs semantic analysis to build the new expression.
1088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001089 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001090 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001092 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 }
1094
Mike Stump11289f42009-09-09 15:08:12 +00001095 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001097 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// By default, performs semantic analysis to build the new expression.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001102 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001103 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 return move(Result);
1108 }
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001114 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001116 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001118 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1119 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 RBracketLoc);
1121 }
1122
1123 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001124 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001127 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 MultiExprArg Args,
1129 SourceLocation *CommaLocs,
1130 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 move(Args), CommaLocs, RParenLoc);
1133 }
1134
1135 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001139 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001140 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001141 NestedNameSpecifier *Qualifier,
1142 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001143 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001144 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001145 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001146 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001147 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001148 if (!Member->getDeclName()) {
1149 // We have a reference to an unnamed field.
1150 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001151
John McCallb268a282010-08-23 23:25:46 +00001152 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001153 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001154 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001155
Mike Stump11289f42009-09-09 15:08:12 +00001156 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001157 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001158 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001159 cast<FieldDecl>(Member)->getType());
1160 return getSema().Owned(ME);
1161 }
Mike Stump11289f42009-09-09 15:08:12 +00001162
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001163 CXXScopeSpec SS;
1164 if (Qualifier) {
1165 SS.setRange(QualifierRange);
1166 SS.setScopeRep(Qualifier);
1167 }
1168
John McCallb268a282010-08-23 23:25:46 +00001169 getSema().DefaultFunctionArrayConversion(Base);
1170 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001171
John McCall16df1e52010-03-30 21:47:33 +00001172 // FIXME: this involves duplicating earlier analysis in a lot of
1173 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001174 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001175 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001176 R.resolveKind();
1177
John McCallb268a282010-08-23 23:25:46 +00001178 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001179 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001180 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001188 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001189 Expr *LHS, Expr *RHS) {
1190 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001191 }
1192
1193 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001194 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001195 /// By default, performs semantic analysis to build the new expression.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001199 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001201 Expr *RHS) {
1202 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1203 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 }
1205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001207 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001210 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001211 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001213 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001214 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001215 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001219 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// By default, performs semantic analysis to build the new expression.
1221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001222 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001223 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001225 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001226 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001227 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 }
Mike Stump11289f42009-09-09 15:08:12 +00001229
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001231 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 SourceLocation OpLoc,
1236 SourceLocation AccessorLoc,
1237 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001238
John McCall10eae182009-11-30 22:42:35 +00001239 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001240 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001241 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001242 OpLoc, /*IsArrow*/ false,
1243 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001244 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001245 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001249 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001252 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001254 SourceLocation RBraceLoc,
1255 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001256 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001257 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1258 if (Result.isInvalid() || ResultTy->isDependentType())
1259 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001260
Douglas Gregord3d93062009-11-09 17:16:50 +00001261 // Patch in the result type we were given, which may have been computed
1262 // when the initial InitListExpr was built.
1263 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1264 ILE->setType(ResultTy);
1265 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001266 }
Mike Stump11289f42009-09-09 15:08:12 +00001267
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001269 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001272 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 MultiExprArg ArrayExprs,
1274 SourceLocation EqualOrColonLoc,
1275 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001276 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001279 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 ArrayExprs.release();
1284 return move(Result);
1285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001288 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// By default, builds the implicit value initialization without performing
1290 /// any semantic analysis. Subclasses may override this routine to provide
1291 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1294 }
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001297 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001300 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001301 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001302 SourceLocation RParenLoc) {
1303 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001304 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001305 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 }
1307
1308 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001309 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// By default, performs semantic analysis to build the new expression.
1311 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001312 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 MultiExprArg SubExprs,
1314 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001315 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001316 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
1321 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// rather than attempting to map the label statement itself.
1323 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001324 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 SourceLocation LabelLoc,
1326 LabelStmt *Label) {
1327 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001335 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001337 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 }
Mike Stump11289f42009-09-09 15:08:12 +00001339
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 /// \brief Build a new __builtin_types_compatible_p expression.
1341 ///
1342 /// By default, performs semantic analysis to build the new expression.
1343 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001344 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001345 TypeSourceInfo *TInfo1,
1346 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001348 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1349 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 RParenLoc);
1351 }
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// \brief Build a new __builtin_choose_expr expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001358 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 SourceLocation RParenLoc) {
1360 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001361 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 RParenLoc);
1363 }
Mike Stump11289f42009-09-09 15:08:12 +00001364
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 /// \brief Build a new overloaded operator call expression.
1366 ///
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// The semantic analysis provides the behavior of template instantiation,
1369 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001370 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// argument-dependent lookup, etc. Subclasses may override this routine to
1372 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001373 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001375 Expr *Callee,
1376 Expr *First,
1377 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001378
1379 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 /// reinterpret_cast.
1381 ///
1382 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001383 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001385 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 Stmt::StmtClass Class,
1387 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001388 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 SourceLocation RAngleLoc,
1390 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001391 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 SourceLocation RParenLoc) {
1393 switch (Class) {
1394 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001397 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001398
1399 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001402 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001405 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001406 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001407 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001413 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 default:
1416 assert(false && "Invalid C++ named cast");
1417 break;
1418 }
Mike Stump11289f42009-09-09 15:08:12 +00001419
John McCallfaf5fb42010-08-26 23:41:50 +00001420 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 }
Mike Stump11289f42009-09-09 15:08:12 +00001422
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// \brief Build a new C++ static_cast expression.
1424 ///
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001427 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001429 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 SourceLocation RAngleLoc,
1431 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001432 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001435 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001436 SourceRange(LAngleLoc, RAngleLoc),
1437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 }
1439
1440 /// \brief Build a new C++ dynamic_cast expression.
1441 ///
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001444 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001446 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 SourceLocation RAngleLoc,
1448 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001449 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001452 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001453 SourceRange(LAngleLoc, RAngleLoc),
1454 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 }
1456
1457 /// \brief Build a new C++ reinterpret_cast expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001461 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001463 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 SourceLocation RAngleLoc,
1465 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001466 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001468 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001469 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001470 SourceRange(LAngleLoc, RAngleLoc),
1471 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 }
1473
1474 /// \brief Build a new C++ const_cast expression.
1475 ///
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001480 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 SourceLocation RAngleLoc,
1482 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001483 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001485 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001486 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001487 SourceRange(LAngleLoc, RAngleLoc),
1488 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 }
Mike Stump11289f42009-09-09 15:08:12 +00001490
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 /// \brief Build a new C++ functional-style cast expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001495 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1496 SourceLocation LParenLoc,
1497 Expr *Sub,
1498 SourceLocation RParenLoc) {
1499 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001500 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 RParenLoc);
1502 }
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// \brief Build a new C++ typeid(type) expression.
1505 ///
1506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001508 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001509 SourceLocation TypeidLoc,
1510 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001512 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001513 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 }
Mike Stump11289f42009-09-09 15:08:12 +00001515
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 /// \brief Build a new C++ typeid(expr) expression.
1517 ///
1518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001520 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001521 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001522 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001524 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001525 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001526 }
1527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new C++ "this" expression.
1529 ///
1530 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001531 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001533 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001534 QualType ThisType,
1535 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001537 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1538 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 }
1540
1541 /// \brief Build a new C++ throw expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001545 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001546 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 }
1548
1549 /// \brief Build a new C++ default-argument expression.
1550 ///
1551 /// By default, builds a new default-argument expression, which does not
1552 /// require any semantic analysis. Subclasses may override this routine to
1553 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001554 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001555 ParmVarDecl *Param) {
1556 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1557 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 }
1559
1560 /// \brief Build a new C++ zero-initialization expression.
1561 ///
1562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001564 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1565 SourceLocation LParenLoc,
1566 SourceLocation RParenLoc) {
1567 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001568 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001569 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 }
Mike Stump11289f42009-09-09 15:08:12 +00001571
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 /// \brief Build a new C++ "new" expression.
1573 ///
1574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001576 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001577 bool UseGlobal,
1578 SourceLocation PlacementLParen,
1579 MultiExprArg PlacementArgs,
1580 SourceLocation PlacementRParen,
1581 SourceRange TypeIdParens,
1582 QualType AllocatedType,
1583 TypeSourceInfo *AllocatedTypeInfo,
1584 Expr *ArraySize,
1585 SourceLocation ConstructorLParen,
1586 MultiExprArg ConstructorArgs,
1587 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001588 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 PlacementLParen,
1590 move(PlacementArgs),
1591 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001592 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001593 AllocatedType,
1594 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001595 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 ConstructorLParen,
1597 move(ConstructorArgs),
1598 ConstructorRParen);
1599 }
Mike Stump11289f42009-09-09 15:08:12 +00001600
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 /// \brief Build a new C++ "delete" expression.
1602 ///
1603 /// By default, performs semantic analysis to build the new expression.
1604 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001605 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 bool IsGlobalDelete,
1607 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001608 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001610 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 }
Mike Stump11289f42009-09-09 15:08:12 +00001612
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 /// \brief Build a new unary type trait expression.
1614 ///
1615 /// By default, performs semantic analysis to build the new expression.
1616 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001617 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 SourceLocation StartLoc,
1619 SourceLocation LParenLoc,
1620 QualType T,
1621 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001622 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallba7bf592010-08-24 05:47:05 +00001623 ParsedType::make(T), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 }
1625
Mike Stump11289f42009-09-09 15:08:12 +00001626 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 /// expression.
1628 ///
1629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001631 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001633 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001634 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 CXXScopeSpec SS;
1636 SS.setRange(QualifierRange);
1637 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001638
1639 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001640 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001641 *TemplateArgs);
1642
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001643 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 }
1645
1646 /// \brief Build a new template-id expression.
1647 ///
1648 /// By default, performs semantic analysis to build the new expression.
1649 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001650 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001651 LookupResult &R,
1652 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001653 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001654 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 }
1656
1657 /// \brief Build a new object-construction expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001661 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001662 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 CXXConstructorDecl *Constructor,
1664 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001665 MultiExprArg Args,
1666 bool RequiresZeroInit,
1667 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCall37ad5512010-08-23 06:44:23 +00001668 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001669 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001670 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001671 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001672
Douglas Gregordb121ba2009-12-14 16:27:04 +00001673 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001674 move_arg(ConvertedArgs),
1675 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 }
1677
1678 /// \brief Build a new object-construction expression.
1679 ///
1680 /// By default, performs semantic analysis to build the new expression.
1681 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001682 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1683 SourceLocation LParenLoc,
1684 MultiExprArg Args,
1685 SourceLocation RParenLoc) {
1686 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 LParenLoc,
1688 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 RParenLoc);
1690 }
1691
1692 /// \brief Build a new object-construction expression.
1693 ///
1694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001696 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1697 SourceLocation LParenLoc,
1698 MultiExprArg Args,
1699 SourceLocation RParenLoc) {
1700 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 LParenLoc,
1702 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 RParenLoc);
1704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 /// \brief Build a new member reference expression.
1707 ///
1708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001710 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001711 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 bool IsArrow,
1713 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001714 NestedNameSpecifier *Qualifier,
1715 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001716 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001717 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001718 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001720 SS.setRange(QualifierRange);
1721 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001722
John McCallb268a282010-08-23 23:25:46 +00001723 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001724 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001725 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001726 MemberNameInfo,
1727 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 }
1729
John McCall10eae182009-11-30 22:42:35 +00001730 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001734 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001735 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001736 SourceLocation OperatorLoc,
1737 bool IsArrow,
1738 NestedNameSpecifier *Qualifier,
1739 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001740 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001741 LookupResult &R,
1742 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001743 CXXScopeSpec SS;
1744 SS.setRange(QualifierRange);
1745 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001746
John McCallb268a282010-08-23 23:25:46 +00001747 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001748 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001749 SS, FirstQualifierInScope,
1750 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 /// \brief Build a new Objective-C @encode expression.
1754 ///
1755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001757 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001758 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001760 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001762 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001763
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001764 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001766 Selector Sel,
1767 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001768 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001769 MultiExprArg Args,
1770 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001771 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1772 ReceiverTypeInfo->getType(),
1773 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001774 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001775 move(Args));
1776 }
1777
1778 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001779 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001780 Selector Sel,
1781 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001782 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001783 MultiExprArg Args,
1784 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001785 return SemaRef.BuildInstanceMessage(Receiver,
1786 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001787 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001788 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001789 move(Args));
1790 }
1791
Douglas Gregord51d90d2010-04-26 20:11:03 +00001792 /// \brief Build a new Objective-C ivar reference expression.
1793 ///
1794 /// By default, performs semantic analysis to build the new expression.
1795 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001796 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001797 SourceLocation IvarLoc,
1798 bool IsArrow, bool IsFreeIvar) {
1799 // FIXME: We lose track of the IsFreeIvar bit.
1800 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001801 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001802 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1803 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001805 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001806 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001807 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001808 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001809 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001810
Douglas Gregord51d90d2010-04-26 20:11:03 +00001811 if (Result.get())
1812 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001813
John McCallb268a282010-08-23 23:25:46 +00001814 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001815 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001816 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001817 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001818 /*TemplateArgs=*/0);
1819 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001820
1821 /// \brief Build a new Objective-C property reference expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001825 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001826 ObjCPropertyDecl *Property,
1827 SourceLocation PropertyLoc) {
1828 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001829 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001830 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1831 Sema::LookupMemberName);
1832 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001833 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001834 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001835 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001836 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001837 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001838
Douglas Gregor9faee212010-04-26 20:47:02 +00001839 if (Result.get())
1840 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001841
John McCallb268a282010-08-23 23:25:46 +00001842 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001843 /*FIXME:*/PropertyLoc, IsArrow,
1844 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001845 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001846 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001847 /*TemplateArgs=*/0);
1848 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001849
1850 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001851 /// expression.
1852 ///
1853 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001856 ObjCMethodDecl *Getter,
1857 QualType T,
1858 ObjCMethodDecl *Setter,
1859 SourceLocation NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001860 Expr *Base) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001861 // Since these expressions can only be value-dependent, we do not need to
1862 // perform semantic analysis again.
John McCallb268a282010-08-23 23:25:46 +00001863 return Owned(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001864 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1865 Setter,
1866 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001867 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001868 }
1869
Douglas Gregord51d90d2010-04-26 20:11:03 +00001870 /// \brief Build a new Objective-C "isa" expression.
1871 ///
1872 /// By default, performs semantic analysis to build the new expression.
1873 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001874 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001875 bool IsArrow) {
1876 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001877 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001878 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1879 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001881 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001882 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001883 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001884 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001885
Douglas Gregord51d90d2010-04-26 20:11:03 +00001886 if (Result.get())
1887 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001888
John McCallb268a282010-08-23 23:25:46 +00001889 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001890 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001891 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001892 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001893 /*TemplateArgs=*/0);
1894 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001895
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// \brief Build a new shuffle vector expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 MultiExprArg SubExprs,
1902 SourceLocation RParenLoc) {
1903 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001904 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1906 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1907 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1908 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001909
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 // Build a reference to the __builtin_shufflevector builtin
1911 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001912 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001914 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001916
1917 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 unsigned NumSubExprs = SubExprs.size();
1919 Expr **Subs = (Expr **)SubExprs.release();
1920 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1921 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001922 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001924 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001925
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001927 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001930
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001932 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001934};
Douglas Gregora16548e2009-08-11 05:31:07 +00001935
Douglas Gregorebe10102009-08-20 07:17:43 +00001936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001937StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001938 if (!S)
1939 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregorebe10102009-08-20 07:17:43 +00001941 switch (S->getStmtClass()) {
1942 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001943
Douglas Gregorebe10102009-08-20 07:17:43 +00001944 // Transform individual statement nodes
1945#define STMT(Node, Parent) \
1946 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1947#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001948#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001949
Douglas Gregorebe10102009-08-20 07:17:43 +00001950 // Transform expressions by calling TransformExpr.
1951#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001952#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001953#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001954#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001955 {
John McCalldadc5752010-08-24 06:29:42 +00001956 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00001957 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001958 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001959
John McCallb268a282010-08-23 23:25:46 +00001960 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00001961 }
Mike Stump11289f42009-09-09 15:08:12 +00001962 }
1963
Douglas Gregorebe10102009-08-20 07:17:43 +00001964 return SemaRef.Owned(S->Retain());
1965}
Mike Stump11289f42009-09-09 15:08:12 +00001966
1967
Douglas Gregore922c772009-08-04 22:27:00 +00001968template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001969ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 if (!E)
1971 return SemaRef.Owned(E);
1972
1973 switch (E->getStmtClass()) {
1974 case Stmt::NoStmtClass: break;
1975#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00001976#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00001977#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001978 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00001979#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001980 }
1981
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001983}
1984
1985template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001986NestedNameSpecifier *
1987TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001988 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001989 QualType ObjectType,
1990 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001991 if (!NNS)
1992 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001993
Douglas Gregorebe10102009-08-20 07:17:43 +00001994 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001995 NestedNameSpecifier *Prefix = NNS->getPrefix();
1996 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001997 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001998 ObjectType,
1999 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002000 if (!Prefix)
2001 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002002
2003 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002004 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002005 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002006 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002007 }
Mike Stump11289f42009-09-09 15:08:12 +00002008
Douglas Gregor1135c352009-08-06 05:28:30 +00002009 switch (NNS->getKind()) {
2010 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002011 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002012 "Identifier nested-name-specifier with no prefix or object type");
2013 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2014 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002015 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002016
2017 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002018 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002019 ObjectType,
2020 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002021
Douglas Gregor1135c352009-08-06 05:28:30 +00002022 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002023 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002024 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002025 getDerived().TransformDecl(Range.getBegin(),
2026 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002027 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002028 Prefix == NNS->getPrefix() &&
2029 NS == NNS->getAsNamespace())
2030 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002031
Douglas Gregor1135c352009-08-06 05:28:30 +00002032 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2033 }
Mike Stump11289f42009-09-09 15:08:12 +00002034
Douglas Gregor1135c352009-08-06 05:28:30 +00002035 case NestedNameSpecifier::Global:
2036 // There is no meaningful transformation that one could perform on the
2037 // global scope.
2038 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregor1135c352009-08-06 05:28:30 +00002040 case NestedNameSpecifier::TypeSpecWithTemplate:
2041 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002042 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002043 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2044 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002045 if (T.isNull())
2046 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002047
Douglas Gregor1135c352009-08-06 05:28:30 +00002048 if (!getDerived().AlwaysRebuild() &&
2049 Prefix == NNS->getPrefix() &&
2050 T == QualType(NNS->getAsType(), 0))
2051 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002052
2053 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2054 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002055 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002056 }
2057 }
Mike Stump11289f42009-09-09 15:08:12 +00002058
Douglas Gregor1135c352009-08-06 05:28:30 +00002059 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002060 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002061}
2062
2063template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002064DeclarationNameInfo
2065TreeTransform<Derived>
2066::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2067 QualType ObjectType) {
2068 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002069 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002070 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002071
2072 switch (Name.getNameKind()) {
2073 case DeclarationName::Identifier:
2074 case DeclarationName::ObjCZeroArgSelector:
2075 case DeclarationName::ObjCOneArgSelector:
2076 case DeclarationName::ObjCMultiArgSelector:
2077 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002078 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002079 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002080 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregorf816bd72009-09-03 22:13:48 +00002082 case DeclarationName::CXXConstructorName:
2083 case DeclarationName::CXXDestructorName:
2084 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002085 TypeSourceInfo *NewTInfo;
2086 CanQualType NewCanTy;
2087 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2088 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2089 if (!NewTInfo)
2090 return DeclarationNameInfo();
2091 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2092 }
2093 else {
2094 NewTInfo = 0;
2095 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2096 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2097 ObjectType);
2098 if (NewT.isNull())
2099 return DeclarationNameInfo();
2100 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2101 }
Mike Stump11289f42009-09-09 15:08:12 +00002102
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002103 DeclarationName NewName
2104 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2105 NewCanTy);
2106 DeclarationNameInfo NewNameInfo(NameInfo);
2107 NewNameInfo.setName(NewName);
2108 NewNameInfo.setNamedTypeInfo(NewTInfo);
2109 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002110 }
Mike Stump11289f42009-09-09 15:08:12 +00002111 }
2112
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002113 assert(0 && "Unknown name kind.");
2114 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002115}
2116
2117template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002118TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002119TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2120 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002121 SourceLocation Loc = getDerived().getBaseLocation();
2122
Douglas Gregor71dc5092009-08-06 06:41:21 +00002123 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002124 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002125 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002126 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2127 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002128 if (!NNS)
2129 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002130
Douglas Gregor71dc5092009-08-06 06:41:21 +00002131 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002132 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002133 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002134 if (!TransTemplate)
2135 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002136
Douglas Gregor71dc5092009-08-06 06:41:21 +00002137 if (!getDerived().AlwaysRebuild() &&
2138 NNS == QTN->getQualifier() &&
2139 TransTemplate == Template)
2140 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002141
Douglas Gregor71dc5092009-08-06 06:41:21 +00002142 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2143 TransTemplate);
2144 }
Mike Stump11289f42009-09-09 15:08:12 +00002145
John McCalle66edc12009-11-24 19:00:30 +00002146 // These should be getting filtered out before they make it into the AST.
2147 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002148 }
Mike Stump11289f42009-09-09 15:08:12 +00002149
Douglas Gregor71dc5092009-08-06 06:41:21 +00002150 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002151 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002152 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002153 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2154 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002155 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002156 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002157
Douglas Gregor71dc5092009-08-06 06:41:21 +00002158 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002159 NNS == DTN->getQualifier() &&
2160 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002161 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002162
Douglas Gregor71395fa2009-11-04 00:56:37 +00002163 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002164 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002165 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002166
2167 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002168 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002169 }
Mike Stump11289f42009-09-09 15:08:12 +00002170
Douglas Gregor71dc5092009-08-06 06:41:21 +00002171 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002172 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002173 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002174 if (!TransTemplate)
2175 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 if (!getDerived().AlwaysRebuild() &&
2178 TransTemplate == Template)
2179 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002180
Douglas Gregor71dc5092009-08-06 06:41:21 +00002181 return TemplateName(TransTemplate);
2182 }
Mike Stump11289f42009-09-09 15:08:12 +00002183
John McCalle66edc12009-11-24 19:00:30 +00002184 // These should be getting filtered out before they reach the AST.
2185 assert(false && "overloaded function decl survived to here");
2186 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187}
2188
2189template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002190void TreeTransform<Derived>::InventTemplateArgumentLoc(
2191 const TemplateArgument &Arg,
2192 TemplateArgumentLoc &Output) {
2193 SourceLocation Loc = getDerived().getBaseLocation();
2194 switch (Arg.getKind()) {
2195 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002196 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002197 break;
2198
2199 case TemplateArgument::Type:
2200 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002201 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002202
John McCall0ad16662009-10-29 08:12:44 +00002203 break;
2204
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002205 case TemplateArgument::Template:
2206 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2207 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002208
John McCall0ad16662009-10-29 08:12:44 +00002209 case TemplateArgument::Expression:
2210 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2211 break;
2212
2213 case TemplateArgument::Declaration:
2214 case TemplateArgument::Integral:
2215 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002216 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002217 break;
2218 }
2219}
2220
2221template<typename Derived>
2222bool TreeTransform<Derived>::TransformTemplateArgument(
2223 const TemplateArgumentLoc &Input,
2224 TemplateArgumentLoc &Output) {
2225 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002226 switch (Arg.getKind()) {
2227 case TemplateArgument::Null:
2228 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002229 Output = Input;
2230 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002231
Douglas Gregore922c772009-08-04 22:27:00 +00002232 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002233 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002234 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002235 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002236
2237 DI = getDerived().TransformType(DI);
2238 if (!DI) return true;
2239
2240 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2241 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002242 }
Mike Stump11289f42009-09-09 15:08:12 +00002243
Douglas Gregore922c772009-08-04 22:27:00 +00002244 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002245 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002246 DeclarationName Name;
2247 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2248 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002249 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002250 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002251 if (!D) return true;
2252
John McCall0d07eb32009-10-29 18:45:58 +00002253 Expr *SourceExpr = Input.getSourceDeclExpression();
2254 if (SourceExpr) {
2255 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002256 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002257 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002258 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002259 }
2260
2261 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002262 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002263 }
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002265 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002266 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002267 TemplateName Template
2268 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2269 if (Template.isNull())
2270 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002271
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002272 Output = TemplateArgumentLoc(TemplateArgument(Template),
2273 Input.getTemplateQualifierRange(),
2274 Input.getTemplateNameLoc());
2275 return false;
2276 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002277
Douglas Gregore922c772009-08-04 22:27:00 +00002278 case TemplateArgument::Expression: {
2279 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002280 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002281 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002282
John McCall0ad16662009-10-29 08:12:44 +00002283 Expr *InputExpr = Input.getSourceExpression();
2284 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2285
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002287 = getDerived().TransformExpr(InputExpr);
2288 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002289 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002290 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002291 }
Mike Stump11289f42009-09-09 15:08:12 +00002292
Douglas Gregore922c772009-08-04 22:27:00 +00002293 case TemplateArgument::Pack: {
2294 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2295 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002296 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002297 AEnd = Arg.pack_end();
2298 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002299
John McCall0ad16662009-10-29 08:12:44 +00002300 // FIXME: preserve source information here when we start
2301 // caring about parameter packs.
2302
John McCall0d07eb32009-10-29 18:45:58 +00002303 TemplateArgumentLoc InputArg;
2304 TemplateArgumentLoc OutputArg;
2305 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2306 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002307 return true;
2308
John McCall0d07eb32009-10-29 18:45:58 +00002309 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002310 }
2311 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002312 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002313 true);
John McCall0d07eb32009-10-29 18:45:58 +00002314 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002315 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002316 }
2317 }
Mike Stump11289f42009-09-09 15:08:12 +00002318
Douglas Gregore922c772009-08-04 22:27:00 +00002319 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002320 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002321}
2322
Douglas Gregord6ff3322009-08-04 16:50:30 +00002323//===----------------------------------------------------------------------===//
2324// Type transformation
2325//===----------------------------------------------------------------------===//
2326
2327template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002328QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002329 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002330 if (getDerived().AlreadyTransformed(T))
2331 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002332
John McCall550e0c22009-10-21 00:40:46 +00002333 // Temporary workaround. All of these transformations should
2334 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002335 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002336 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002337
Douglas Gregorfe17d252010-02-16 19:09:40 +00002338 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002339
John McCall550e0c22009-10-21 00:40:46 +00002340 if (!NewDI)
2341 return QualType();
2342
2343 return NewDI->getType();
2344}
2345
2346template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002347TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2348 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002349 if (getDerived().AlreadyTransformed(DI->getType()))
2350 return DI;
2351
2352 TypeLocBuilder TLB;
2353
2354 TypeLoc TL = DI->getTypeLoc();
2355 TLB.reserve(TL.getFullDataSize());
2356
Douglas Gregorfe17d252010-02-16 19:09:40 +00002357 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002358 if (Result.isNull())
2359 return 0;
2360
John McCallbcd03502009-12-07 02:54:59 +00002361 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002362}
2363
2364template<typename Derived>
2365QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002366TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2367 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002368 switch (T.getTypeLocClass()) {
2369#define ABSTRACT_TYPELOC(CLASS, PARENT)
2370#define TYPELOC(CLASS, PARENT) \
2371 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002372 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2373 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002374#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002375 }
Mike Stump11289f42009-09-09 15:08:12 +00002376
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002377 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002378 return QualType();
2379}
2380
2381/// FIXME: By default, this routine adds type qualifiers only to types
2382/// that can have qualifiers, and silently suppresses those qualifiers
2383/// that are not permitted (e.g., qualifiers on reference or function
2384/// types). This is the right thing for template instantiation, but
2385/// probably not for other clients.
2386template<typename Derived>
2387QualType
2388TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002389 QualifiedTypeLoc T,
2390 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002391 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002392
Douglas Gregorfe17d252010-02-16 19:09:40 +00002393 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2394 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002395 if (Result.isNull())
2396 return QualType();
2397
2398 // Silently suppress qualifiers if the result type can't be qualified.
2399 // FIXME: this is the right thing for template instantiation, but
2400 // probably not for other clients.
2401 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002402 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002403
John McCallcb0f89a2010-06-05 06:41:15 +00002404 if (!Quals.empty()) {
2405 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2406 TLB.push<QualifiedTypeLoc>(Result);
2407 // No location information to preserve.
2408 }
John McCall550e0c22009-10-21 00:40:46 +00002409
2410 return Result;
2411}
2412
2413template <class TyLoc> static inline
2414QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2415 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2416 NewT.setNameLoc(T.getNameLoc());
2417 return T.getType();
2418}
2419
John McCall550e0c22009-10-21 00:40:46 +00002420template<typename Derived>
2421QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002422 BuiltinTypeLoc T,
2423 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002424 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2425 NewT.setBuiltinLoc(T.getBuiltinLoc());
2426 if (T.needsExtraLocalData())
2427 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2428 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002429}
Mike Stump11289f42009-09-09 15:08:12 +00002430
Douglas Gregord6ff3322009-08-04 16:50:30 +00002431template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002432QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002433 ComplexTypeLoc T,
2434 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002435 // FIXME: recurse?
2436 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002437}
Mike Stump11289f42009-09-09 15:08:12 +00002438
Douglas Gregord6ff3322009-08-04 16:50:30 +00002439template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002440QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002441 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002442 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002443 QualType PointeeType
2444 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002445 if (PointeeType.isNull())
2446 return QualType();
2447
2448 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002449 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002450 // A dependent pointer type 'T *' has is being transformed such
2451 // that an Objective-C class type is being replaced for 'T'. The
2452 // resulting pointer type is an ObjCObjectPointerType, not a
2453 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002454 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002455
John McCall8b07ec22010-05-15 11:32:37 +00002456 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2457 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002458 return Result;
2459 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002460
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002461 if (getDerived().AlwaysRebuild() ||
2462 PointeeType != TL.getPointeeLoc().getType()) {
2463 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2464 if (Result.isNull())
2465 return QualType();
2466 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002467
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002468 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2469 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002470 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002471}
Mike Stump11289f42009-09-09 15:08:12 +00002472
2473template<typename Derived>
2474QualType
John McCall550e0c22009-10-21 00:40:46 +00002475TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002476 BlockPointerTypeLoc TL,
2477 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002478 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002479 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2480 if (PointeeType.isNull())
2481 return QualType();
2482
2483 QualType Result = TL.getType();
2484 if (getDerived().AlwaysRebuild() ||
2485 PointeeType != TL.getPointeeLoc().getType()) {
2486 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002487 TL.getSigilLoc());
2488 if (Result.isNull())
2489 return QualType();
2490 }
2491
Douglas Gregor049211a2010-04-22 16:50:51 +00002492 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002493 NewT.setSigilLoc(TL.getSigilLoc());
2494 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002495}
2496
John McCall70dd5f62009-10-30 00:06:24 +00002497/// Transforms a reference type. Note that somewhat paradoxically we
2498/// don't care whether the type itself is an l-value type or an r-value
2499/// type; we only care if the type was *written* as an l-value type
2500/// or an r-value type.
2501template<typename Derived>
2502QualType
2503TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002504 ReferenceTypeLoc TL,
2505 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002506 const ReferenceType *T = TL.getTypePtr();
2507
2508 // Note that this works with the pointee-as-written.
2509 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2510 if (PointeeType.isNull())
2511 return QualType();
2512
2513 QualType Result = TL.getType();
2514 if (getDerived().AlwaysRebuild() ||
2515 PointeeType != T->getPointeeTypeAsWritten()) {
2516 Result = getDerived().RebuildReferenceType(PointeeType,
2517 T->isSpelledAsLValue(),
2518 TL.getSigilLoc());
2519 if (Result.isNull())
2520 return QualType();
2521 }
2522
2523 // r-value references can be rebuilt as l-value references.
2524 ReferenceTypeLoc NewTL;
2525 if (isa<LValueReferenceType>(Result))
2526 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2527 else
2528 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2529 NewTL.setSigilLoc(TL.getSigilLoc());
2530
2531 return Result;
2532}
2533
Mike Stump11289f42009-09-09 15:08:12 +00002534template<typename Derived>
2535QualType
John McCall550e0c22009-10-21 00:40:46 +00002536TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002537 LValueReferenceTypeLoc TL,
2538 QualType ObjectType) {
2539 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002540}
2541
Mike Stump11289f42009-09-09 15:08:12 +00002542template<typename Derived>
2543QualType
John McCall550e0c22009-10-21 00:40:46 +00002544TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002545 RValueReferenceTypeLoc TL,
2546 QualType ObjectType) {
2547 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002548}
Mike Stump11289f42009-09-09 15:08:12 +00002549
Douglas Gregord6ff3322009-08-04 16:50:30 +00002550template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002551QualType
John McCall550e0c22009-10-21 00:40:46 +00002552TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002553 MemberPointerTypeLoc TL,
2554 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002555 MemberPointerType *T = TL.getTypePtr();
2556
2557 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002558 if (PointeeType.isNull())
2559 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002560
John McCall550e0c22009-10-21 00:40:46 +00002561 // TODO: preserve source information for this.
2562 QualType ClassType
2563 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002564 if (ClassType.isNull())
2565 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002566
John McCall550e0c22009-10-21 00:40:46 +00002567 QualType Result = TL.getType();
2568 if (getDerived().AlwaysRebuild() ||
2569 PointeeType != T->getPointeeType() ||
2570 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002571 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2572 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002573 if (Result.isNull())
2574 return QualType();
2575 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002576
John McCall550e0c22009-10-21 00:40:46 +00002577 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2578 NewTL.setSigilLoc(TL.getSigilLoc());
2579
2580 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002581}
2582
Mike Stump11289f42009-09-09 15:08:12 +00002583template<typename Derived>
2584QualType
John McCall550e0c22009-10-21 00:40:46 +00002585TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002586 ConstantArrayTypeLoc TL,
2587 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002588 ConstantArrayType *T = TL.getTypePtr();
2589 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002590 if (ElementType.isNull())
2591 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002592
John McCall550e0c22009-10-21 00:40:46 +00002593 QualType Result = TL.getType();
2594 if (getDerived().AlwaysRebuild() ||
2595 ElementType != T->getElementType()) {
2596 Result = getDerived().RebuildConstantArrayType(ElementType,
2597 T->getSizeModifier(),
2598 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002599 T->getIndexTypeCVRQualifiers(),
2600 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002601 if (Result.isNull())
2602 return QualType();
2603 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002604
John McCall550e0c22009-10-21 00:40:46 +00002605 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2606 NewTL.setLBracketLoc(TL.getLBracketLoc());
2607 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002608
John McCall550e0c22009-10-21 00:40:46 +00002609 Expr *Size = TL.getSizeExpr();
2610 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002611 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002612 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2613 }
2614 NewTL.setSizeExpr(Size);
2615
2616 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002617}
Mike Stump11289f42009-09-09 15:08:12 +00002618
Douglas Gregord6ff3322009-08-04 16:50:30 +00002619template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002620QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002621 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002622 IncompleteArrayTypeLoc TL,
2623 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002624 IncompleteArrayType *T = TL.getTypePtr();
2625 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002626 if (ElementType.isNull())
2627 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002628
John McCall550e0c22009-10-21 00:40:46 +00002629 QualType Result = TL.getType();
2630 if (getDerived().AlwaysRebuild() ||
2631 ElementType != T->getElementType()) {
2632 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002633 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002634 T->getIndexTypeCVRQualifiers(),
2635 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002636 if (Result.isNull())
2637 return QualType();
2638 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002639
John McCall550e0c22009-10-21 00:40:46 +00002640 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2641 NewTL.setLBracketLoc(TL.getLBracketLoc());
2642 NewTL.setRBracketLoc(TL.getRBracketLoc());
2643 NewTL.setSizeExpr(0);
2644
2645 return Result;
2646}
2647
2648template<typename Derived>
2649QualType
2650TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002651 VariableArrayTypeLoc TL,
2652 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002653 VariableArrayType *T = TL.getTypePtr();
2654 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2655 if (ElementType.isNull())
2656 return QualType();
2657
2658 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002659 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002660
John McCalldadc5752010-08-24 06:29:42 +00002661 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002662 = getDerived().TransformExpr(T->getSizeExpr());
2663 if (SizeResult.isInvalid())
2664 return QualType();
2665
John McCallb268a282010-08-23 23:25:46 +00002666 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002667
2668 QualType Result = TL.getType();
2669 if (getDerived().AlwaysRebuild() ||
2670 ElementType != T->getElementType() ||
2671 Size != T->getSizeExpr()) {
2672 Result = getDerived().RebuildVariableArrayType(ElementType,
2673 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002674 Size,
John McCall550e0c22009-10-21 00:40:46 +00002675 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002676 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002677 if (Result.isNull())
2678 return QualType();
2679 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002680
John McCall550e0c22009-10-21 00:40:46 +00002681 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2682 NewTL.setLBracketLoc(TL.getLBracketLoc());
2683 NewTL.setRBracketLoc(TL.getRBracketLoc());
2684 NewTL.setSizeExpr(Size);
2685
2686 return Result;
2687}
2688
2689template<typename Derived>
2690QualType
2691TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002692 DependentSizedArrayTypeLoc TL,
2693 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002694 DependentSizedArrayType *T = TL.getTypePtr();
2695 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2696 if (ElementType.isNull())
2697 return QualType();
2698
2699 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002700 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002701
John McCalldadc5752010-08-24 06:29:42 +00002702 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002703 = getDerived().TransformExpr(T->getSizeExpr());
2704 if (SizeResult.isInvalid())
2705 return QualType();
2706
2707 Expr *Size = static_cast<Expr*>(SizeResult.get());
2708
2709 QualType Result = TL.getType();
2710 if (getDerived().AlwaysRebuild() ||
2711 ElementType != T->getElementType() ||
2712 Size != T->getSizeExpr()) {
2713 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2714 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002715 Size,
John McCall550e0c22009-10-21 00:40:46 +00002716 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002717 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002718 if (Result.isNull())
2719 return QualType();
2720 }
2721 else SizeResult.take();
2722
2723 // We might have any sort of array type now, but fortunately they
2724 // all have the same location layout.
2725 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2726 NewTL.setLBracketLoc(TL.getLBracketLoc());
2727 NewTL.setRBracketLoc(TL.getRBracketLoc());
2728 NewTL.setSizeExpr(Size);
2729
2730 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002731}
Mike Stump11289f42009-09-09 15:08:12 +00002732
2733template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002734QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002735 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002736 DependentSizedExtVectorTypeLoc TL,
2737 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002738 DependentSizedExtVectorType *T = TL.getTypePtr();
2739
2740 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002741 QualType ElementType = getDerived().TransformType(T->getElementType());
2742 if (ElementType.isNull())
2743 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002744
Douglas Gregore922c772009-08-04 22:27:00 +00002745 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002746 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002747
John McCalldadc5752010-08-24 06:29:42 +00002748 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749 if (Size.isInvalid())
2750 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002751
John McCall550e0c22009-10-21 00:40:46 +00002752 QualType Result = TL.getType();
2753 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002754 ElementType != T->getElementType() ||
2755 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002756 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002757 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002759 if (Result.isNull())
2760 return QualType();
2761 }
John McCall550e0c22009-10-21 00:40:46 +00002762
2763 // Result might be dependent or not.
2764 if (isa<DependentSizedExtVectorType>(Result)) {
2765 DependentSizedExtVectorTypeLoc NewTL
2766 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2767 NewTL.setNameLoc(TL.getNameLoc());
2768 } else {
2769 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2770 NewTL.setNameLoc(TL.getNameLoc());
2771 }
2772
2773 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002774}
Mike Stump11289f42009-09-09 15:08:12 +00002775
2776template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002777QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002778 VectorTypeLoc TL,
2779 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002780 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002781 QualType ElementType = getDerived().TransformType(T->getElementType());
2782 if (ElementType.isNull())
2783 return QualType();
2784
John McCall550e0c22009-10-21 00:40:46 +00002785 QualType Result = TL.getType();
2786 if (getDerived().AlwaysRebuild() ||
2787 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002788 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002789 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002790 if (Result.isNull())
2791 return QualType();
2792 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002793
John McCall550e0c22009-10-21 00:40:46 +00002794 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2795 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002796
John McCall550e0c22009-10-21 00:40:46 +00002797 return Result;
2798}
2799
2800template<typename Derived>
2801QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002802 ExtVectorTypeLoc TL,
2803 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002804 VectorType *T = TL.getTypePtr();
2805 QualType ElementType = getDerived().TransformType(T->getElementType());
2806 if (ElementType.isNull())
2807 return QualType();
2808
2809 QualType Result = TL.getType();
2810 if (getDerived().AlwaysRebuild() ||
2811 ElementType != T->getElementType()) {
2812 Result = getDerived().RebuildExtVectorType(ElementType,
2813 T->getNumElements(),
2814 /*FIXME*/ SourceLocation());
2815 if (Result.isNull())
2816 return QualType();
2817 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002818
John McCall550e0c22009-10-21 00:40:46 +00002819 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2820 NewTL.setNameLoc(TL.getNameLoc());
2821
2822 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002823}
Mike Stump11289f42009-09-09 15:08:12 +00002824
2825template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002826ParmVarDecl *
2827TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2828 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2829 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2830 if (!NewDI)
2831 return 0;
2832
2833 if (NewDI == OldDI)
2834 return OldParm;
2835 else
2836 return ParmVarDecl::Create(SemaRef.Context,
2837 OldParm->getDeclContext(),
2838 OldParm->getLocation(),
2839 OldParm->getIdentifier(),
2840 NewDI->getType(),
2841 NewDI,
2842 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002843 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002844 /* DefArg */ NULL);
2845}
2846
2847template<typename Derived>
2848bool TreeTransform<Derived>::
2849 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2850 llvm::SmallVectorImpl<QualType> &PTypes,
2851 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2852 FunctionProtoType *T = TL.getTypePtr();
2853
2854 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2855 ParmVarDecl *OldParm = TL.getArg(i);
2856
2857 QualType NewType;
2858 ParmVarDecl *NewParm;
2859
2860 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002861 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2862 if (!NewParm)
2863 return true;
2864 NewType = NewParm->getType();
2865
2866 // Deal with the possibility that we don't have a parameter
2867 // declaration for this parameter.
2868 } else {
2869 NewParm = 0;
2870
2871 QualType OldType = T->getArgType(i);
2872 NewType = getDerived().TransformType(OldType);
2873 if (NewType.isNull())
2874 return true;
2875 }
2876
2877 PTypes.push_back(NewType);
2878 PVars.push_back(NewParm);
2879 }
2880
2881 return false;
2882}
2883
2884template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002885QualType
John McCall550e0c22009-10-21 00:40:46 +00002886TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002887 FunctionProtoTypeLoc TL,
2888 QualType ObjectType) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00002889 // Transform the parameters and return type.
2890 //
2891 // We instantiate in source order, with the return type first followed by
2892 // the parameters, because users tend to expect this (even if they shouldn't
2893 // rely on it!).
2894 //
2895 // FIXME: When we implement late-specified return types, we'll need to
2896 // instantiate the return tpe *after* the parameter types in that case,
2897 // since the return type can then refer to the parameters themselves (via
2898 // decltype, sizeof, etc.).
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002900 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00002901 FunctionProtoType *T = TL.getTypePtr();
2902 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2903 if (ResultType.isNull())
2904 return QualType();
Douglas Gregor4afc2362010-08-31 00:26:14 +00002905
2906 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2907 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002908
John McCall550e0c22009-10-21 00:40:46 +00002909 QualType Result = TL.getType();
2910 if (getDerived().AlwaysRebuild() ||
2911 ResultType != T->getResultType() ||
2912 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2913 Result = getDerived().RebuildFunctionProtoType(ResultType,
2914 ParamTypes.data(),
2915 ParamTypes.size(),
2916 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002917 T->getTypeQuals(),
2918 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002919 if (Result.isNull())
2920 return QualType();
2921 }
Mike Stump11289f42009-09-09 15:08:12 +00002922
John McCall550e0c22009-10-21 00:40:46 +00002923 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2924 NewTL.setLParenLoc(TL.getLParenLoc());
2925 NewTL.setRParenLoc(TL.getRParenLoc());
2926 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2927 NewTL.setArg(i, ParamDecls[i]);
2928
2929 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002930}
Mike Stump11289f42009-09-09 15:08:12 +00002931
Douglas Gregord6ff3322009-08-04 16:50:30 +00002932template<typename Derived>
2933QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002934 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002935 FunctionNoProtoTypeLoc TL,
2936 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002937 FunctionNoProtoType *T = TL.getTypePtr();
2938 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2939 if (ResultType.isNull())
2940 return QualType();
2941
2942 QualType Result = TL.getType();
2943 if (getDerived().AlwaysRebuild() ||
2944 ResultType != T->getResultType())
2945 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2946
2947 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2948 NewTL.setLParenLoc(TL.getLParenLoc());
2949 NewTL.setRParenLoc(TL.getRParenLoc());
2950
2951 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002952}
Mike Stump11289f42009-09-09 15:08:12 +00002953
John McCallb96ec562009-12-04 22:46:56 +00002954template<typename Derived> QualType
2955TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002956 UnresolvedUsingTypeLoc TL,
2957 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002958 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002959 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002960 if (!D)
2961 return QualType();
2962
2963 QualType Result = TL.getType();
2964 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2965 Result = getDerived().RebuildUnresolvedUsingType(D);
2966 if (Result.isNull())
2967 return QualType();
2968 }
2969
2970 // We might get an arbitrary type spec type back. We should at
2971 // least always get a type spec type, though.
2972 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2973 NewTL.setNameLoc(TL.getNameLoc());
2974
2975 return Result;
2976}
2977
Douglas Gregord6ff3322009-08-04 16:50:30 +00002978template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002979QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002980 TypedefTypeLoc TL,
2981 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002982 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002983 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002984 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2985 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002986 if (!Typedef)
2987 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002988
John McCall550e0c22009-10-21 00:40:46 +00002989 QualType Result = TL.getType();
2990 if (getDerived().AlwaysRebuild() ||
2991 Typedef != T->getDecl()) {
2992 Result = getDerived().RebuildTypedefType(Typedef);
2993 if (Result.isNull())
2994 return QualType();
2995 }
Mike Stump11289f42009-09-09 15:08:12 +00002996
John McCall550e0c22009-10-21 00:40:46 +00002997 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2998 NewTL.setNameLoc(TL.getNameLoc());
2999
3000 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003001}
Mike Stump11289f42009-09-09 15:08:12 +00003002
Douglas Gregord6ff3322009-08-04 16:50:30 +00003003template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003004QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003005 TypeOfExprTypeLoc TL,
3006 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003007 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003008 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003009
John McCalldadc5752010-08-24 06:29:42 +00003010 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003011 if (E.isInvalid())
3012 return QualType();
3013
John McCall550e0c22009-10-21 00:40:46 +00003014 QualType Result = TL.getType();
3015 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003016 E.get() != TL.getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003017 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003018 if (Result.isNull())
3019 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003020 }
John McCall550e0c22009-10-21 00:40:46 +00003021 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003022
John McCall550e0c22009-10-21 00:40:46 +00003023 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003024 NewTL.setTypeofLoc(TL.getTypeofLoc());
3025 NewTL.setLParenLoc(TL.getLParenLoc());
3026 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003027
3028 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003029}
Mike Stump11289f42009-09-09 15:08:12 +00003030
3031template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003032QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003033 TypeOfTypeLoc TL,
3034 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003035 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3036 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3037 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003038 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003039
John McCall550e0c22009-10-21 00:40:46 +00003040 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003041 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3042 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003043 if (Result.isNull())
3044 return QualType();
3045 }
Mike Stump11289f42009-09-09 15:08:12 +00003046
John McCall550e0c22009-10-21 00:40:46 +00003047 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003048 NewTL.setTypeofLoc(TL.getTypeofLoc());
3049 NewTL.setLParenLoc(TL.getLParenLoc());
3050 NewTL.setRParenLoc(TL.getRParenLoc());
3051 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003052
3053 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003054}
Mike Stump11289f42009-09-09 15:08:12 +00003055
3056template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003057QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003058 DecltypeTypeLoc TL,
3059 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003060 DecltypeType *T = TL.getTypePtr();
3061
Douglas Gregore922c772009-08-04 22:27:00 +00003062 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003063 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003064
John McCalldadc5752010-08-24 06:29:42 +00003065 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003066 if (E.isInvalid())
3067 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003068
John McCall550e0c22009-10-21 00:40:46 +00003069 QualType Result = TL.getType();
3070 if (getDerived().AlwaysRebuild() ||
3071 E.get() != T->getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003072 Result = getDerived().RebuildDecltypeType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003073 if (Result.isNull())
3074 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003075 }
John McCall550e0c22009-10-21 00:40:46 +00003076 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003077
John McCall550e0c22009-10-21 00:40:46 +00003078 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3079 NewTL.setNameLoc(TL.getNameLoc());
3080
3081 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003082}
3083
3084template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003085QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003086 RecordTypeLoc TL,
3087 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003088 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003089 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003090 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3091 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003092 if (!Record)
3093 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003094
John McCall550e0c22009-10-21 00:40:46 +00003095 QualType Result = TL.getType();
3096 if (getDerived().AlwaysRebuild() ||
3097 Record != T->getDecl()) {
3098 Result = getDerived().RebuildRecordType(Record);
3099 if (Result.isNull())
3100 return QualType();
3101 }
Mike Stump11289f42009-09-09 15:08:12 +00003102
John McCall550e0c22009-10-21 00:40:46 +00003103 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3104 NewTL.setNameLoc(TL.getNameLoc());
3105
3106 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003107}
Mike Stump11289f42009-09-09 15:08:12 +00003108
3109template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003110QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003111 EnumTypeLoc TL,
3112 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003113 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003114 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003115 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3116 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003117 if (!Enum)
3118 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003119
John McCall550e0c22009-10-21 00:40:46 +00003120 QualType Result = TL.getType();
3121 if (getDerived().AlwaysRebuild() ||
3122 Enum != T->getDecl()) {
3123 Result = getDerived().RebuildEnumType(Enum);
3124 if (Result.isNull())
3125 return QualType();
3126 }
Mike Stump11289f42009-09-09 15:08:12 +00003127
John McCall550e0c22009-10-21 00:40:46 +00003128 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3129 NewTL.setNameLoc(TL.getNameLoc());
3130
3131 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003132}
John McCallfcc33b02009-09-05 00:15:47 +00003133
John McCalle78aac42010-03-10 03:28:59 +00003134template<typename Derived>
3135QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3136 TypeLocBuilder &TLB,
3137 InjectedClassNameTypeLoc TL,
3138 QualType ObjectType) {
3139 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3140 TL.getTypePtr()->getDecl());
3141 if (!D) return QualType();
3142
3143 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3144 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3145 return T;
3146}
3147
Mike Stump11289f42009-09-09 15:08:12 +00003148
Douglas Gregord6ff3322009-08-04 16:50:30 +00003149template<typename Derived>
3150QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003151 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003152 TemplateTypeParmTypeLoc TL,
3153 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003154 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003155}
3156
Mike Stump11289f42009-09-09 15:08:12 +00003157template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003158QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003159 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003160 SubstTemplateTypeParmTypeLoc TL,
3161 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003162 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003163}
3164
3165template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003166QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3167 const TemplateSpecializationType *TST,
3168 QualType ObjectType) {
3169 // FIXME: this entire method is a temporary workaround; callers
3170 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003171
John McCall0ad16662009-10-29 08:12:44 +00003172 // Fake up a TemplateSpecializationTypeLoc.
3173 TypeLocBuilder TLB;
3174 TemplateSpecializationTypeLoc TL
3175 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3176
John McCall0d07eb32009-10-29 18:45:58 +00003177 SourceLocation BaseLoc = getDerived().getBaseLocation();
3178
3179 TL.setTemplateNameLoc(BaseLoc);
3180 TL.setLAngleLoc(BaseLoc);
3181 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003182 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3183 const TemplateArgument &TA = TST->getArg(i);
3184 TemplateArgumentLoc TAL;
3185 getDerived().InventTemplateArgumentLoc(TA, TAL);
3186 TL.setArgLocInfo(i, TAL.getLocInfo());
3187 }
3188
3189 TypeLocBuilder IgnoredTLB;
3190 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003191}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003192
Douglas Gregorc59e5612009-10-19 22:04:39 +00003193template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003194QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003195 TypeLocBuilder &TLB,
3196 TemplateSpecializationTypeLoc TL,
3197 QualType ObjectType) {
3198 const TemplateSpecializationType *T = TL.getTypePtr();
3199
Mike Stump11289f42009-09-09 15:08:12 +00003200 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003201 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003202 if (Template.isNull())
3203 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003204
John McCall6b51f282009-11-23 01:53:49 +00003205 TemplateArgumentListInfo NewTemplateArgs;
3206 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3207 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3208
3209 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3210 TemplateArgumentLoc Loc;
3211 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003212 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003213 NewTemplateArgs.addArgument(Loc);
3214 }
Mike Stump11289f42009-09-09 15:08:12 +00003215
John McCall0ad16662009-10-29 08:12:44 +00003216 // FIXME: maybe don't rebuild if all the template arguments are the same.
3217
3218 QualType Result =
3219 getDerived().RebuildTemplateSpecializationType(Template,
3220 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003221 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003222
3223 if (!Result.isNull()) {
3224 TemplateSpecializationTypeLoc NewTL
3225 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3226 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3227 NewTL.setLAngleLoc(TL.getLAngleLoc());
3228 NewTL.setRAngleLoc(TL.getRAngleLoc());
3229 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3230 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003231 }
Mike Stump11289f42009-09-09 15:08:12 +00003232
John McCall0ad16662009-10-29 08:12:44 +00003233 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003234}
Mike Stump11289f42009-09-09 15:08:12 +00003235
3236template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003237QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003238TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3239 ElaboratedTypeLoc TL,
3240 QualType ObjectType) {
3241 ElaboratedType *T = TL.getTypePtr();
3242
3243 NestedNameSpecifier *NNS = 0;
3244 // NOTE: the qualifier in an ElaboratedType is optional.
3245 if (T->getQualifier() != 0) {
3246 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003247 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003248 ObjectType);
3249 if (!NNS)
3250 return QualType();
3251 }
Mike Stump11289f42009-09-09 15:08:12 +00003252
Abramo Bagnarad7548482010-05-19 21:37:53 +00003253 QualType NamedT;
3254 // FIXME: this test is meant to workaround a problem (failing assertion)
3255 // occurring if directly executing the code in the else branch.
3256 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3257 TemplateSpecializationTypeLoc OldNamedTL
3258 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3259 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003260 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003261 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3262 if (NamedT.isNull())
3263 return QualType();
3264 TemplateSpecializationTypeLoc NewNamedTL
3265 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3266 NewNamedTL.copy(OldNamedTL);
3267 }
3268 else {
3269 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3270 if (NamedT.isNull())
3271 return QualType();
3272 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003273
John McCall550e0c22009-10-21 00:40:46 +00003274 QualType Result = TL.getType();
3275 if (getDerived().AlwaysRebuild() ||
3276 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003277 NamedT != T->getNamedType()) {
3278 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003279 if (Result.isNull())
3280 return QualType();
3281 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282
Abramo Bagnara6150c882010-05-11 21:36:43 +00003283 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003284 NewTL.setKeywordLoc(TL.getKeywordLoc());
3285 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003286
3287 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003288}
Mike Stump11289f42009-09-09 15:08:12 +00003289
3290template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003291QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3292 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003293 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003294 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003295
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003297 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3298 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003299 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300 if (!NNS)
3301 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003302
John McCallc392f372010-06-11 00:33:02 +00003303 QualType Result
3304 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3305 T->getIdentifier(),
3306 TL.getKeywordLoc(),
3307 TL.getQualifierRange(),
3308 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003309 if (Result.isNull())
3310 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003311
Abramo Bagnarad7548482010-05-19 21:37:53 +00003312 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3313 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003314 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3315
Abramo Bagnarad7548482010-05-19 21:37:53 +00003316 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3317 NewTL.setKeywordLoc(TL.getKeywordLoc());
3318 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003319 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003320 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3321 NewTL.setKeywordLoc(TL.getKeywordLoc());
3322 NewTL.setQualifierRange(TL.getQualifierRange());
3323 NewTL.setNameLoc(TL.getNameLoc());
3324 }
John McCall550e0c22009-10-21 00:40:46 +00003325 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003326}
Mike Stump11289f42009-09-09 15:08:12 +00003327
Douglas Gregord6ff3322009-08-04 16:50:30 +00003328template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003329QualType TreeTransform<Derived>::
3330 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3331 DependentTemplateSpecializationTypeLoc TL,
3332 QualType ObjectType) {
3333 DependentTemplateSpecializationType *T = TL.getTypePtr();
3334
3335 NestedNameSpecifier *NNS
3336 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3337 TL.getQualifierRange(),
3338 ObjectType);
3339 if (!NNS)
3340 return QualType();
3341
3342 TemplateArgumentListInfo NewTemplateArgs;
3343 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3344 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3345
3346 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3347 TemplateArgumentLoc Loc;
3348 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3349 return QualType();
3350 NewTemplateArgs.addArgument(Loc);
3351 }
3352
3353 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3354 T->getKeyword(),
3355 NNS,
3356 T->getIdentifier(),
3357 TL.getNameLoc(),
3358 NewTemplateArgs);
3359 if (Result.isNull())
3360 return QualType();
3361
3362 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3363 QualType NamedT = ElabT->getNamedType();
3364
3365 // Copy information relevant to the template specialization.
3366 TemplateSpecializationTypeLoc NamedTL
3367 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3368 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3369 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3370 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3371 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3372
3373 // Copy information relevant to the elaborated type.
3374 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3375 NewTL.setKeywordLoc(TL.getKeywordLoc());
3376 NewTL.setQualifierRange(TL.getQualifierRange());
3377 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003378 TypeLoc NewTL(Result, TL.getOpaqueData());
3379 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003380 }
3381 return Result;
3382}
3383
3384template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003385QualType
3386TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003387 ObjCInterfaceTypeLoc TL,
3388 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003389 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003390 TLB.pushFullCopy(TL);
3391 return TL.getType();
3392}
3393
3394template<typename Derived>
3395QualType
3396TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3397 ObjCObjectTypeLoc TL,
3398 QualType ObjectType) {
3399 // ObjCObjectType is never dependent.
3400 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003401 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003402}
Mike Stump11289f42009-09-09 15:08:12 +00003403
3404template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003405QualType
3406TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003407 ObjCObjectPointerTypeLoc TL,
3408 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003409 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003410 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003411 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003412}
3413
Douglas Gregord6ff3322009-08-04 16:50:30 +00003414//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003415// Statement transformation
3416//===----------------------------------------------------------------------===//
3417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003418StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003419TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3420 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003421}
3422
3423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003424StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003425TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3426 return getDerived().TransformCompoundStmt(S, false);
3427}
3428
3429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003430StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003431TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003432 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003433 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003434 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003435 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003436 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3437 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003438 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003439 if (Result.isInvalid()) {
3440 // Immediately fail if this was a DeclStmt, since it's very
3441 // likely that this will cause problems for future statements.
3442 if (isa<DeclStmt>(*B))
3443 return StmtError();
3444
3445 // Otherwise, just keep processing substatements and fail later.
3446 SubStmtInvalid = true;
3447 continue;
3448 }
Mike Stump11289f42009-09-09 15:08:12 +00003449
Douglas Gregorebe10102009-08-20 07:17:43 +00003450 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3451 Statements.push_back(Result.takeAs<Stmt>());
3452 }
Mike Stump11289f42009-09-09 15:08:12 +00003453
John McCall1ababa62010-08-27 19:56:05 +00003454 if (SubStmtInvalid)
3455 return StmtError();
3456
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>
John McCalldadc5752010-08-24 06:29:42 +00003468StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003469TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003470 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003471 {
3472 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003473 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::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())
John McCallfaf5fb42010-08-26 23:41:50 +00003478 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003483 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003484 }
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.
John McCalldadc5752010-08-24 06:29:42 +00003489 StmtResult 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003495 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003496
Douglas Gregorebe10102009-08-20 07:17:43 +00003497 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003498 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003499 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003500 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003507StmtResult
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
John McCalldadc5752010-08-24 06:29:42 +00003510 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003511 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003512 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003520StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003521TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003522 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003523 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003524 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003533StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003534TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003535 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003536 ExprResult 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)
John McCallfaf5fb42010-08-26 23:41:50 +00003545 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003550 return 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()) {
John McCalldadc5752010-08-24 06:29:42 +00003554 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003555 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003556 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003557 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003558 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003566 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003567
Douglas Gregorebe10102009-08-20 07:17:43 +00003568 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003569 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003570 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003571 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003572
Douglas Gregorebe10102009-08-20 07:17:43 +00003573 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003574 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003575 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003576 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003591StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003592TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003593 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003594 ExprResult 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)
John McCallfaf5fb42010-08-26 23:41:50 +00003603 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003608 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003609 }
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003612 StmtResult 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003616 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003617
Douglas Gregorebe10102009-08-20 07:17:43 +00003618 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003619 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003620 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003621 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003622
Douglas Gregorebe10102009-08-20 07:17:43 +00003623 // 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>
John McCalldadc5752010-08-24 06:29:42 +00003629StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003630TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003631 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003632 ExprResult 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)
John McCallfaf5fb42010-08-26 23:41:50 +00003641 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003646 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003647
3648 if (S->getCond()) {
3649 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003650 ExprResult 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003654 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003661 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003662
Douglas Gregorebe10102009-08-20 07:17:43 +00003663 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003664 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003665 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003666 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003679StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003680TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003682 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003683 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003684 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003685
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003686 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003687 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003688 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003689 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003690
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>
John McCalldadc5752010-08-24 06:29:42 +00003702StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003703TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003705 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003706 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003707 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003708
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003710 ExprResult 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)
John McCallfaf5fb42010-08-26 23:41:50 +00003719 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003720 } 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003724 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003725
3726 if (S->getCond()) {
3727 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003728 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003729 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003730 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003731 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003732 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003733
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())
John McCallfaf5fb42010-08-26 23:41:50 +00003740 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003741
Douglas Gregorebe10102009-08-20 07:17:43 +00003742 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003743 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003744 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003745 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00003749 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003750
Douglas Gregorebe10102009-08-20 07:17:43 +00003751 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003752 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003753 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003754 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003769StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003770TreeTransform<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>
John McCalldadc5752010-08-24 06:29:42 +00003777StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003778TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003779 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003780 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003781 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003792StmtResult
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>
John McCalldadc5752010-08-24 06:29:42 +00003798StmtResult
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>
John McCalldadc5752010-08-24 06:29:42 +00003804StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003805TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003806 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003807 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003808 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003809
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>
John McCalldadc5752010-08-24 06:29:42 +00003816StmtResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00003825 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003841StmtResult
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>
John McCalldadc5752010-08-24 06:29:42 +00003848StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003849TreeTransform<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 McCalldadc5752010-08-24 06:29:42 +00003855 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003856 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);
John McCalldadc5752010-08-24 06:29:42 +00003869 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003870 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003871 return 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);
John McCalldadc5752010-08-24 06:29:42 +00003887 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003888 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003889 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003922StmtResult
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.
John McCalldadc5752010-08-24 06:29:42 +00003925 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003926 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003927 return 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) {
John McCalldadc5752010-08-24 06:29:42 +00003933 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003934 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003935 return 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 McCalldadc5752010-08-24 06:29:42 +00003942 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00003943 if (S->getFinallyStmt()) {
3944 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3945 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003946 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00003947 }
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>
John McCalldadc5752010-08-24 06:29:42 +00003962StmtResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00003971 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003972 }
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())
John McCallfaf5fb42010-08-26 23:41:50 +00003980 return 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)
John McCallfaf5fb42010-08-26 23:41:50 +00003985 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003986 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003987
John McCalldadc5752010-08-24 06:29:42 +00003988 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003989 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003990 return 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>
John McCalldadc5752010-08-24 06:29:42 +00003998StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003999TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004000 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004001 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004002 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004003 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004016StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004017TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004018 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004019 if (S->getThrowExpr()) {
4020 Operand = getDerived().TransformExpr(S->getThrowExpr());
4021 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004022 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004023 }
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>
John McCalldadc5752010-08-24 06:29:42 +00004033StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004034TreeTransform<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.
John McCalldadc5752010-08-24 06:29:42 +00004037 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004038 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004039 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004040
Douglas Gregor6148de72010-04-22 22:01:21 +00004041 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004042 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004043 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004044 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004058StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004059TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004060 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004061 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004062 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004063 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004064 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004065
Douglas Gregorf68a5082010-04-22 23:10:45 +00004066 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004067 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004068 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004069 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004070
Douglas Gregorf68a5082010-04-22 23:10:45 +00004071 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004072 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004073 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004074 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004094StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004095TreeTransform<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())
John McCallfaf5fb42010-08-26 23:41:50 +00004105 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00004115 return 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.
John McCalldadc5752010-08-24 06:29:42 +00004119 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004120 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004121 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004134StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004135TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4136 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004137 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004138 = getDerived().TransformCompoundStmt(S->getTryBlock());
4139 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004140 return 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) {
John McCalldadc5752010-08-24 06:29:42 +00004146 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004147 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4148 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004149 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004168ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004174ExprResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004181 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004182 }
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004188 return 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())
John McCallfaf5fb42010-08-26 23:41:50 +00004194 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004195 }
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))
John McCallfaf5fb42010-08-26 23:41:50 +00004218 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004219 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>
John McCalldadc5752010-08-24 06:29:42 +00004228ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004234ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004240ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004246ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004252ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004259TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004260 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004262 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004273TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004274 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004275 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004276 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004287ExprResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004292 return 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;
John McCallfaf5fb42010-08-26 23:41:50 +00004301 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004302 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());
John McCalldadc5752010-08-24 06:29:42 +00004313 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004314 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004315 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004353ExprResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004360 return 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 McCalldadc5752010-08-24 06:29:42 +00004370 ExprResult 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 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004375 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::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())
John McCallfaf5fb42010-08-26 23:41:50 +00004379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004380
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->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>
John McCalldadc5752010-08-24 06:29:42 +00004391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004392TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004393 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004394 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004395 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004396
John McCalldadc5752010-08-24 06:29:42 +00004397 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004399 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004415TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004417 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004418 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004419 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004420
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) {
John McCalldadc5752010-08-24 06:29:42 +00004426 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004428 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004453ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004454TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004455 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004457 return 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)
John McCallfaf5fb42010-08-26 23:41:50 +00004465 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004466 }
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004472 return 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)
John McCallfaf5fb42010-08-26 23:41:50 +00004481 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004482 }
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))
John McCallfaf5fb42010-08-26 23:41:50 +00004504 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004532ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004533TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004534 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004536 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004537
John McCalldadc5752010-08-24 06:29:42 +00004538 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004540 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004552ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004553TreeTransform<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>
John McCalldadc5752010-08-24 06:29:42 +00004559ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004560TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004561 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004563 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004564
John McCalldadc5752010-08-24 06:29:42 +00004565 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004568
John McCalldadc5752010-08-24 06:29:42 +00004569 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004571 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004587ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004595ExprResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004608 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004609 }
Mike Stump11289f42009-09-09 15:08:12 +00004610
John McCalldadc5752010-08-24 06:29:42 +00004611 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004612 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004613 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004614 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004628ExprResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004633 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004634
John McCalldadc5752010-08-24 06:29:42 +00004635 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004636 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004637 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004655TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004656 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 if (!getDerived().AlwaysRebuild() &&
4661 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>
John McCalldadc5752010-08-24 06:29:42 +00004673ExprResult
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) {
John McCalldadc5752010-08-24 06:29:42 +00004679 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004680 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004681 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004695ExprResult
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
John McCalldadc5752010-08-24 06:29:42 +00004700 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004702 return 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()) {
John McCalldadc5752010-08-24 06:29:42 +00004718 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004719 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004720 return 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?");
John McCalldadc5752010-08-24 06:29:42 +00004731 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4733 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004735
John McCalldadc5752010-08-24 06:29:42 +00004736 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004738 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004763ExprResult
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())
John McCallfaf5fb42010-08-26 23:41:50 +00004772 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004782ExprResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
John McCalldadc5752010-08-24 06:29:42 +00004788 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004789 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004790 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004802ExprResult
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) {
John McCalldadc5752010-08-24 06:29:42 +00004807 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004808 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004809 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004826ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004833ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004834TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004835 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004836 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4837 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004838 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004850ExprResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00004857 return 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)
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return 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>
John McCalldadc5752010-08-24 06:29:42 +00004874ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004875TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004876 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004879
John McCalldadc5752010-08-24 06:29:42 +00004880 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004881 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004882 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004883
John McCalldadc5752010-08-24 06:29:42 +00004884 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004885 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004886 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004887
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 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>
John McCalldadc5752010-08-24 06:29:42 +00004900ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00004906ExprResult
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");
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return 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.
John McCalldadc5752010-08-24 06:29:42 +00004921 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004922 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004923 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004924
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
John McCalldadc5752010-08-24 06:29:42 +00004937 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004938 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004939 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004940
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");
John McCallfaf5fb42010-08-26 23:41:50 +00004965 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004966
4967 case OO_None:
4968 case NUM_OVERLOADED_OPERATORS:
4969 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00004970 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004971 }
4972
John McCalldadc5752010-08-24 06:29:42 +00004973 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004974 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004976
John McCalldadc5752010-08-24 06:29:42 +00004977 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004978 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004979 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004980
John McCalldadc5752010-08-24 06:29:42 +00004981 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 if (E->getNumArgs() == 2) {
4983 Second = getDerived().TransformExpr(E->getArg(1));
4984 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004985 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 }
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>
John McCalldadc5752010-08-24 06:29:42 +00005002ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00005008ExprResult
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)
John McCallfaf5fb42010-08-26 23:41:50 +00005021 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005022 }
Mike Stump11289f42009-09-09 15:08:12 +00005023
John McCalldadc5752010-08-24 06:29:42 +00005024 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005025 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005027 return 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>
John McCalldadc5752010-08-24 06:29:42 +00005052ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00005058ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00005064ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005065TreeTransform<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>
John McCalldadc5752010-08-24 06:29:42 +00005071ExprResult
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>
John McCalldadc5752010-08-24 06:29:42 +00005077ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005078TreeTransform<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)
John McCallfaf5fb42010-08-26 23:41:50 +00005088 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 }
Mike Stump11289f42009-09-09 15:08:12 +00005090
John McCalldadc5752010-08-24 06:29:42 +00005091 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005092 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005093 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005094 return 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 Gregor2b88c112010-09-08 00:15:04 +00005101 return getDerived().RebuildCXXFunctionalCastExpr(NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005102 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005103 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 E->getRParenLoc());
5105}
Mike Stump11289f42009-09-09 15:08:12 +00005106
Douglas Gregora16548e2009-08-11 05:31:07 +00005107template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005108ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005109TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005110 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005111 TypeSourceInfo *TInfo
5112 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5113 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005114 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005115
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005117 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005119
Douglas Gregor9da64192010-04-26 22:37:10 +00005120 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5121 E->getLocStart(),
5122 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 E->getLocEnd());
5124 }
Mike Stump11289f42009-09-09 15:08:12 +00005125
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 // We don't know whether the expression is potentially evaluated until
5127 // after we perform semantic analysis, so the expression is potentially
5128 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005129 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005130 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005131
John McCalldadc5752010-08-24 06:29:42 +00005132 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005134 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregora16548e2009-08-11 05:31:07 +00005136 if (!getDerived().AlwaysRebuild() &&
5137 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005138 return SemaRef.Owned(E->Retain());
5139
Douglas Gregor9da64192010-04-26 22:37:10 +00005140 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5141 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005142 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005143 E->getLocEnd());
5144}
5145
5146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005148TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005149 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005150}
Mike Stump11289f42009-09-09 15:08:12 +00005151
Douglas Gregora16548e2009-08-11 05:31:07 +00005152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005153ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005154TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005155 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005156 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005157}
Mike Stump11289f42009-09-09 15:08:12 +00005158
Douglas Gregora16548e2009-08-11 05:31:07 +00005159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005161TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 QualType T = getDerived().TransformType(E->getType());
5165 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 if (!getDerived().AlwaysRebuild() &&
5169 T == E->getType())
5170 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005171
Douglas Gregorb15af892010-01-07 23:12:05 +00005172 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005173}
Mike Stump11289f42009-09-09 15:08:12 +00005174
Douglas Gregora16548e2009-08-11 05:31:07 +00005175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005177TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005178 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005179 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005180 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005181
Douglas Gregora16548e2009-08-11 05:31:07 +00005182 if (!getDerived().AlwaysRebuild() &&
5183 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005184 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005185
John McCallb268a282010-08-23 23:25:46 +00005186 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005187}
Mike Stump11289f42009-09-09 15:08:12 +00005188
Douglas Gregora16548e2009-08-11 05:31:07 +00005189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005191TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005192 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005193 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5194 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005195 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005197
Chandler Carruth794da4c2010-02-08 06:42:49 +00005198 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005199 Param == E->getParam())
5200 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005201
Douglas Gregor033f6752009-12-23 23:03:06 +00005202 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005203}
Mike Stump11289f42009-09-09 15:08:12 +00005204
Douglas Gregora16548e2009-08-11 05:31:07 +00005205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005206ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005207TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5208 CXXScalarValueInitExpr *E) {
5209 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5210 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005211 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005212
Douglas Gregora16548e2009-08-11 05:31:07 +00005213 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005214 T == E->getTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005215 return SemaRef.Owned(E->Retain());
5216
Douglas Gregor2b88c112010-09-08 00:15:04 +00005217 return getDerived().RebuildCXXScalarValueInitExpr(T,
5218 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005219 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005220}
Mike Stump11289f42009-09-09 15:08:12 +00005221
Douglas Gregora16548e2009-08-11 05:31:07 +00005222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005224TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005225 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005226 TypeSourceInfo *AllocTypeInfo
5227 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5228 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005229 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregora16548e2009-08-11 05:31:07 +00005231 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005232 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005233 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005234 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005235
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 // Transform the placement arguments (if any).
5237 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005238 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005240 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5245 PlacementArgs.push_back(Arg.take());
5246 }
Mike Stump11289f42009-09-09 15:08:12 +00005247
Douglas Gregorebe10102009-08-20 07:17:43 +00005248 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005249 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005250 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005251 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5252 break;
5253
John McCalldadc5752010-08-24 06:29:42 +00005254 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005255 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005256 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005257
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5259 ConstructorArgs.push_back(Arg.take());
5260 }
Mike Stump11289f42009-09-09 15:08:12 +00005261
Douglas Gregord2d9da02010-02-26 00:38:10 +00005262 // Transform constructor, new operator, and delete operator.
5263 CXXConstructorDecl *Constructor = 0;
5264 if (E->getConstructor()) {
5265 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005266 getDerived().TransformDecl(E->getLocStart(),
5267 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005268 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005269 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005270 }
5271
5272 FunctionDecl *OperatorNew = 0;
5273 if (E->getOperatorNew()) {
5274 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005275 getDerived().TransformDecl(E->getLocStart(),
5276 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005277 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005278 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005279 }
5280
5281 FunctionDecl *OperatorDelete = 0;
5282 if (E->getOperatorDelete()) {
5283 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005284 getDerived().TransformDecl(E->getLocStart(),
5285 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005286 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005287 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005288 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005289
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005291 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005292 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005293 Constructor == E->getConstructor() &&
5294 OperatorNew == E->getOperatorNew() &&
5295 OperatorDelete == E->getOperatorDelete() &&
5296 !ArgumentChanged) {
5297 // Mark any declarations we need as referenced.
5298 // FIXME: instantiation-specific.
5299 if (Constructor)
5300 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5301 if (OperatorNew)
5302 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5303 if (OperatorDelete)
5304 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005305 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005306 }
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregor0744ef62010-09-07 21:49:58 +00005308 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005309 if (!ArraySize.get()) {
5310 // If no array size was specified, but the new expression was
5311 // instantiated with an array type (e.g., "new T" where T is
5312 // instantiated with "int[4]"), extract the outer bound from the
5313 // array type as our array size. We do this with constant and
5314 // dependently-sized array types.
5315 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5316 if (!ArrayT) {
5317 // Do nothing
5318 } else if (const ConstantArrayType *ConsArrayT
5319 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005320 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005321 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5322 ConsArrayT->getSize(),
5323 SemaRef.Context.getSizeType(),
5324 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005325 AllocType = ConsArrayT->getElementType();
5326 } else if (const DependentSizedArrayType *DepArrayT
5327 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5328 if (DepArrayT->getSizeExpr()) {
5329 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5330 AllocType = DepArrayT->getElementType();
5331 }
5332 }
5333 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005334
Douglas Gregora16548e2009-08-11 05:31:07 +00005335 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5336 E->isGlobalNew(),
5337 /*FIXME:*/E->getLocStart(),
5338 move_arg(PlacementArgs),
5339 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005340 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005341 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005342 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005343 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005344 /*FIXME:*/E->getLocStart(),
5345 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005346 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005347}
Mike Stump11289f42009-09-09 15:08:12 +00005348
Douglas Gregora16548e2009-08-11 05:31:07 +00005349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005351TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005352 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005353 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005355
Douglas Gregord2d9da02010-02-26 00:38:10 +00005356 // Transform the delete operator, if known.
5357 FunctionDecl *OperatorDelete = 0;
5358 if (E->getOperatorDelete()) {
5359 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005360 getDerived().TransformDecl(E->getLocStart(),
5361 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005362 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005363 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005364 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005365
Douglas Gregora16548e2009-08-11 05:31:07 +00005366 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005367 Operand.get() == E->getArgument() &&
5368 OperatorDelete == E->getOperatorDelete()) {
5369 // Mark any declarations we need as referenced.
5370 // FIXME: instantiation-specific.
5371 if (OperatorDelete)
5372 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005373 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005374 }
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregora16548e2009-08-11 05:31:07 +00005376 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5377 E->isGlobalDelete(),
5378 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005379 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005380}
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregora16548e2009-08-11 05:31:07 +00005382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005383ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005384TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005385 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005386 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005387 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005389
John McCallba7bf592010-08-24 05:47:05 +00005390 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005391 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005392 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005393 E->getOperatorLoc(),
5394 E->isArrow()? tok::arrow : tok::period,
5395 ObjectTypePtr,
5396 MayBePseudoDestructor);
5397 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005398 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005399
John McCallba7bf592010-08-24 05:47:05 +00005400 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005401 NestedNameSpecifier *Qualifier
5402 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005403 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005404 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005405 if (E->getQualifier() && !Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005406 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005407
Douglas Gregor678f90d2010-02-25 01:56:36 +00005408 PseudoDestructorTypeStorage Destroyed;
5409 if (E->getDestroyedTypeInfo()) {
5410 TypeSourceInfo *DestroyedTypeInfo
5411 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5412 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005413 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005414 Destroyed = DestroyedTypeInfo;
5415 } else if (ObjectType->isDependentType()) {
5416 // We aren't likely to be able to resolve the identifier down to a type
5417 // now anyway, so just retain the identifier.
5418 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5419 E->getDestroyedTypeLoc());
5420 } else {
5421 // Look for a destructor known with the given name.
5422 CXXScopeSpec SS;
5423 if (Qualifier) {
5424 SS.setScopeRep(Qualifier);
5425 SS.setRange(E->getQualifierRange());
5426 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005427
John McCallba7bf592010-08-24 05:47:05 +00005428 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005429 *E->getDestroyedTypeIdentifier(),
5430 E->getDestroyedTypeLoc(),
5431 /*Scope=*/0,
5432 SS, ObjectTypePtr,
5433 false);
5434 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005435 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005436
Douglas Gregor678f90d2010-02-25 01:56:36 +00005437 Destroyed
5438 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5439 E->getDestroyedTypeLoc());
5440 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005441
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005442 TypeSourceInfo *ScopeTypeInfo = 0;
5443 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005444 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005445 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005446 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005447 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005448 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005449
John McCallb268a282010-08-23 23:25:46 +00005450 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005451 E->getOperatorLoc(),
5452 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005453 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005454 E->getQualifierRange(),
5455 ScopeTypeInfo,
5456 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005457 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005458 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005459}
Mike Stump11289f42009-09-09 15:08:12 +00005460
Douglas Gregorad8a3362009-09-04 17:36:40 +00005461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005462ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005463TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005464 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005465 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5466
5467 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5468 Sema::LookupOrdinaryName);
5469
5470 // Transform all the decls.
5471 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5472 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005473 NamedDecl *InstD = static_cast<NamedDecl*>(
5474 getDerived().TransformDecl(Old->getNameLoc(),
5475 *I));
John McCall84d87672009-12-10 09:41:52 +00005476 if (!InstD) {
5477 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5478 // This can happen because of dependent hiding.
5479 if (isa<UsingShadowDecl>(*I))
5480 continue;
5481 else
John McCallfaf5fb42010-08-26 23:41:50 +00005482 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005483 }
John McCalle66edc12009-11-24 19:00:30 +00005484
5485 // Expand using declarations.
5486 if (isa<UsingDecl>(InstD)) {
5487 UsingDecl *UD = cast<UsingDecl>(InstD);
5488 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5489 E = UD->shadow_end(); I != E; ++I)
5490 R.addDecl(*I);
5491 continue;
5492 }
5493
5494 R.addDecl(InstD);
5495 }
5496
5497 // Resolve a kind, but don't do any further analysis. If it's
5498 // ambiguous, the callee needs to deal with it.
5499 R.resolveKind();
5500
5501 // Rebuild the nested-name qualifier, if present.
5502 CXXScopeSpec SS;
5503 NestedNameSpecifier *Qualifier = 0;
5504 if (Old->getQualifier()) {
5505 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005506 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005507 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005508 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005509
John McCalle66edc12009-11-24 19:00:30 +00005510 SS.setScopeRep(Qualifier);
5511 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005512 }
5513
Douglas Gregor9262f472010-04-27 18:19:34 +00005514 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005515 CXXRecordDecl *NamingClass
5516 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5517 Old->getNameLoc(),
5518 Old->getNamingClass()));
5519 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005520 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005521
Douglas Gregorda7be082010-04-27 16:10:10 +00005522 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005523 }
5524
5525 // If we have no template arguments, it's a normal declaration name.
5526 if (!Old->hasExplicitTemplateArgs())
5527 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5528
5529 // If we have template arguments, rebuild them, then rebuild the
5530 // templateid expression.
5531 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5532 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5533 TemplateArgumentLoc Loc;
5534 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005535 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005536 TransArgs.addArgument(Loc);
5537 }
5538
5539 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5540 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005541}
Mike Stump11289f42009-09-09 15:08:12 +00005542
Douglas Gregora16548e2009-08-11 05:31:07 +00005543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005544ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005545TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 QualType T = getDerived().TransformType(E->getQueriedType());
5549 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 if (!getDerived().AlwaysRebuild() &&
5553 T == E->getQueriedType())
5554 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005555
Douglas Gregora16548e2009-08-11 05:31:07 +00005556 // FIXME: Bad location information
5557 SourceLocation FakeLParenLoc
5558 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005559
5560 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 E->getLocStart(),
5562 /*FIXME:*/FakeLParenLoc,
5563 T,
5564 E->getLocEnd());
5565}
Mike Stump11289f42009-09-09 15:08:12 +00005566
Douglas Gregora16548e2009-08-11 05:31:07 +00005567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005568ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005569TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005570 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005572 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005573 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005574 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005575 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005576
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005577 DeclarationNameInfo NameInfo
5578 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5579 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005581
John McCalle66edc12009-11-24 19:00:30 +00005582 if (!E->hasExplicitTemplateArgs()) {
5583 if (!getDerived().AlwaysRebuild() &&
5584 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005585 // Note: it is sufficient to compare the Name component of NameInfo:
5586 // if name has not changed, DNLoc has not changed either.
5587 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005588 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005589
John McCalle66edc12009-11-24 19:00:30 +00005590 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5591 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005592 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005593 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005594 }
John McCall6b51f282009-11-23 01:53:49 +00005595
5596 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005597 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005598 TemplateArgumentLoc Loc;
5599 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005601 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 }
5603
John McCalle66edc12009-11-24 19:00:30 +00005604 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5605 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005606 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005607 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005608}
5609
5610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005611ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005612TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005613 // CXXConstructExprs are always implicit, so when we have a
5614 // 1-argument construction we just transform that argument.
5615 if (E->getNumArgs() == 1 ||
5616 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5617 return getDerived().TransformExpr(E->getArg(0));
5618
Douglas Gregora16548e2009-08-11 05:31:07 +00005619 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5620
5621 QualType T = getDerived().TransformType(E->getType());
5622 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005624
5625 CXXConstructorDecl *Constructor
5626 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005627 getDerived().TransformDecl(E->getLocStart(),
5628 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005630 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005631
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005633 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005634 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 ArgEnd = E->arg_end();
5636 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005637 if (getDerived().DropCallArgument(*Arg)) {
5638 ArgumentChanged = true;
5639 break;
5640 }
5641
John McCalldadc5752010-08-24 06:29:42 +00005642 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005647 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005648 }
5649
5650 if (!getDerived().AlwaysRebuild() &&
5651 T == E->getType() &&
5652 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005653 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005654 // Mark the constructor as referenced.
5655 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005656 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005658 }
Mike Stump11289f42009-09-09 15:08:12 +00005659
Douglas Gregordb121ba2009-12-14 16:27:04 +00005660 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5661 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005662 move_arg(Args),
5663 E->requiresZeroInitialization(),
5664 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005665}
Mike Stump11289f42009-09-09 15:08:12 +00005666
Douglas Gregora16548e2009-08-11 05:31:07 +00005667/// \brief Transform a C++ temporary-binding expression.
5668///
Douglas Gregor363b1512009-12-24 18:51:59 +00005669/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5670/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005673TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005674 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005675}
Mike Stump11289f42009-09-09 15:08:12 +00005676
5677/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005678/// be destroyed after the expression is evaluated.
5679///
Douglas Gregor363b1512009-12-24 18:51:59 +00005680/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5681/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005683ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005684TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005685 CXXExprWithTemporaries *E) {
5686 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005687}
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregora16548e2009-08-11 05:31:07 +00005689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005690ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005691TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005692 CXXTemporaryObjectExpr *E) {
5693 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5694 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 CXXConstructorDecl *Constructor
5698 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005699 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005700 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005701 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregora16548e2009-08-11 05:31:07 +00005704 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005705 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005707 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 ArgEnd = E->arg_end();
5709 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005710 if (getDerived().DropCallArgument(*Arg)) {
5711 ArgumentChanged = true;
5712 break;
5713 }
5714
John McCalldadc5752010-08-24 06:29:42 +00005715 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005716 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005718
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5720 Args.push_back((Expr *)TransArg.release());
5721 }
Mike Stump11289f42009-09-09 15:08:12 +00005722
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005724 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005725 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005726 !ArgumentChanged) {
5727 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005728 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005729 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005730 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005731
5732 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5733 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 E->getLocEnd());
5736}
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregora16548e2009-08-11 05:31:07 +00005738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005739ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005740TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005741 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005742 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5743 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005744 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregora16548e2009-08-11 05:31:07 +00005746 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005747 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005748 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5749 ArgEnd = E->arg_end();
5750 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005751 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005752 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005754
Douglas Gregora16548e2009-08-11 05:31:07 +00005755 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005756 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005757 }
Mike Stump11289f42009-09-09 15:08:12 +00005758
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005760 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005761 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005762 return SemaRef.Owned(E->Retain());
5763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005765 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005766 E->getLParenLoc(),
5767 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 E->getRParenLoc());
5769}
Mike Stump11289f42009-09-09 15:08:12 +00005770
Douglas Gregora16548e2009-08-11 05:31:07 +00005771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005772ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005773TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005774 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005775 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005776 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005777 Expr *OldBase;
5778 QualType BaseType;
5779 QualType ObjectType;
5780 if (!E->isImplicitAccess()) {
5781 OldBase = E->getBase();
5782 Base = getDerived().TransformExpr(OldBase);
5783 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005785
John McCall2d74de92009-12-01 22:10:20 +00005786 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005787 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005788 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005789 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005790 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005791 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005792 ObjectTy,
5793 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005794 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005795 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005796
John McCallba7bf592010-08-24 05:47:05 +00005797 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005798 BaseType = ((Expr*) Base.get())->getType();
5799 } else {
5800 OldBase = 0;
5801 BaseType = getDerived().TransformType(E->getBaseType());
5802 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5803 }
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005805 // Transform the first part of the nested-name-specifier that qualifies
5806 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005807 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005808 = getDerived().TransformFirstQualifierInScope(
5809 E->getFirstQualifierFoundInScope(),
5810 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005811
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005812 NestedNameSpecifier *Qualifier = 0;
5813 if (E->getQualifier()) {
5814 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5815 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005816 ObjectType,
5817 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005818 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005819 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005820 }
Mike Stump11289f42009-09-09 15:08:12 +00005821
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005822 DeclarationNameInfo NameInfo
5823 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5824 ObjectType);
5825 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005827
John McCall2d74de92009-12-01 22:10:20 +00005828 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005829 // This is a reference to a member without an explicitly-specified
5830 // template argument list. Optimize for this common case.
5831 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005832 Base.get() == OldBase &&
5833 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005834 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005835 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005836 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005837 return SemaRef.Owned(E->Retain());
5838
John McCallb268a282010-08-23 23:25:46 +00005839 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005840 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005841 E->isArrow(),
5842 E->getOperatorLoc(),
5843 Qualifier,
5844 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005845 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005846 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005847 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005848 }
5849
John McCall6b51f282009-11-23 01:53:49 +00005850 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005851 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005852 TemplateArgumentLoc Loc;
5853 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005854 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005855 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005856 }
Mike Stump11289f42009-09-09 15:08:12 +00005857
John McCallb268a282010-08-23 23:25:46 +00005858 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005859 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 E->isArrow(),
5861 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005862 Qualifier,
5863 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005864 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005865 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005866 &TransArgs);
5867}
5868
5869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005871TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005872 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005873 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005874 QualType BaseType;
5875 if (!Old->isImplicitAccess()) {
5876 Base = getDerived().TransformExpr(Old->getBase());
5877 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005879 BaseType = ((Expr*) Base.get())->getType();
5880 } else {
5881 BaseType = getDerived().TransformType(Old->getBaseType());
5882 }
John McCall10eae182009-11-30 22:42:35 +00005883
5884 NestedNameSpecifier *Qualifier = 0;
5885 if (Old->getQualifier()) {
5886 Qualifier
5887 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005888 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005889 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005890 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005891 }
5892
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005893 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005894 Sema::LookupOrdinaryName);
5895
5896 // Transform all the decls.
5897 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5898 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005899 NamedDecl *InstD = static_cast<NamedDecl*>(
5900 getDerived().TransformDecl(Old->getMemberLoc(),
5901 *I));
John McCall84d87672009-12-10 09:41:52 +00005902 if (!InstD) {
5903 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5904 // This can happen because of dependent hiding.
5905 if (isa<UsingShadowDecl>(*I))
5906 continue;
5907 else
John McCallfaf5fb42010-08-26 23:41:50 +00005908 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005909 }
John McCall10eae182009-11-30 22:42:35 +00005910
5911 // Expand using declarations.
5912 if (isa<UsingDecl>(InstD)) {
5913 UsingDecl *UD = cast<UsingDecl>(InstD);
5914 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5915 E = UD->shadow_end(); I != E; ++I)
5916 R.addDecl(*I);
5917 continue;
5918 }
5919
5920 R.addDecl(InstD);
5921 }
5922
5923 R.resolveKind();
5924
Douglas Gregor9262f472010-04-27 18:19:34 +00005925 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005926 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005927 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005928 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005929 Old->getMemberLoc(),
5930 Old->getNamingClass()));
5931 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005932 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005933
Douglas Gregorda7be082010-04-27 16:10:10 +00005934 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005935 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005936
John McCall10eae182009-11-30 22:42:35 +00005937 TemplateArgumentListInfo TransArgs;
5938 if (Old->hasExplicitTemplateArgs()) {
5939 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5940 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5941 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5942 TemplateArgumentLoc Loc;
5943 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5944 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005945 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005946 TransArgs.addArgument(Loc);
5947 }
5948 }
John McCall38836f02010-01-15 08:34:02 +00005949
5950 // FIXME: to do this check properly, we will need to preserve the
5951 // first-qualifier-in-scope here, just in case we had a dependent
5952 // base (and therefore couldn't do the check) and a
5953 // nested-name-qualifier (and therefore could do the lookup).
5954 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005955
John McCallb268a282010-08-23 23:25:46 +00005956 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005957 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005958 Old->getOperatorLoc(),
5959 Old->isArrow(),
5960 Qualifier,
5961 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005962 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005963 R,
5964 (Old->hasExplicitTemplateArgs()
5965 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005966}
5967
5968template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005969ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005970TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005971 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005972}
5973
Mike Stump11289f42009-09-09 15:08:12 +00005974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005975ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005976TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005977 TypeSourceInfo *EncodedTypeInfo
5978 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5979 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005981
Douglas Gregora16548e2009-08-11 05:31:07 +00005982 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005983 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005984 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005985
5986 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005987 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005988 E->getRParenLoc());
5989}
Mike Stump11289f42009-09-09 15:08:12 +00005990
Douglas Gregora16548e2009-08-11 05:31:07 +00005991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005992ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005993TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005994 // Transform arguments.
5995 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005996 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005997 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005998 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005999 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006000 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006001
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006002 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006003 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006004 }
6005
6006 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6007 // Class message: transform the receiver type.
6008 TypeSourceInfo *ReceiverTypeInfo
6009 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6010 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006012
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006013 // If nothing changed, just retain the existing message send.
6014 if (!getDerived().AlwaysRebuild() &&
6015 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6016 return SemaRef.Owned(E->Retain());
6017
6018 // Build a new class message send.
6019 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6020 E->getSelector(),
6021 E->getMethodDecl(),
6022 E->getLeftLoc(),
6023 move_arg(Args),
6024 E->getRightLoc());
6025 }
6026
6027 // Instance message: transform the receiver
6028 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6029 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006030 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006031 = getDerived().TransformExpr(E->getInstanceReceiver());
6032 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006033 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006034
6035 // If nothing changed, just retain the existing message send.
6036 if (!getDerived().AlwaysRebuild() &&
6037 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6038 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006039
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006040 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006041 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006042 E->getSelector(),
6043 E->getMethodDecl(),
6044 E->getLeftLoc(),
6045 move_arg(Args),
6046 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006047}
6048
Mike Stump11289f42009-09-09 15:08:12 +00006049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006051TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006052 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006053}
6054
Mike Stump11289f42009-09-09 15:08:12 +00006055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006056ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006057TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006058 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006059}
6060
Mike Stump11289f42009-09-09 15:08:12 +00006061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006063TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006064 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006065 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006066 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006067 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006068
6069 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006070
Douglas Gregord51d90d2010-04-26 20:11:03 +00006071 // If nothing changed, just retain the existing expression.
6072 if (!getDerived().AlwaysRebuild() &&
6073 Base.get() == E->getBase())
6074 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006075
John McCallb268a282010-08-23 23:25:46 +00006076 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006077 E->getLocation(),
6078 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006079}
6080
Mike Stump11289f42009-09-09 15:08:12 +00006081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006082ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006083TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006084 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006085 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006086 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006087 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006088
Douglas Gregor9faee212010-04-26 20:47:02 +00006089 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006090
Douglas Gregor9faee212010-04-26 20:47:02 +00006091 // If nothing changed, just retain the existing expression.
6092 if (!getDerived().AlwaysRebuild() &&
6093 Base.get() == E->getBase())
6094 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006095
John McCallb268a282010-08-23 23:25:46 +00006096 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006097 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006098}
6099
Mike Stump11289f42009-09-09 15:08:12 +00006100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006101ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006102TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006103 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006104 // If this implicit setter/getter refers to class methods, it cannot have any
6105 // dependent parts. Just retain the existing declaration.
6106 if (E->getInterfaceDecl())
6107 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006108
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006109 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006110 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006111 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006112 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006113
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006114 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006115
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006116 // If nothing changed, just retain the existing expression.
6117 if (!getDerived().AlwaysRebuild() &&
6118 Base.get() == E->getBase())
6119 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006120
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006121 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6122 E->getGetterMethod(),
6123 E->getType(),
6124 E->getSetterMethod(),
6125 E->getLocation(),
John McCallb268a282010-08-23 23:25:46 +00006126 Base.get());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006127
Douglas Gregora16548e2009-08-11 05:31:07 +00006128}
6129
Mike Stump11289f42009-09-09 15:08:12 +00006130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006132TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006133 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006134 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006135}
6136
Mike Stump11289f42009-09-09 15:08:12 +00006137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006138ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006139TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006140 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006141 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006142 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006144
Douglas Gregord51d90d2010-04-26 20:11:03 +00006145 // If nothing changed, just retain the existing expression.
6146 if (!getDerived().AlwaysRebuild() &&
6147 Base.get() == E->getBase())
6148 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006149
John McCallb268a282010-08-23 23:25:46 +00006150 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006151 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006152}
6153
Mike Stump11289f42009-09-09 15:08:12 +00006154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006155ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006156TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006157 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006158 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006160 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006161 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006162 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006163
Douglas Gregora16548e2009-08-11 05:31:07 +00006164 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006165 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 }
Mike Stump11289f42009-09-09 15:08:12 +00006167
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 if (!getDerived().AlwaysRebuild() &&
6169 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006170 return SemaRef.Owned(E->Retain());
6171
Douglas Gregora16548e2009-08-11 05:31:07 +00006172 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6173 move_arg(SubExprs),
6174 E->getRParenLoc());
6175}
6176
Mike Stump11289f42009-09-09 15:08:12 +00006177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006178ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006179TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006180 SourceLocation CaretLoc(E->getExprLoc());
6181
6182 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6183 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6184 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6185 llvm::SmallVector<ParmVarDecl*, 4> Params;
6186 llvm::SmallVector<QualType, 4> ParamTypes;
6187
6188 // Parameter substitution.
6189 const BlockDecl *BD = E->getBlockDecl();
6190 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6191 EN = BD->param_end(); P != EN; ++P) {
6192 ParmVarDecl *OldParm = (*P);
6193 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6194 QualType NewType = NewParm->getType();
6195 Params.push_back(NewParm);
6196 ParamTypes.push_back(NewParm->getType());
6197 }
6198
6199 const FunctionType *BExprFunctionType = E->getFunctionType();
6200 QualType BExprResultType = BExprFunctionType->getResultType();
6201 if (!BExprResultType.isNull()) {
6202 if (!BExprResultType->isDependentType())
6203 CurBlock->ReturnType = BExprResultType;
6204 else if (BExprResultType != SemaRef.Context.DependentTy)
6205 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6206 }
6207
6208 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006209 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006210 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006211 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006212 // Set the parameters on the block decl.
6213 if (!Params.empty())
6214 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6215
6216 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6217 CurBlock->ReturnType,
6218 ParamTypes.data(),
6219 ParamTypes.size(),
6220 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006221 0,
6222 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006223
6224 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006225 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006226}
6227
Mike Stump11289f42009-09-09 15:08:12 +00006228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006231 NestedNameSpecifier *Qualifier = 0;
6232
6233 ValueDecl *ND
6234 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6235 E->getDecl()));
6236 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006238
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006239 if (!getDerived().AlwaysRebuild() &&
6240 ND == E->getDecl()) {
6241 // Mark it referenced in the new context regardless.
6242 // FIXME: this is a bit instantiation-specific.
6243 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6244
6245 return SemaRef.Owned(E->Retain());
6246 }
6247
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006248 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006249 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006250 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006251}
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregora16548e2009-08-11 05:31:07 +00006253//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006254// Type reconstruction
6255//===----------------------------------------------------------------------===//
6256
Mike Stump11289f42009-09-09 15:08:12 +00006257template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006258QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6259 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006260 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006261 getDerived().getBaseEntity());
6262}
6263
Mike Stump11289f42009-09-09 15:08:12 +00006264template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006265QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6266 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006267 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006268 getDerived().getBaseEntity());
6269}
6270
Mike Stump11289f42009-09-09 15:08:12 +00006271template<typename Derived>
6272QualType
John McCall70dd5f62009-10-30 00:06:24 +00006273TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6274 bool WrittenAsLValue,
6275 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006276 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006277 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006278}
6279
6280template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006281QualType
John McCall70dd5f62009-10-30 00:06:24 +00006282TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6283 QualType ClassType,
6284 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006285 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006286 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006287}
6288
6289template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006290QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006291TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6292 ArrayType::ArraySizeModifier SizeMod,
6293 const llvm::APInt *Size,
6294 Expr *SizeExpr,
6295 unsigned IndexTypeQuals,
6296 SourceRange BracketsRange) {
6297 if (SizeExpr || !Size)
6298 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6299 IndexTypeQuals, BracketsRange,
6300 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006301
6302 QualType Types[] = {
6303 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6304 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6305 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006306 };
6307 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6308 QualType SizeType;
6309 for (unsigned I = 0; I != NumTypes; ++I)
6310 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6311 SizeType = Types[I];
6312 break;
6313 }
Mike Stump11289f42009-09-09 15:08:12 +00006314
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006315 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6316 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006317 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006318 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006319 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006320}
Mike Stump11289f42009-09-09 15:08:12 +00006321
Douglas Gregord6ff3322009-08-04 16:50:30 +00006322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006323QualType
6324TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006325 ArrayType::ArraySizeModifier SizeMod,
6326 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006327 unsigned IndexTypeQuals,
6328 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006329 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006330 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006331}
6332
6333template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006334QualType
Mike Stump11289f42009-09-09 15:08:12 +00006335TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006336 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006337 unsigned IndexTypeQuals,
6338 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006339 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006340 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006341}
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregord6ff3322009-08-04 16:50:30 +00006343template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006344QualType
6345TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006346 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006347 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006348 unsigned IndexTypeQuals,
6349 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006350 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006351 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006352 IndexTypeQuals, BracketsRange);
6353}
6354
6355template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006356QualType
6357TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006358 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006359 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006360 unsigned IndexTypeQuals,
6361 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006362 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006363 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006364 IndexTypeQuals, BracketsRange);
6365}
6366
6367template<typename Derived>
6368QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006369 unsigned NumElements,
6370 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006371 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006372 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006373}
Mike Stump11289f42009-09-09 15:08:12 +00006374
Douglas Gregord6ff3322009-08-04 16:50:30 +00006375template<typename Derived>
6376QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6377 unsigned NumElements,
6378 SourceLocation AttributeLoc) {
6379 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6380 NumElements, true);
6381 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006382 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6383 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006384 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006385}
Mike Stump11289f42009-09-09 15:08:12 +00006386
Douglas Gregord6ff3322009-08-04 16:50:30 +00006387template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006388QualType
6389TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006390 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006392 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006393}
Mike Stump11289f42009-09-09 15:08:12 +00006394
Douglas Gregord6ff3322009-08-04 16:50:30 +00006395template<typename Derived>
6396QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006397 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006398 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006399 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006400 unsigned Quals,
6401 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006402 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006403 Quals,
6404 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006405 getDerived().getBaseEntity(),
6406 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006407}
Mike Stump11289f42009-09-09 15:08:12 +00006408
Douglas Gregord6ff3322009-08-04 16:50:30 +00006409template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006410QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6411 return SemaRef.Context.getFunctionNoProtoType(T);
6412}
6413
6414template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006415QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6416 assert(D && "no decl found");
6417 if (D->isInvalidDecl()) return QualType();
6418
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006419 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006420 TypeDecl *Ty;
6421 if (isa<UsingDecl>(D)) {
6422 UsingDecl *Using = cast<UsingDecl>(D);
6423 assert(Using->isTypeName() &&
6424 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6425
6426 // A valid resolved using typename decl points to exactly one type decl.
6427 assert(++Using->shadow_begin() == Using->shadow_end());
6428 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006429
John McCallb96ec562009-12-04 22:46:56 +00006430 } else {
6431 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6432 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6433 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6434 }
6435
6436 return SemaRef.Context.getTypeDeclType(Ty);
6437}
6438
6439template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006440QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6441 return SemaRef.BuildTypeofExprType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006442}
6443
6444template<typename Derived>
6445QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6446 return SemaRef.Context.getTypeOfType(Underlying);
6447}
6448
6449template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006450QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6451 return SemaRef.BuildDecltypeType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006452}
6453
6454template<typename Derived>
6455QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006456 TemplateName Template,
6457 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006458 const TemplateArgumentListInfo &TemplateArgs) {
6459 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006460}
Mike Stump11289f42009-09-09 15:08:12 +00006461
Douglas Gregor1135c352009-08-06 05:28:30 +00006462template<typename Derived>
6463NestedNameSpecifier *
6464TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6465 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006466 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006467 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006468 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006469 CXXScopeSpec SS;
6470 // FIXME: The source location information is all wrong.
6471 SS.setRange(Range);
6472 SS.setScopeRep(Prefix);
6473 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006474 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006475 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006476 ObjectType,
6477 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006478 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006479}
6480
6481template<typename Derived>
6482NestedNameSpecifier *
6483TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6484 SourceRange Range,
6485 NamespaceDecl *NS) {
6486 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6487}
6488
6489template<typename Derived>
6490NestedNameSpecifier *
6491TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6492 SourceRange Range,
6493 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006494 QualType T) {
6495 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006496 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006497 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006498 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6499 T.getTypePtr());
6500 }
Mike Stump11289f42009-09-09 15:08:12 +00006501
Douglas Gregor1135c352009-08-06 05:28:30 +00006502 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6503 return 0;
6504}
Mike Stump11289f42009-09-09 15:08:12 +00006505
Douglas Gregor71dc5092009-08-06 06:41:21 +00006506template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006507TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006508TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6509 bool TemplateKW,
6510 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006511 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006512 Template);
6513}
6514
6515template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006516TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006517TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006518 const IdentifierInfo &II,
6519 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006520 CXXScopeSpec SS;
6521 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006522 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006523 UnqualifiedId Name;
6524 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006525 Sema::TemplateTy Template;
6526 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6527 /*FIXME:*/getDerived().getBaseLocation(),
6528 SS,
6529 Name,
John McCallba7bf592010-08-24 05:47:05 +00006530 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006531 /*EnteringContext=*/false,
6532 Template);
6533 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006534}
Mike Stump11289f42009-09-09 15:08:12 +00006535
Douglas Gregora16548e2009-08-11 05:31:07 +00006536template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006537TemplateName
6538TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6539 OverloadedOperatorKind Operator,
6540 QualType ObjectType) {
6541 CXXScopeSpec SS;
6542 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6543 SS.setScopeRep(Qualifier);
6544 UnqualifiedId Name;
6545 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6546 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6547 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006548 Sema::TemplateTy Template;
6549 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006550 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006551 SS,
6552 Name,
John McCallba7bf592010-08-24 05:47:05 +00006553 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006554 /*EnteringContext=*/false,
6555 Template);
6556 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006557}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006558
Douglas Gregor71395fa2009-11-04 00:56:37 +00006559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006560ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006561TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6562 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006563 Expr *OrigCallee,
6564 Expr *First,
6565 Expr *Second) {
6566 Expr *Callee = OrigCallee->IgnoreParenCasts();
6567 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006568
Douglas Gregora16548e2009-08-11 05:31:07 +00006569 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006570 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006571 if (!First->getType()->isOverloadableType() &&
6572 !Second->getType()->isOverloadableType())
6573 return getSema().CreateBuiltinArraySubscriptExpr(First,
6574 Callee->getLocStart(),
6575 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006576 } else if (Op == OO_Arrow) {
6577 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006578 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6579 } else if (Second == 0 || isPostIncDec) {
6580 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006581 // The argument is not of overloadable type, so try to create a
6582 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006583 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006584 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006585
John McCallb268a282010-08-23 23:25:46 +00006586 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006587 }
6588 } else {
John McCallb268a282010-08-23 23:25:46 +00006589 if (!First->getType()->isOverloadableType() &&
6590 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006591 // Neither of the arguments is an overloadable type, so try to
6592 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006593 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006594 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006595 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006596 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006598
Douglas Gregora16548e2009-08-11 05:31:07 +00006599 return move(Result);
6600 }
6601 }
Mike Stump11289f42009-09-09 15:08:12 +00006602
6603 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006604 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006605 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006606
John McCallb268a282010-08-23 23:25:46 +00006607 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006608 assert(ULE->requiresADL());
6609
6610 // FIXME: Do we have to check
6611 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006612 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006613 } else {
John McCallb268a282010-08-23 23:25:46 +00006614 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006615 }
Mike Stump11289f42009-09-09 15:08:12 +00006616
Douglas Gregora16548e2009-08-11 05:31:07 +00006617 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006618 Expr *Args[2] = { First, Second };
6619 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006620
Douglas Gregora16548e2009-08-11 05:31:07 +00006621 // Create the overloaded operator invocation for unary operators.
6622 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006623 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006624 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006625 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 }
Mike Stump11289f42009-09-09 15:08:12 +00006627
Sebastian Redladba46e2009-10-29 20:17:01 +00006628 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006629 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006630 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006631 First,
6632 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006633
Douglas Gregora16548e2009-08-11 05:31:07 +00006634 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006635 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006636 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006637 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6638 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006639 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006640
Mike Stump11289f42009-09-09 15:08:12 +00006641 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006642}
Mike Stump11289f42009-09-09 15:08:12 +00006643
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006645ExprResult
John McCallb268a282010-08-23 23:25:46 +00006646TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006647 SourceLocation OperatorLoc,
6648 bool isArrow,
6649 NestedNameSpecifier *Qualifier,
6650 SourceRange QualifierRange,
6651 TypeSourceInfo *ScopeType,
6652 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006653 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006654 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006655 CXXScopeSpec SS;
6656 if (Qualifier) {
6657 SS.setRange(QualifierRange);
6658 SS.setScopeRep(Qualifier);
6659 }
6660
John McCallb268a282010-08-23 23:25:46 +00006661 QualType BaseType = Base->getType();
6662 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006663 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006664 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006665 !BaseType->getAs<PointerType>()->getPointeeType()
6666 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006667 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006668 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006669 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006670 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006671 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006672 /*FIXME?*/true);
6673 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006674
Douglas Gregor678f90d2010-02-25 01:56:36 +00006675 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006676 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6677 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6678 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6679 NameInfo.setNamedTypeInfo(DestroyedType);
6680
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006681 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006682
John McCallb268a282010-08-23 23:25:46 +00006683 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006684 OperatorLoc, isArrow,
6685 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006686 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006687 /*TemplateArgs*/ 0);
6688}
6689
Douglas Gregord6ff3322009-08-04 16:50:30 +00006690} // end namespace clang
6691
6692#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H