blob: d318bc6e5c79db091fabb1474a0dc601fad49d15 [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 McCall36e7fe32010-10-12 00:20:44 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
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 McCall36e7fe32010-10-12 00:20:44 +0000509 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
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,
Douglas Gregora5614c52010-09-08 23:56:00 +0000537 NestedNameSpecifier *Qualifier,
538 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000539 const IdentifierInfo *Name,
540 SourceLocation NameLoc,
541 const TemplateArgumentListInfo &Args) {
542 // Rebuild the template name.
543 // TODO: avoid TemplateName abstraction
544 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000545 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
546 QualType());
John McCallc392f372010-06-11 00:33:02 +0000547
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCallc392f372010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000554 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000561
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000562 // NOTE: NNS is already recorded in template specialization type T.
563 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000564 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
566 /// \brief Build a new typename type that refers to an identifier.
567 ///
568 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000571 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000572 NestedNameSpecifier *NNS,
573 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 SourceLocation KeywordLoc,
575 SourceRange NNSRange,
576 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000577 CXXScopeSpec SS;
578 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000579 SS.setRange(NNSRange);
580
Douglas Gregore677daf2010-03-31 22:19:08 +0000581 if (NNS->isDependent()) {
582 // If the name is still dependent, just build a new dependent name type.
583 if (!SemaRef.computeDeclContext(SS))
584 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 }
586
Abramo Bagnara6150c882010-05-11 21:36:43 +0000587 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000588 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
589 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590
591 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
592
Abramo Bagnarad7548482010-05-19 21:37:53 +0000593 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000594 // into a non-dependent elaborated-type-specifier. Find the tag we're
595 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000596 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000597 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
598 if (!DC)
599 return QualType();
600
John McCallbf8c5192010-05-27 06:40:31 +0000601 if (SemaRef.RequireCompleteDeclContext(SS, DC))
602 return QualType();
603
Douglas Gregore677daf2010-03-31 22:19:08 +0000604 TagDecl *Tag = 0;
605 SemaRef.LookupQualifiedName(Result, DC);
606 switch (Result.getResultKind()) {
607 case LookupResult::NotFound:
608 case LookupResult::NotFoundInCurrentInstantiation:
609 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000610
Douglas Gregore677daf2010-03-31 22:19:08 +0000611 case LookupResult::Found:
612 Tag = Result.getAsSingle<TagDecl>();
613 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000614
Douglas Gregore677daf2010-03-31 22:19:08 +0000615 case LookupResult::FoundOverloaded:
616 case LookupResult::FoundUnresolvedValue:
617 llvm_unreachable("Tag lookup cannot find non-tags");
618 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000619
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 case LookupResult::Ambiguous:
621 // Let the LookupResult structure handle ambiguities.
622 return QualType();
623 }
624
625 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000627 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000628 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000629 return QualType();
630 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000631
Abramo Bagnarad7548482010-05-19 21:37:53 +0000632 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
633 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000634 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
635 return QualType();
636 }
637
638 // Build the elaborated-type-specifier type.
639 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000640 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 }
Mike Stump11289f42009-09-09 15:08:12 +0000642
Douglas Gregor1135c352009-08-06 05:28:30 +0000643 /// \brief Build a new nested-name-specifier given the prefix and an
644 /// identifier that names the next step in the nested-name-specifier.
645 ///
646 /// By default, performs semantic analysis when building the new
647 /// nested-name-specifier. Subclasses may override this routine to provide
648 /// different behavior.
649 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
650 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000651 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000652 QualType ObjectType,
653 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000654
655 /// \brief Build a new nested-name-specifier given the prefix and the
656 /// namespace named in the next step in the nested-name-specifier.
657 ///
658 /// By default, performs semantic analysis when building the new
659 /// nested-name-specifier. Subclasses may override this routine to provide
660 /// different behavior.
661 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
662 SourceRange Range,
663 NamespaceDecl *NS);
664
665 /// \brief Build a new nested-name-specifier given the prefix and the
666 /// type named in the next step in the nested-name-specifier.
667 ///
668 /// By default, performs semantic analysis when building the new
669 /// nested-name-specifier. Subclasses may override this routine to provide
670 /// different behavior.
671 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
672 SourceRange Range,
673 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000674 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000675
676 /// \brief Build a new template name given a nested name specifier, a flag
677 /// indicating whether the "template" keyword was provided, and the template
678 /// that the template name refers to.
679 ///
680 /// By default, builds the new template name directly. Subclasses may override
681 /// this routine to provide different behavior.
682 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
683 bool TemplateKW,
684 TemplateDecl *Template);
685
Douglas Gregor71dc5092009-08-06 06:41:21 +0000686 /// \brief Build a new template name given a nested name specifier and the
687 /// name that is referred to as a template.
688 ///
689 /// By default, performs semantic analysis to determine whether the name can
690 /// be resolved to a specific template, then builds the appropriate kind of
691 /// template name. Subclasses may override this routine to provide different
692 /// behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000694 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000695 const IdentifierInfo &II,
696 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000697
Douglas Gregor71395fa2009-11-04 00:56:37 +0000698 /// \brief Build a new template name given a nested name specifier and the
699 /// overloaded operator name that is referred to as a template.
700 ///
701 /// By default, performs semantic analysis to determine whether the name can
702 /// be resolved to a specific template, then builds the appropriate kind of
703 /// template name. Subclasses may override this routine to provide different
704 /// behavior.
705 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
706 OverloadedOperatorKind Operator,
707 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000708
Douglas Gregorebe10102009-08-20 07:17:43 +0000709 /// \brief Build a new compound statement.
710 ///
711 /// By default, performs semantic analysis to build the new statement.
712 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000713 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000714 MultiStmtArg Statements,
715 SourceLocation RBraceLoc,
716 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000717 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000718 IsStmtExpr);
719 }
720
721 /// \brief Build a new case statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000725 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000726 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000728 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000730 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 ColonLoc);
732 }
Mike Stump11289f42009-09-09 15:08:12 +0000733
Douglas Gregorebe10102009-08-20 07:17:43 +0000734 /// \brief Attach the body to a new case statement.
735 ///
736 /// By default, performs semantic analysis to build the new statement.
737 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000738 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000739 getSema().ActOnCaseStmtBody(S, Body);
740 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000741 }
Mike Stump11289f42009-09-09 15:08:12 +0000742
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /// \brief Build a new default statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000747 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000748 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000749 Stmt *SubStmt) {
750 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 /*CurScope=*/0);
752 }
Mike Stump11289f42009-09-09 15:08:12 +0000753
Douglas Gregorebe10102009-08-20 07:17:43 +0000754 /// \brief Build a new label statement.
755 ///
756 /// By default, performs semantic analysis to build the new statement.
757 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000758 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000759 IdentifierInfo *Id,
760 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000761 Stmt *SubStmt, bool HasUnusedAttr) {
762 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
763 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000764 }
Mike Stump11289f42009-09-09 15:08:12 +0000765
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 /// \brief Build a new "if" statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000770 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000771 VarDecl *CondVar, Stmt *Then,
772 SourceLocation ElseLoc, Stmt *Else) {
773 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000774 }
Mike Stump11289f42009-09-09 15:08:12 +0000775
Douglas Gregorebe10102009-08-20 07:17:43 +0000776 /// \brief Start building a new switch statement.
777 ///
778 /// By default, performs semantic analysis to build the new statement.
779 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000780 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000781 Expr *Cond, VarDecl *CondVar) {
782 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000783 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000784 }
Mike Stump11289f42009-09-09 15:08:12 +0000785
Douglas Gregorebe10102009-08-20 07:17:43 +0000786 /// \brief Attach the body to the switch statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000790 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000791 Stmt *Switch, Stmt *Body) {
792 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000793 }
794
795 /// \brief Build a new while statement.
796 ///
797 /// By default, performs semantic analysis to build the new statement.
798 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000799 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000800 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000801 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000802 Stmt *Body) {
803 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 }
Mike Stump11289f42009-09-09 15:08:12 +0000805
Douglas Gregorebe10102009-08-20 07:17:43 +0000806 /// \brief Build a new do-while statement.
807 ///
808 /// By default, performs semantic analysis to build the new statement.
809 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000810 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000811 SourceLocation WhileLoc,
812 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000813 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000815 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
816 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000817 }
818
819 /// \brief Build a new for statement.
820 ///
821 /// By default, performs semantic analysis to build the new statement.
822 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000823 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000824 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000825 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000826 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000827 SourceLocation RParenLoc, Stmt *Body) {
828 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000829 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000830 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000831 }
Mike Stump11289f42009-09-09 15:08:12 +0000832
Douglas Gregorebe10102009-08-20 07:17:43 +0000833 /// \brief Build a new goto statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000837 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000838 SourceLocation LabelLoc,
839 LabelStmt *Label) {
840 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
841 }
842
843 /// \brief Build a new indirect goto statement.
844 ///
845 /// By default, performs semantic analysis to build the new statement.
846 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000847 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000848 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000849 Expr *Target) {
850 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000851 }
Mike Stump11289f42009-09-09 15:08:12 +0000852
Douglas Gregorebe10102009-08-20 07:17:43 +0000853 /// \brief Build a new return statement.
854 ///
855 /// By default, performs semantic analysis to build the new statement.
856 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000857 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000858 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000859
John McCallb268a282010-08-23 23:25:46 +0000860 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000861 }
Mike Stump11289f42009-09-09 15:08:12 +0000862
Douglas Gregorebe10102009-08-20 07:17:43 +0000863 /// \brief Build a new declaration statement.
864 ///
865 /// By default, performs semantic analysis to build the new statement.
866 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000867 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000868 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000869 SourceLocation EndLoc) {
870 return getSema().Owned(
871 new (getSema().Context) DeclStmt(
872 DeclGroupRef::Create(getSema().Context,
873 Decls, NumDecls),
874 StartLoc, EndLoc));
875 }
Mike Stump11289f42009-09-09 15:08:12 +0000876
Anders Carlssonaaeef072010-01-24 05:50:09 +0000877 /// \brief Build a new inline asm statement.
878 ///
879 /// By default, performs semantic analysis to build the new statement.
880 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000881 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000882 bool IsSimple,
883 bool IsVolatile,
884 unsigned NumOutputs,
885 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000886 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000887 MultiExprArg Constraints,
888 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000889 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000890 MultiExprArg Clobbers,
891 SourceLocation RParenLoc,
892 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000893 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000894 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000895 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000896 RParenLoc, MSAsm);
897 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000898
899 /// \brief Build a new Objective-C @try statement.
900 ///
901 /// By default, performs semantic analysis to build the new statement.
902 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000903 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000904 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000905 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000906 Stmt *Finally) {
907 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
908 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000909 }
910
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000911 /// \brief Rebuild an Objective-C exception declaration.
912 ///
913 /// By default, performs semantic analysis to build the new declaration.
914 /// Subclasses may override this routine to provide different behavior.
915 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
916 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000917 return getSema().BuildObjCExceptionDecl(TInfo, T,
918 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000919 ExceptionDecl->getLocation());
920 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000921
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000922 /// \brief Build a new Objective-C @catch statement.
923 ///
924 /// By default, performs semantic analysis to build the new statement.
925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000926 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000927 SourceLocation RParenLoc,
928 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000929 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000930 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000931 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000932 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000933
Douglas Gregor306de2f2010-04-22 23:59:56 +0000934 /// \brief Build a new Objective-C @finally statement.
935 ///
936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000938 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000939 Stmt *Body) {
940 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000941 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000942
Douglas Gregor6148de72010-04-22 22:01:21 +0000943 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000944 ///
945 /// By default, performs semantic analysis to build the new statement.
946 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000947 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000948 Expr *Operand) {
949 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000950 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000951
Douglas Gregor6148de72010-04-22 22:01:21 +0000952 /// \brief Build a new Objective-C @synchronized statement.
953 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000954 /// By default, performs semantic analysis to build the new statement.
955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000956 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000957 Expr *Object,
958 Stmt *Body) {
959 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
960 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000961 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000962
963 /// \brief Build a new Objective-C fast enumeration statement.
964 ///
965 /// By default, performs semantic analysis to build the new statement.
966 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000967 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000968 SourceLocation LParenLoc,
969 Stmt *Element,
970 Expr *Collection,
971 SourceLocation RParenLoc,
972 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000973 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000974 Element,
975 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000976 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000977 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000978 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000979
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 /// \brief Build a new C++ exception declaration.
981 ///
982 /// By default, performs semantic analysis to build the new decaration.
983 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000984 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +0000985 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000987 SourceLocation Loc) {
988 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 }
990
991 /// \brief Build a new C++ catch statement.
992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000995 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000996 VarDecl *ExceptionDecl,
997 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +0000998 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
999 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 }
Mike Stump11289f42009-09-09 15:08:12 +00001001
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 /// \brief Build a new C++ try statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001006 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001007 Stmt *TryBlock,
1008 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001009 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001010 }
Mike Stump11289f42009-09-09 15:08:12 +00001011
Douglas Gregora16548e2009-08-11 05:31:07 +00001012 /// \brief Build a new expression that references a declaration.
1013 ///
1014 /// By default, performs semantic analysis to build the new expression.
1015 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001016 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001017 LookupResult &R,
1018 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001019 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1020 }
1021
1022
1023 /// \brief Build a new expression that references a declaration.
1024 ///
1025 /// By default, performs semantic analysis to build the new expression.
1026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001027 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001028 SourceRange QualifierRange,
1029 ValueDecl *VD,
1030 const DeclarationNameInfo &NameInfo,
1031 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001032 CXXScopeSpec SS;
1033 SS.setScopeRep(Qualifier);
1034 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001035
1036 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001037
1038 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001042 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 /// By default, performs semantic analysis to build the new expression.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001047 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 }
1049
Douglas Gregorad8a3362009-09-04 17:36:40 +00001050 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001051 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001054 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001055 SourceLocation OperatorLoc,
1056 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001057 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001058 SourceRange QualifierRange,
1059 TypeSourceInfo *ScopeType,
1060 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001061 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001062 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001063
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001065 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 /// By default, performs semantic analysis to build the new expression.
1067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001068 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001069 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001070 Expr *SubExpr) {
1071 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 }
Mike Stump11289f42009-09-09 15:08:12 +00001073
Douglas Gregor882211c2010-04-28 22:16:22 +00001074 /// \brief Build a new builtin offsetof expression.
1075 ///
1076 /// By default, performs semantic analysis to build the new expression.
1077 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001078 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001079 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001080 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001081 unsigned NumComponents,
1082 SourceLocation RParenLoc) {
1083 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1084 NumComponents, RParenLoc);
1085 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001086
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001091 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001092 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001094 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001095 }
1096
Mike Stump11289f42009-09-09 15:08:12 +00001097 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001099 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001102 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001104 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001105 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 return move(Result);
1110 }
Mike Stump11289f42009-09-09 15:08:12 +00001111
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001113 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001114 /// By default, performs semantic analysis to build the new expression.
1115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001116 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001118 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001120 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1121 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 RBracketLoc);
1123 }
1124
1125 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001126 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 /// By default, performs semantic analysis to build the new expression.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001131 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001132 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001133 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 }
1135
1136 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001140 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001141 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001142 NestedNameSpecifier *Qualifier,
1143 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001144 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001145 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001146 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001147 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001148 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001149 if (!Member->getDeclName()) {
1150 // We have a reference to an unnamed field.
1151 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001152
John McCallb268a282010-08-23 23:25:46 +00001153 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001154 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001155 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001156
Mike Stump11289f42009-09-09 15:08:12 +00001157 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001158 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001159 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001160 cast<FieldDecl>(Member)->getType());
1161 return getSema().Owned(ME);
1162 }
Mike Stump11289f42009-09-09 15:08:12 +00001163
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001164 CXXScopeSpec SS;
1165 if (Qualifier) {
1166 SS.setRange(QualifierRange);
1167 SS.setScopeRep(Qualifier);
1168 }
1169
John McCallb268a282010-08-23 23:25:46 +00001170 getSema().DefaultFunctionArrayConversion(Base);
1171 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001172
John McCall16df1e52010-03-30 21:47:33 +00001173 // FIXME: this involves duplicating earlier analysis in a lot of
1174 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001175 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001176 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001177 R.resolveKind();
1178
John McCallb268a282010-08-23 23:25:46 +00001179 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001180 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001181 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001182 }
Mike Stump11289f42009-09-09 15:08:12 +00001183
Douglas Gregora16548e2009-08-11 05:31:07 +00001184 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001185 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001188 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001189 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001190 Expr *LHS, Expr *RHS) {
1191 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001192 }
1193
1194 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001195 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001198 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001200 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001201 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001202 Expr *RHS) {
1203 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1204 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001205 }
1206
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001208 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// By default, performs semantic analysis to build the new expression.
1210 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001211 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001212 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001214 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001215 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001216 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 }
Mike Stump11289f42009-09-09 15:08:12 +00001218
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001220 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// By default, performs semantic analysis to build the new expression.
1222 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001223 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001224 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001226 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001227 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001228 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 }
Mike Stump11289f42009-09-09 15:08:12 +00001230
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001232 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 /// By default, performs semantic analysis to build the new expression.
1234 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001235 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 SourceLocation OpLoc,
1237 SourceLocation AccessorLoc,
1238 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001239
John McCall10eae182009-11-30 22:42:35 +00001240 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001241 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001242 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001243 OpLoc, /*IsArrow*/ false,
1244 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001245 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001246 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 }
Mike Stump11289f42009-09-09 15:08:12 +00001248
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001250 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001253 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001255 SourceLocation RBraceLoc,
1256 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001257 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001258 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1259 if (Result.isInvalid() || ResultTy->isDependentType())
1260 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001261
Douglas Gregord3d93062009-11-09 17:16:50 +00001262 // Patch in the result type we were given, which may have been computed
1263 // when the initial InitListExpr was built.
1264 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1265 ILE->setType(ResultTy);
1266 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001267 }
Mike Stump11289f42009-09-09 15:08:12 +00001268
Douglas Gregora16548e2009-08-11 05:31:07 +00001269 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001270 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001273 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 MultiExprArg ArrayExprs,
1275 SourceLocation EqualOrColonLoc,
1276 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001277 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001278 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001280 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001282 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001283
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 ArrayExprs.release();
1285 return move(Result);
1286 }
Mike Stump11289f42009-09-09 15:08:12 +00001287
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001289 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 /// By default, builds the implicit value initialization without performing
1291 /// any semantic analysis. Subclasses may override this routine to provide
1292 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001293 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1295 }
Mike Stump11289f42009-09-09 15:08:12 +00001296
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001298 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001301 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001302 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001303 SourceLocation RParenLoc) {
1304 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001305 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001306 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 }
1308
1309 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001310 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001313 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 MultiExprArg SubExprs,
1315 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001316 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001317 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 }
Mike Stump11289f42009-09-09 15:08:12 +00001319
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001321 ///
1322 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// rather than attempting to map the label statement itself.
1324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001325 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 SourceLocation LabelLoc,
1327 LabelStmt *Label) {
1328 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1329 }
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001336 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001338 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// \brief Build a new __builtin_types_compatible_p expression.
1342 ///
1343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001346 TypeSourceInfo *TInfo1,
1347 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001349 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1350 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 RParenLoc);
1352 }
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 /// \brief Build a new __builtin_choose_expr expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001358 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001359 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 SourceLocation RParenLoc) {
1361 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001362 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 RParenLoc);
1364 }
Mike Stump11289f42009-09-09 15:08:12 +00001365
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 /// \brief Build a new overloaded operator call expression.
1367 ///
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// The semantic analysis provides the behavior of template instantiation,
1370 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001371 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 /// argument-dependent lookup, etc. Subclasses may override this routine to
1373 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001376 Expr *Callee,
1377 Expr *First,
1378 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001379
1380 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 /// reinterpret_cast.
1382 ///
1383 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001384 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001386 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 Stmt::StmtClass Class,
1388 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001389 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 SourceLocation RAngleLoc,
1391 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001392 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 SourceLocation RParenLoc) {
1394 switch (Class) {
1395 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001396 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001397 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001398 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001399
1400 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001403 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001404
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001408 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001410
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001412 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001413 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001414 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001415
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 default:
1417 assert(false && "Invalid C++ named cast");
1418 break;
1419 }
Mike Stump11289f42009-09-09 15:08:12 +00001420
John McCallfaf5fb42010-08-26 23:41:50 +00001421 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 }
Mike Stump11289f42009-09-09 15:08:12 +00001423
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// \brief Build a new C++ static_cast expression.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001428 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001430 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 SourceLocation RAngleLoc,
1432 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001433 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001435 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001436 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001437 SourceRange(LAngleLoc, RAngleLoc),
1438 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 }
1440
1441 /// \brief Build a new C++ dynamic_cast expression.
1442 ///
1443 /// By default, performs semantic analysis to build the new expression.
1444 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001445 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001447 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 SourceLocation RAngleLoc,
1449 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001450 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001452 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001453 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001454 SourceRange(LAngleLoc, RAngleLoc),
1455 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 }
1457
1458 /// \brief Build a new C++ reinterpret_cast expression.
1459 ///
1460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001462 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001464 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 SourceLocation RAngleLoc,
1466 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001467 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001468 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001469 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001470 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001471 SourceRange(LAngleLoc, RAngleLoc),
1472 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 }
1474
1475 /// \brief Build a new C++ const_cast expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001479 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001481 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 SourceLocation RAngleLoc,
1483 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001484 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001486 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001487 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001488 SourceRange(LAngleLoc, RAngleLoc),
1489 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 }
Mike Stump11289f42009-09-09 15:08:12 +00001491
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// \brief Build a new C++ functional-style cast expression.
1493 ///
1494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001496 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1497 SourceLocation LParenLoc,
1498 Expr *Sub,
1499 SourceLocation RParenLoc) {
1500 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001501 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 RParenLoc);
1503 }
Mike Stump11289f42009-09-09 15:08:12 +00001504
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 /// \brief Build a new C++ typeid(type) expression.
1506 ///
1507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001509 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001510 SourceLocation TypeidLoc,
1511 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001513 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001514 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 }
Mike Stump11289f42009-09-09 15:08:12 +00001516
Francois Pichet9f4f2072010-09-08 12:20:18 +00001517
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 /// \brief Build a new C++ typeid(expr) expression.
1519 ///
1520 /// By default, performs semantic analysis to build the new expression.
1521 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001522 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001523 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001524 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001526 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001527 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001528 }
1529
Francois Pichet9f4f2072010-09-08 12:20:18 +00001530 /// \brief Build a new C++ __uuidof(type) expression.
1531 ///
1532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
1534 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1535 SourceLocation TypeidLoc,
1536 TypeSourceInfo *Operand,
1537 SourceLocation RParenLoc) {
1538 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1539 RParenLoc);
1540 }
1541
1542 /// \brief Build a new C++ __uuidof(expr) expression.
1543 ///
1544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
1546 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1547 SourceLocation TypeidLoc,
1548 Expr *Operand,
1549 SourceLocation RParenLoc) {
1550 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1551 RParenLoc);
1552 }
1553
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 /// \brief Build a new C++ "this" expression.
1555 ///
1556 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001557 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001559 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001560 QualType ThisType,
1561 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001563 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1564 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new C++ throw expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001571 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001572 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 }
1574
1575 /// \brief Build a new C++ default-argument expression.
1576 ///
1577 /// By default, builds a new default-argument expression, which does not
1578 /// require any semantic analysis. Subclasses may override this routine to
1579 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001580 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001581 ParmVarDecl *Param) {
1582 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1583 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 }
1585
1586 /// \brief Build a new C++ zero-initialization expression.
1587 ///
1588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001590 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1591 SourceLocation LParenLoc,
1592 SourceLocation RParenLoc) {
1593 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001594 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001595 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 }
Mike Stump11289f42009-09-09 15:08:12 +00001597
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 /// \brief Build a new C++ "new" expression.
1599 ///
1600 /// By default, performs semantic analysis to build the new expression.
1601 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001602 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001603 bool UseGlobal,
1604 SourceLocation PlacementLParen,
1605 MultiExprArg PlacementArgs,
1606 SourceLocation PlacementRParen,
1607 SourceRange TypeIdParens,
1608 QualType AllocatedType,
1609 TypeSourceInfo *AllocatedTypeInfo,
1610 Expr *ArraySize,
1611 SourceLocation ConstructorLParen,
1612 MultiExprArg ConstructorArgs,
1613 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001614 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 PlacementLParen,
1616 move(PlacementArgs),
1617 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001618 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001619 AllocatedType,
1620 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001621 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 ConstructorLParen,
1623 move(ConstructorArgs),
1624 ConstructorRParen);
1625 }
Mike Stump11289f42009-09-09 15:08:12 +00001626
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 /// \brief Build a new C++ "delete" 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 RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 bool IsGlobalDelete,
1633 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001634 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001636 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 }
Mike Stump11289f42009-09-09 15:08:12 +00001638
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 /// \brief Build a new unary type trait expression.
1640 ///
1641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001643 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001644 SourceLocation StartLoc,
1645 TypeSourceInfo *T,
1646 SourceLocation RParenLoc) {
1647 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 }
1649
Mike Stump11289f42009-09-09 15:08:12 +00001650 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 /// expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001657 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001658 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 CXXScopeSpec SS;
1660 SS.setRange(QualifierRange);
1661 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001662
1663 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001664 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001665 *TemplateArgs);
1666
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001667 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 }
1669
1670 /// \brief Build a new template-id expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001674 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001675 LookupResult &R,
1676 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001677 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001678 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new object-construction expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001685 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001686 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 CXXConstructorDecl *Constructor,
1688 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001689 MultiExprArg Args,
1690 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001691 CXXConstructExpr::ConstructionKind ConstructKind,
1692 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001693 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001694 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001695 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001696 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001697
Douglas Gregordb121ba2009-12-14 16:27:04 +00001698 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001699 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001700 RequiresZeroInit, ConstructKind,
1701 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 }
1703
1704 /// \brief Build a new object-construction expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001708 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1709 SourceLocation LParenLoc,
1710 MultiExprArg Args,
1711 SourceLocation RParenLoc) {
1712 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 LParenLoc,
1714 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 RParenLoc);
1716 }
1717
1718 /// \brief Build a new object-construction expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001722 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1723 SourceLocation LParenLoc,
1724 MultiExprArg Args,
1725 SourceLocation RParenLoc) {
1726 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 LParenLoc,
1728 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 RParenLoc);
1730 }
Mike Stump11289f42009-09-09 15:08:12 +00001731
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// \brief Build a new member reference expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001736 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001737 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 bool IsArrow,
1739 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001740 NestedNameSpecifier *Qualifier,
1741 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001742 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001743 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001744 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001746 SS.setRange(QualifierRange);
1747 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001748
John McCallb268a282010-08-23 23:25:46 +00001749 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001750 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001751 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001752 MemberNameInfo,
1753 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 }
1755
John McCall10eae182009-11-30 22:42:35 +00001756 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001760 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001761 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001762 SourceLocation OperatorLoc,
1763 bool IsArrow,
1764 NestedNameSpecifier *Qualifier,
1765 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001766 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001767 LookupResult &R,
1768 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001769 CXXScopeSpec SS;
1770 SS.setRange(QualifierRange);
1771 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001772
John McCallb268a282010-08-23 23:25:46 +00001773 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001774 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001775 SS, FirstQualifierInScope,
1776 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001777 }
Mike Stump11289f42009-09-09 15:08:12 +00001778
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001779 /// \brief Build a new noexcept expression.
1780 ///
1781 /// By default, performs semantic analysis to build the new expression.
1782 /// Subclasses may override this routine to provide different behavior.
1783 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1784 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1785 }
1786
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 /// \brief Build a new Objective-C @encode expression.
1788 ///
1789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001791 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001792 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001794 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001796 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001797
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001798 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001799 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001800 Selector Sel,
1801 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001802 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001803 MultiExprArg Args,
1804 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001805 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1806 ReceiverTypeInfo->getType(),
1807 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001808 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001809 move(Args));
1810 }
1811
1812 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001813 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001814 Selector Sel,
1815 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001816 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001817 MultiExprArg Args,
1818 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001819 return SemaRef.BuildInstanceMessage(Receiver,
1820 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001821 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001822 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001823 move(Args));
1824 }
1825
Douglas Gregord51d90d2010-04-26 20:11:03 +00001826 /// \brief Build a new Objective-C ivar reference expression.
1827 ///
1828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001830 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001831 SourceLocation IvarLoc,
1832 bool IsArrow, bool IsFreeIvar) {
1833 // FIXME: We lose track of the IsFreeIvar bit.
1834 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001835 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001836 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1837 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001838 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001839 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001840 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001841 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001842 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001843 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001844
Douglas Gregord51d90d2010-04-26 20:11:03 +00001845 if (Result.get())
1846 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001847
John McCallb268a282010-08-23 23:25:46 +00001848 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001849 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001850 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001851 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001852 /*TemplateArgs=*/0);
1853 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001854
1855 /// \brief Build a new Objective-C property reference expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001859 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001860 ObjCPropertyDecl *Property,
1861 SourceLocation PropertyLoc) {
1862 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001863 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001864 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1865 Sema::LookupMemberName);
1866 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001867 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001868 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001869 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001870 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001871 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001872
Douglas Gregor9faee212010-04-26 20:47:02 +00001873 if (Result.get())
1874 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001875
John McCallb268a282010-08-23 23:25:46 +00001876 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001877 /*FIXME:*/PropertyLoc, IsArrow,
1878 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001879 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001880 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001881 /*TemplateArgs=*/0);
1882 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001883
1884 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001885 /// expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001888 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001889 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001890 ObjCMethodDecl *Getter,
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001891 QualType T,
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001892 ObjCMethodDecl *Setter,
1893 SourceLocation NameLoc,
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001894 Expr *Base,
1895 SourceLocation SuperLoc,
1896 QualType SuperTy,
1897 bool Super) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001898 // Since these expressions can only be value-dependent, we do not need to
1899 // perform semantic analysis again.
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001900 if (Super)
1901 return Owned(
1902 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1903 Setter,
1904 NameLoc,
1905 SuperLoc,
1906 SuperTy));
1907 else
1908 return Owned(
1909 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(
1910 Getter, T,
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001911 Setter,
1912 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001913 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001914 }
1915
Douglas Gregord51d90d2010-04-26 20:11:03 +00001916 /// \brief Build a new Objective-C "isa" expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001920 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001921 bool IsArrow) {
1922 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001923 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001924 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1925 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001926 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001927 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001928 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001929 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001930 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001931
Douglas Gregord51d90d2010-04-26 20:11:03 +00001932 if (Result.get())
1933 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001934
John McCallb268a282010-08-23 23:25:46 +00001935 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001936 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001937 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001938 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001939 /*TemplateArgs=*/0);
1940 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001941
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 /// \brief Build a new shuffle vector expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001946 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 MultiExprArg SubExprs,
1948 SourceLocation RParenLoc) {
1949 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001950 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1952 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1953 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1954 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001955
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 // Build a reference to the __builtin_shufflevector builtin
1957 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001958 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001960 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001962
1963 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 unsigned NumSubExprs = SubExprs.size();
1965 Expr **Subs = (Expr **)SubExprs.release();
1966 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1967 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001968 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001970 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001973 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001978 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001980};
Douglas Gregora16548e2009-08-11 05:31:07 +00001981
Douglas Gregorebe10102009-08-20 07:17:43 +00001982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001983StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001984 if (!S)
1985 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001986
Douglas Gregorebe10102009-08-20 07:17:43 +00001987 switch (S->getStmtClass()) {
1988 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001989
Douglas Gregorebe10102009-08-20 07:17:43 +00001990 // Transform individual statement nodes
1991#define STMT(Node, Parent) \
1992 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1993#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001994#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregorebe10102009-08-20 07:17:43 +00001996 // Transform expressions by calling TransformExpr.
1997#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001998#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001999#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002000#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002001 {
John McCalldadc5752010-08-24 06:29:42 +00002002 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002003 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002004 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002005
John McCallb268a282010-08-23 23:25:46 +00002006 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002007 }
Mike Stump11289f42009-09-09 15:08:12 +00002008 }
2009
John McCallc3007a22010-10-26 07:05:15 +00002010 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002011}
Mike Stump11289f42009-09-09 15:08:12 +00002012
2013
Douglas Gregore922c772009-08-04 22:27:00 +00002014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002015ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 if (!E)
2017 return SemaRef.Owned(E);
2018
2019 switch (E->getStmtClass()) {
2020 case Stmt::NoStmtClass: break;
2021#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002022#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002023#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002024 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002025#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002026 }
2027
John McCallc3007a22010-10-26 07:05:15 +00002028 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002029}
2030
2031template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002032NestedNameSpecifier *
2033TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002034 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002035 QualType ObjectType,
2036 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002037 if (!NNS)
2038 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregorebe10102009-08-20 07:17:43 +00002040 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002041 NestedNameSpecifier *Prefix = NNS->getPrefix();
2042 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002043 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002044 ObjectType,
2045 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002046 if (!Prefix)
2047 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002048
2049 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002050 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002051 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002052 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 }
Mike Stump11289f42009-09-09 15:08:12 +00002054
Douglas Gregor1135c352009-08-06 05:28:30 +00002055 switch (NNS->getKind()) {
2056 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002057 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002058 "Identifier nested-name-specifier with no prefix or object type");
2059 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2060 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002061 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002062
2063 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002064 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002065 ObjectType,
2066 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002067
Douglas Gregor1135c352009-08-06 05:28:30 +00002068 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002069 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002070 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002071 getDerived().TransformDecl(Range.getBegin(),
2072 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002073 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002074 Prefix == NNS->getPrefix() &&
2075 NS == NNS->getAsNamespace())
2076 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002077
Douglas Gregor1135c352009-08-06 05:28:30 +00002078 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2079 }
Mike Stump11289f42009-09-09 15:08:12 +00002080
Douglas Gregor1135c352009-08-06 05:28:30 +00002081 case NestedNameSpecifier::Global:
2082 // There is no meaningful transformation that one could perform on the
2083 // global scope.
2084 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregor1135c352009-08-06 05:28:30 +00002086 case NestedNameSpecifier::TypeSpecWithTemplate:
2087 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002088 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002089 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2090 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002091 if (T.isNull())
2092 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002093
Douglas Gregor1135c352009-08-06 05:28:30 +00002094 if (!getDerived().AlwaysRebuild() &&
2095 Prefix == NNS->getPrefix() &&
2096 T == QualType(NNS->getAsType(), 0))
2097 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002098
2099 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2100 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002101 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002102 }
2103 }
Mike Stump11289f42009-09-09 15:08:12 +00002104
Douglas Gregor1135c352009-08-06 05:28:30 +00002105 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002106 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002107}
2108
2109template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002110DeclarationNameInfo
2111TreeTransform<Derived>
2112::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2113 QualType ObjectType) {
2114 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002115 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002116 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002117
2118 switch (Name.getNameKind()) {
2119 case DeclarationName::Identifier:
2120 case DeclarationName::ObjCZeroArgSelector:
2121 case DeclarationName::ObjCOneArgSelector:
2122 case DeclarationName::ObjCMultiArgSelector:
2123 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002124 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002125 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002126 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregorf816bd72009-09-03 22:13:48 +00002128 case DeclarationName::CXXConstructorName:
2129 case DeclarationName::CXXDestructorName:
2130 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002131 TypeSourceInfo *NewTInfo;
2132 CanQualType NewCanTy;
2133 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2134 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2135 if (!NewTInfo)
2136 return DeclarationNameInfo();
2137 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2138 }
2139 else {
2140 NewTInfo = 0;
2141 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2142 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2143 ObjectType);
2144 if (NewT.isNull())
2145 return DeclarationNameInfo();
2146 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2147 }
Mike Stump11289f42009-09-09 15:08:12 +00002148
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002149 DeclarationName NewName
2150 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2151 NewCanTy);
2152 DeclarationNameInfo NewNameInfo(NameInfo);
2153 NewNameInfo.setName(NewName);
2154 NewNameInfo.setNamedTypeInfo(NewTInfo);
2155 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002156 }
Mike Stump11289f42009-09-09 15:08:12 +00002157 }
2158
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002159 assert(0 && "Unknown name kind.");
2160 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002161}
2162
2163template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002164TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002165TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2166 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002167 SourceLocation Loc = getDerived().getBaseLocation();
2168
Douglas Gregor71dc5092009-08-06 06:41:21 +00002169 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002170 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002171 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002172 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2173 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002174 if (!NNS)
2175 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002178 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002179 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002180 if (!TransTemplate)
2181 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002182
Douglas Gregor71dc5092009-08-06 06:41:21 +00002183 if (!getDerived().AlwaysRebuild() &&
2184 NNS == QTN->getQualifier() &&
2185 TransTemplate == Template)
2186 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregor71dc5092009-08-06 06:41:21 +00002188 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2189 TransTemplate);
2190 }
Mike Stump11289f42009-09-09 15:08:12 +00002191
John McCalle66edc12009-11-24 19:00:30 +00002192 // These should be getting filtered out before they make it into the AST.
2193 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002194 }
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregor71dc5092009-08-06 06:41:21 +00002196 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002197 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002198 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002199 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2200 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002201 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002202 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002203
Douglas Gregor71dc5092009-08-06 06:41:21 +00002204 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002205 NNS == DTN->getQualifier() &&
2206 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002207 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora5614c52010-09-08 23:56:00 +00002209 if (DTN->isIdentifier()) {
2210 // FIXME: Bad range
2211 SourceRange QualifierRange(getDerived().getBaseLocation());
2212 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2213 *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002214 ObjectType);
Douglas Gregora5614c52010-09-08 23:56:00 +00002215 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002216
2217 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002218 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002219 }
Mike Stump11289f42009-09-09 15:08:12 +00002220
Douglas Gregor71dc5092009-08-06 06:41:21 +00002221 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002222 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002223 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002224 if (!TransTemplate)
2225 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002226
Douglas Gregor71dc5092009-08-06 06:41:21 +00002227 if (!getDerived().AlwaysRebuild() &&
2228 TransTemplate == Template)
2229 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002230
Douglas Gregor71dc5092009-08-06 06:41:21 +00002231 return TemplateName(TransTemplate);
2232 }
Mike Stump11289f42009-09-09 15:08:12 +00002233
John McCalle66edc12009-11-24 19:00:30 +00002234 // These should be getting filtered out before they reach the AST.
2235 assert(false && "overloaded function decl survived to here");
2236 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002237}
2238
2239template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002240void TreeTransform<Derived>::InventTemplateArgumentLoc(
2241 const TemplateArgument &Arg,
2242 TemplateArgumentLoc &Output) {
2243 SourceLocation Loc = getDerived().getBaseLocation();
2244 switch (Arg.getKind()) {
2245 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002246 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002247 break;
2248
2249 case TemplateArgument::Type:
2250 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002251 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002252
John McCall0ad16662009-10-29 08:12:44 +00002253 break;
2254
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002255 case TemplateArgument::Template:
2256 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2257 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002258
John McCall0ad16662009-10-29 08:12:44 +00002259 case TemplateArgument::Expression:
2260 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2261 break;
2262
2263 case TemplateArgument::Declaration:
2264 case TemplateArgument::Integral:
2265 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002266 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002267 break;
2268 }
2269}
2270
2271template<typename Derived>
2272bool TreeTransform<Derived>::TransformTemplateArgument(
2273 const TemplateArgumentLoc &Input,
2274 TemplateArgumentLoc &Output) {
2275 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002276 switch (Arg.getKind()) {
2277 case TemplateArgument::Null:
2278 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002279 Output = Input;
2280 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregore922c772009-08-04 22:27:00 +00002282 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002283 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002284 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002285 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002286
2287 DI = getDerived().TransformType(DI);
2288 if (!DI) return true;
2289
2290 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2291 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002292 }
Mike Stump11289f42009-09-09 15:08:12 +00002293
Douglas Gregore922c772009-08-04 22:27:00 +00002294 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002295 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002296 DeclarationName Name;
2297 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2298 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002299 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002300 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002301 if (!D) return true;
2302
John McCall0d07eb32009-10-29 18:45:58 +00002303 Expr *SourceExpr = Input.getSourceDeclExpression();
2304 if (SourceExpr) {
2305 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002306 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002307 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002308 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002309 }
2310
2311 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002312 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002313 }
Mike Stump11289f42009-09-09 15:08:12 +00002314
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002315 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002316 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002317 TemplateName Template
2318 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2319 if (Template.isNull())
2320 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002321
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002322 Output = TemplateArgumentLoc(TemplateArgument(Template),
2323 Input.getTemplateQualifierRange(),
2324 Input.getTemplateNameLoc());
2325 return false;
2326 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002327
Douglas Gregore922c772009-08-04 22:27:00 +00002328 case TemplateArgument::Expression: {
2329 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002330 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002331 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002332
John McCall0ad16662009-10-29 08:12:44 +00002333 Expr *InputExpr = Input.getSourceExpression();
2334 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2335
John McCalldadc5752010-08-24 06:29:42 +00002336 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002337 = getDerived().TransformExpr(InputExpr);
2338 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002339 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002340 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002341 }
Mike Stump11289f42009-09-09 15:08:12 +00002342
Douglas Gregore922c772009-08-04 22:27:00 +00002343 case TemplateArgument::Pack: {
2344 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2345 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002346 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002347 AEnd = Arg.pack_end();
2348 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002349
John McCall0ad16662009-10-29 08:12:44 +00002350 // FIXME: preserve source information here when we start
2351 // caring about parameter packs.
2352
John McCall0d07eb32009-10-29 18:45:58 +00002353 TemplateArgumentLoc InputArg;
2354 TemplateArgumentLoc OutputArg;
2355 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2356 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002357 return true;
2358
John McCall0d07eb32009-10-29 18:45:58 +00002359 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002360 }
2361 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002362 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002363 true);
John McCall0d07eb32009-10-29 18:45:58 +00002364 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002365 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002366 }
2367 }
Mike Stump11289f42009-09-09 15:08:12 +00002368
Douglas Gregore922c772009-08-04 22:27:00 +00002369 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002370 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002371}
2372
Douglas Gregord6ff3322009-08-04 16:50:30 +00002373//===----------------------------------------------------------------------===//
2374// Type transformation
2375//===----------------------------------------------------------------------===//
2376
2377template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002378QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002379 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002380 if (getDerived().AlreadyTransformed(T))
2381 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002382
John McCall550e0c22009-10-21 00:40:46 +00002383 // Temporary workaround. All of these transformations should
2384 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002385 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002386 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002387
Douglas Gregorfe17d252010-02-16 19:09:40 +00002388 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002389
John McCall550e0c22009-10-21 00:40:46 +00002390 if (!NewDI)
2391 return QualType();
2392
2393 return NewDI->getType();
2394}
2395
2396template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002397TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2398 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002399 if (getDerived().AlreadyTransformed(DI->getType()))
2400 return DI;
2401
2402 TypeLocBuilder TLB;
2403
2404 TypeLoc TL = DI->getTypeLoc();
2405 TLB.reserve(TL.getFullDataSize());
2406
Douglas Gregorfe17d252010-02-16 19:09:40 +00002407 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002408 if (Result.isNull())
2409 return 0;
2410
John McCallbcd03502009-12-07 02:54:59 +00002411 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002412}
2413
2414template<typename Derived>
2415QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002416TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2417 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002418 switch (T.getTypeLocClass()) {
2419#define ABSTRACT_TYPELOC(CLASS, PARENT)
2420#define TYPELOC(CLASS, PARENT) \
2421 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002422 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2423 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002424#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002425 }
Mike Stump11289f42009-09-09 15:08:12 +00002426
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002427 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002428 return QualType();
2429}
2430
2431/// FIXME: By default, this routine adds type qualifiers only to types
2432/// that can have qualifiers, and silently suppresses those qualifiers
2433/// that are not permitted (e.g., qualifiers on reference or function
2434/// types). This is the right thing for template instantiation, but
2435/// probably not for other clients.
2436template<typename Derived>
2437QualType
2438TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002439 QualifiedTypeLoc T,
2440 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002441 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002442
Douglas Gregorfe17d252010-02-16 19:09:40 +00002443 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2444 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002445 if (Result.isNull())
2446 return QualType();
2447
2448 // Silently suppress qualifiers if the result type can't be qualified.
2449 // FIXME: this is the right thing for template instantiation, but
2450 // probably not for other clients.
2451 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002452 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002453
John McCallcb0f89a2010-06-05 06:41:15 +00002454 if (!Quals.empty()) {
2455 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2456 TLB.push<QualifiedTypeLoc>(Result);
2457 // No location information to preserve.
2458 }
John McCall550e0c22009-10-21 00:40:46 +00002459
2460 return Result;
2461}
2462
2463template <class TyLoc> static inline
2464QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2465 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2466 NewT.setNameLoc(T.getNameLoc());
2467 return T.getType();
2468}
2469
John McCall550e0c22009-10-21 00:40:46 +00002470template<typename Derived>
2471QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002472 BuiltinTypeLoc T,
2473 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002474 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2475 NewT.setBuiltinLoc(T.getBuiltinLoc());
2476 if (T.needsExtraLocalData())
2477 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2478 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002479}
Mike Stump11289f42009-09-09 15:08:12 +00002480
Douglas Gregord6ff3322009-08-04 16:50:30 +00002481template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002482QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002483 ComplexTypeLoc T,
2484 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002485 // FIXME: recurse?
2486 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002487}
Mike Stump11289f42009-09-09 15:08:12 +00002488
Douglas Gregord6ff3322009-08-04 16:50:30 +00002489template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002490QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002491 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002492 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002493 QualType PointeeType
2494 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002495 if (PointeeType.isNull())
2496 return QualType();
2497
2498 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002499 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002500 // A dependent pointer type 'T *' has is being transformed such
2501 // that an Objective-C class type is being replaced for 'T'. The
2502 // resulting pointer type is an ObjCObjectPointerType, not a
2503 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002504 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002505
John McCall8b07ec22010-05-15 11:32:37 +00002506 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2507 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002508 return Result;
2509 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002510
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002511 if (getDerived().AlwaysRebuild() ||
2512 PointeeType != TL.getPointeeLoc().getType()) {
2513 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2514 if (Result.isNull())
2515 return QualType();
2516 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002517
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002518 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2519 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002520 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002521}
Mike Stump11289f42009-09-09 15:08:12 +00002522
2523template<typename Derived>
2524QualType
John McCall550e0c22009-10-21 00:40:46 +00002525TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002526 BlockPointerTypeLoc TL,
2527 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002528 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002529 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2530 if (PointeeType.isNull())
2531 return QualType();
2532
2533 QualType Result = TL.getType();
2534 if (getDerived().AlwaysRebuild() ||
2535 PointeeType != TL.getPointeeLoc().getType()) {
2536 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002537 TL.getSigilLoc());
2538 if (Result.isNull())
2539 return QualType();
2540 }
2541
Douglas Gregor049211a2010-04-22 16:50:51 +00002542 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002543 NewT.setSigilLoc(TL.getSigilLoc());
2544 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002545}
2546
John McCall70dd5f62009-10-30 00:06:24 +00002547/// Transforms a reference type. Note that somewhat paradoxically we
2548/// don't care whether the type itself is an l-value type or an r-value
2549/// type; we only care if the type was *written* as an l-value type
2550/// or an r-value type.
2551template<typename Derived>
2552QualType
2553TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002554 ReferenceTypeLoc TL,
2555 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002556 const ReferenceType *T = TL.getTypePtr();
2557
2558 // Note that this works with the pointee-as-written.
2559 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2560 if (PointeeType.isNull())
2561 return QualType();
2562
2563 QualType Result = TL.getType();
2564 if (getDerived().AlwaysRebuild() ||
2565 PointeeType != T->getPointeeTypeAsWritten()) {
2566 Result = getDerived().RebuildReferenceType(PointeeType,
2567 T->isSpelledAsLValue(),
2568 TL.getSigilLoc());
2569 if (Result.isNull())
2570 return QualType();
2571 }
2572
2573 // r-value references can be rebuilt as l-value references.
2574 ReferenceTypeLoc NewTL;
2575 if (isa<LValueReferenceType>(Result))
2576 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2577 else
2578 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2579 NewTL.setSigilLoc(TL.getSigilLoc());
2580
2581 return Result;
2582}
2583
Mike Stump11289f42009-09-09 15:08:12 +00002584template<typename Derived>
2585QualType
John McCall550e0c22009-10-21 00:40:46 +00002586TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002587 LValueReferenceTypeLoc TL,
2588 QualType ObjectType) {
2589 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002590}
2591
Mike Stump11289f42009-09-09 15:08:12 +00002592template<typename Derived>
2593QualType
John McCall550e0c22009-10-21 00:40:46 +00002594TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002595 RValueReferenceTypeLoc TL,
2596 QualType ObjectType) {
2597 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002598}
Mike Stump11289f42009-09-09 15:08:12 +00002599
Douglas Gregord6ff3322009-08-04 16:50:30 +00002600template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002601QualType
John McCall550e0c22009-10-21 00:40:46 +00002602TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002603 MemberPointerTypeLoc TL,
2604 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002605 MemberPointerType *T = TL.getTypePtr();
2606
2607 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608 if (PointeeType.isNull())
2609 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002610
John McCall550e0c22009-10-21 00:40:46 +00002611 // TODO: preserve source information for this.
2612 QualType ClassType
2613 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002614 if (ClassType.isNull())
2615 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002616
John McCall550e0c22009-10-21 00:40:46 +00002617 QualType Result = TL.getType();
2618 if (getDerived().AlwaysRebuild() ||
2619 PointeeType != T->getPointeeType() ||
2620 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002621 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2622 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002623 if (Result.isNull())
2624 return QualType();
2625 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002626
John McCall550e0c22009-10-21 00:40:46 +00002627 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2628 NewTL.setSigilLoc(TL.getSigilLoc());
2629
2630 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002631}
2632
Mike Stump11289f42009-09-09 15:08:12 +00002633template<typename Derived>
2634QualType
John McCall550e0c22009-10-21 00:40:46 +00002635TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002636 ConstantArrayTypeLoc TL,
2637 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002638 ConstantArrayType *T = TL.getTypePtr();
2639 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002640 if (ElementType.isNull())
2641 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002642
John McCall550e0c22009-10-21 00:40:46 +00002643 QualType Result = TL.getType();
2644 if (getDerived().AlwaysRebuild() ||
2645 ElementType != T->getElementType()) {
2646 Result = getDerived().RebuildConstantArrayType(ElementType,
2647 T->getSizeModifier(),
2648 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002649 T->getIndexTypeCVRQualifiers(),
2650 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002651 if (Result.isNull())
2652 return QualType();
2653 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002654
John McCall550e0c22009-10-21 00:40:46 +00002655 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2656 NewTL.setLBracketLoc(TL.getLBracketLoc());
2657 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002658
John McCall550e0c22009-10-21 00:40:46 +00002659 Expr *Size = TL.getSizeExpr();
2660 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002661 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002662 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2663 }
2664 NewTL.setSizeExpr(Size);
2665
2666 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002667}
Mike Stump11289f42009-09-09 15:08:12 +00002668
Douglas Gregord6ff3322009-08-04 16:50:30 +00002669template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002670QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002671 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002672 IncompleteArrayTypeLoc TL,
2673 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002674 IncompleteArrayType *T = TL.getTypePtr();
2675 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002676 if (ElementType.isNull())
2677 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002678
John McCall550e0c22009-10-21 00:40:46 +00002679 QualType Result = TL.getType();
2680 if (getDerived().AlwaysRebuild() ||
2681 ElementType != T->getElementType()) {
2682 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002683 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002684 T->getIndexTypeCVRQualifiers(),
2685 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002686 if (Result.isNull())
2687 return QualType();
2688 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002689
John McCall550e0c22009-10-21 00:40:46 +00002690 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2691 NewTL.setLBracketLoc(TL.getLBracketLoc());
2692 NewTL.setRBracketLoc(TL.getRBracketLoc());
2693 NewTL.setSizeExpr(0);
2694
2695 return Result;
2696}
2697
2698template<typename Derived>
2699QualType
2700TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002701 VariableArrayTypeLoc TL,
2702 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002703 VariableArrayType *T = TL.getTypePtr();
2704 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2705 if (ElementType.isNull())
2706 return QualType();
2707
2708 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002709 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002710
John McCalldadc5752010-08-24 06:29:42 +00002711 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002712 = getDerived().TransformExpr(T->getSizeExpr());
2713 if (SizeResult.isInvalid())
2714 return QualType();
2715
John McCallb268a282010-08-23 23:25:46 +00002716 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002717
2718 QualType Result = TL.getType();
2719 if (getDerived().AlwaysRebuild() ||
2720 ElementType != T->getElementType() ||
2721 Size != T->getSizeExpr()) {
2722 Result = getDerived().RebuildVariableArrayType(ElementType,
2723 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002724 Size,
John McCall550e0c22009-10-21 00:40:46 +00002725 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002726 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002727 if (Result.isNull())
2728 return QualType();
2729 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002730
John McCall550e0c22009-10-21 00:40:46 +00002731 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2732 NewTL.setLBracketLoc(TL.getLBracketLoc());
2733 NewTL.setRBracketLoc(TL.getRBracketLoc());
2734 NewTL.setSizeExpr(Size);
2735
2736 return Result;
2737}
2738
2739template<typename Derived>
2740QualType
2741TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002742 DependentSizedArrayTypeLoc TL,
2743 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002744 DependentSizedArrayType *T = TL.getTypePtr();
2745 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2746 if (ElementType.isNull())
2747 return QualType();
2748
2749 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002750 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002751
John McCalldadc5752010-08-24 06:29:42 +00002752 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002753 = getDerived().TransformExpr(T->getSizeExpr());
2754 if (SizeResult.isInvalid())
2755 return QualType();
2756
2757 Expr *Size = static_cast<Expr*>(SizeResult.get());
2758
2759 QualType Result = TL.getType();
2760 if (getDerived().AlwaysRebuild() ||
2761 ElementType != T->getElementType() ||
2762 Size != T->getSizeExpr()) {
2763 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2764 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002765 Size,
John McCall550e0c22009-10-21 00:40:46 +00002766 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002767 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002768 if (Result.isNull())
2769 return QualType();
2770 }
2771 else SizeResult.take();
2772
2773 // We might have any sort of array type now, but fortunately they
2774 // all have the same location layout.
2775 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2776 NewTL.setLBracketLoc(TL.getLBracketLoc());
2777 NewTL.setRBracketLoc(TL.getRBracketLoc());
2778 NewTL.setSizeExpr(Size);
2779
2780 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002781}
Mike Stump11289f42009-09-09 15:08:12 +00002782
2783template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002784QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002785 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002786 DependentSizedExtVectorTypeLoc TL,
2787 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002788 DependentSizedExtVectorType *T = TL.getTypePtr();
2789
2790 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002791 QualType ElementType = getDerived().TransformType(T->getElementType());
2792 if (ElementType.isNull())
2793 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002794
Douglas Gregore922c772009-08-04 22:27:00 +00002795 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002796 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002797
John McCalldadc5752010-08-24 06:29:42 +00002798 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002799 if (Size.isInvalid())
2800 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002801
John McCall550e0c22009-10-21 00:40:46 +00002802 QualType Result = TL.getType();
2803 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002804 ElementType != T->getElementType() ||
2805 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002806 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002807 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002808 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002809 if (Result.isNull())
2810 return QualType();
2811 }
John McCall550e0c22009-10-21 00:40:46 +00002812
2813 // Result might be dependent or not.
2814 if (isa<DependentSizedExtVectorType>(Result)) {
2815 DependentSizedExtVectorTypeLoc NewTL
2816 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2817 NewTL.setNameLoc(TL.getNameLoc());
2818 } else {
2819 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2820 NewTL.setNameLoc(TL.getNameLoc());
2821 }
2822
2823 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002824}
Mike Stump11289f42009-09-09 15:08:12 +00002825
2826template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002827QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002828 VectorTypeLoc TL,
2829 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002830 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002831 QualType ElementType = getDerived().TransformType(T->getElementType());
2832 if (ElementType.isNull())
2833 return QualType();
2834
John McCall550e0c22009-10-21 00:40:46 +00002835 QualType Result = TL.getType();
2836 if (getDerived().AlwaysRebuild() ||
2837 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002838 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002839 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002840 if (Result.isNull())
2841 return QualType();
2842 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002843
John McCall550e0c22009-10-21 00:40:46 +00002844 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2845 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002846
John McCall550e0c22009-10-21 00:40:46 +00002847 return Result;
2848}
2849
2850template<typename Derived>
2851QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002852 ExtVectorTypeLoc TL,
2853 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002854 VectorType *T = TL.getTypePtr();
2855 QualType ElementType = getDerived().TransformType(T->getElementType());
2856 if (ElementType.isNull())
2857 return QualType();
2858
2859 QualType Result = TL.getType();
2860 if (getDerived().AlwaysRebuild() ||
2861 ElementType != T->getElementType()) {
2862 Result = getDerived().RebuildExtVectorType(ElementType,
2863 T->getNumElements(),
2864 /*FIXME*/ SourceLocation());
2865 if (Result.isNull())
2866 return QualType();
2867 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002868
John McCall550e0c22009-10-21 00:40:46 +00002869 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2870 NewTL.setNameLoc(TL.getNameLoc());
2871
2872 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002873}
Mike Stump11289f42009-09-09 15:08:12 +00002874
2875template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002876ParmVarDecl *
2877TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2878 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2879 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2880 if (!NewDI)
2881 return 0;
2882
2883 if (NewDI == OldDI)
2884 return OldParm;
2885 else
2886 return ParmVarDecl::Create(SemaRef.Context,
2887 OldParm->getDeclContext(),
2888 OldParm->getLocation(),
2889 OldParm->getIdentifier(),
2890 NewDI->getType(),
2891 NewDI,
2892 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002893 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002894 /* DefArg */ NULL);
2895}
2896
2897template<typename Derived>
2898bool TreeTransform<Derived>::
2899 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2900 llvm::SmallVectorImpl<QualType> &PTypes,
2901 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2902 FunctionProtoType *T = TL.getTypePtr();
2903
2904 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2905 ParmVarDecl *OldParm = TL.getArg(i);
2906
2907 QualType NewType;
2908 ParmVarDecl *NewParm;
2909
2910 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002911 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2912 if (!NewParm)
2913 return true;
2914 NewType = NewParm->getType();
2915
2916 // Deal with the possibility that we don't have a parameter
2917 // declaration for this parameter.
2918 } else {
2919 NewParm = 0;
2920
2921 QualType OldType = T->getArgType(i);
2922 NewType = getDerived().TransformType(OldType);
2923 if (NewType.isNull())
2924 return true;
2925 }
2926
2927 PTypes.push_back(NewType);
2928 PVars.push_back(NewParm);
2929 }
2930
2931 return false;
2932}
2933
2934template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002935QualType
John McCall550e0c22009-10-21 00:40:46 +00002936TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002937 FunctionProtoTypeLoc TL,
2938 QualType ObjectType) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00002939 // Transform the parameters and return type.
2940 //
2941 // We instantiate in source order, with the return type first followed by
2942 // the parameters, because users tend to expect this (even if they shouldn't
2943 // rely on it!).
2944 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00002945 // When the function has a trailing return type, we instantiate the
2946 // parameters before the return type, since the return type can then refer
2947 // to the parameters themselves (via decltype, sizeof, etc.).
2948 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00002949 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002950 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00002951 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00002952
Douglas Gregor7fb25412010-10-01 18:44:50 +00002953 QualType ResultType;
2954
2955 if (TL.getTrailingReturn()) {
2956 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2957 return QualType();
2958
2959 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2960 if (ResultType.isNull())
2961 return QualType();
2962 }
2963 else {
2964 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2965 if (ResultType.isNull())
2966 return QualType();
2967
2968 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2969 return QualType();
2970 }
2971
John McCall550e0c22009-10-21 00:40:46 +00002972 QualType Result = TL.getType();
2973 if (getDerived().AlwaysRebuild() ||
2974 ResultType != T->getResultType() ||
2975 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2976 Result = getDerived().RebuildFunctionProtoType(ResultType,
2977 ParamTypes.data(),
2978 ParamTypes.size(),
2979 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002980 T->getTypeQuals(),
2981 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002982 if (Result.isNull())
2983 return QualType();
2984 }
Mike Stump11289f42009-09-09 15:08:12 +00002985
John McCall550e0c22009-10-21 00:40:46 +00002986 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2987 NewTL.setLParenLoc(TL.getLParenLoc());
2988 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00002989 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00002990 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2991 NewTL.setArg(i, ParamDecls[i]);
2992
2993 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002994}
Mike Stump11289f42009-09-09 15:08:12 +00002995
Douglas Gregord6ff3322009-08-04 16:50:30 +00002996template<typename Derived>
2997QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002998 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002999 FunctionNoProtoTypeLoc TL,
3000 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003001 FunctionNoProtoType *T = TL.getTypePtr();
3002 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3003 if (ResultType.isNull())
3004 return QualType();
3005
3006 QualType Result = TL.getType();
3007 if (getDerived().AlwaysRebuild() ||
3008 ResultType != T->getResultType())
3009 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3010
3011 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3012 NewTL.setLParenLoc(TL.getLParenLoc());
3013 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003014 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003015
3016 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003017}
Mike Stump11289f42009-09-09 15:08:12 +00003018
John McCallb96ec562009-12-04 22:46:56 +00003019template<typename Derived> QualType
3020TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003021 UnresolvedUsingTypeLoc TL,
3022 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00003023 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003024 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003025 if (!D)
3026 return QualType();
3027
3028 QualType Result = TL.getType();
3029 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3030 Result = getDerived().RebuildUnresolvedUsingType(D);
3031 if (Result.isNull())
3032 return QualType();
3033 }
3034
3035 // We might get an arbitrary type spec type back. We should at
3036 // least always get a type spec type, though.
3037 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3038 NewTL.setNameLoc(TL.getNameLoc());
3039
3040 return Result;
3041}
3042
Douglas Gregord6ff3322009-08-04 16:50:30 +00003043template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003044QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003045 TypedefTypeLoc TL,
3046 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003047 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003048 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003049 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3050 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003051 if (!Typedef)
3052 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003053
John McCall550e0c22009-10-21 00:40:46 +00003054 QualType Result = TL.getType();
3055 if (getDerived().AlwaysRebuild() ||
3056 Typedef != T->getDecl()) {
3057 Result = getDerived().RebuildTypedefType(Typedef);
3058 if (Result.isNull())
3059 return QualType();
3060 }
Mike Stump11289f42009-09-09 15:08:12 +00003061
John McCall550e0c22009-10-21 00:40:46 +00003062 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3063 NewTL.setNameLoc(TL.getNameLoc());
3064
3065 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003066}
Mike Stump11289f42009-09-09 15:08:12 +00003067
Douglas Gregord6ff3322009-08-04 16:50:30 +00003068template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003069QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003070 TypeOfExprTypeLoc TL,
3071 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003072 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003073 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003074
John McCalldadc5752010-08-24 06:29:42 +00003075 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076 if (E.isInvalid())
3077 return QualType();
3078
John McCall550e0c22009-10-21 00:40:46 +00003079 QualType Result = TL.getType();
3080 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003081 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003082 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003083 if (Result.isNull())
3084 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003085 }
John McCall550e0c22009-10-21 00:40:46 +00003086 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003087
John McCall550e0c22009-10-21 00:40:46 +00003088 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003089 NewTL.setTypeofLoc(TL.getTypeofLoc());
3090 NewTL.setLParenLoc(TL.getLParenLoc());
3091 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003092
3093 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003094}
Mike Stump11289f42009-09-09 15:08:12 +00003095
3096template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003097QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003098 TypeOfTypeLoc TL,
3099 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003100 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3101 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3102 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003103 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003104
John McCall550e0c22009-10-21 00:40:46 +00003105 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003106 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3107 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003108 if (Result.isNull())
3109 return QualType();
3110 }
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003113 NewTL.setTypeofLoc(TL.getTypeofLoc());
3114 NewTL.setLParenLoc(TL.getLParenLoc());
3115 NewTL.setRParenLoc(TL.getRParenLoc());
3116 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003117
3118 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003119}
Mike Stump11289f42009-09-09 15:08:12 +00003120
3121template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003122QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003123 DecltypeTypeLoc TL,
3124 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003125 DecltypeType *T = TL.getTypePtr();
3126
Douglas Gregore922c772009-08-04 22:27:00 +00003127 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003128 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003129
John McCalldadc5752010-08-24 06:29:42 +00003130 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003131 if (E.isInvalid())
3132 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003133
John McCall550e0c22009-10-21 00:40:46 +00003134 QualType Result = TL.getType();
3135 if (getDerived().AlwaysRebuild() ||
3136 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003137 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003138 if (Result.isNull())
3139 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140 }
John McCall550e0c22009-10-21 00:40:46 +00003141 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003142
John McCall550e0c22009-10-21 00:40:46 +00003143 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3144 NewTL.setNameLoc(TL.getNameLoc());
3145
3146 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147}
3148
3149template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003150QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003151 RecordTypeLoc TL,
3152 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003153 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003154 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003155 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3156 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003157 if (!Record)
3158 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003159
John McCall550e0c22009-10-21 00:40:46 +00003160 QualType Result = TL.getType();
3161 if (getDerived().AlwaysRebuild() ||
3162 Record != T->getDecl()) {
3163 Result = getDerived().RebuildRecordType(Record);
3164 if (Result.isNull())
3165 return QualType();
3166 }
Mike Stump11289f42009-09-09 15:08:12 +00003167
John McCall550e0c22009-10-21 00:40:46 +00003168 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3169 NewTL.setNameLoc(TL.getNameLoc());
3170
3171 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003172}
Mike Stump11289f42009-09-09 15:08:12 +00003173
3174template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003175QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003176 EnumTypeLoc TL,
3177 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003178 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003179 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003180 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3181 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003182 if (!Enum)
3183 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003184
John McCall550e0c22009-10-21 00:40:46 +00003185 QualType Result = TL.getType();
3186 if (getDerived().AlwaysRebuild() ||
3187 Enum != T->getDecl()) {
3188 Result = getDerived().RebuildEnumType(Enum);
3189 if (Result.isNull())
3190 return QualType();
3191 }
Mike Stump11289f42009-09-09 15:08:12 +00003192
John McCall550e0c22009-10-21 00:40:46 +00003193 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3194 NewTL.setNameLoc(TL.getNameLoc());
3195
3196 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003197}
John McCallfcc33b02009-09-05 00:15:47 +00003198
John McCalle78aac42010-03-10 03:28:59 +00003199template<typename Derived>
3200QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3201 TypeLocBuilder &TLB,
3202 InjectedClassNameTypeLoc TL,
3203 QualType ObjectType) {
3204 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3205 TL.getTypePtr()->getDecl());
3206 if (!D) return QualType();
3207
3208 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3209 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3210 return T;
3211}
3212
Mike Stump11289f42009-09-09 15:08:12 +00003213
Douglas Gregord6ff3322009-08-04 16:50:30 +00003214template<typename Derived>
3215QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003216 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003217 TemplateTypeParmTypeLoc TL,
3218 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003219 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003220}
3221
Mike Stump11289f42009-09-09 15:08:12 +00003222template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003223QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003224 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003225 SubstTemplateTypeParmTypeLoc TL,
3226 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003227 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003228}
3229
3230template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003231QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3232 const TemplateSpecializationType *TST,
3233 QualType ObjectType) {
3234 // FIXME: this entire method is a temporary workaround; callers
3235 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003236
John McCall0ad16662009-10-29 08:12:44 +00003237 // Fake up a TemplateSpecializationTypeLoc.
3238 TypeLocBuilder TLB;
3239 TemplateSpecializationTypeLoc TL
3240 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3241
John McCall0d07eb32009-10-29 18:45:58 +00003242 SourceLocation BaseLoc = getDerived().getBaseLocation();
3243
3244 TL.setTemplateNameLoc(BaseLoc);
3245 TL.setLAngleLoc(BaseLoc);
3246 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003247 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3248 const TemplateArgument &TA = TST->getArg(i);
3249 TemplateArgumentLoc TAL;
3250 getDerived().InventTemplateArgumentLoc(TA, TAL);
3251 TL.setArgLocInfo(i, TAL.getLocInfo());
3252 }
3253
3254 TypeLocBuilder IgnoredTLB;
3255 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003256}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003257
Douglas Gregorc59e5612009-10-19 22:04:39 +00003258template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003259QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003260 TypeLocBuilder &TLB,
3261 TemplateSpecializationTypeLoc TL,
3262 QualType ObjectType) {
3263 const TemplateSpecializationType *T = TL.getTypePtr();
3264
Mike Stump11289f42009-09-09 15:08:12 +00003265 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003266 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003267 if (Template.isNull())
3268 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003269
John McCall6b51f282009-11-23 01:53:49 +00003270 TemplateArgumentListInfo NewTemplateArgs;
3271 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3272 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3273
3274 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3275 TemplateArgumentLoc Loc;
3276 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003277 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003278 NewTemplateArgs.addArgument(Loc);
3279 }
Mike Stump11289f42009-09-09 15:08:12 +00003280
John McCall0ad16662009-10-29 08:12:44 +00003281 // FIXME: maybe don't rebuild if all the template arguments are the same.
3282
3283 QualType Result =
3284 getDerived().RebuildTemplateSpecializationType(Template,
3285 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003286 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003287
3288 if (!Result.isNull()) {
3289 TemplateSpecializationTypeLoc NewTL
3290 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3291 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3292 NewTL.setLAngleLoc(TL.getLAngleLoc());
3293 NewTL.setRAngleLoc(TL.getRAngleLoc());
3294 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3295 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296 }
Mike Stump11289f42009-09-09 15:08:12 +00003297
John McCall0ad16662009-10-29 08:12:44 +00003298 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003299}
Mike Stump11289f42009-09-09 15:08:12 +00003300
3301template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003302QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003303TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3304 ElaboratedTypeLoc TL,
3305 QualType ObjectType) {
3306 ElaboratedType *T = TL.getTypePtr();
3307
3308 NestedNameSpecifier *NNS = 0;
3309 // NOTE: the qualifier in an ElaboratedType is optional.
3310 if (T->getQualifier() != 0) {
3311 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003312 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003313 ObjectType);
3314 if (!NNS)
3315 return QualType();
3316 }
Mike Stump11289f42009-09-09 15:08:12 +00003317
Abramo Bagnarad7548482010-05-19 21:37:53 +00003318 QualType NamedT;
3319 // FIXME: this test is meant to workaround a problem (failing assertion)
3320 // occurring if directly executing the code in the else branch.
3321 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3322 TemplateSpecializationTypeLoc OldNamedTL
3323 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3324 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003325 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003326 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3327 if (NamedT.isNull())
3328 return QualType();
3329 TemplateSpecializationTypeLoc NewNamedTL
3330 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3331 NewNamedTL.copy(OldNamedTL);
3332 }
3333 else {
3334 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3335 if (NamedT.isNull())
3336 return QualType();
3337 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003338
John McCall550e0c22009-10-21 00:40:46 +00003339 QualType Result = TL.getType();
3340 if (getDerived().AlwaysRebuild() ||
3341 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003342 NamedT != T->getNamedType()) {
3343 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003344 if (Result.isNull())
3345 return QualType();
3346 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003347
Abramo Bagnara6150c882010-05-11 21:36:43 +00003348 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003349 NewTL.setKeywordLoc(TL.getKeywordLoc());
3350 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003351
3352 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003353}
Mike Stump11289f42009-09-09 15:08:12 +00003354
3355template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003356QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3357 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003358 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003359 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003360
Douglas Gregord6ff3322009-08-04 16:50:30 +00003361 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003362 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3363 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003364 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365 if (!NNS)
3366 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003367
John McCallc392f372010-06-11 00:33:02 +00003368 QualType Result
3369 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3370 T->getIdentifier(),
3371 TL.getKeywordLoc(),
3372 TL.getQualifierRange(),
3373 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003374 if (Result.isNull())
3375 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003376
Abramo Bagnarad7548482010-05-19 21:37:53 +00003377 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3378 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003379 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3380
Abramo Bagnarad7548482010-05-19 21:37:53 +00003381 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3382 NewTL.setKeywordLoc(TL.getKeywordLoc());
3383 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003384 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003385 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3386 NewTL.setKeywordLoc(TL.getKeywordLoc());
3387 NewTL.setQualifierRange(TL.getQualifierRange());
3388 NewTL.setNameLoc(TL.getNameLoc());
3389 }
John McCall550e0c22009-10-21 00:40:46 +00003390 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003391}
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregord6ff3322009-08-04 16:50:30 +00003393template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003394QualType TreeTransform<Derived>::
3395 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3396 DependentTemplateSpecializationTypeLoc TL,
3397 QualType ObjectType) {
3398 DependentTemplateSpecializationType *T = TL.getTypePtr();
3399
3400 NestedNameSpecifier *NNS
3401 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3402 TL.getQualifierRange(),
3403 ObjectType);
3404 if (!NNS)
3405 return QualType();
3406
3407 TemplateArgumentListInfo NewTemplateArgs;
3408 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3409 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3410
3411 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3412 TemplateArgumentLoc Loc;
3413 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3414 return QualType();
3415 NewTemplateArgs.addArgument(Loc);
3416 }
3417
Douglas Gregora5614c52010-09-08 23:56:00 +00003418 QualType Result
3419 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3420 NNS,
3421 TL.getQualifierRange(),
3422 T->getIdentifier(),
3423 TL.getNameLoc(),
3424 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003425 if (Result.isNull())
3426 return QualType();
3427
3428 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3429 QualType NamedT = ElabT->getNamedType();
3430
3431 // Copy information relevant to the template specialization.
3432 TemplateSpecializationTypeLoc NamedTL
3433 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3434 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3435 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3436 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3437 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3438
3439 // Copy information relevant to the elaborated type.
3440 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3441 NewTL.setKeywordLoc(TL.getKeywordLoc());
3442 NewTL.setQualifierRange(TL.getQualifierRange());
3443 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003444 TypeLoc NewTL(Result, TL.getOpaqueData());
3445 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003446 }
3447 return Result;
3448}
3449
3450template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003451QualType
3452TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003453 ObjCInterfaceTypeLoc TL,
3454 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003455 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003456 TLB.pushFullCopy(TL);
3457 return TL.getType();
3458}
3459
3460template<typename Derived>
3461QualType
3462TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3463 ObjCObjectTypeLoc TL,
3464 QualType ObjectType) {
3465 // ObjCObjectType is never dependent.
3466 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003467 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003468}
Mike Stump11289f42009-09-09 15:08:12 +00003469
3470template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003471QualType
3472TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003473 ObjCObjectPointerTypeLoc TL,
3474 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003475 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003476 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003477 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003478}
3479
Douglas Gregord6ff3322009-08-04 16:50:30 +00003480//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003481// Statement transformation
3482//===----------------------------------------------------------------------===//
3483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003484StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003485TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003486 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003487}
3488
3489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003490StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003491TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3492 return getDerived().TransformCompoundStmt(S, false);
3493}
3494
3495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003496StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003497TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003498 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003499 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003500 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003501 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003502 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3503 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003504 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003505 if (Result.isInvalid()) {
3506 // Immediately fail if this was a DeclStmt, since it's very
3507 // likely that this will cause problems for future statements.
3508 if (isa<DeclStmt>(*B))
3509 return StmtError();
3510
3511 // Otherwise, just keep processing substatements and fail later.
3512 SubStmtInvalid = true;
3513 continue;
3514 }
Mike Stump11289f42009-09-09 15:08:12 +00003515
Douglas Gregorebe10102009-08-20 07:17:43 +00003516 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3517 Statements.push_back(Result.takeAs<Stmt>());
3518 }
Mike Stump11289f42009-09-09 15:08:12 +00003519
John McCall1ababa62010-08-27 19:56:05 +00003520 if (SubStmtInvalid)
3521 return StmtError();
3522
Douglas Gregorebe10102009-08-20 07:17:43 +00003523 if (!getDerived().AlwaysRebuild() &&
3524 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003525 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003526
3527 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3528 move_arg(Statements),
3529 S->getRBracLoc(),
3530 IsStmtExpr);
3531}
Mike Stump11289f42009-09-09 15:08:12 +00003532
Douglas Gregorebe10102009-08-20 07:17:43 +00003533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003534StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003535TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003536 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003537 {
3538 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003539 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003540
Eli Friedman06577382009-11-19 03:14:00 +00003541 // Transform the left-hand case value.
3542 LHS = getDerived().TransformExpr(S->getLHS());
3543 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003544 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003545
Eli Friedman06577382009-11-19 03:14:00 +00003546 // Transform the right-hand case value (for the GNU case-range extension).
3547 RHS = getDerived().TransformExpr(S->getRHS());
3548 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003549 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003550 }
Mike Stump11289f42009-09-09 15:08:12 +00003551
Douglas Gregorebe10102009-08-20 07:17:43 +00003552 // Build the case statement.
3553 // Case statements are always rebuilt so that they will attached to their
3554 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003555 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003556 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003557 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003558 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003559 S->getColonLoc());
3560 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003561 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003562
Douglas Gregorebe10102009-08-20 07:17:43 +00003563 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003564 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003565 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003566 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003567
Douglas Gregorebe10102009-08-20 07:17:43 +00003568 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003569 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003570}
3571
3572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003573StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003574TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003575 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003576 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003577 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003578 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003579
Douglas Gregorebe10102009-08-20 07:17:43 +00003580 // Default statements are always rebuilt
3581 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003582 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003583}
Mike Stump11289f42009-09-09 15:08:12 +00003584
Douglas Gregorebe10102009-08-20 07:17:43 +00003585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003586StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003587TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003588 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003589 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003590 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003591
Douglas Gregorebe10102009-08-20 07:17:43 +00003592 // FIXME: Pass the real colon location in.
3593 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3594 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003595 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003596}
Mike Stump11289f42009-09-09 15:08:12 +00003597
Douglas Gregorebe10102009-08-20 07:17:43 +00003598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003599StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003600TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003601 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003602 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003603 VarDecl *ConditionVar = 0;
3604 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003605 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003606 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003607 getDerived().TransformDefinition(
3608 S->getConditionVariable()->getLocation(),
3609 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003610 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003611 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003612 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003613 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003614
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003615 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003616 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003617
3618 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003619 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003620 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003621 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003622 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003623 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003624 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003625
John McCallb268a282010-08-23 23:25:46 +00003626 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003627 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003628 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003629
John McCallb268a282010-08-23 23:25:46 +00003630 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3631 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003632 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003633
Douglas Gregorebe10102009-08-20 07:17:43 +00003634 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003635 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003636 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003637 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003638
Douglas Gregorebe10102009-08-20 07:17:43 +00003639 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003640 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003641 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003642 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003643
Douglas Gregorebe10102009-08-20 07:17:43 +00003644 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003645 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003646 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003647 Then.get() == S->getThen() &&
3648 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003649 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003650
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003651 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003652 Then.get(),
3653 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003654}
3655
3656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003657StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003658TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003659 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003660 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003661 VarDecl *ConditionVar = 0;
3662 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003663 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003664 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003665 getDerived().TransformDefinition(
3666 S->getConditionVariable()->getLocation(),
3667 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003668 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003669 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003670 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003671 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003672
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003673 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003674 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003675 }
Mike Stump11289f42009-09-09 15:08:12 +00003676
Douglas Gregorebe10102009-08-20 07:17:43 +00003677 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003678 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003679 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003680 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003682 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003683
Douglas Gregorebe10102009-08-20 07:17:43 +00003684 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003685 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003686 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003688
Douglas Gregorebe10102009-08-20 07:17:43 +00003689 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003690 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3691 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003692}
Mike Stump11289f42009-09-09 15:08:12 +00003693
Douglas Gregorebe10102009-08-20 07:17:43 +00003694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003695StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003696TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003697 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003698 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003699 VarDecl *ConditionVar = 0;
3700 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003701 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003702 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003703 getDerived().TransformDefinition(
3704 S->getConditionVariable()->getLocation(),
3705 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003706 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003707 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003708 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003709 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003710
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003711 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003712 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003713
3714 if (S->getCond()) {
3715 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003716 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003717 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003718 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003719 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003720 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003721 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003722 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003723 }
Mike Stump11289f42009-09-09 15:08:12 +00003724
John McCallb268a282010-08-23 23:25:46 +00003725 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3726 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003727 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003728
Douglas Gregorebe10102009-08-20 07:17:43 +00003729 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003730 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003731 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003732 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003733
Douglas Gregorebe10102009-08-20 07:17:43 +00003734 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003735 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003736 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003737 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003738 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003740 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003741 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003742}
Mike Stump11289f42009-09-09 15:08:12 +00003743
Douglas Gregorebe10102009-08-20 07:17:43 +00003744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003745StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003746TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003747 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003748 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003749 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003750 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003751
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003752 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003753 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003754 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003755 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003756
Douglas Gregorebe10102009-08-20 07:17:43 +00003757 if (!getDerived().AlwaysRebuild() &&
3758 Cond.get() == S->getCond() &&
3759 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003760 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003761
John McCallb268a282010-08-23 23:25:46 +00003762 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3763 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003764 S->getRParenLoc());
3765}
Mike Stump11289f42009-09-09 15:08:12 +00003766
Douglas Gregorebe10102009-08-20 07:17:43 +00003767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003768StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003769TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003771 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003772 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003773 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003774
Douglas Gregorebe10102009-08-20 07:17:43 +00003775 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003776 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003777 VarDecl *ConditionVar = 0;
3778 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003779 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003780 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003781 getDerived().TransformDefinition(
3782 S->getConditionVariable()->getLocation(),
3783 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003784 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003785 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003786 } else {
3787 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003788
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003789 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003790 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003791
3792 if (S->getCond()) {
3793 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003794 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003795 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003796 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003797 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003798 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003799
John McCallb268a282010-08-23 23:25:46 +00003800 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003801 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003802 }
Mike Stump11289f42009-09-09 15:08:12 +00003803
John McCallb268a282010-08-23 23:25:46 +00003804 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3805 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003806 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003807
Douglas Gregorebe10102009-08-20 07:17:43 +00003808 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003809 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003810 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003811 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003812
John McCallb268a282010-08-23 23:25:46 +00003813 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3814 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003815 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003816
Douglas Gregorebe10102009-08-20 07:17:43 +00003817 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003818 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003819 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003820 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003821
Douglas Gregorebe10102009-08-20 07:17:43 +00003822 if (!getDerived().AlwaysRebuild() &&
3823 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003824 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003825 Inc.get() == S->getInc() &&
3826 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003827 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003828
Douglas Gregorebe10102009-08-20 07:17:43 +00003829 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003830 Init.get(), FullCond, ConditionVar,
3831 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003832}
3833
3834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003835StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003836TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003837 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003838 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003839 S->getLabel());
3840}
3841
3842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003843StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003844TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003845 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003846 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003847 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003848
Douglas Gregorebe10102009-08-20 07:17:43 +00003849 if (!getDerived().AlwaysRebuild() &&
3850 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003851 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003852
3853 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003854 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003855}
3856
3857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003858StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003859TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003860 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003861}
Mike Stump11289f42009-09-09 15:08:12 +00003862
Douglas Gregorebe10102009-08-20 07:17:43 +00003863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003864StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003865TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003866 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003867}
Mike Stump11289f42009-09-09 15:08:12 +00003868
Douglas Gregorebe10102009-08-20 07:17:43 +00003869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003870StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003871TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003872 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003873 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003874 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003875
Mike Stump11289f42009-09-09 15:08:12 +00003876 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003877 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003878 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003879}
Mike Stump11289f42009-09-09 15:08:12 +00003880
Douglas Gregorebe10102009-08-20 07:17:43 +00003881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003882StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003883TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003884 bool DeclChanged = false;
3885 llvm::SmallVector<Decl *, 4> Decls;
3886 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3887 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003888 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3889 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003890 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003891 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003892
Douglas Gregorebe10102009-08-20 07:17:43 +00003893 if (Transformed != *D)
3894 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregorebe10102009-08-20 07:17:43 +00003896 Decls.push_back(Transformed);
3897 }
Mike Stump11289f42009-09-09 15:08:12 +00003898
Douglas Gregorebe10102009-08-20 07:17:43 +00003899 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00003900 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003901
3902 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003903 S->getStartLoc(), S->getEndLoc());
3904}
Mike Stump11289f42009-09-09 15:08:12 +00003905
Douglas Gregorebe10102009-08-20 07:17:43 +00003906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003907StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003908TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003909 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00003910 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003911}
3912
3913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003914StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003915TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003916
John McCall37ad5512010-08-23 06:44:23 +00003917 ASTOwningVector<Expr*> Constraints(getSema());
3918 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003919 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003920
John McCalldadc5752010-08-24 06:29:42 +00003921 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003922 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003923
3924 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003925
Anders Carlssonaaeef072010-01-24 05:50:09 +00003926 // Go through the outputs.
3927 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003928 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003929
Anders Carlssonaaeef072010-01-24 05:50:09 +00003930 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003931 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003932
Anders Carlssonaaeef072010-01-24 05:50:09 +00003933 // Transform the output expr.
3934 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003935 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003936 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003937 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003938
Anders Carlssonaaeef072010-01-24 05:50:09 +00003939 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003940
John McCallb268a282010-08-23 23:25:46 +00003941 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003942 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003943
Anders Carlssonaaeef072010-01-24 05:50:09 +00003944 // Go through the inputs.
3945 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003946 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003947
Anders Carlssonaaeef072010-01-24 05:50:09 +00003948 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003949 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003950
Anders Carlssonaaeef072010-01-24 05:50:09 +00003951 // Transform the input expr.
3952 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003953 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003954 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003955 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003956
Anders Carlssonaaeef072010-01-24 05:50:09 +00003957 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003958
John McCallb268a282010-08-23 23:25:46 +00003959 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003960 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003961
Anders Carlssonaaeef072010-01-24 05:50:09 +00003962 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00003963 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003964
3965 // Go through the clobbers.
3966 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00003967 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00003968
3969 // No need to transform the asm string literal.
3970 AsmString = SemaRef.Owned(S->getAsmString());
3971
3972 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3973 S->isSimple(),
3974 S->isVolatile(),
3975 S->getNumOutputs(),
3976 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003977 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003978 move_arg(Constraints),
3979 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003980 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003981 move_arg(Clobbers),
3982 S->getRParenLoc(),
3983 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003984}
3985
3986
3987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003988StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003989TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003990 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00003991 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003992 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003993 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003994
Douglas Gregor96c79492010-04-23 22:50:49 +00003995 // Transform the @catch statements (if present).
3996 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003997 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00003998 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00003999 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004000 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004001 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004002 if (Catch.get() != S->getCatchStmt(I))
4003 AnyCatchChanged = true;
4004 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004005 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004006
Douglas Gregor306de2f2010-04-22 23:59:56 +00004007 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004008 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004009 if (S->getFinallyStmt()) {
4010 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4011 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004012 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004013 }
4014
4015 // If nothing changed, just retain this statement.
4016 if (!getDerived().AlwaysRebuild() &&
4017 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004018 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004019 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004020 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004021
Douglas Gregor306de2f2010-04-22 23:59:56 +00004022 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004023 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4024 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004025}
Mike Stump11289f42009-09-09 15:08:12 +00004026
Douglas Gregorebe10102009-08-20 07:17:43 +00004027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004028StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004029TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004030 // Transform the @catch parameter, if there is one.
4031 VarDecl *Var = 0;
4032 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4033 TypeSourceInfo *TSInfo = 0;
4034 if (FromVar->getTypeSourceInfo()) {
4035 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4036 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004037 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004038 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004039
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004040 QualType T;
4041 if (TSInfo)
4042 T = TSInfo->getType();
4043 else {
4044 T = getDerived().TransformType(FromVar->getType());
4045 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004046 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004047 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004048
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004049 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4050 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004051 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004052 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004053
John McCalldadc5752010-08-24 06:29:42 +00004054 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004055 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004056 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004057
4058 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004059 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004060 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
Douglas Gregorebe10102009-08-20 07:17:43 +00004063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004064StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004065TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004066 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004067 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004068 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004069 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004070
Douglas Gregor306de2f2010-04-22 23:59:56 +00004071 // If nothing changed, just retain this statement.
4072 if (!getDerived().AlwaysRebuild() &&
4073 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004074 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004075
4076 // Build a new statement.
4077 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004078 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004079}
Mike Stump11289f42009-09-09 15:08:12 +00004080
Douglas Gregorebe10102009-08-20 07:17:43 +00004081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004082StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004083TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004084 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004085 if (S->getThrowExpr()) {
4086 Operand = getDerived().TransformExpr(S->getThrowExpr());
4087 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004088 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004089 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004090
Douglas Gregor2900c162010-04-22 21:44:01 +00004091 if (!getDerived().AlwaysRebuild() &&
4092 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004093 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004094
John McCallb268a282010-08-23 23:25:46 +00004095 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004096}
Mike Stump11289f42009-09-09 15:08:12 +00004097
Douglas Gregorebe10102009-08-20 07:17:43 +00004098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004099StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004100TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004101 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004102 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004103 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004104 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004105 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004106
Douglas Gregor6148de72010-04-22 22:01:21 +00004107 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004108 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004109 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004110 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004111
Douglas Gregor6148de72010-04-22 22:01:21 +00004112 // If nothing change, just retain the current statement.
4113 if (!getDerived().AlwaysRebuild() &&
4114 Object.get() == S->getSynchExpr() &&
4115 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004116 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004117
4118 // Build a new statement.
4119 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004120 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004121}
4122
4123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004124StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004125TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004126 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004127 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004128 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004129 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004130 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004131
Douglas Gregorf68a5082010-04-22 23:10:45 +00004132 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004133 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004134 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004135 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004136
Douglas Gregorf68a5082010-04-22 23:10:45 +00004137 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004138 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004139 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004140 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004141
Douglas Gregorf68a5082010-04-22 23:10:45 +00004142 // If nothing changed, just retain this statement.
4143 if (!getDerived().AlwaysRebuild() &&
4144 Element.get() == S->getElement() &&
4145 Collection.get() == S->getCollection() &&
4146 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004147 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004148
Douglas Gregorf68a5082010-04-22 23:10:45 +00004149 // Build a new statement.
4150 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4151 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004152 Element.get(),
4153 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004154 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004155 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004156}
4157
4158
4159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004160StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004161TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4162 // Transform the exception declaration, if any.
4163 VarDecl *Var = 0;
4164 if (S->getExceptionDecl()) {
4165 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004166 TypeSourceInfo *T = getDerived().TransformType(
4167 ExceptionDecl->getTypeSourceInfo());
4168 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004169 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004170
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004171 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004172 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004173 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004174 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004175 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004176 }
Mike Stump11289f42009-09-09 15:08:12 +00004177
Douglas Gregorebe10102009-08-20 07:17:43 +00004178 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004179 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004180 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004181 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004182
Douglas Gregorebe10102009-08-20 07:17:43 +00004183 if (!getDerived().AlwaysRebuild() &&
4184 !Var &&
4185 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004186 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004187
4188 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4189 Var,
John McCallb268a282010-08-23 23:25:46 +00004190 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004191}
Mike Stump11289f42009-09-09 15:08:12 +00004192
Douglas Gregorebe10102009-08-20 07:17:43 +00004193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004194StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004195TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4196 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004197 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004198 = getDerived().TransformCompoundStmt(S->getTryBlock());
4199 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004200 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregorebe10102009-08-20 07:17:43 +00004202 // Transform the handlers.
4203 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004204 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004205 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004206 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004207 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4208 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004209 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004210
Douglas Gregorebe10102009-08-20 07:17:43 +00004211 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4212 Handlers.push_back(Handler.takeAs<Stmt>());
4213 }
Mike Stump11289f42009-09-09 15:08:12 +00004214
Douglas Gregorebe10102009-08-20 07:17:43 +00004215 if (!getDerived().AlwaysRebuild() &&
4216 TryBlock.get() == S->getTryBlock() &&
4217 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004218 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004219
John McCallb268a282010-08-23 23:25:46 +00004220 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004221 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004222}
Mike Stump11289f42009-09-09 15:08:12 +00004223
Douglas Gregorebe10102009-08-20 07:17:43 +00004224//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004225// Expression transformation
4226//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004228ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004229TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004230 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
4233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004235TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004236 NestedNameSpecifier *Qualifier = 0;
4237 if (E->getQualifier()) {
4238 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004239 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004240 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004241 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004242 }
John McCallce546572009-12-08 09:08:17 +00004243
4244 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004245 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4246 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004247 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004248 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004249
John McCall815039a2010-08-17 21:27:17 +00004250 DeclarationNameInfo NameInfo = E->getNameInfo();
4251 if (NameInfo.getName()) {
4252 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4253 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004254 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004255 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004256
4257 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004258 Qualifier == E->getQualifier() &&
4259 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004260 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004261 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004262
4263 // Mark it referenced in the new context regardless.
4264 // FIXME: this is a bit instantiation-specific.
4265 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4266
John McCallc3007a22010-10-26 07:05:15 +00004267 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004268 }
John McCallce546572009-12-08 09:08:17 +00004269
4270 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004271 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004272 TemplateArgs = &TransArgs;
4273 TransArgs.setLAngleLoc(E->getLAngleLoc());
4274 TransArgs.setRAngleLoc(E->getRAngleLoc());
4275 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4276 TemplateArgumentLoc Loc;
4277 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004278 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004279 TransArgs.addArgument(Loc);
4280 }
4281 }
4282
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004283 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004284 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004285}
Mike Stump11289f42009-09-09 15:08:12 +00004286
Douglas Gregora16548e2009-08-11 05:31:07 +00004287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004289TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004290 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004291}
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004295TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004296 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004297}
Mike Stump11289f42009-09-09 15:08:12 +00004298
Douglas Gregora16548e2009-08-11 05:31:07 +00004299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004300ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004301TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004302 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004303}
Mike Stump11289f42009-09-09 15:08:12 +00004304
Douglas Gregora16548e2009-08-11 05:31:07 +00004305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004307TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004308 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004313TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004314 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004315}
4316
4317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004319TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004320 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004321 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004322 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004323
Douglas Gregora16548e2009-08-11 05:31:07 +00004324 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004325 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004326
John McCallb268a282010-08-23 23:25:46 +00004327 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004328 E->getRParen());
4329}
4330
Mike Stump11289f42009-09-09 15:08:12 +00004331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004332ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004333TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004334 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004335 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004337
Douglas Gregora16548e2009-08-11 05:31:07 +00004338 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004339 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004340
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4342 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004343 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004344}
Mike Stump11289f42009-09-09 15:08:12 +00004345
Douglas Gregora16548e2009-08-11 05:31:07 +00004346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004347ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004348TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4349 // Transform the type.
4350 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4351 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004352 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004353
Douglas Gregor882211c2010-04-28 22:16:22 +00004354 // Transform all of the components into components similar to what the
4355 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004356 // FIXME: It would be slightly more efficient in the non-dependent case to
4357 // just map FieldDecls, rather than requiring the rebuilder to look for
4358 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004359 // template code that we don't care.
4360 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004361 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004362 typedef OffsetOfExpr::OffsetOfNode Node;
4363 llvm::SmallVector<Component, 4> Components;
4364 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4365 const Node &ON = E->getComponent(I);
4366 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004367 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004368 Comp.LocStart = ON.getRange().getBegin();
4369 Comp.LocEnd = ON.getRange().getEnd();
4370 switch (ON.getKind()) {
4371 case Node::Array: {
4372 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004373 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004374 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004375 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004376
Douglas Gregor882211c2010-04-28 22:16:22 +00004377 ExprChanged = ExprChanged || Index.get() != FromIndex;
4378 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004379 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004380 break;
4381 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004382
Douglas Gregor882211c2010-04-28 22:16:22 +00004383 case Node::Field:
4384 case Node::Identifier:
4385 Comp.isBrackets = false;
4386 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004387 if (!Comp.U.IdentInfo)
4388 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004389
Douglas Gregor882211c2010-04-28 22:16:22 +00004390 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004391
Douglas Gregord1702062010-04-29 00:18:15 +00004392 case Node::Base:
4393 // Will be recomputed during the rebuild.
4394 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004395 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004396
Douglas Gregor882211c2010-04-28 22:16:22 +00004397 Components.push_back(Comp);
4398 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004399
Douglas Gregor882211c2010-04-28 22:16:22 +00004400 // If nothing changed, retain the existing expression.
4401 if (!getDerived().AlwaysRebuild() &&
4402 Type == E->getTypeSourceInfo() &&
4403 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004404 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004405
Douglas Gregor882211c2010-04-28 22:16:22 +00004406 // Build a new offsetof expression.
4407 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4408 Components.data(), Components.size(),
4409 E->getRParenLoc());
4410}
4411
4412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004414TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004415 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004416 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004417
John McCallbcd03502009-12-07 02:54:59 +00004418 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004419 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004420 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004421
John McCall4c98fd82009-11-04 07:28:41 +00004422 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004423 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004424
John McCall4c98fd82009-11-04 07:28:41 +00004425 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004426 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 E->getSourceRange());
4428 }
Mike Stump11289f42009-09-09 15:08:12 +00004429
John McCalldadc5752010-08-24 06:29:42 +00004430 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004431 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 // C++0x [expr.sizeof]p1:
4433 // The operand is either an expression, which is an unevaluated operand
4434 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004435 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4438 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004439 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004440
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004442 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 }
Mike Stump11289f42009-09-09 15:08:12 +00004444
John McCallb268a282010-08-23 23:25:46 +00004445 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 E->isSizeOf(),
4447 E->getSourceRange());
4448}
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004452TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004453 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004454 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004455 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004456
John McCalldadc5752010-08-24 06:29:42 +00004457 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004459 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004460
4461
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 if (!getDerived().AlwaysRebuild() &&
4463 LHS.get() == E->getLHS() &&
4464 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004465 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004466
John McCallb268a282010-08-23 23:25:46 +00004467 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004469 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 E->getRBracketLoc());
4471}
Mike Stump11289f42009-09-09 15:08:12 +00004472
4473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004474ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004475TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004477 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004479 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004480
4481 // Transform arguments.
4482 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004483 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004484 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004485 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004486 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004488
Mike Stump11289f42009-09-09 15:08:12 +00004489 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004490 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004491 }
Mike Stump11289f42009-09-09 15:08:12 +00004492
Douglas Gregora16548e2009-08-11 05:31:07 +00004493 if (!getDerived().AlwaysRebuild() &&
4494 Callee.get() == E->getCallee() &&
4495 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004496 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004497
Douglas Gregora16548e2009-08-11 05:31:07 +00004498 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004499 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004501 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004502 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004503 E->getRParenLoc());
4504}
Mike Stump11289f42009-09-09 15:08:12 +00004505
4506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004507ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004508TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004509 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004510 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004512
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004513 NestedNameSpecifier *Qualifier = 0;
4514 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004515 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004516 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004517 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004518 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004519 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004520 }
Mike Stump11289f42009-09-09 15:08:12 +00004521
Eli Friedman2cfcef62009-12-04 06:40:45 +00004522 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004523 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4524 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004525 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004527
John McCall16df1e52010-03-30 21:47:33 +00004528 NamedDecl *FoundDecl = E->getFoundDecl();
4529 if (FoundDecl == E->getMemberDecl()) {
4530 FoundDecl = Member;
4531 } else {
4532 FoundDecl = cast_or_null<NamedDecl>(
4533 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4534 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004535 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004536 }
4537
Douglas Gregora16548e2009-08-11 05:31:07 +00004538 if (!getDerived().AlwaysRebuild() &&
4539 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004540 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004541 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004542 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004543 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004544
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004545 // Mark it referenced in the new context regardless.
4546 // FIXME: this is a bit instantiation-specific.
4547 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004548 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004549 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004550
John McCall6b51f282009-11-23 01:53:49 +00004551 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004552 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004553 TransArgs.setLAngleLoc(E->getLAngleLoc());
4554 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004555 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004556 TemplateArgumentLoc Loc;
4557 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004558 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004559 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004560 }
4561 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004562
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 // FIXME: Bogus source location for the operator
4564 SourceLocation FakeOperatorLoc
4565 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4566
John McCall38836f02010-01-15 08:34:02 +00004567 // FIXME: to do this check properly, we will need to preserve the
4568 // first-qualifier-in-scope here, just in case we had a dependent
4569 // base (and therefore couldn't do the check) and a
4570 // nested-name-qualifier (and therefore could do the lookup).
4571 NamedDecl *FirstQualifierInScope = 0;
4572
John McCallb268a282010-08-23 23:25:46 +00004573 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004575 Qualifier,
4576 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004577 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004578 Member,
John McCall16df1e52010-03-30 21:47:33 +00004579 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004580 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004581 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004582 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregora16548e2009-08-11 05:31:07 +00004585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004587TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004588 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004589 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004590 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004591
John McCalldadc5752010-08-24 06:29:42 +00004592 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004593 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004595
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 if (!getDerived().AlwaysRebuild() &&
4597 LHS.get() == E->getLHS() &&
4598 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004599 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004600
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004602 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004603}
4604
Mike Stump11289f42009-09-09 15:08:12 +00004605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004606ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004607TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004608 CompoundAssignOperator *E) {
4609 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004610}
Mike Stump11289f42009-09-09 15:08:12 +00004611
Douglas Gregora16548e2009-08-11 05:31:07 +00004612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004614TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004615 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004617 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004618
John McCalldadc5752010-08-24 06:29:42 +00004619 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004622
John McCalldadc5752010-08-24 06:29:42 +00004623 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 if (!getDerived().AlwaysRebuild() &&
4628 Cond.get() == E->getCond() &&
4629 LHS.get() == E->getLHS() &&
4630 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004631 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004632
John McCallb268a282010-08-23 23:25:46 +00004633 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004634 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004635 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004636 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004637 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004638}
Mike Stump11289f42009-09-09 15:08:12 +00004639
4640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004641ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004642TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004643 // Implicit casts are eliminated during transformation, since they
4644 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004645 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004646}
Mike Stump11289f42009-09-09 15:08:12 +00004647
Douglas Gregora16548e2009-08-11 05:31:07 +00004648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004649ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004650TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004651 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4652 if (!Type)
4653 return ExprError();
4654
John McCalldadc5752010-08-24 06:29:42 +00004655 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004656 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 if (SubExpr.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() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004661 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004663 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004664
John McCall97513962010-01-15 18:39:57 +00004665 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004666 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004668 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004669}
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004673TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004674 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4675 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4676 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004677 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004678
John McCalldadc5752010-08-24 06:29:42 +00004679 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
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 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004684 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004686 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004687
John McCall5d7aa7f2010-01-19 22:33:45 +00004688 // Note: the expression type doesn't necessarily match the
4689 // type-as-written, but that's okay, because it should always be
4690 // derivable from the initializer.
4691
John McCalle15bbff2010-01-18 19:35:47 +00004692 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004694 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004695}
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004698ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004699TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004700 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 if (!getDerived().AlwaysRebuild() &&
4705 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004706 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregora16548e2009-08-11 05:31:07 +00004708 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004709 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004711 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004712 E->getAccessorLoc(),
4713 E->getAccessor());
4714}
Mike Stump11289f42009-09-09 15:08:12 +00004715
Douglas Gregora16548e2009-08-11 05:31:07 +00004716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004718TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004719 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004720
John McCall37ad5512010-08-23 06:44:23 +00004721 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004723 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004728 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 }
Mike Stump11289f42009-09-09 15:08:12 +00004730
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004732 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004733
Douglas Gregora16548e2009-08-11 05:31:07 +00004734 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004735 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004736}
Mike Stump11289f42009-09-09 15:08:12 +00004737
Douglas Gregora16548e2009-08-11 05:31:07 +00004738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004740TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004742
Douglas Gregorebe10102009-08-20 07:17:43 +00004743 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004744 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004745 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregorebe10102009-08-20 07:17:43 +00004748 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004749 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 bool ExprChanged = false;
4751 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4752 DEnd = E->designators_end();
4753 D != DEnd; ++D) {
4754 if (D->isFieldDesignator()) {
4755 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4756 D->getDotLoc(),
4757 D->getFieldLoc()));
4758 continue;
4759 }
Mike Stump11289f42009-09-09 15:08:12 +00004760
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004762 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004763 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004764 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004765
4766 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004767 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004768
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4770 ArrayExprs.push_back(Index.release());
4771 continue;
4772 }
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregora16548e2009-08-11 05:31:07 +00004774 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004775 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4777 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004779
John McCalldadc5752010-08-24 06:29:42 +00004780 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004781 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004783
4784 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 End.get(),
4786 D->getLBracketLoc(),
4787 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregora16548e2009-08-11 05:31:07 +00004789 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4790 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 ArrayExprs.push_back(Start.release());
4793 ArrayExprs.push_back(End.release());
4794 }
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 if (!getDerived().AlwaysRebuild() &&
4797 Init.get() == E->getInit() &&
4798 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004799 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004800
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4802 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004803 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004804}
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregora16548e2009-08-11 05:31:07 +00004806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004807ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004808TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004809 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004810 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004811
Douglas Gregor3da3c062009-10-28 00:29:27 +00004812 // FIXME: Will we ever have proper type location here? Will we actually
4813 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 QualType T = getDerived().TransformType(E->getType());
4815 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 if (!getDerived().AlwaysRebuild() &&
4819 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004820 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregora16548e2009-08-11 05:31:07 +00004822 return getDerived().RebuildImplicitValueInitExpr(T);
4823}
Mike Stump11289f42009-09-09 15:08:12 +00004824
Douglas Gregora16548e2009-08-11 05:31:07 +00004825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004826ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004827TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004828 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4829 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004831
John McCalldadc5752010-08-24 06:29:42 +00004832 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregora16548e2009-08-11 05:31:07 +00004836 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004837 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004839 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004840
John McCallb268a282010-08-23 23:25:46 +00004841 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004842 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004843}
4844
4845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004847TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004848 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004849 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004850 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004851 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004852 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004854
Douglas Gregora16548e2009-08-11 05:31:07 +00004855 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004856 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004857 }
Mike Stump11289f42009-09-09 15:08:12 +00004858
Douglas Gregora16548e2009-08-11 05:31:07 +00004859 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4860 move_arg(Inits),
4861 E->getRParenLoc());
4862}
Mike Stump11289f42009-09-09 15:08:12 +00004863
Douglas Gregora16548e2009-08-11 05:31:07 +00004864/// \brief Transform an address-of-label expression.
4865///
4866/// By default, the transformation of an address-of-label expression always
4867/// rebuilds the expression, so that the label identifier can be resolved to
4868/// the corresponding label statement by semantic analysis.
4869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004871TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004872 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4873 E->getLabel());
4874}
Mike Stump11289f42009-09-09 15:08:12 +00004875
4876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004878TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004879 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004880 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4881 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004882 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004883
Douglas Gregora16548e2009-08-11 05:31:07 +00004884 if (!getDerived().AlwaysRebuild() &&
4885 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00004886 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004887
4888 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004889 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004890 E->getRParenLoc());
4891}
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregora16548e2009-08-11 05:31:07 +00004893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004894ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004895TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004896 TypeSourceInfo *TInfo1;
4897 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004898
4899 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4900 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004901 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregor7058c262010-08-10 14:27:00 +00004903 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4904 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004905 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004906
4907 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004908 TInfo1 == E->getArgTInfo1() &&
4909 TInfo2 == E->getArgTInfo2())
John McCallc3007a22010-10-26 07:05:15 +00004910 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004911
Douglas Gregora16548e2009-08-11 05:31:07 +00004912 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004913 TInfo1, TInfo2,
4914 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004915}
Mike Stump11289f42009-09-09 15:08:12 +00004916
Douglas Gregora16548e2009-08-11 05:31:07 +00004917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004918ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004919TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004920 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004921 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004923
John McCalldadc5752010-08-24 06:29:42 +00004924 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004925 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004926 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004927
John McCalldadc5752010-08-24 06:29:42 +00004928 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004929 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004930 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004931
Douglas Gregora16548e2009-08-11 05:31:07 +00004932 if (!getDerived().AlwaysRebuild() &&
4933 Cond.get() == E->getCond() &&
4934 LHS.get() == E->getLHS() &&
4935 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004936 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004939 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004940 E->getRParenLoc());
4941}
Mike Stump11289f42009-09-09 15:08:12 +00004942
Douglas Gregora16548e2009-08-11 05:31:07 +00004943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004945TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004946 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004947}
4948
4949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004950ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004951TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004952 switch (E->getOperator()) {
4953 case OO_New:
4954 case OO_Delete:
4955 case OO_Array_New:
4956 case OO_Array_Delete:
4957 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004958 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004959
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004960 case OO_Call: {
4961 // This is a call to an object's operator().
4962 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4963
4964 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004965 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004966 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004967 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004968
4969 // FIXME: Poor location information
4970 SourceLocation FakeLParenLoc
4971 = SemaRef.PP.getLocForEndOfToken(
4972 static_cast<Expr *>(Object.get())->getLocEnd());
4973
4974 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004975 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004976 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004977 if (getDerived().DropCallArgument(E->getArg(I)))
4978 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004979
John McCalldadc5752010-08-24 06:29:42 +00004980 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004981 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004982 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004983
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004984 Args.push_back(Arg.release());
4985 }
4986
John McCallb268a282010-08-23 23:25:46 +00004987 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004988 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004989 E->getLocEnd());
4990 }
4991
4992#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4993 case OO_##Name:
4994#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4995#include "clang/Basic/OperatorKinds.def"
4996 case OO_Subscript:
4997 // Handled below.
4998 break;
4999
5000 case OO_Conditional:
5001 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005002 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005003
5004 case OO_None:
5005 case NUM_OVERLOADED_OPERATORS:
5006 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005007 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005008 }
5009
John McCalldadc5752010-08-24 06:29:42 +00005010 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005013
John McCalldadc5752010-08-24 06:29:42 +00005014 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005016 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005017
John McCalldadc5752010-08-24 06:29:42 +00005018 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 if (E->getNumArgs() == 2) {
5020 Second = getDerived().TransformExpr(E->getArg(1));
5021 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005022 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 }
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregora16548e2009-08-11 05:31:07 +00005025 if (!getDerived().AlwaysRebuild() &&
5026 Callee.get() == E->getCallee() &&
5027 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005028 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005029 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005030
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5032 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005033 Callee.get(),
5034 First.get(),
5035 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005036}
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregora16548e2009-08-11 05:31:07 +00005038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005039ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005040TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5041 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005042}
Mike Stump11289f42009-09-09 15:08:12 +00005043
Douglas Gregora16548e2009-08-11 05:31:07 +00005044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005046TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005047 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5048 if (!Type)
5049 return ExprError();
5050
John McCalldadc5752010-08-24 06:29:42 +00005051 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005052 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005057 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005058 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005059 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005060
Douglas Gregora16548e2009-08-11 05:31:07 +00005061 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005062 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5064 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5065 SourceLocation FakeRParenLoc
5066 = SemaRef.PP.getLocForEndOfToken(
5067 E->getSubExpr()->getSourceRange().getEnd());
5068 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005069 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005070 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005071 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005072 FakeRAngleLoc,
5073 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005074 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005075 FakeRParenLoc);
5076}
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregora16548e2009-08-11 05:31:07 +00005078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005079ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005080TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5081 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005082}
Mike Stump11289f42009-09-09 15:08:12 +00005083
5084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005085ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005086TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5087 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005088}
5089
Douglas Gregora16548e2009-08-11 05:31:07 +00005090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005091ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005092TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005093 CXXReinterpretCastExpr *E) {
5094 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005095}
Mike Stump11289f42009-09-09 15:08:12 +00005096
Douglas Gregora16548e2009-08-11 05:31:07 +00005097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005098ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005099TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5100 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005101}
Mike Stump11289f42009-09-09 15:08:12 +00005102
Douglas Gregora16548e2009-08-11 05:31:07 +00005103template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005104ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005105TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005106 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005107 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5108 if (!Type)
5109 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005110
John McCalldadc5752010-08-24 06:29:42 +00005111 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005112 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 if (SubExpr.isInvalid())
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 Gregor3b29b2c2010-09-09 16:55:46 +00005117 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005119 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005121 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005123 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 E->getRParenLoc());
5125}
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregora16548e2009-08-11 05:31:07 +00005127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005129TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005131 TypeSourceInfo *TInfo
5132 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5133 if (!TInfo)
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() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005137 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005138 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005139
Douglas Gregor9da64192010-04-26 22:37:10 +00005140 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5141 E->getLocStart(),
5142 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005143 E->getLocEnd());
5144 }
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 // We don't know whether the expression is potentially evaluated until
5147 // after we perform semantic analysis, so the expression is potentially
5148 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005149 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005150 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005151
John McCalldadc5752010-08-24 06:29:42 +00005152 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005154 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005155
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 if (!getDerived().AlwaysRebuild() &&
5157 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005158 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregor9da64192010-04-26 22:37:10 +00005160 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5161 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005162 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 E->getLocEnd());
5164}
5165
5166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005167ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005168TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5169 if (E->isTypeOperand()) {
5170 TypeSourceInfo *TInfo
5171 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5172 if (!TInfo)
5173 return ExprError();
5174
5175 if (!getDerived().AlwaysRebuild() &&
5176 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005177 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005178
5179 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5180 E->getLocStart(),
5181 TInfo,
5182 E->getLocEnd());
5183 }
5184
5185 // We don't know whether the expression is potentially evaluated until
5186 // after we perform semantic analysis, so the expression is potentially
5187 // potentially evaluated.
5188 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5189
5190 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5191 if (SubExpr.isInvalid())
5192 return ExprError();
5193
5194 if (!getDerived().AlwaysRebuild() &&
5195 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005196 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005197
5198 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5199 E->getLocStart(),
5200 SubExpr.get(),
5201 E->getLocEnd());
5202}
5203
5204template<typename Derived>
5205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005206TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005207 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005208}
Mike Stump11289f42009-09-09 15:08:12 +00005209
Douglas Gregora16548e2009-08-11 05:31:07 +00005210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005211ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005212TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005213 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005214 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005215}
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregora16548e2009-08-11 05:31:07 +00005217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005219TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005220 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5221 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5222 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005224 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005225 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregorb15af892010-01-07 23:12:05 +00005227 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005228}
Mike Stump11289f42009-09-09 15:08:12 +00005229
Douglas Gregora16548e2009-08-11 05:31:07 +00005230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005232TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005233 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005234 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregora16548e2009-08-11 05:31:07 +00005237 if (!getDerived().AlwaysRebuild() &&
5238 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005239 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005240
John McCallb268a282010-08-23 23:25:46 +00005241 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005242}
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregora16548e2009-08-11 05:31:07 +00005244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005245ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005246TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005247 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005248 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5249 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005250 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005252
Chandler Carruth794da4c2010-02-08 06:42:49 +00005253 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005254 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005255 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregor033f6752009-12-23 23:03:06 +00005257 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005258}
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregora16548e2009-08-11 05:31:07 +00005260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005261ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005262TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5263 CXXScalarValueInitExpr *E) {
5264 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5265 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005266 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005267
Douglas Gregora16548e2009-08-11 05:31:07 +00005268 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005269 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005270 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregor2b88c112010-09-08 00:15:04 +00005272 return getDerived().RebuildCXXScalarValueInitExpr(T,
5273 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005274 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005275}
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregora16548e2009-08-11 05:31:07 +00005277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005279TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005280 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005281 TypeSourceInfo *AllocTypeInfo
5282 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5283 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005285
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005287 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005288 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005289 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005290
Douglas Gregora16548e2009-08-11 05:31:07 +00005291 // Transform the placement arguments (if any).
5292 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005293 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005295 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5296 ArgumentChanged = true;
5297 break;
5298 }
5299
John McCalldadc5752010-08-24 06:29:42 +00005300 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005303
Douglas Gregora16548e2009-08-11 05:31:07 +00005304 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5305 PlacementArgs.push_back(Arg.take());
5306 }
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregorebe10102009-08-20 07:17:43 +00005308 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005309 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005310 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005311 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5312 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005313 break;
John McCall09d13692010-10-05 22:36:42 +00005314 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005315
John McCalldadc5752010-08-24 06:29:42 +00005316 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005318 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005319
Douglas Gregora16548e2009-08-11 05:31:07 +00005320 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5321 ConstructorArgs.push_back(Arg.take());
5322 }
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregord2d9da02010-02-26 00:38:10 +00005324 // Transform constructor, new operator, and delete operator.
5325 CXXConstructorDecl *Constructor = 0;
5326 if (E->getConstructor()) {
5327 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005328 getDerived().TransformDecl(E->getLocStart(),
5329 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005330 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005331 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005332 }
5333
5334 FunctionDecl *OperatorNew = 0;
5335 if (E->getOperatorNew()) {
5336 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005337 getDerived().TransformDecl(E->getLocStart(),
5338 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005339 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005340 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005341 }
5342
5343 FunctionDecl *OperatorDelete = 0;
5344 if (E->getOperatorDelete()) {
5345 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005346 getDerived().TransformDecl(E->getLocStart(),
5347 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005348 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005349 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005350 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005351
Douglas Gregora16548e2009-08-11 05:31:07 +00005352 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005353 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005354 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005355 Constructor == E->getConstructor() &&
5356 OperatorNew == E->getOperatorNew() &&
5357 OperatorDelete == E->getOperatorDelete() &&
5358 !ArgumentChanged) {
5359 // Mark any declarations we need as referenced.
5360 // FIXME: instantiation-specific.
5361 if (Constructor)
5362 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5363 if (OperatorNew)
5364 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5365 if (OperatorDelete)
5366 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005367 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005368 }
Mike Stump11289f42009-09-09 15:08:12 +00005369
Douglas Gregor0744ef62010-09-07 21:49:58 +00005370 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005371 if (!ArraySize.get()) {
5372 // If no array size was specified, but the new expression was
5373 // instantiated with an array type (e.g., "new T" where T is
5374 // instantiated with "int[4]"), extract the outer bound from the
5375 // array type as our array size. We do this with constant and
5376 // dependently-sized array types.
5377 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5378 if (!ArrayT) {
5379 // Do nothing
5380 } else if (const ConstantArrayType *ConsArrayT
5381 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005382 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005383 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5384 ConsArrayT->getSize(),
5385 SemaRef.Context.getSizeType(),
5386 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005387 AllocType = ConsArrayT->getElementType();
5388 } else if (const DependentSizedArrayType *DepArrayT
5389 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5390 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005391 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005392 AllocType = DepArrayT->getElementType();
5393 }
5394 }
5395 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005396
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5398 E->isGlobalNew(),
5399 /*FIXME:*/E->getLocStart(),
5400 move_arg(PlacementArgs),
5401 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005402 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005404 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005405 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005406 /*FIXME:*/E->getLocStart(),
5407 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005408 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005409}
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregora16548e2009-08-11 05:31:07 +00005411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005412ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005413TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005414 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005415 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregord2d9da02010-02-26 00:38:10 +00005418 // Transform the delete operator, if known.
5419 FunctionDecl *OperatorDelete = 0;
5420 if (E->getOperatorDelete()) {
5421 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005422 getDerived().TransformDecl(E->getLocStart(),
5423 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005424 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005425 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005426 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005427
Douglas Gregora16548e2009-08-11 05:31:07 +00005428 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005429 Operand.get() == E->getArgument() &&
5430 OperatorDelete == E->getOperatorDelete()) {
5431 // Mark any declarations we need as referenced.
5432 // FIXME: instantiation-specific.
5433 if (OperatorDelete)
5434 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005435
5436 if (!E->getArgument()->isTypeDependent()) {
5437 QualType Destroyed = SemaRef.Context.getBaseElementType(
5438 E->getDestroyedType());
5439 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5440 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5441 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5442 SemaRef.LookupDestructor(Record));
5443 }
5444 }
5445
John McCallc3007a22010-10-26 07:05:15 +00005446 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005447 }
Mike Stump11289f42009-09-09 15:08:12 +00005448
Douglas Gregora16548e2009-08-11 05:31:07 +00005449 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5450 E->isGlobalDelete(),
5451 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005452 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005453}
Mike Stump11289f42009-09-09 15:08:12 +00005454
Douglas Gregora16548e2009-08-11 05:31:07 +00005455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005456ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005457TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005458 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005459 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005460 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005462
John McCallba7bf592010-08-24 05:47:05 +00005463 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005464 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005465 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005466 E->getOperatorLoc(),
5467 E->isArrow()? tok::arrow : tok::period,
5468 ObjectTypePtr,
5469 MayBePseudoDestructor);
5470 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005472
John McCallba7bf592010-08-24 05:47:05 +00005473 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005474 NestedNameSpecifier *Qualifier
5475 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005476 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005477 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005478 if (E->getQualifier() && !Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005479 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregor678f90d2010-02-25 01:56:36 +00005481 PseudoDestructorTypeStorage Destroyed;
5482 if (E->getDestroyedTypeInfo()) {
5483 TypeSourceInfo *DestroyedTypeInfo
5484 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5485 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005486 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005487 Destroyed = DestroyedTypeInfo;
5488 } else if (ObjectType->isDependentType()) {
5489 // We aren't likely to be able to resolve the identifier down to a type
5490 // now anyway, so just retain the identifier.
5491 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5492 E->getDestroyedTypeLoc());
5493 } else {
5494 // Look for a destructor known with the given name.
5495 CXXScopeSpec SS;
5496 if (Qualifier) {
5497 SS.setScopeRep(Qualifier);
5498 SS.setRange(E->getQualifierRange());
5499 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005500
John McCallba7bf592010-08-24 05:47:05 +00005501 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005502 *E->getDestroyedTypeIdentifier(),
5503 E->getDestroyedTypeLoc(),
5504 /*Scope=*/0,
5505 SS, ObjectTypePtr,
5506 false);
5507 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005508 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005509
Douglas Gregor678f90d2010-02-25 01:56:36 +00005510 Destroyed
5511 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5512 E->getDestroyedTypeLoc());
5513 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005514
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005515 TypeSourceInfo *ScopeTypeInfo = 0;
5516 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005517 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005518 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005519 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005520 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005521 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005522
John McCallb268a282010-08-23 23:25:46 +00005523 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005524 E->getOperatorLoc(),
5525 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005526 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005527 E->getQualifierRange(),
5528 ScopeTypeInfo,
5529 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005530 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005531 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005532}
Mike Stump11289f42009-09-09 15:08:12 +00005533
Douglas Gregorad8a3362009-09-04 17:36:40 +00005534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005535ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005536TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005537 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005538 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5539
5540 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5541 Sema::LookupOrdinaryName);
5542
5543 // Transform all the decls.
5544 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5545 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005546 NamedDecl *InstD = static_cast<NamedDecl*>(
5547 getDerived().TransformDecl(Old->getNameLoc(),
5548 *I));
John McCall84d87672009-12-10 09:41:52 +00005549 if (!InstD) {
5550 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5551 // This can happen because of dependent hiding.
5552 if (isa<UsingShadowDecl>(*I))
5553 continue;
5554 else
John McCallfaf5fb42010-08-26 23:41:50 +00005555 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005556 }
John McCalle66edc12009-11-24 19:00:30 +00005557
5558 // Expand using declarations.
5559 if (isa<UsingDecl>(InstD)) {
5560 UsingDecl *UD = cast<UsingDecl>(InstD);
5561 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5562 E = UD->shadow_end(); I != E; ++I)
5563 R.addDecl(*I);
5564 continue;
5565 }
5566
5567 R.addDecl(InstD);
5568 }
5569
5570 // Resolve a kind, but don't do any further analysis. If it's
5571 // ambiguous, the callee needs to deal with it.
5572 R.resolveKind();
5573
5574 // Rebuild the nested-name qualifier, if present.
5575 CXXScopeSpec SS;
5576 NestedNameSpecifier *Qualifier = 0;
5577 if (Old->getQualifier()) {
5578 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005579 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005580 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005582
John McCalle66edc12009-11-24 19:00:30 +00005583 SS.setScopeRep(Qualifier);
5584 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005585 }
5586
Douglas Gregor9262f472010-04-27 18:19:34 +00005587 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005588 CXXRecordDecl *NamingClass
5589 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5590 Old->getNameLoc(),
5591 Old->getNamingClass()));
5592 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005593 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005594
Douglas Gregorda7be082010-04-27 16:10:10 +00005595 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005596 }
5597
5598 // If we have no template arguments, it's a normal declaration name.
5599 if (!Old->hasExplicitTemplateArgs())
5600 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5601
5602 // If we have template arguments, rebuild them, then rebuild the
5603 // templateid expression.
5604 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5605 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5606 TemplateArgumentLoc Loc;
5607 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005608 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005609 TransArgs.addArgument(Loc);
5610 }
5611
5612 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5613 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005614}
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregora16548e2009-08-11 05:31:07 +00005616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005618TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005619 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5620 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005624 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005625 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005626
Mike Stump11289f42009-09-09 15:08:12 +00005627 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 T,
5630 E->getLocEnd());
5631}
Mike Stump11289f42009-09-09 15:08:12 +00005632
Douglas Gregora16548e2009-08-11 05:31:07 +00005633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005634ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005635TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005636 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005638 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005639 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005642
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005643 DeclarationNameInfo NameInfo
5644 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5645 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005646 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005647
John McCalle66edc12009-11-24 19:00:30 +00005648 if (!E->hasExplicitTemplateArgs()) {
5649 if (!getDerived().AlwaysRebuild() &&
5650 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005651 // Note: it is sufficient to compare the Name component of NameInfo:
5652 // if name has not changed, DNLoc has not changed either.
5653 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005654 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005655
John McCalle66edc12009-11-24 19:00:30 +00005656 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5657 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005658 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005659 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005660 }
John McCall6b51f282009-11-23 01:53:49 +00005661
5662 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005664 TemplateArgumentLoc Loc;
5665 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005666 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005667 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005668 }
5669
John McCalle66edc12009-11-24 19:00:30 +00005670 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5671 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005672 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005673 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005674}
5675
5676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005678TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005679 // CXXConstructExprs are always implicit, so when we have a
5680 // 1-argument construction we just transform that argument.
5681 if (E->getNumArgs() == 1 ||
5682 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5683 return getDerived().TransformExpr(E->getArg(0));
5684
Douglas Gregora16548e2009-08-11 05:31:07 +00005685 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5686
5687 QualType T = getDerived().TransformType(E->getType());
5688 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005689 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005690
5691 CXXConstructorDecl *Constructor
5692 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005693 getDerived().TransformDecl(E->getLocStart(),
5694 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregora16548e2009-08-11 05:31:07 +00005698 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005699 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005700 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005701 ArgEnd = E->arg_end();
5702 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005703 if (getDerived().DropCallArgument(*Arg)) {
5704 ArgumentChanged = true;
5705 break;
5706 }
5707
John McCalldadc5752010-08-24 06:29:42 +00005708 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005709 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005713 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 }
5715
5716 if (!getDerived().AlwaysRebuild() &&
5717 T == E->getType() &&
5718 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005719 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005720 // Mark the constructor as referenced.
5721 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005722 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005723 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005724 }
Mike Stump11289f42009-09-09 15:08:12 +00005725
Douglas Gregordb121ba2009-12-14 16:27:04 +00005726 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5727 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005728 move_arg(Args),
5729 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005730 E->getConstructionKind(),
5731 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005732}
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734/// \brief Transform a C++ temporary-binding expression.
5735///
Douglas Gregor363b1512009-12-24 18:51:59 +00005736/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5737/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005740TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005741 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005742}
Mike Stump11289f42009-09-09 15:08:12 +00005743
5744/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005745/// be destroyed after the expression is evaluated.
5746///
Douglas Gregor363b1512009-12-24 18:51:59 +00005747/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5748/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005749template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005750ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005751TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005752 CXXExprWithTemporaries *E) {
5753 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005754}
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregora16548e2009-08-11 05:31:07 +00005756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005757ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005758TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005759 CXXTemporaryObjectExpr *E) {
5760 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5761 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005762 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 CXXConstructorDecl *Constructor
5765 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005766 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005767 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005770
Douglas Gregora16548e2009-08-11 05:31:07 +00005771 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005772 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005774 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005775 ArgEnd = E->arg_end();
5776 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005777 if (getDerived().DropCallArgument(*Arg)) {
5778 ArgumentChanged = true;
5779 break;
5780 }
5781
John McCalldadc5752010-08-24 06:29:42 +00005782 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005785
Douglas Gregora16548e2009-08-11 05:31:07 +00005786 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5787 Args.push_back((Expr *)TransArg.release());
5788 }
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005791 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005793 !ArgumentChanged) {
5794 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005795 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005796 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005797 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005798
5799 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5800 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005801 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 E->getLocEnd());
5803}
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005806ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005807TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005808 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005809 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5810 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005812
Douglas Gregora16548e2009-08-11 05:31:07 +00005813 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005814 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5816 ArgEnd = E->arg_end();
5817 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005818 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005819 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005821
Douglas Gregora16548e2009-08-11 05:31:07 +00005822 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005823 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 }
Mike Stump11289f42009-09-09 15:08:12 +00005825
Douglas Gregora16548e2009-08-11 05:31:07 +00005826 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005827 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005829 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005830
Douglas Gregora16548e2009-08-11 05:31:07 +00005831 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005832 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005833 E->getLParenLoc(),
5834 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005835 E->getRParenLoc());
5836}
Mike Stump11289f42009-09-09 15:08:12 +00005837
Douglas Gregora16548e2009-08-11 05:31:07 +00005838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005839ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005840TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005841 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005842 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005843 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005844 Expr *OldBase;
5845 QualType BaseType;
5846 QualType ObjectType;
5847 if (!E->isImplicitAccess()) {
5848 OldBase = E->getBase();
5849 Base = getDerived().TransformExpr(OldBase);
5850 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005852
John McCall2d74de92009-12-01 22:10:20 +00005853 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005854 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005855 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005856 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005857 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005858 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005859 ObjectTy,
5860 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005861 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005862 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005863
John McCallba7bf592010-08-24 05:47:05 +00005864 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005865 BaseType = ((Expr*) Base.get())->getType();
5866 } else {
5867 OldBase = 0;
5868 BaseType = getDerived().TransformType(E->getBaseType());
5869 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5870 }
Mike Stump11289f42009-09-09 15:08:12 +00005871
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005872 // Transform the first part of the nested-name-specifier that qualifies
5873 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005874 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005875 = getDerived().TransformFirstQualifierInScope(
5876 E->getFirstQualifierFoundInScope(),
5877 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005878
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005879 NestedNameSpecifier *Qualifier = 0;
5880 if (E->getQualifier()) {
5881 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5882 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005883 ObjectType,
5884 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005885 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005886 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005887 }
Mike Stump11289f42009-09-09 15:08:12 +00005888
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005889 DeclarationNameInfo NameInfo
5890 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5891 ObjectType);
5892 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005894
John McCall2d74de92009-12-01 22:10:20 +00005895 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005896 // This is a reference to a member without an explicitly-specified
5897 // template argument list. Optimize for this common case.
5898 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005899 Base.get() == OldBase &&
5900 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005901 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005902 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005903 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00005904 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005905
John McCallb268a282010-08-23 23:25:46 +00005906 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005907 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005908 E->isArrow(),
5909 E->getOperatorLoc(),
5910 Qualifier,
5911 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005912 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005913 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005914 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005915 }
5916
John McCall6b51f282009-11-23 01:53:49 +00005917 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005918 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005919 TemplateArgumentLoc Loc;
5920 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005922 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005923 }
Mike Stump11289f42009-09-09 15:08:12 +00005924
John McCallb268a282010-08-23 23:25:46 +00005925 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005926 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 E->isArrow(),
5928 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005929 Qualifier,
5930 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005931 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005932 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005933 &TransArgs);
5934}
5935
5936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005937ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005938TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005939 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005940 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005941 QualType BaseType;
5942 if (!Old->isImplicitAccess()) {
5943 Base = getDerived().TransformExpr(Old->getBase());
5944 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005945 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005946 BaseType = ((Expr*) Base.get())->getType();
5947 } else {
5948 BaseType = getDerived().TransformType(Old->getBaseType());
5949 }
John McCall10eae182009-11-30 22:42:35 +00005950
5951 NestedNameSpecifier *Qualifier = 0;
5952 if (Old->getQualifier()) {
5953 Qualifier
5954 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005955 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005956 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005957 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005958 }
5959
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005960 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005961 Sema::LookupOrdinaryName);
5962
5963 // Transform all the decls.
5964 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5965 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005966 NamedDecl *InstD = static_cast<NamedDecl*>(
5967 getDerived().TransformDecl(Old->getMemberLoc(),
5968 *I));
John McCall84d87672009-12-10 09:41:52 +00005969 if (!InstD) {
5970 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5971 // This can happen because of dependent hiding.
5972 if (isa<UsingShadowDecl>(*I))
5973 continue;
5974 else
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005976 }
John McCall10eae182009-11-30 22:42:35 +00005977
5978 // Expand using declarations.
5979 if (isa<UsingDecl>(InstD)) {
5980 UsingDecl *UD = cast<UsingDecl>(InstD);
5981 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5982 E = UD->shadow_end(); I != E; ++I)
5983 R.addDecl(*I);
5984 continue;
5985 }
5986
5987 R.addDecl(InstD);
5988 }
5989
5990 R.resolveKind();
5991
Douglas Gregor9262f472010-04-27 18:19:34 +00005992 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005993 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005994 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005995 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005996 Old->getMemberLoc(),
5997 Old->getNamingClass()));
5998 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005999 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006000
Douglas Gregorda7be082010-04-27 16:10:10 +00006001 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006002 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006003
John McCall10eae182009-11-30 22:42:35 +00006004 TemplateArgumentListInfo TransArgs;
6005 if (Old->hasExplicitTemplateArgs()) {
6006 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6007 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6008 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6009 TemplateArgumentLoc Loc;
6010 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6011 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006013 TransArgs.addArgument(Loc);
6014 }
6015 }
John McCall38836f02010-01-15 08:34:02 +00006016
6017 // FIXME: to do this check properly, we will need to preserve the
6018 // first-qualifier-in-scope here, just in case we had a dependent
6019 // base (and therefore couldn't do the check) and a
6020 // nested-name-qualifier (and therefore could do the lookup).
6021 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006022
John McCallb268a282010-08-23 23:25:46 +00006023 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006024 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006025 Old->getOperatorLoc(),
6026 Old->isArrow(),
6027 Qualifier,
6028 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006029 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006030 R,
6031 (Old->hasExplicitTemplateArgs()
6032 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006033}
6034
6035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006036ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006037TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6038 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6039 if (SubExpr.isInvalid())
6040 return ExprError();
6041
6042 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006043 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006044
6045 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6046}
6047
6048template<typename Derived>
6049ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006050TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006051 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006052}
6053
Mike Stump11289f42009-09-09 15:08:12 +00006054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006056TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006057 TypeSourceInfo *EncodedTypeInfo
6058 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6059 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006060 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006061
Douglas Gregora16548e2009-08-11 05:31:07 +00006062 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006063 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006064 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006065
6066 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006067 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006068 E->getRParenLoc());
6069}
Mike Stump11289f42009-09-09 15:08:12 +00006070
Douglas Gregora16548e2009-08-11 05:31:07 +00006071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006073TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006074 // Transform arguments.
6075 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006076 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006077 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006078 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006079 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006080 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006081
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006082 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006083 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006084 }
6085
6086 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6087 // Class message: transform the receiver type.
6088 TypeSourceInfo *ReceiverTypeInfo
6089 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6090 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006091 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006092
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006093 // If nothing changed, just retain the existing message send.
6094 if (!getDerived().AlwaysRebuild() &&
6095 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006096 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006097
6098 // Build a new class message send.
6099 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6100 E->getSelector(),
6101 E->getMethodDecl(),
6102 E->getLeftLoc(),
6103 move_arg(Args),
6104 E->getRightLoc());
6105 }
6106
6107 // Instance message: transform the receiver
6108 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6109 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006110 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006111 = getDerived().TransformExpr(E->getInstanceReceiver());
6112 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006113 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006114
6115 // If nothing changed, just retain the existing message send.
6116 if (!getDerived().AlwaysRebuild() &&
6117 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006118 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006119
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006120 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006121 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006122 E->getSelector(),
6123 E->getMethodDecl(),
6124 E->getLeftLoc(),
6125 move_arg(Args),
6126 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006127}
6128
Mike Stump11289f42009-09-09 15:08:12 +00006129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006132 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006133}
6134
Mike Stump11289f42009-09-09 15:08:12 +00006135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006139}
6140
Mike Stump11289f42009-09-09 15:08:12 +00006141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006144 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006145 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006146 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006147 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006148
6149 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006150
Douglas Gregord51d90d2010-04-26 20:11:03 +00006151 // If nothing changed, just retain the existing expression.
6152 if (!getDerived().AlwaysRebuild() &&
6153 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006154 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006155
John McCallb268a282010-08-23 23:25:46 +00006156 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006157 E->getLocation(),
6158 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006159}
6160
Mike Stump11289f42009-09-09 15:08:12 +00006161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006163TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006164 // 'super' never changes. Property never changes. Just retain the existing
6165 // expression.
6166 if (E->isSuperReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006167 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006168
Douglas Gregor9faee212010-04-26 20:47:02 +00006169 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006170 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006171 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006172 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006173
Douglas Gregor9faee212010-04-26 20:47:02 +00006174 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006175
Douglas Gregor9faee212010-04-26 20:47:02 +00006176 // If nothing changed, just retain the existing expression.
6177 if (!getDerived().AlwaysRebuild() &&
6178 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006179 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006180
John McCallb268a282010-08-23 23:25:46 +00006181 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006182 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006183}
6184
Mike Stump11289f42009-09-09 15:08:12 +00006185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006186ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006187TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006188 ObjCImplicitSetterGetterRefExpr *E) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006189 // If this implicit setter/getter refers to super, it cannot have any
6190 // dependent parts. Just retain the existing declaration.
6191 if (E->isSuperReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006192 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006193
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006194 // If this implicit setter/getter refers to class methods, it cannot have any
6195 // dependent parts. Just retain the existing declaration.
6196 if (E->getInterfaceDecl())
John McCallc3007a22010-10-26 07:05:15 +00006197 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006198
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006199 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006200 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006201 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006202 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006203
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006204 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006205
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006206 // If nothing changed, just retain the existing expression.
6207 if (!getDerived().AlwaysRebuild() &&
6208 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006209 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006210
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006211 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6212 E->getGetterMethod(),
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006213 E->getType(),
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006214 E->getSetterMethod(),
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006215 E->getLocation(),
6216 Base.get(),
6217 E->getSuperLocation(),
6218 E->getSuperType(),
6219 E->isSuperReceiver());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006220
Douglas Gregora16548e2009-08-11 05:31:07 +00006221}
6222
Mike Stump11289f42009-09-09 15:08:12 +00006223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006225TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006226 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006227 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006228 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006229 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006230
Douglas Gregord51d90d2010-04-26 20:11:03 +00006231 // If nothing changed, just retain the existing expression.
6232 if (!getDerived().AlwaysRebuild() &&
6233 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006234 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006235
John McCallb268a282010-08-23 23:25:46 +00006236 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006237 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006238}
6239
Mike Stump11289f42009-09-09 15:08:12 +00006240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006241ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006242TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006243 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006244 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006245 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006246 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006247 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006248 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006249
Douglas Gregora16548e2009-08-11 05:31:07 +00006250 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006251 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006252 }
Mike Stump11289f42009-09-09 15:08:12 +00006253
Douglas Gregora16548e2009-08-11 05:31:07 +00006254 if (!getDerived().AlwaysRebuild() &&
6255 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006256 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006257
Douglas Gregora16548e2009-08-11 05:31:07 +00006258 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6259 move_arg(SubExprs),
6260 E->getRParenLoc());
6261}
6262
Mike Stump11289f42009-09-09 15:08:12 +00006263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006265TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006266 SourceLocation CaretLoc(E->getExprLoc());
6267
6268 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6269 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6270 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6271 llvm::SmallVector<ParmVarDecl*, 4> Params;
6272 llvm::SmallVector<QualType, 4> ParamTypes;
6273
6274 // Parameter substitution.
6275 const BlockDecl *BD = E->getBlockDecl();
6276 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6277 EN = BD->param_end(); P != EN; ++P) {
6278 ParmVarDecl *OldParm = (*P);
6279 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6280 QualType NewType = NewParm->getType();
6281 Params.push_back(NewParm);
6282 ParamTypes.push_back(NewParm->getType());
6283 }
6284
6285 const FunctionType *BExprFunctionType = E->getFunctionType();
6286 QualType BExprResultType = BExprFunctionType->getResultType();
6287 if (!BExprResultType.isNull()) {
6288 if (!BExprResultType->isDependentType())
6289 CurBlock->ReturnType = BExprResultType;
6290 else if (BExprResultType != SemaRef.Context.DependentTy)
6291 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6292 }
6293
6294 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006295 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006296 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006297 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006298 // Set the parameters on the block decl.
6299 if (!Params.empty())
6300 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6301
6302 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6303 CurBlock->ReturnType,
6304 ParamTypes.data(),
6305 ParamTypes.size(),
6306 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006307 0,
6308 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006309
6310 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006311 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006312}
6313
Mike Stump11289f42009-09-09 15:08:12 +00006314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006316TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006317 NestedNameSpecifier *Qualifier = 0;
6318
6319 ValueDecl *ND
6320 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6321 E->getDecl()));
6322 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006323 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006324
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006325 if (!getDerived().AlwaysRebuild() &&
6326 ND == E->getDecl()) {
6327 // Mark it referenced in the new context regardless.
6328 // FIXME: this is a bit instantiation-specific.
6329 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6330
John McCallc3007a22010-10-26 07:05:15 +00006331 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006332 }
6333
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006334 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006335 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006336 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006337}
Mike Stump11289f42009-09-09 15:08:12 +00006338
Douglas Gregora16548e2009-08-11 05:31:07 +00006339//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006340// Type reconstruction
6341//===----------------------------------------------------------------------===//
6342
Mike Stump11289f42009-09-09 15:08:12 +00006343template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006344QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6345 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006346 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006347 getDerived().getBaseEntity());
6348}
6349
Mike Stump11289f42009-09-09 15:08:12 +00006350template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006351QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6352 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006353 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006354 getDerived().getBaseEntity());
6355}
6356
Mike Stump11289f42009-09-09 15:08:12 +00006357template<typename Derived>
6358QualType
John McCall70dd5f62009-10-30 00:06:24 +00006359TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6360 bool WrittenAsLValue,
6361 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006362 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006363 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006364}
6365
6366template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006367QualType
John McCall70dd5f62009-10-30 00:06:24 +00006368TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6369 QualType ClassType,
6370 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006371 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006372 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006373}
6374
6375template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006376QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006377TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6378 ArrayType::ArraySizeModifier SizeMod,
6379 const llvm::APInt *Size,
6380 Expr *SizeExpr,
6381 unsigned IndexTypeQuals,
6382 SourceRange BracketsRange) {
6383 if (SizeExpr || !Size)
6384 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6385 IndexTypeQuals, BracketsRange,
6386 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006387
6388 QualType Types[] = {
6389 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6390 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6391 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006392 };
6393 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6394 QualType SizeType;
6395 for (unsigned I = 0; I != NumTypes; ++I)
6396 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6397 SizeType = Types[I];
6398 break;
6399 }
Mike Stump11289f42009-09-09 15:08:12 +00006400
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006401 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6402 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006403 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006404 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006405 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006406}
Mike Stump11289f42009-09-09 15:08:12 +00006407
Douglas Gregord6ff3322009-08-04 16:50:30 +00006408template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006409QualType
6410TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006411 ArrayType::ArraySizeModifier SizeMod,
6412 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006413 unsigned IndexTypeQuals,
6414 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006415 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006416 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006417}
6418
6419template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006420QualType
Mike Stump11289f42009-09-09 15:08:12 +00006421TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006422 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006423 unsigned IndexTypeQuals,
6424 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006425 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006426 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006427}
Mike Stump11289f42009-09-09 15:08:12 +00006428
Douglas Gregord6ff3322009-08-04 16:50:30 +00006429template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006430QualType
6431TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006432 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006433 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006434 unsigned IndexTypeQuals,
6435 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006436 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006437 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438 IndexTypeQuals, BracketsRange);
6439}
6440
6441template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006442QualType
6443TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006444 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006445 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006446 unsigned IndexTypeQuals,
6447 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006448 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006449 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006450 IndexTypeQuals, BracketsRange);
6451}
6452
6453template<typename Derived>
6454QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006455 unsigned NumElements,
6456 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006457 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006458 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006459}
Mike Stump11289f42009-09-09 15:08:12 +00006460
Douglas Gregord6ff3322009-08-04 16:50:30 +00006461template<typename Derived>
6462QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6463 unsigned NumElements,
6464 SourceLocation AttributeLoc) {
6465 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6466 NumElements, true);
6467 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006468 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6469 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006470 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006471}
Mike Stump11289f42009-09-09 15:08:12 +00006472
Douglas Gregord6ff3322009-08-04 16:50:30 +00006473template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006474QualType
6475TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006476 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006477 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006478 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006479}
Mike Stump11289f42009-09-09 15:08:12 +00006480
Douglas Gregord6ff3322009-08-04 16:50:30 +00006481template<typename Derived>
6482QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006483 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006484 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006485 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006486 unsigned Quals,
6487 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006488 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006489 Quals,
6490 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006491 getDerived().getBaseEntity(),
6492 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006493}
Mike Stump11289f42009-09-09 15:08:12 +00006494
Douglas Gregord6ff3322009-08-04 16:50:30 +00006495template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006496QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6497 return SemaRef.Context.getFunctionNoProtoType(T);
6498}
6499
6500template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006501QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6502 assert(D && "no decl found");
6503 if (D->isInvalidDecl()) return QualType();
6504
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006505 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006506 TypeDecl *Ty;
6507 if (isa<UsingDecl>(D)) {
6508 UsingDecl *Using = cast<UsingDecl>(D);
6509 assert(Using->isTypeName() &&
6510 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6511
6512 // A valid resolved using typename decl points to exactly one type decl.
6513 assert(++Using->shadow_begin() == Using->shadow_end());
6514 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006515
John McCallb96ec562009-12-04 22:46:56 +00006516 } else {
6517 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6518 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6519 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6520 }
6521
6522 return SemaRef.Context.getTypeDeclType(Ty);
6523}
6524
6525template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006526QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6527 SourceLocation Loc) {
6528 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006529}
6530
6531template<typename Derived>
6532QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6533 return SemaRef.Context.getTypeOfType(Underlying);
6534}
6535
6536template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006537QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6538 SourceLocation Loc) {
6539 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006540}
6541
6542template<typename Derived>
6543QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006544 TemplateName Template,
6545 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006546 const TemplateArgumentListInfo &TemplateArgs) {
6547 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006548}
Mike Stump11289f42009-09-09 15:08:12 +00006549
Douglas Gregor1135c352009-08-06 05:28:30 +00006550template<typename Derived>
6551NestedNameSpecifier *
6552TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6553 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006554 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006555 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006556 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006557 CXXScopeSpec SS;
6558 // FIXME: The source location information is all wrong.
6559 SS.setRange(Range);
6560 SS.setScopeRep(Prefix);
6561 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006562 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006563 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006564 ObjectType,
6565 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006566 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006567}
6568
6569template<typename Derived>
6570NestedNameSpecifier *
6571TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6572 SourceRange Range,
6573 NamespaceDecl *NS) {
6574 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6575}
6576
6577template<typename Derived>
6578NestedNameSpecifier *
6579TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6580 SourceRange Range,
6581 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006582 QualType T) {
6583 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006584 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006585 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006586 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6587 T.getTypePtr());
6588 }
Mike Stump11289f42009-09-09 15:08:12 +00006589
Douglas Gregor1135c352009-08-06 05:28:30 +00006590 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6591 return 0;
6592}
Mike Stump11289f42009-09-09 15:08:12 +00006593
Douglas Gregor71dc5092009-08-06 06:41:21 +00006594template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006595TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006596TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6597 bool TemplateKW,
6598 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006599 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006600 Template);
6601}
6602
6603template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006604TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006605TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006606 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006607 const IdentifierInfo &II,
6608 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006609 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006610 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006611 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006612 UnqualifiedId Name;
6613 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006614 Sema::TemplateTy Template;
6615 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6616 /*FIXME:*/getDerived().getBaseLocation(),
6617 SS,
6618 Name,
John McCallba7bf592010-08-24 05:47:05 +00006619 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006620 /*EnteringContext=*/false,
6621 Template);
6622 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006623}
Mike Stump11289f42009-09-09 15:08:12 +00006624
Douglas Gregora16548e2009-08-11 05:31:07 +00006625template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006626TemplateName
6627TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6628 OverloadedOperatorKind Operator,
6629 QualType ObjectType) {
6630 CXXScopeSpec SS;
6631 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6632 SS.setScopeRep(Qualifier);
6633 UnqualifiedId Name;
6634 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6635 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6636 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006637 Sema::TemplateTy Template;
6638 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006639 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006640 SS,
6641 Name,
John McCallba7bf592010-08-24 05:47:05 +00006642 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006643 /*EnteringContext=*/false,
6644 Template);
6645 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006646}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006647
Douglas Gregor71395fa2009-11-04 00:56:37 +00006648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006649ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006650TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6651 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006652 Expr *OrigCallee,
6653 Expr *First,
6654 Expr *Second) {
6655 Expr *Callee = OrigCallee->IgnoreParenCasts();
6656 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006657
Douglas Gregora16548e2009-08-11 05:31:07 +00006658 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006659 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006660 if (!First->getType()->isOverloadableType() &&
6661 !Second->getType()->isOverloadableType())
6662 return getSema().CreateBuiltinArraySubscriptExpr(First,
6663 Callee->getLocStart(),
6664 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006665 } else if (Op == OO_Arrow) {
6666 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006667 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6668 } else if (Second == 0 || isPostIncDec) {
6669 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 // The argument is not of overloadable type, so try to create a
6671 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006672 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006673 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006674
John McCallb268a282010-08-23 23:25:46 +00006675 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 }
6677 } else {
John McCallb268a282010-08-23 23:25:46 +00006678 if (!First->getType()->isOverloadableType() &&
6679 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 // Neither of the arguments is an overloadable type, so try to
6681 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006682 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006683 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006684 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006685 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006687
Douglas Gregora16548e2009-08-11 05:31:07 +00006688 return move(Result);
6689 }
6690 }
Mike Stump11289f42009-09-09 15:08:12 +00006691
6692 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006693 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006694 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006695
John McCallb268a282010-08-23 23:25:46 +00006696 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006697 assert(ULE->requiresADL());
6698
6699 // FIXME: Do we have to check
6700 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006701 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006702 } else {
John McCallb268a282010-08-23 23:25:46 +00006703 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006704 }
Mike Stump11289f42009-09-09 15:08:12 +00006705
Douglas Gregora16548e2009-08-11 05:31:07 +00006706 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006707 Expr *Args[2] = { First, Second };
6708 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006709
Douglas Gregora16548e2009-08-11 05:31:07 +00006710 // Create the overloaded operator invocation for unary operators.
6711 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006712 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006713 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006714 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006715 }
Mike Stump11289f42009-09-09 15:08:12 +00006716
Sebastian Redladba46e2009-10-29 20:17:01 +00006717 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006718 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006719 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006720 First,
6721 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006722
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006724 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006725 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006726 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6727 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006729
Mike Stump11289f42009-09-09 15:08:12 +00006730 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006731}
Mike Stump11289f42009-09-09 15:08:12 +00006732
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006734ExprResult
John McCallb268a282010-08-23 23:25:46 +00006735TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006736 SourceLocation OperatorLoc,
6737 bool isArrow,
6738 NestedNameSpecifier *Qualifier,
6739 SourceRange QualifierRange,
6740 TypeSourceInfo *ScopeType,
6741 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006742 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006743 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006744 CXXScopeSpec SS;
6745 if (Qualifier) {
6746 SS.setRange(QualifierRange);
6747 SS.setScopeRep(Qualifier);
6748 }
6749
John McCallb268a282010-08-23 23:25:46 +00006750 QualType BaseType = Base->getType();
6751 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006752 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006753 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006754 !BaseType->getAs<PointerType>()->getPointeeType()
6755 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006756 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006757 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006758 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006759 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006760 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006761 /*FIXME?*/true);
6762 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006763
Douglas Gregor678f90d2010-02-25 01:56:36 +00006764 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006765 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6766 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6767 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6768 NameInfo.setNamedTypeInfo(DestroyedType);
6769
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006770 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006771
John McCallb268a282010-08-23 23:25:46 +00006772 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006773 OperatorLoc, isArrow,
6774 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006775 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006776 /*TemplateArgs*/ 0);
6777}
6778
Douglas Gregord6ff3322009-08-04 16:50:30 +00006779} // end namespace clang
6780
6781#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H