blob: 765ce0f5e873e858dfad2199fc74a4c53a6ea771 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000028#include "clang/AST/TypeLocBuilder.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000036using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000037
Douglas Gregord6ff3322009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump11289f42009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump11289f42009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000093
94public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000097
Douglas Gregord6ff3322009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000104 }
105
John McCalldadc5752010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000119
Douglas Gregord6ff3322009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump11289f42009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregora16548e2009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000141
Douglas Gregora16548e2009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregora16548e2009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Douglas Gregora16548e2009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump11289f42009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregord196a582009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000182
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCall550e0c22009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000192 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000193
John McCall550e0c22009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 ///
John McCall550e0c22009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000203 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000204
205 /// \brief Transform the given type-with-location into a new
206 /// type, collecting location information in the given builder
207 /// as necessary.
208 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000209 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000210 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000211
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000213 ///
Mike Stump11289f42009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000221 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000222
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000231 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000232
Douglas Gregord6ff3322009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000238 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump11289f42009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000244 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
245 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 }
Mike Stump11289f42009-09-09 15:08:12 +0000247
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000251 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000259 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000260
Douglas Gregord6ff3322009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump11289f42009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000270
Douglas Gregorf816bd72009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000277 DeclarationNameInfo
278 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
279 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000280
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000282 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000288
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump11289f42009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCallbcd03502009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump11289f42009-09-09 15:08:12 +0000309
John McCall550e0c22009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000314#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000315
John McCall58f10c32010-03-11 09:03:00 +0000316 /// \brief Transforms the parameters of a function type into the
317 /// given vectors.
318 ///
319 /// The result vectors should be kept in sync; null entries in the
320 /// variables vector are acceptable.
321 ///
322 /// Return true on error.
323 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
324 llvm::SmallVectorImpl<QualType> &PTypes,
325 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
326
327 /// \brief Transforms a single function-type parameter. Return null
328 /// on error.
329 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
330
Alexis Hunta8136cc2010-05-05 15:23:54 +0000331 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000332 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000333
Alexis Hunta8136cc2010-05-05 15:23:54 +0000334 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000335 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
336 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000337
John McCalldadc5752010-08-24 06:29:42 +0000338 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
339 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000340
Douglas Gregorebe10102009-08-20 07:17:43 +0000341#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000342 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000343#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000344 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000345#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000346#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000347
Douglas Gregord6ff3322009-08-04 16:50:30 +0000348 /// \brief Build a new pointer type given its pointee type.
349 ///
350 /// By default, performs semantic analysis when building the pointer type.
351 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000352 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000353
354 /// \brief Build a new block pointer type given its pointee type.
355 ///
Mike Stump11289f42009-09-09 15:08:12 +0000356 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000357 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000358 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359
John McCall70dd5f62009-10-30 00:06:24 +0000360 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361 ///
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// By default, performs semantic analysis when building the
363 /// reference type. Subclasses may override this routine to provide
364 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000365 ///
John McCall70dd5f62009-10-30 00:06:24 +0000366 /// \param LValue whether the type was written with an lvalue sigil
367 /// or an rvalue sigil.
368 QualType RebuildReferenceType(QualType ReferentType,
369 bool LValue,
370 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000371
Douglas Gregord6ff3322009-08-04 16:50:30 +0000372 /// \brief Build a new member pointer type given the pointee type and the
373 /// class type it refers into.
374 ///
375 /// By default, performs semantic analysis when building the member pointer
376 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000377 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
378 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000379
Douglas Gregord6ff3322009-08-04 16:50:30 +0000380 /// \brief Build a new array type given the element type, size
381 /// modifier, size of the array (if known), size expression, and index type
382 /// qualifiers.
383 ///
384 /// By default, performs semantic analysis when building the array type.
385 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000386 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000387 QualType RebuildArrayType(QualType ElementType,
388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt *Size,
390 Expr *SizeExpr,
391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Build a new constant array type given the element type, size
395 /// modifier, (known) size of the array, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000399 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
401 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// \brief Build a new incomplete array type given the element type, size
406 /// modifier, and index type qualifiers.
407 ///
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000410 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000414
Mike Stump11289f42009-09-09 15:08:12 +0000415 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000420 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000422 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
Mike Stump11289f42009-09-09 15:08:12 +0000426 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000427 /// size modifier, size expression, and index type qualifiers.
428 ///
429 /// By default, performs semantic analysis when building the array type.
430 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000431 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000433 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 unsigned IndexTypeQuals,
435 SourceRange BracketsRange);
436
437 /// \brief Build a new vector type given the element type and
438 /// number of elements.
439 ///
440 /// By default, performs semantic analysis when building the vector type.
441 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000442 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner37141f42010-06-23 06:00:24 +0000443 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump11289f42009-09-09 15:08:12 +0000444
Douglas Gregord6ff3322009-08-04 16:50:30 +0000445 /// \brief Build a new extended vector type given the element type and
446 /// number of elements.
447 ///
448 /// By default, performs semantic analysis when building the vector type.
449 /// Subclasses may override this routine to provide different behavior.
450 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
451 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000452
453 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000454 /// given the element type and number of elements.
455 ///
456 /// By default, performs semantic analysis when building the vector type.
457 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000458 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000459 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000460 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000461
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 /// \brief Build a new function type.
463 ///
464 /// By default, performs semantic analysis when building the function type.
465 /// Subclasses may override this routine to provide different behavior.
466 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000467 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000468 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000469 bool Variadic, unsigned Quals,
470 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000471
John McCall550e0c22009-10-21 00:40:46 +0000472 /// \brief Build a new unprototyped function type.
473 QualType RebuildFunctionNoProtoType(QualType ResultType);
474
John McCallb96ec562009-12-04 22:46:56 +0000475 /// \brief Rebuild an unresolved typename type, given the decl that
476 /// the UnresolvedUsingTypenameDecl was transformed to.
477 QualType RebuildUnresolvedUsingType(Decl *D);
478
Douglas Gregord6ff3322009-08-04 16:50:30 +0000479 /// \brief Build a new typedef type.
480 QualType RebuildTypedefType(TypedefDecl *Typedef) {
481 return SemaRef.Context.getTypeDeclType(Typedef);
482 }
483
484 /// \brief Build a new class/struct/union type.
485 QualType RebuildRecordType(RecordDecl *Record) {
486 return SemaRef.Context.getTypeDeclType(Record);
487 }
488
489 /// \brief Build a new Enum type.
490 QualType RebuildEnumType(EnumDecl *Enum) {
491 return SemaRef.Context.getTypeDeclType(Enum);
492 }
John McCallfcc33b02009-09-05 00:15:47 +0000493
Mike Stump11289f42009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000495 ///
496 /// By default, performs semantic analysis when building the typeof type.
497 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, builds a new TypeOfType with the given underlying type.
503 QualType RebuildTypeOfType(QualType Underlying);
504
Mike Stump11289f42009-09-09 15:08:12 +0000505 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 ///
507 /// By default, performs semantic analysis when building the decltype type.
508 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000509 QualType RebuildDecltypeType(Expr *Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000510
Douglas Gregord6ff3322009-08-04 16:50:30 +0000511 /// \brief Build a new template specialization type.
512 ///
513 /// By default, performs semantic analysis when building the template
514 /// specialization type. Subclasses may override this routine to provide
515 /// different behavior.
516 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000517 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000518 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000519
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 /// \brief Build a new qualified name type.
521 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000522 /// By default, builds a new ElaboratedType type from the keyword,
523 /// the nested-name-specifier and the named type.
524 /// Subclasses may override this routine to provide different behavior.
525 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
526 NestedNameSpecifier *NNS, QualType Named) {
527 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000528 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529
530 /// \brief Build a new typename type that refers to a template-id.
531 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000532 /// By default, builds a new DependentNameType type from the
533 /// nested-name-specifier and the given type. Subclasses may override
534 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000535 QualType RebuildDependentTemplateSpecializationType(
536 ElaboratedTypeKeyword Keyword,
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,
John McCallb268a282010-08-23 23:25:46 +0000761 Stmt *SubStmt) {
762 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 /// \brief Build a new "if" statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000769 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000770 VarDecl *CondVar, Stmt *Then,
771 SourceLocation ElseLoc, Stmt *Else) {
772 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000773 }
Mike Stump11289f42009-09-09 15:08:12 +0000774
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 /// \brief Start building a new switch statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000779 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000780 Expr *Cond, VarDecl *CondVar) {
781 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000782 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 }
Mike Stump11289f42009-09-09 15:08:12 +0000784
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 /// \brief Attach the body to the switch statement.
786 ///
787 /// By default, performs semantic analysis to build the new statement.
788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000789 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000790 Stmt *Switch, Stmt *Body) {
791 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000792 }
793
794 /// \brief Build a new while statement.
795 ///
796 /// By default, performs semantic analysis to build the new statement.
797 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000798 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000799 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000800 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000801 Stmt *Body) {
802 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000803 }
Mike Stump11289f42009-09-09 15:08:12 +0000804
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 /// \brief Build a new do-while statement.
806 ///
807 /// By default, performs semantic analysis to build the new statement.
808 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000809 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 SourceLocation WhileLoc,
811 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000812 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000813 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000814 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
815 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000816 }
817
818 /// \brief Build a new for statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000822 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000823 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000824 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000825 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000826 SourceLocation RParenLoc, Stmt *Body) {
827 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000828 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000829 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000830 }
Mike Stump11289f42009-09-09 15:08:12 +0000831
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 /// \brief Build a new goto statement.
833 ///
834 /// By default, performs semantic analysis to build the new statement.
835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000836 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000837 SourceLocation LabelLoc,
838 LabelStmt *Label) {
839 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
840 }
841
842 /// \brief Build a new indirect goto statement.
843 ///
844 /// By default, performs semantic analysis to build the new statement.
845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000846 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000848 Expr *Target) {
849 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000850 }
Mike Stump11289f42009-09-09 15:08:12 +0000851
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 /// \brief Build a new return statement.
853 ///
854 /// By default, performs semantic analysis to build the new statement.
855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000856 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000857 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000858
John McCallb268a282010-08-23 23:25:46 +0000859 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000860 }
Mike Stump11289f42009-09-09 15:08:12 +0000861
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 /// \brief Build a new declaration statement.
863 ///
864 /// By default, performs semantic analysis to build the new statement.
865 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000866 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000867 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000868 SourceLocation EndLoc) {
869 return getSema().Owned(
870 new (getSema().Context) DeclStmt(
871 DeclGroupRef::Create(getSema().Context,
872 Decls, NumDecls),
873 StartLoc, EndLoc));
874 }
Mike Stump11289f42009-09-09 15:08:12 +0000875
Anders Carlssonaaeef072010-01-24 05:50:09 +0000876 /// \brief Build a new inline asm statement.
877 ///
878 /// By default, performs semantic analysis to build the new statement.
879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000880 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000881 bool IsSimple,
882 bool IsVolatile,
883 unsigned NumOutputs,
884 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000885 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000886 MultiExprArg Constraints,
887 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000888 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000889 MultiExprArg Clobbers,
890 SourceLocation RParenLoc,
891 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000892 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000893 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000894 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000895 RParenLoc, MSAsm);
896 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000897
898 /// \brief Build a new Objective-C @try statement.
899 ///
900 /// By default, performs semantic analysis to build the new statement.
901 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000902 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000903 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000904 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000905 Stmt *Finally) {
906 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
907 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000908 }
909
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000910 /// \brief Rebuild an Objective-C exception declaration.
911 ///
912 /// By default, performs semantic analysis to build the new declaration.
913 /// Subclasses may override this routine to provide different behavior.
914 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
915 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000916 return getSema().BuildObjCExceptionDecl(TInfo, T,
917 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000918 ExceptionDecl->getLocation());
919 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000920
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000921 /// \brief Build a new Objective-C @catch statement.
922 ///
923 /// By default, performs semantic analysis to build the new statement.
924 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000925 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000926 SourceLocation RParenLoc,
927 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000928 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000929 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000930 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000931 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000932
Douglas Gregor306de2f2010-04-22 23:59:56 +0000933 /// \brief Build a new Objective-C @finally statement.
934 ///
935 /// By default, performs semantic analysis to build the new statement.
936 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000937 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000938 Stmt *Body) {
939 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000940 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000941
Douglas Gregor6148de72010-04-22 22:01:21 +0000942 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000943 ///
944 /// By default, performs semantic analysis to build the new statement.
945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000946 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000947 Expr *Operand) {
948 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000949 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000950
Douglas Gregor6148de72010-04-22 22:01:21 +0000951 /// \brief Build a new Objective-C @synchronized statement.
952 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000953 /// By default, performs semantic analysis to build the new statement.
954 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000955 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000956 Expr *Object,
957 Stmt *Body) {
958 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
959 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000960 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000961
962 /// \brief Build a new Objective-C fast enumeration statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000966 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000967 SourceLocation LParenLoc,
968 Stmt *Element,
969 Expr *Collection,
970 SourceLocation RParenLoc,
971 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000972 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000973 Element,
974 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000975 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000976 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000977 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000978
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 /// \brief Build a new C++ exception declaration.
980 ///
981 /// By default, performs semantic analysis to build the new decaration.
982 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000983 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +0000984 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000985 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000986 SourceLocation Loc) {
987 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000988 }
989
990 /// \brief Build a new C++ catch statement.
991 ///
992 /// By default, performs semantic analysis to build the new statement.
993 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000994 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000995 VarDecl *ExceptionDecl,
996 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +0000997 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
998 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 }
Mike Stump11289f42009-09-09 15:08:12 +00001000
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 /// \brief Build a new C++ try statement.
1002 ///
1003 /// By default, performs semantic analysis to build the new statement.
1004 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001005 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001006 Stmt *TryBlock,
1007 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001008 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 }
Mike Stump11289f42009-09-09 15:08:12 +00001010
Douglas Gregora16548e2009-08-11 05:31:07 +00001011 /// \brief Build a new expression that references a declaration.
1012 ///
1013 /// By default, performs semantic analysis to build the new expression.
1014 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001015 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001016 LookupResult &R,
1017 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001018 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1019 }
1020
1021
1022 /// \brief Build a new expression that references a declaration.
1023 ///
1024 /// By default, performs semantic analysis to build the new expression.
1025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001026 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001027 SourceRange QualifierRange,
1028 ValueDecl *VD,
1029 const DeclarationNameInfo &NameInfo,
1030 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001031 CXXScopeSpec SS;
1032 SS.setScopeRep(Qualifier);
1033 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001034
1035 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001036
1037 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001038 }
Mike Stump11289f42009-09-09 15:08:12 +00001039
Douglas Gregora16548e2009-08-11 05:31:07 +00001040 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001041 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 /// By default, performs semantic analysis to build the new expression.
1043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001044 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001046 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 }
1048
Douglas Gregorad8a3362009-09-04 17:36:40 +00001049 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001050 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001051 /// By default, performs semantic analysis to build the new expression.
1052 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001053 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001054 SourceLocation OperatorLoc,
1055 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001056 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001057 SourceRange QualifierRange,
1058 TypeSourceInfo *ScopeType,
1059 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001060 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001061 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001062
Douglas Gregora16548e2009-08-11 05:31:07 +00001063 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001064 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001065 /// By default, performs semantic analysis to build the new expression.
1066 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001067 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001068 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001069 Expr *SubExpr) {
1070 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Douglas Gregor882211c2010-04-28 22:16:22 +00001073 /// \brief Build a new builtin offsetof expression.
1074 ///
1075 /// By default, performs semantic analysis to build the new expression.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001078 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001079 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001080 unsigned NumComponents,
1081 SourceLocation RParenLoc) {
1082 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1083 NumComponents, RParenLoc);
1084 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001085
Douglas Gregora16548e2009-08-11 05:31:07 +00001086 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001087 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// By default, performs semantic analysis to build the new expression.
1089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001090 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001091 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001092 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001093 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 }
1095
Mike Stump11289f42009-09-09 15:08:12 +00001096 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// By default, performs semantic analysis to build the new expression.
1100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001101 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001103 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001104 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001106 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001107
Douglas Gregora16548e2009-08-11 05:31:07 +00001108 return move(Result);
1109 }
Mike Stump11289f42009-09-09 15:08:12 +00001110
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001112 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// By default, performs semantic analysis to build the new expression.
1114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001115 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001117 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001119 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1120 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 RBracketLoc);
1122 }
1123
1124 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// By default, performs semantic analysis to build the new expression.
1127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001128 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001132 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 }
1134
1135 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001139 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001140 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001141 NestedNameSpecifier *Qualifier,
1142 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001143 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001144 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001145 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001146 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001147 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001148 if (!Member->getDeclName()) {
1149 // We have a reference to an unnamed field.
1150 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001151
John McCallb268a282010-08-23 23:25:46 +00001152 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001153 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001154 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001155
Mike Stump11289f42009-09-09 15:08:12 +00001156 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001157 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001158 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001159 cast<FieldDecl>(Member)->getType());
1160 return getSema().Owned(ME);
1161 }
Mike Stump11289f42009-09-09 15:08:12 +00001162
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001163 CXXScopeSpec SS;
1164 if (Qualifier) {
1165 SS.setRange(QualifierRange);
1166 SS.setScopeRep(Qualifier);
1167 }
1168
John McCallb268a282010-08-23 23:25:46 +00001169 getSema().DefaultFunctionArrayConversion(Base);
1170 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001171
John McCall16df1e52010-03-30 21:47:33 +00001172 // FIXME: this involves duplicating earlier analysis in a lot of
1173 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001174 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001175 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001176 R.resolveKind();
1177
John McCallb268a282010-08-23 23:25:46 +00001178 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001179 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001180 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001188 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001189 Expr *LHS, Expr *RHS) {
1190 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001191 }
1192
1193 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001194 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001195 /// By default, performs semantic analysis to build the new expression.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001199 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001201 Expr *RHS) {
1202 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1203 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 }
1205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001207 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001210 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001211 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001213 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001214 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001215 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001219 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// By default, performs semantic analysis to build the new expression.
1221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001222 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001223 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001225 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001226 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001227 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 }
Mike Stump11289f42009-09-09 15:08:12 +00001229
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001231 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 SourceLocation OpLoc,
1236 SourceLocation AccessorLoc,
1237 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001238
John McCall10eae182009-11-30 22:42:35 +00001239 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001240 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001241 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001242 OpLoc, /*IsArrow*/ false,
1243 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001244 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001245 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001249 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001252 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001254 SourceLocation RBraceLoc,
1255 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001256 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001257 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1258 if (Result.isInvalid() || ResultTy->isDependentType())
1259 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001260
Douglas Gregord3d93062009-11-09 17:16:50 +00001261 // Patch in the result type we were given, which may have been computed
1262 // when the initial InitListExpr was built.
1263 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1264 ILE->setType(ResultTy);
1265 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001266 }
Mike Stump11289f42009-09-09 15:08:12 +00001267
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001269 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001272 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 MultiExprArg ArrayExprs,
1274 SourceLocation EqualOrColonLoc,
1275 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001276 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001279 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 ArrayExprs.release();
1284 return move(Result);
1285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001288 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// By default, builds the implicit value initialization without performing
1290 /// any semantic analysis. Subclasses may override this routine to provide
1291 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1294 }
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001297 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001300 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001301 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001302 SourceLocation RParenLoc) {
1303 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001304 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001305 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 }
1307
1308 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001309 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// By default, performs semantic analysis to build the new expression.
1311 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001312 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 MultiExprArg SubExprs,
1314 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001315 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001316 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
1321 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// rather than attempting to map the label statement itself.
1323 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001324 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 SourceLocation LabelLoc,
1326 LabelStmt *Label) {
1327 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001335 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001337 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 }
Mike Stump11289f42009-09-09 15:08:12 +00001339
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 /// \brief Build a new __builtin_types_compatible_p expression.
1341 ///
1342 /// By default, performs semantic analysis to build the new expression.
1343 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001344 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001345 TypeSourceInfo *TInfo1,
1346 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001348 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1349 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 RParenLoc);
1351 }
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// \brief Build a new __builtin_choose_expr expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001358 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 SourceLocation RParenLoc) {
1360 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001361 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 RParenLoc);
1363 }
Mike Stump11289f42009-09-09 15:08:12 +00001364
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 /// \brief Build a new overloaded operator call expression.
1366 ///
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// The semantic analysis provides the behavior of template instantiation,
1369 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001370 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// argument-dependent lookup, etc. Subclasses may override this routine to
1372 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001373 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001375 Expr *Callee,
1376 Expr *First,
1377 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001378
1379 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 /// reinterpret_cast.
1381 ///
1382 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001383 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001385 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 Stmt::StmtClass Class,
1387 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001388 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 SourceLocation RAngleLoc,
1390 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001391 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 SourceLocation RParenLoc) {
1393 switch (Class) {
1394 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001397 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001398
1399 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001402 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001405 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001406 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001407 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001413 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 default:
1416 assert(false && "Invalid C++ named cast");
1417 break;
1418 }
Mike Stump11289f42009-09-09 15:08:12 +00001419
John McCallfaf5fb42010-08-26 23:41:50 +00001420 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 }
Mike Stump11289f42009-09-09 15:08:12 +00001422
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// \brief Build a new C++ static_cast expression.
1424 ///
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001427 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001429 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 SourceLocation RAngleLoc,
1431 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001432 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001435 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001436 SourceRange(LAngleLoc, RAngleLoc),
1437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 }
1439
1440 /// \brief Build a new C++ dynamic_cast expression.
1441 ///
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001444 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001446 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 SourceLocation RAngleLoc,
1448 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001449 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001452 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001453 SourceRange(LAngleLoc, RAngleLoc),
1454 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 }
1456
1457 /// \brief Build a new C++ reinterpret_cast expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001461 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001463 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 SourceLocation RAngleLoc,
1465 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001466 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001468 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001469 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001470 SourceRange(LAngleLoc, RAngleLoc),
1471 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 }
1473
1474 /// \brief Build a new C++ const_cast expression.
1475 ///
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001480 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 SourceLocation RAngleLoc,
1482 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001483 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001485 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001486 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001487 SourceRange(LAngleLoc, RAngleLoc),
1488 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 }
Mike Stump11289f42009-09-09 15:08:12 +00001490
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 /// \brief Build a new C++ functional-style cast expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001495 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1496 SourceLocation LParenLoc,
1497 Expr *Sub,
1498 SourceLocation RParenLoc) {
1499 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001500 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 RParenLoc);
1502 }
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// \brief Build a new C++ typeid(type) expression.
1505 ///
1506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001508 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001509 SourceLocation TypeidLoc,
1510 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001512 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001513 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 }
Mike Stump11289f42009-09-09 15:08:12 +00001515
Francois Pichet9f4f2072010-09-08 12:20:18 +00001516
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 /// \brief Build a new C++ typeid(expr) expression.
1518 ///
1519 /// By default, performs semantic analysis to build the new expression.
1520 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001521 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001522 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001523 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001525 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001526 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001527 }
1528
Francois Pichet9f4f2072010-09-08 12:20:18 +00001529 /// \brief Build a new C++ __uuidof(type) expression.
1530 ///
1531 /// By default, performs semantic analysis to build the new expression.
1532 /// Subclasses may override this routine to provide different behavior.
1533 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1534 SourceLocation TypeidLoc,
1535 TypeSourceInfo *Operand,
1536 SourceLocation RParenLoc) {
1537 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1538 RParenLoc);
1539 }
1540
1541 /// \brief Build a new C++ __uuidof(expr) expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
1545 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1546 SourceLocation TypeidLoc,
1547 Expr *Operand,
1548 SourceLocation RParenLoc) {
1549 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1550 RParenLoc);
1551 }
1552
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// \brief Build a new C++ "this" expression.
1554 ///
1555 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001556 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001559 QualType ThisType,
1560 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001562 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1563 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 }
1565
1566 /// \brief Build a new C++ throw expression.
1567 ///
1568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001570 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001571 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 }
1573
1574 /// \brief Build a new C++ default-argument expression.
1575 ///
1576 /// By default, builds a new default-argument expression, which does not
1577 /// require any semantic analysis. Subclasses may override this routine to
1578 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001579 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001580 ParmVarDecl *Param) {
1581 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1582 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 }
1584
1585 /// \brief Build a new C++ zero-initialization expression.
1586 ///
1587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001589 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1590 SourceLocation LParenLoc,
1591 SourceLocation RParenLoc) {
1592 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001593 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001594 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 }
Mike Stump11289f42009-09-09 15:08:12 +00001596
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 /// \brief Build a new C++ "new" expression.
1598 ///
1599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001601 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001602 bool UseGlobal,
1603 SourceLocation PlacementLParen,
1604 MultiExprArg PlacementArgs,
1605 SourceLocation PlacementRParen,
1606 SourceRange TypeIdParens,
1607 QualType AllocatedType,
1608 TypeSourceInfo *AllocatedTypeInfo,
1609 Expr *ArraySize,
1610 SourceLocation ConstructorLParen,
1611 MultiExprArg ConstructorArgs,
1612 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001613 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 PlacementLParen,
1615 move(PlacementArgs),
1616 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001617 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001618 AllocatedType,
1619 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001620 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 ConstructorLParen,
1622 move(ConstructorArgs),
1623 ConstructorRParen);
1624 }
Mike Stump11289f42009-09-09 15:08:12 +00001625
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// \brief Build a new C++ "delete" expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001630 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 bool IsGlobalDelete,
1632 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001633 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001635 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 }
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// \brief Build a new unary type trait expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001642 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001643 SourceLocation StartLoc,
1644 TypeSourceInfo *T,
1645 SourceLocation RParenLoc) {
1646 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 }
1648
Mike Stump11289f42009-09-09 15:08:12 +00001649 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 /// expression.
1651 ///
1652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001654 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001656 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001657 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 CXXScopeSpec SS;
1659 SS.setRange(QualifierRange);
1660 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001661
1662 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001663 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001664 *TemplateArgs);
1665
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001666 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 }
1668
1669 /// \brief Build a new template-id expression.
1670 ///
1671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001673 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001674 LookupResult &R,
1675 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001676 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001677 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 }
1679
1680 /// \brief Build a new object-construction expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001685 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 CXXConstructorDecl *Constructor,
1687 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001688 MultiExprArg Args,
1689 bool RequiresZeroInit,
1690 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCall37ad5512010-08-23 06:44:23 +00001691 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001692 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001693 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001694 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001695
Douglas Gregordb121ba2009-12-14 16:27:04 +00001696 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001697 move_arg(ConvertedArgs),
1698 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001699 }
1700
1701 /// \brief Build a new object-construction expression.
1702 ///
1703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001705 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1706 SourceLocation LParenLoc,
1707 MultiExprArg Args,
1708 SourceLocation RParenLoc) {
1709 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 LParenLoc,
1711 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 RParenLoc);
1713 }
1714
1715 /// \brief Build a new object-construction expression.
1716 ///
1717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001719 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1720 SourceLocation LParenLoc,
1721 MultiExprArg Args,
1722 SourceLocation RParenLoc) {
1723 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 LParenLoc,
1725 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 RParenLoc);
1727 }
Mike Stump11289f42009-09-09 15:08:12 +00001728
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 /// \brief Build a new member reference expression.
1730 ///
1731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001733 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001734 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 bool IsArrow,
1736 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001737 NestedNameSpecifier *Qualifier,
1738 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001739 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001740 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001741 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001743 SS.setRange(QualifierRange);
1744 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001745
John McCallb268a282010-08-23 23:25:46 +00001746 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001747 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001748 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001749 MemberNameInfo,
1750 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
1752
John McCall10eae182009-11-30 22:42:35 +00001753 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001754 ///
1755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001757 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001758 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001759 SourceLocation OperatorLoc,
1760 bool IsArrow,
1761 NestedNameSpecifier *Qualifier,
1762 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001763 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001764 LookupResult &R,
1765 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001766 CXXScopeSpec SS;
1767 SS.setRange(QualifierRange);
1768 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001769
John McCallb268a282010-08-23 23:25:46 +00001770 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001771 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001772 SS, FirstQualifierInScope,
1773 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001774 }
Mike Stump11289f42009-09-09 15:08:12 +00001775
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001776 /// \brief Build a new noexcept expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
1780 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1781 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1782 }
1783
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 /// \brief Build a new Objective-C @encode expression.
1785 ///
1786 /// By default, performs semantic analysis to build the new expression.
1787 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001788 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001789 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001791 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001793 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001794
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001795 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001796 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001797 Selector Sel,
1798 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001799 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001800 MultiExprArg Args,
1801 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001802 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1803 ReceiverTypeInfo->getType(),
1804 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001805 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001806 move(Args));
1807 }
1808
1809 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001810 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001811 Selector Sel,
1812 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001813 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001814 MultiExprArg Args,
1815 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001816 return SemaRef.BuildInstanceMessage(Receiver,
1817 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001818 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001819 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001820 move(Args));
1821 }
1822
Douglas Gregord51d90d2010-04-26 20:11:03 +00001823 /// \brief Build a new Objective-C ivar reference expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001827 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001828 SourceLocation IvarLoc,
1829 bool IsArrow, bool IsFreeIvar) {
1830 // FIXME: We lose track of the IsFreeIvar bit.
1831 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001832 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001833 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1834 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001836 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001837 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001838 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001839 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001840 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001841
Douglas Gregord51d90d2010-04-26 20:11:03 +00001842 if (Result.get())
1843 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001844
John McCallb268a282010-08-23 23:25:46 +00001845 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001846 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001847 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001848 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001849 /*TemplateArgs=*/0);
1850 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001851
1852 /// \brief Build a new Objective-C property reference expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001856 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001857 ObjCPropertyDecl *Property,
1858 SourceLocation PropertyLoc) {
1859 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001860 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001861 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1862 Sema::LookupMemberName);
1863 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001864 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001865 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001866 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001867 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001868 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001869
Douglas Gregor9faee212010-04-26 20:47:02 +00001870 if (Result.get())
1871 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001872
John McCallb268a282010-08-23 23:25:46 +00001873 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001874 /*FIXME:*/PropertyLoc, IsArrow,
1875 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001876 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001877 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001878 /*TemplateArgs=*/0);
1879 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001880
1881 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001882 /// expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001885 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001886 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001887 ObjCMethodDecl *Getter,
1888 QualType T,
1889 ObjCMethodDecl *Setter,
1890 SourceLocation NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001891 Expr *Base) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001892 // Since these expressions can only be value-dependent, we do not need to
1893 // perform semantic analysis again.
John McCallb268a282010-08-23 23:25:46 +00001894 return Owned(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001895 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1896 Setter,
1897 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001898 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001899 }
1900
Douglas Gregord51d90d2010-04-26 20:11:03 +00001901 /// \brief Build a new Objective-C "isa" expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001905 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001906 bool IsArrow) {
1907 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001908 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001909 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1910 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001911 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001912 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001913 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001914 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001915 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001916
Douglas Gregord51d90d2010-04-26 20:11:03 +00001917 if (Result.get())
1918 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001919
John McCallb268a282010-08-23 23:25:46 +00001920 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001921 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001922 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001923 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001924 /*TemplateArgs=*/0);
1925 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// \brief Build a new shuffle vector expression.
1928 ///
1929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 MultiExprArg SubExprs,
1933 SourceLocation RParenLoc) {
1934 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001935 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1937 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1938 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1939 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 // Build a reference to the __builtin_shufflevector builtin
1942 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001943 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001945 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001947
1948 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 unsigned NumSubExprs = SubExprs.size();
1950 Expr **Subs = (Expr **)SubExprs.release();
1951 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1952 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001953 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001955 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001958 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001960 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001963 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001965};
Douglas Gregora16548e2009-08-11 05:31:07 +00001966
Douglas Gregorebe10102009-08-20 07:17:43 +00001967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001968StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001969 if (!S)
1970 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregorebe10102009-08-20 07:17:43 +00001972 switch (S->getStmtClass()) {
1973 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001974
Douglas Gregorebe10102009-08-20 07:17:43 +00001975 // Transform individual statement nodes
1976#define STMT(Node, Parent) \
1977 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1978#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001979#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001980
Douglas Gregorebe10102009-08-20 07:17:43 +00001981 // Transform expressions by calling TransformExpr.
1982#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001983#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001984#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001985#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001986 {
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00001988 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001989 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001990
John McCallb268a282010-08-23 23:25:46 +00001991 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00001992 }
Mike Stump11289f42009-09-09 15:08:12 +00001993 }
1994
Douglas Gregorebe10102009-08-20 07:17:43 +00001995 return SemaRef.Owned(S->Retain());
1996}
Mike Stump11289f42009-09-09 15:08:12 +00001997
1998
Douglas Gregore922c772009-08-04 22:27:00 +00001999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002000ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 if (!E)
2002 return SemaRef.Owned(E);
2003
2004 switch (E->getStmtClass()) {
2005 case Stmt::NoStmtClass: break;
2006#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002007#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002008#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002009 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002010#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002011 }
2012
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002014}
2015
2016template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002017NestedNameSpecifier *
2018TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002019 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002020 QualType ObjectType,
2021 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002022 if (!NNS)
2023 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002024
Douglas Gregorebe10102009-08-20 07:17:43 +00002025 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002026 NestedNameSpecifier *Prefix = NNS->getPrefix();
2027 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002028 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002029 ObjectType,
2030 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002031 if (!Prefix)
2032 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002033
2034 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002035 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002036 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002037 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002038 }
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregor1135c352009-08-06 05:28:30 +00002040 switch (NNS->getKind()) {
2041 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002042 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002043 "Identifier nested-name-specifier with no prefix or object type");
2044 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2045 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002046 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002047
2048 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002049 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002050 ObjectType,
2051 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002052
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002054 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002055 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002056 getDerived().TransformDecl(Range.getBegin(),
2057 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002058 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002059 Prefix == NNS->getPrefix() &&
2060 NS == NNS->getAsNamespace())
2061 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002062
Douglas Gregor1135c352009-08-06 05:28:30 +00002063 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2064 }
Mike Stump11289f42009-09-09 15:08:12 +00002065
Douglas Gregor1135c352009-08-06 05:28:30 +00002066 case NestedNameSpecifier::Global:
2067 // There is no meaningful transformation that one could perform on the
2068 // global scope.
2069 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002070
Douglas Gregor1135c352009-08-06 05:28:30 +00002071 case NestedNameSpecifier::TypeSpecWithTemplate:
2072 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002073 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002074 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2075 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002076 if (T.isNull())
2077 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002078
Douglas Gregor1135c352009-08-06 05:28:30 +00002079 if (!getDerived().AlwaysRebuild() &&
2080 Prefix == NNS->getPrefix() &&
2081 T == QualType(NNS->getAsType(), 0))
2082 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002083
2084 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2085 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002086 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002087 }
2088 }
Mike Stump11289f42009-09-09 15:08:12 +00002089
Douglas Gregor1135c352009-08-06 05:28:30 +00002090 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002091 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002092}
2093
2094template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002095DeclarationNameInfo
2096TreeTransform<Derived>
2097::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2098 QualType ObjectType) {
2099 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002100 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002101 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002102
2103 switch (Name.getNameKind()) {
2104 case DeclarationName::Identifier:
2105 case DeclarationName::ObjCZeroArgSelector:
2106 case DeclarationName::ObjCOneArgSelector:
2107 case DeclarationName::ObjCMultiArgSelector:
2108 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002109 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002110 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002111 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002112
Douglas Gregorf816bd72009-09-03 22:13:48 +00002113 case DeclarationName::CXXConstructorName:
2114 case DeclarationName::CXXDestructorName:
2115 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002116 TypeSourceInfo *NewTInfo;
2117 CanQualType NewCanTy;
2118 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2119 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2120 if (!NewTInfo)
2121 return DeclarationNameInfo();
2122 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2123 }
2124 else {
2125 NewTInfo = 0;
2126 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2127 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2128 ObjectType);
2129 if (NewT.isNull())
2130 return DeclarationNameInfo();
2131 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2132 }
Mike Stump11289f42009-09-09 15:08:12 +00002133
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002134 DeclarationName NewName
2135 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2136 NewCanTy);
2137 DeclarationNameInfo NewNameInfo(NameInfo);
2138 NewNameInfo.setName(NewName);
2139 NewNameInfo.setNamedTypeInfo(NewTInfo);
2140 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002141 }
Mike Stump11289f42009-09-09 15:08:12 +00002142 }
2143
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002144 assert(0 && "Unknown name kind.");
2145 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002146}
2147
2148template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002149TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002150TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2151 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002152 SourceLocation Loc = getDerived().getBaseLocation();
2153
Douglas Gregor71dc5092009-08-06 06:41:21 +00002154 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002155 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002156 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002157 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2158 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002159 if (!NNS)
2160 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002161
Douglas Gregor71dc5092009-08-06 06:41:21 +00002162 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002163 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002164 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002165 if (!TransTemplate)
2166 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregor71dc5092009-08-06 06:41:21 +00002168 if (!getDerived().AlwaysRebuild() &&
2169 NNS == QTN->getQualifier() &&
2170 TransTemplate == Template)
2171 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregor71dc5092009-08-06 06:41:21 +00002173 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2174 TransTemplate);
2175 }
Mike Stump11289f42009-09-09 15:08:12 +00002176
John McCalle66edc12009-11-24 19:00:30 +00002177 // These should be getting filtered out before they make it into the AST.
2178 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002179 }
Mike Stump11289f42009-09-09 15:08:12 +00002180
Douglas Gregor71dc5092009-08-06 06:41:21 +00002181 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002182 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002183 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002184 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2185 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002186 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregor71dc5092009-08-06 06:41:21 +00002189 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002190 NNS == DTN->getQualifier() &&
2191 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002192 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002193
Douglas Gregora5614c52010-09-08 23:56:00 +00002194 if (DTN->isIdentifier()) {
2195 // FIXME: Bad range
2196 SourceRange QualifierRange(getDerived().getBaseLocation());
2197 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2198 *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002199 ObjectType);
Douglas Gregora5614c52010-09-08 23:56:00 +00002200 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002201
2202 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002203 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002204 }
Mike Stump11289f42009-09-09 15:08:12 +00002205
Douglas Gregor71dc5092009-08-06 06:41:21 +00002206 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002207 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002208 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002209 if (!TransTemplate)
2210 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002211
Douglas Gregor71dc5092009-08-06 06:41:21 +00002212 if (!getDerived().AlwaysRebuild() &&
2213 TransTemplate == Template)
2214 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002215
Douglas Gregor71dc5092009-08-06 06:41:21 +00002216 return TemplateName(TransTemplate);
2217 }
Mike Stump11289f42009-09-09 15:08:12 +00002218
John McCalle66edc12009-11-24 19:00:30 +00002219 // These should be getting filtered out before they reach the AST.
2220 assert(false && "overloaded function decl survived to here");
2221 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002222}
2223
2224template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002225void TreeTransform<Derived>::InventTemplateArgumentLoc(
2226 const TemplateArgument &Arg,
2227 TemplateArgumentLoc &Output) {
2228 SourceLocation Loc = getDerived().getBaseLocation();
2229 switch (Arg.getKind()) {
2230 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002231 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002232 break;
2233
2234 case TemplateArgument::Type:
2235 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002236 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002237
John McCall0ad16662009-10-29 08:12:44 +00002238 break;
2239
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002240 case TemplateArgument::Template:
2241 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2242 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002243
John McCall0ad16662009-10-29 08:12:44 +00002244 case TemplateArgument::Expression:
2245 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2246 break;
2247
2248 case TemplateArgument::Declaration:
2249 case TemplateArgument::Integral:
2250 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002251 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002252 break;
2253 }
2254}
2255
2256template<typename Derived>
2257bool TreeTransform<Derived>::TransformTemplateArgument(
2258 const TemplateArgumentLoc &Input,
2259 TemplateArgumentLoc &Output) {
2260 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002261 switch (Arg.getKind()) {
2262 case TemplateArgument::Null:
2263 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002264 Output = Input;
2265 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002266
Douglas Gregore922c772009-08-04 22:27:00 +00002267 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002268 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002269 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002270 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002271
2272 DI = getDerived().TransformType(DI);
2273 if (!DI) return true;
2274
2275 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2276 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002277 }
Mike Stump11289f42009-09-09 15:08:12 +00002278
Douglas Gregore922c772009-08-04 22:27:00 +00002279 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002280 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002281 DeclarationName Name;
2282 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2283 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002284 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002285 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002286 if (!D) return true;
2287
John McCall0d07eb32009-10-29 18:45:58 +00002288 Expr *SourceExpr = Input.getSourceDeclExpression();
2289 if (SourceExpr) {
2290 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002291 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002292 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002293 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002294 }
2295
2296 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002297 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002298 }
Mike Stump11289f42009-09-09 15:08:12 +00002299
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002300 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002301 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002302 TemplateName Template
2303 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2304 if (Template.isNull())
2305 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002306
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002307 Output = TemplateArgumentLoc(TemplateArgument(Template),
2308 Input.getTemplateQualifierRange(),
2309 Input.getTemplateNameLoc());
2310 return false;
2311 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002312
Douglas Gregore922c772009-08-04 22:27:00 +00002313 case TemplateArgument::Expression: {
2314 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002315 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002316 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002317
John McCall0ad16662009-10-29 08:12:44 +00002318 Expr *InputExpr = Input.getSourceExpression();
2319 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2320
John McCalldadc5752010-08-24 06:29:42 +00002321 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002322 = getDerived().TransformExpr(InputExpr);
2323 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002324 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002325 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002326 }
Mike Stump11289f42009-09-09 15:08:12 +00002327
Douglas Gregore922c772009-08-04 22:27:00 +00002328 case TemplateArgument::Pack: {
2329 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2330 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002331 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002332 AEnd = Arg.pack_end();
2333 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002334
John McCall0ad16662009-10-29 08:12:44 +00002335 // FIXME: preserve source information here when we start
2336 // caring about parameter packs.
2337
John McCall0d07eb32009-10-29 18:45:58 +00002338 TemplateArgumentLoc InputArg;
2339 TemplateArgumentLoc OutputArg;
2340 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2341 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002342 return true;
2343
John McCall0d07eb32009-10-29 18:45:58 +00002344 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002345 }
2346 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002347 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002348 true);
John McCall0d07eb32009-10-29 18:45:58 +00002349 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002350 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002351 }
2352 }
Mike Stump11289f42009-09-09 15:08:12 +00002353
Douglas Gregore922c772009-08-04 22:27:00 +00002354 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002355 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002356}
2357
Douglas Gregord6ff3322009-08-04 16:50:30 +00002358//===----------------------------------------------------------------------===//
2359// Type transformation
2360//===----------------------------------------------------------------------===//
2361
2362template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002363QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002364 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002365 if (getDerived().AlreadyTransformed(T))
2366 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002367
John McCall550e0c22009-10-21 00:40:46 +00002368 // Temporary workaround. All of these transformations should
2369 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002370 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002371 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002372
Douglas Gregorfe17d252010-02-16 19:09:40 +00002373 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002374
John McCall550e0c22009-10-21 00:40:46 +00002375 if (!NewDI)
2376 return QualType();
2377
2378 return NewDI->getType();
2379}
2380
2381template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002382TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2383 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002384 if (getDerived().AlreadyTransformed(DI->getType()))
2385 return DI;
2386
2387 TypeLocBuilder TLB;
2388
2389 TypeLoc TL = DI->getTypeLoc();
2390 TLB.reserve(TL.getFullDataSize());
2391
Douglas Gregorfe17d252010-02-16 19:09:40 +00002392 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002393 if (Result.isNull())
2394 return 0;
2395
John McCallbcd03502009-12-07 02:54:59 +00002396 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002397}
2398
2399template<typename Derived>
2400QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002401TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2402 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002403 switch (T.getTypeLocClass()) {
2404#define ABSTRACT_TYPELOC(CLASS, PARENT)
2405#define TYPELOC(CLASS, PARENT) \
2406 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002407 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2408 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002409#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002410 }
Mike Stump11289f42009-09-09 15:08:12 +00002411
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002412 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002413 return QualType();
2414}
2415
2416/// FIXME: By default, this routine adds type qualifiers only to types
2417/// that can have qualifiers, and silently suppresses those qualifiers
2418/// that are not permitted (e.g., qualifiers on reference or function
2419/// types). This is the right thing for template instantiation, but
2420/// probably not for other clients.
2421template<typename Derived>
2422QualType
2423TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002424 QualifiedTypeLoc T,
2425 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002426 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002427
Douglas Gregorfe17d252010-02-16 19:09:40 +00002428 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2429 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002430 if (Result.isNull())
2431 return QualType();
2432
2433 // Silently suppress qualifiers if the result type can't be qualified.
2434 // FIXME: this is the right thing for template instantiation, but
2435 // probably not for other clients.
2436 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002437 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002438
John McCallcb0f89a2010-06-05 06:41:15 +00002439 if (!Quals.empty()) {
2440 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2441 TLB.push<QualifiedTypeLoc>(Result);
2442 // No location information to preserve.
2443 }
John McCall550e0c22009-10-21 00:40:46 +00002444
2445 return Result;
2446}
2447
2448template <class TyLoc> static inline
2449QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2450 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2451 NewT.setNameLoc(T.getNameLoc());
2452 return T.getType();
2453}
2454
John McCall550e0c22009-10-21 00:40:46 +00002455template<typename Derived>
2456QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002457 BuiltinTypeLoc T,
2458 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002459 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2460 NewT.setBuiltinLoc(T.getBuiltinLoc());
2461 if (T.needsExtraLocalData())
2462 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2463 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002464}
Mike Stump11289f42009-09-09 15:08:12 +00002465
Douglas Gregord6ff3322009-08-04 16:50:30 +00002466template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002467QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002468 ComplexTypeLoc T,
2469 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002470 // FIXME: recurse?
2471 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002472}
Mike Stump11289f42009-09-09 15:08:12 +00002473
Douglas Gregord6ff3322009-08-04 16:50:30 +00002474template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002475QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002476 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002477 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002478 QualType PointeeType
2479 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002480 if (PointeeType.isNull())
2481 return QualType();
2482
2483 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002484 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002485 // A dependent pointer type 'T *' has is being transformed such
2486 // that an Objective-C class type is being replaced for 'T'. The
2487 // resulting pointer type is an ObjCObjectPointerType, not a
2488 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002489 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002490
John McCall8b07ec22010-05-15 11:32:37 +00002491 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2492 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002493 return Result;
2494 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002495
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002496 if (getDerived().AlwaysRebuild() ||
2497 PointeeType != TL.getPointeeLoc().getType()) {
2498 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2499 if (Result.isNull())
2500 return QualType();
2501 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002502
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002503 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2504 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002505 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002506}
Mike Stump11289f42009-09-09 15:08:12 +00002507
2508template<typename Derived>
2509QualType
John McCall550e0c22009-10-21 00:40:46 +00002510TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002511 BlockPointerTypeLoc TL,
2512 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002513 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002514 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2515 if (PointeeType.isNull())
2516 return QualType();
2517
2518 QualType Result = TL.getType();
2519 if (getDerived().AlwaysRebuild() ||
2520 PointeeType != TL.getPointeeLoc().getType()) {
2521 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002522 TL.getSigilLoc());
2523 if (Result.isNull())
2524 return QualType();
2525 }
2526
Douglas Gregor049211a2010-04-22 16:50:51 +00002527 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002528 NewT.setSigilLoc(TL.getSigilLoc());
2529 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002530}
2531
John McCall70dd5f62009-10-30 00:06:24 +00002532/// Transforms a reference type. Note that somewhat paradoxically we
2533/// don't care whether the type itself is an l-value type or an r-value
2534/// type; we only care if the type was *written* as an l-value type
2535/// or an r-value type.
2536template<typename Derived>
2537QualType
2538TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002539 ReferenceTypeLoc TL,
2540 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002541 const ReferenceType *T = TL.getTypePtr();
2542
2543 // Note that this works with the pointee-as-written.
2544 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2545 if (PointeeType.isNull())
2546 return QualType();
2547
2548 QualType Result = TL.getType();
2549 if (getDerived().AlwaysRebuild() ||
2550 PointeeType != T->getPointeeTypeAsWritten()) {
2551 Result = getDerived().RebuildReferenceType(PointeeType,
2552 T->isSpelledAsLValue(),
2553 TL.getSigilLoc());
2554 if (Result.isNull())
2555 return QualType();
2556 }
2557
2558 // r-value references can be rebuilt as l-value references.
2559 ReferenceTypeLoc NewTL;
2560 if (isa<LValueReferenceType>(Result))
2561 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2562 else
2563 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2564 NewTL.setSigilLoc(TL.getSigilLoc());
2565
2566 return Result;
2567}
2568
Mike Stump11289f42009-09-09 15:08:12 +00002569template<typename Derived>
2570QualType
John McCall550e0c22009-10-21 00:40:46 +00002571TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002572 LValueReferenceTypeLoc TL,
2573 QualType ObjectType) {
2574 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002575}
2576
Mike Stump11289f42009-09-09 15:08:12 +00002577template<typename Derived>
2578QualType
John McCall550e0c22009-10-21 00:40:46 +00002579TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002580 RValueReferenceTypeLoc TL,
2581 QualType ObjectType) {
2582 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583}
Mike Stump11289f42009-09-09 15:08:12 +00002584
Douglas Gregord6ff3322009-08-04 16:50:30 +00002585template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002586QualType
John McCall550e0c22009-10-21 00:40:46 +00002587TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002588 MemberPointerTypeLoc TL,
2589 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002590 MemberPointerType *T = TL.getTypePtr();
2591
2592 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002593 if (PointeeType.isNull())
2594 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002595
John McCall550e0c22009-10-21 00:40:46 +00002596 // TODO: preserve source information for this.
2597 QualType ClassType
2598 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002599 if (ClassType.isNull())
2600 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002601
John McCall550e0c22009-10-21 00:40:46 +00002602 QualType Result = TL.getType();
2603 if (getDerived().AlwaysRebuild() ||
2604 PointeeType != T->getPointeeType() ||
2605 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002606 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2607 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002608 if (Result.isNull())
2609 return QualType();
2610 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002611
John McCall550e0c22009-10-21 00:40:46 +00002612 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2613 NewTL.setSigilLoc(TL.getSigilLoc());
2614
2615 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002616}
2617
Mike Stump11289f42009-09-09 15:08:12 +00002618template<typename Derived>
2619QualType
John McCall550e0c22009-10-21 00:40:46 +00002620TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002621 ConstantArrayTypeLoc TL,
2622 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002623 ConstantArrayType *T = TL.getTypePtr();
2624 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002625 if (ElementType.isNull())
2626 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002627
John McCall550e0c22009-10-21 00:40:46 +00002628 QualType Result = TL.getType();
2629 if (getDerived().AlwaysRebuild() ||
2630 ElementType != T->getElementType()) {
2631 Result = getDerived().RebuildConstantArrayType(ElementType,
2632 T->getSizeModifier(),
2633 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002634 T->getIndexTypeCVRQualifiers(),
2635 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002636 if (Result.isNull())
2637 return QualType();
2638 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002639
John McCall550e0c22009-10-21 00:40:46 +00002640 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2641 NewTL.setLBracketLoc(TL.getLBracketLoc());
2642 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002643
John McCall550e0c22009-10-21 00:40:46 +00002644 Expr *Size = TL.getSizeExpr();
2645 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002646 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002647 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2648 }
2649 NewTL.setSizeExpr(Size);
2650
2651 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002652}
Mike Stump11289f42009-09-09 15:08:12 +00002653
Douglas Gregord6ff3322009-08-04 16:50:30 +00002654template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002655QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002656 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002657 IncompleteArrayTypeLoc TL,
2658 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002659 IncompleteArrayType *T = TL.getTypePtr();
2660 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002661 if (ElementType.isNull())
2662 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002663
John McCall550e0c22009-10-21 00:40:46 +00002664 QualType Result = TL.getType();
2665 if (getDerived().AlwaysRebuild() ||
2666 ElementType != T->getElementType()) {
2667 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002668 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002669 T->getIndexTypeCVRQualifiers(),
2670 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002671 if (Result.isNull())
2672 return QualType();
2673 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002674
John McCall550e0c22009-10-21 00:40:46 +00002675 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2676 NewTL.setLBracketLoc(TL.getLBracketLoc());
2677 NewTL.setRBracketLoc(TL.getRBracketLoc());
2678 NewTL.setSizeExpr(0);
2679
2680 return Result;
2681}
2682
2683template<typename Derived>
2684QualType
2685TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002686 VariableArrayTypeLoc TL,
2687 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002688 VariableArrayType *T = TL.getTypePtr();
2689 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2690 if (ElementType.isNull())
2691 return QualType();
2692
2693 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002694 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002695
John McCalldadc5752010-08-24 06:29:42 +00002696 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002697 = getDerived().TransformExpr(T->getSizeExpr());
2698 if (SizeResult.isInvalid())
2699 return QualType();
2700
John McCallb268a282010-08-23 23:25:46 +00002701 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002702
2703 QualType Result = TL.getType();
2704 if (getDerived().AlwaysRebuild() ||
2705 ElementType != T->getElementType() ||
2706 Size != T->getSizeExpr()) {
2707 Result = getDerived().RebuildVariableArrayType(ElementType,
2708 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002709 Size,
John McCall550e0c22009-10-21 00:40:46 +00002710 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002711 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002712 if (Result.isNull())
2713 return QualType();
2714 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002715
John McCall550e0c22009-10-21 00:40:46 +00002716 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2717 NewTL.setLBracketLoc(TL.getLBracketLoc());
2718 NewTL.setRBracketLoc(TL.getRBracketLoc());
2719 NewTL.setSizeExpr(Size);
2720
2721 return Result;
2722}
2723
2724template<typename Derived>
2725QualType
2726TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002727 DependentSizedArrayTypeLoc TL,
2728 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002729 DependentSizedArrayType *T = TL.getTypePtr();
2730 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2731 if (ElementType.isNull())
2732 return QualType();
2733
2734 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002735 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002736
John McCalldadc5752010-08-24 06:29:42 +00002737 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002738 = getDerived().TransformExpr(T->getSizeExpr());
2739 if (SizeResult.isInvalid())
2740 return QualType();
2741
2742 Expr *Size = static_cast<Expr*>(SizeResult.get());
2743
2744 QualType Result = TL.getType();
2745 if (getDerived().AlwaysRebuild() ||
2746 ElementType != T->getElementType() ||
2747 Size != T->getSizeExpr()) {
2748 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2749 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002750 Size,
John McCall550e0c22009-10-21 00:40:46 +00002751 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002752 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002753 if (Result.isNull())
2754 return QualType();
2755 }
2756 else SizeResult.take();
2757
2758 // We might have any sort of array type now, but fortunately they
2759 // all have the same location layout.
2760 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2761 NewTL.setLBracketLoc(TL.getLBracketLoc());
2762 NewTL.setRBracketLoc(TL.getRBracketLoc());
2763 NewTL.setSizeExpr(Size);
2764
2765 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766}
Mike Stump11289f42009-09-09 15:08:12 +00002767
2768template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002769QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002770 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002771 DependentSizedExtVectorTypeLoc TL,
2772 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002773 DependentSizedExtVectorType *T = TL.getTypePtr();
2774
2775 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002776 QualType ElementType = getDerived().TransformType(T->getElementType());
2777 if (ElementType.isNull())
2778 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002779
Douglas Gregore922c772009-08-04 22:27:00 +00002780 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002781 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002782
John McCalldadc5752010-08-24 06:29:42 +00002783 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002784 if (Size.isInvalid())
2785 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002786
John McCall550e0c22009-10-21 00:40:46 +00002787 QualType Result = TL.getType();
2788 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002789 ElementType != T->getElementType() ||
2790 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002791 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002792 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002793 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002794 if (Result.isNull())
2795 return QualType();
2796 }
John McCall550e0c22009-10-21 00:40:46 +00002797
2798 // Result might be dependent or not.
2799 if (isa<DependentSizedExtVectorType>(Result)) {
2800 DependentSizedExtVectorTypeLoc NewTL
2801 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2802 NewTL.setNameLoc(TL.getNameLoc());
2803 } else {
2804 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2805 NewTL.setNameLoc(TL.getNameLoc());
2806 }
2807
2808 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002809}
Mike Stump11289f42009-09-09 15:08:12 +00002810
2811template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002812QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002813 VectorTypeLoc TL,
2814 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002815 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002816 QualType ElementType = getDerived().TransformType(T->getElementType());
2817 if (ElementType.isNull())
2818 return QualType();
2819
John McCall550e0c22009-10-21 00:40:46 +00002820 QualType Result = TL.getType();
2821 if (getDerived().AlwaysRebuild() ||
2822 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002823 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002824 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002825 if (Result.isNull())
2826 return QualType();
2827 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002828
John McCall550e0c22009-10-21 00:40:46 +00002829 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2830 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002831
John McCall550e0c22009-10-21 00:40:46 +00002832 return Result;
2833}
2834
2835template<typename Derived>
2836QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002837 ExtVectorTypeLoc TL,
2838 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002839 VectorType *T = TL.getTypePtr();
2840 QualType ElementType = getDerived().TransformType(T->getElementType());
2841 if (ElementType.isNull())
2842 return QualType();
2843
2844 QualType Result = TL.getType();
2845 if (getDerived().AlwaysRebuild() ||
2846 ElementType != T->getElementType()) {
2847 Result = getDerived().RebuildExtVectorType(ElementType,
2848 T->getNumElements(),
2849 /*FIXME*/ SourceLocation());
2850 if (Result.isNull())
2851 return QualType();
2852 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002853
John McCall550e0c22009-10-21 00:40:46 +00002854 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2855 NewTL.setNameLoc(TL.getNameLoc());
2856
2857 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002858}
Mike Stump11289f42009-09-09 15:08:12 +00002859
2860template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002861ParmVarDecl *
2862TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2863 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2864 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2865 if (!NewDI)
2866 return 0;
2867
2868 if (NewDI == OldDI)
2869 return OldParm;
2870 else
2871 return ParmVarDecl::Create(SemaRef.Context,
2872 OldParm->getDeclContext(),
2873 OldParm->getLocation(),
2874 OldParm->getIdentifier(),
2875 NewDI->getType(),
2876 NewDI,
2877 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002878 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002879 /* DefArg */ NULL);
2880}
2881
2882template<typename Derived>
2883bool TreeTransform<Derived>::
2884 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2885 llvm::SmallVectorImpl<QualType> &PTypes,
2886 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2887 FunctionProtoType *T = TL.getTypePtr();
2888
2889 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2890 ParmVarDecl *OldParm = TL.getArg(i);
2891
2892 QualType NewType;
2893 ParmVarDecl *NewParm;
2894
2895 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002896 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2897 if (!NewParm)
2898 return true;
2899 NewType = NewParm->getType();
2900
2901 // Deal with the possibility that we don't have a parameter
2902 // declaration for this parameter.
2903 } else {
2904 NewParm = 0;
2905
2906 QualType OldType = T->getArgType(i);
2907 NewType = getDerived().TransformType(OldType);
2908 if (NewType.isNull())
2909 return true;
2910 }
2911
2912 PTypes.push_back(NewType);
2913 PVars.push_back(NewParm);
2914 }
2915
2916 return false;
2917}
2918
2919template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002920QualType
John McCall550e0c22009-10-21 00:40:46 +00002921TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002922 FunctionProtoTypeLoc TL,
2923 QualType ObjectType) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00002924 // Transform the parameters and return type.
2925 //
2926 // We instantiate in source order, with the return type first followed by
2927 // the parameters, because users tend to expect this (even if they shouldn't
2928 // rely on it!).
2929 //
2930 // FIXME: When we implement late-specified return types, we'll need to
2931 // instantiate the return tpe *after* the parameter types in that case,
2932 // since the return type can then refer to the parameters themselves (via
2933 // decltype, sizeof, etc.).
Douglas Gregord6ff3322009-08-04 16:50:30 +00002934 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002935 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00002936 FunctionProtoType *T = TL.getTypePtr();
2937 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2938 if (ResultType.isNull())
2939 return QualType();
Douglas Gregor4afc2362010-08-31 00:26:14 +00002940
2941 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2942 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002943
John McCall550e0c22009-10-21 00:40:46 +00002944 QualType Result = TL.getType();
2945 if (getDerived().AlwaysRebuild() ||
2946 ResultType != T->getResultType() ||
2947 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2948 Result = getDerived().RebuildFunctionProtoType(ResultType,
2949 ParamTypes.data(),
2950 ParamTypes.size(),
2951 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002952 T->getTypeQuals(),
2953 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002954 if (Result.isNull())
2955 return QualType();
2956 }
Mike Stump11289f42009-09-09 15:08:12 +00002957
John McCall550e0c22009-10-21 00:40:46 +00002958 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2959 NewTL.setLParenLoc(TL.getLParenLoc());
2960 NewTL.setRParenLoc(TL.getRParenLoc());
2961 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2962 NewTL.setArg(i, ParamDecls[i]);
2963
2964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002965}
Mike Stump11289f42009-09-09 15:08:12 +00002966
Douglas Gregord6ff3322009-08-04 16:50:30 +00002967template<typename Derived>
2968QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002969 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002970 FunctionNoProtoTypeLoc TL,
2971 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002972 FunctionNoProtoType *T = TL.getTypePtr();
2973 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2974 if (ResultType.isNull())
2975 return QualType();
2976
2977 QualType Result = TL.getType();
2978 if (getDerived().AlwaysRebuild() ||
2979 ResultType != T->getResultType())
2980 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2981
2982 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2983 NewTL.setLParenLoc(TL.getLParenLoc());
2984 NewTL.setRParenLoc(TL.getRParenLoc());
2985
2986 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987}
Mike Stump11289f42009-09-09 15:08:12 +00002988
John McCallb96ec562009-12-04 22:46:56 +00002989template<typename Derived> QualType
2990TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002991 UnresolvedUsingTypeLoc TL,
2992 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002993 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002994 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002995 if (!D)
2996 return QualType();
2997
2998 QualType Result = TL.getType();
2999 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3000 Result = getDerived().RebuildUnresolvedUsingType(D);
3001 if (Result.isNull())
3002 return QualType();
3003 }
3004
3005 // We might get an arbitrary type spec type back. We should at
3006 // least always get a type spec type, though.
3007 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3008 NewTL.setNameLoc(TL.getNameLoc());
3009
3010 return Result;
3011}
3012
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003014QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003015 TypedefTypeLoc TL,
3016 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003017 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003018 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003019 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3020 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021 if (!Typedef)
3022 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003023
John McCall550e0c22009-10-21 00:40:46 +00003024 QualType Result = TL.getType();
3025 if (getDerived().AlwaysRebuild() ||
3026 Typedef != T->getDecl()) {
3027 Result = getDerived().RebuildTypedefType(Typedef);
3028 if (Result.isNull())
3029 return QualType();
3030 }
Mike Stump11289f42009-09-09 15:08:12 +00003031
John McCall550e0c22009-10-21 00:40:46 +00003032 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3033 NewTL.setNameLoc(TL.getNameLoc());
3034
3035 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003036}
Mike Stump11289f42009-09-09 15:08:12 +00003037
Douglas Gregord6ff3322009-08-04 16:50:30 +00003038template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003039QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003040 TypeOfExprTypeLoc TL,
3041 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003042 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003043 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003044
John McCalldadc5752010-08-24 06:29:42 +00003045 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003046 if (E.isInvalid())
3047 return QualType();
3048
John McCall550e0c22009-10-21 00:40:46 +00003049 QualType Result = TL.getType();
3050 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003051 E.get() != TL.getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003052 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003053 if (Result.isNull())
3054 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003055 }
John McCall550e0c22009-10-21 00:40:46 +00003056 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003057
John McCall550e0c22009-10-21 00:40:46 +00003058 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003059 NewTL.setTypeofLoc(TL.getTypeofLoc());
3060 NewTL.setLParenLoc(TL.getLParenLoc());
3061 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003062
3063 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003064}
Mike Stump11289f42009-09-09 15:08:12 +00003065
3066template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003067QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003068 TypeOfTypeLoc TL,
3069 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003070 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3071 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3072 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003073 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003074
John McCall550e0c22009-10-21 00:40:46 +00003075 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003076 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3077 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003078 if (Result.isNull())
3079 return QualType();
3080 }
Mike Stump11289f42009-09-09 15:08:12 +00003081
John McCall550e0c22009-10-21 00:40:46 +00003082 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003083 NewTL.setTypeofLoc(TL.getTypeofLoc());
3084 NewTL.setLParenLoc(TL.getLParenLoc());
3085 NewTL.setRParenLoc(TL.getRParenLoc());
3086 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003087
3088 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003089}
Mike Stump11289f42009-09-09 15:08:12 +00003090
3091template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003092QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003093 DecltypeTypeLoc TL,
3094 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003095 DecltypeType *T = TL.getTypePtr();
3096
Douglas Gregore922c772009-08-04 22:27:00 +00003097 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003098 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003099
John McCalldadc5752010-08-24 06:29:42 +00003100 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003101 if (E.isInvalid())
3102 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003103
John McCall550e0c22009-10-21 00:40:46 +00003104 QualType Result = TL.getType();
3105 if (getDerived().AlwaysRebuild() ||
3106 E.get() != T->getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003107 Result = getDerived().RebuildDecltypeType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003108 if (Result.isNull())
3109 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003110 }
John McCall550e0c22009-10-21 00:40:46 +00003111 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003112
John McCall550e0c22009-10-21 00:40:46 +00003113 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3114 NewTL.setNameLoc(TL.getNameLoc());
3115
3116 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003117}
3118
3119template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003120QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003121 RecordTypeLoc TL,
3122 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003123 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003124 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003125 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3126 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127 if (!Record)
3128 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003129
John McCall550e0c22009-10-21 00:40:46 +00003130 QualType Result = TL.getType();
3131 if (getDerived().AlwaysRebuild() ||
3132 Record != T->getDecl()) {
3133 Result = getDerived().RebuildRecordType(Record);
3134 if (Result.isNull())
3135 return QualType();
3136 }
Mike Stump11289f42009-09-09 15:08:12 +00003137
John McCall550e0c22009-10-21 00:40:46 +00003138 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3139 NewTL.setNameLoc(TL.getNameLoc());
3140
3141 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142}
Mike Stump11289f42009-09-09 15:08:12 +00003143
3144template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003145QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003146 EnumTypeLoc TL,
3147 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003148 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003149 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003150 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3151 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152 if (!Enum)
3153 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003154
John McCall550e0c22009-10-21 00:40:46 +00003155 QualType Result = TL.getType();
3156 if (getDerived().AlwaysRebuild() ||
3157 Enum != T->getDecl()) {
3158 Result = getDerived().RebuildEnumType(Enum);
3159 if (Result.isNull())
3160 return QualType();
3161 }
Mike Stump11289f42009-09-09 15:08:12 +00003162
John McCall550e0c22009-10-21 00:40:46 +00003163 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3164 NewTL.setNameLoc(TL.getNameLoc());
3165
3166 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003167}
John McCallfcc33b02009-09-05 00:15:47 +00003168
John McCalle78aac42010-03-10 03:28:59 +00003169template<typename Derived>
3170QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3171 TypeLocBuilder &TLB,
3172 InjectedClassNameTypeLoc TL,
3173 QualType ObjectType) {
3174 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3175 TL.getTypePtr()->getDecl());
3176 if (!D) return QualType();
3177
3178 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3179 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3180 return T;
3181}
3182
Mike Stump11289f42009-09-09 15:08:12 +00003183
Douglas Gregord6ff3322009-08-04 16:50:30 +00003184template<typename Derived>
3185QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003186 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003187 TemplateTypeParmTypeLoc TL,
3188 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003189 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003190}
3191
Mike Stump11289f42009-09-09 15:08:12 +00003192template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003193QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003194 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003195 SubstTemplateTypeParmTypeLoc TL,
3196 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003197 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003198}
3199
3200template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003201QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3202 const TemplateSpecializationType *TST,
3203 QualType ObjectType) {
3204 // FIXME: this entire method is a temporary workaround; callers
3205 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003206
John McCall0ad16662009-10-29 08:12:44 +00003207 // Fake up a TemplateSpecializationTypeLoc.
3208 TypeLocBuilder TLB;
3209 TemplateSpecializationTypeLoc TL
3210 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3211
John McCall0d07eb32009-10-29 18:45:58 +00003212 SourceLocation BaseLoc = getDerived().getBaseLocation();
3213
3214 TL.setTemplateNameLoc(BaseLoc);
3215 TL.setLAngleLoc(BaseLoc);
3216 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003217 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3218 const TemplateArgument &TA = TST->getArg(i);
3219 TemplateArgumentLoc TAL;
3220 getDerived().InventTemplateArgumentLoc(TA, TAL);
3221 TL.setArgLocInfo(i, TAL.getLocInfo());
3222 }
3223
3224 TypeLocBuilder IgnoredTLB;
3225 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003226}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003227
Douglas Gregorc59e5612009-10-19 22:04:39 +00003228template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003229QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003230 TypeLocBuilder &TLB,
3231 TemplateSpecializationTypeLoc TL,
3232 QualType ObjectType) {
3233 const TemplateSpecializationType *T = TL.getTypePtr();
3234
Mike Stump11289f42009-09-09 15:08:12 +00003235 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003236 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003237 if (Template.isNull())
3238 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003239
John McCall6b51f282009-11-23 01:53:49 +00003240 TemplateArgumentListInfo NewTemplateArgs;
3241 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3242 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3243
3244 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3245 TemplateArgumentLoc Loc;
3246 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003247 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003248 NewTemplateArgs.addArgument(Loc);
3249 }
Mike Stump11289f42009-09-09 15:08:12 +00003250
John McCall0ad16662009-10-29 08:12:44 +00003251 // FIXME: maybe don't rebuild if all the template arguments are the same.
3252
3253 QualType Result =
3254 getDerived().RebuildTemplateSpecializationType(Template,
3255 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003256 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003257
3258 if (!Result.isNull()) {
3259 TemplateSpecializationTypeLoc NewTL
3260 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3261 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3262 NewTL.setLAngleLoc(TL.getLAngleLoc());
3263 NewTL.setRAngleLoc(TL.getRAngleLoc());
3264 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3265 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003266 }
Mike Stump11289f42009-09-09 15:08:12 +00003267
John McCall0ad16662009-10-29 08:12:44 +00003268 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003269}
Mike Stump11289f42009-09-09 15:08:12 +00003270
3271template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003272QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003273TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3274 ElaboratedTypeLoc TL,
3275 QualType ObjectType) {
3276 ElaboratedType *T = TL.getTypePtr();
3277
3278 NestedNameSpecifier *NNS = 0;
3279 // NOTE: the qualifier in an ElaboratedType is optional.
3280 if (T->getQualifier() != 0) {
3281 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003282 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003283 ObjectType);
3284 if (!NNS)
3285 return QualType();
3286 }
Mike Stump11289f42009-09-09 15:08:12 +00003287
Abramo Bagnarad7548482010-05-19 21:37:53 +00003288 QualType NamedT;
3289 // FIXME: this test is meant to workaround a problem (failing assertion)
3290 // occurring if directly executing the code in the else branch.
3291 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3292 TemplateSpecializationTypeLoc OldNamedTL
3293 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3294 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003295 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003296 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3297 if (NamedT.isNull())
3298 return QualType();
3299 TemplateSpecializationTypeLoc NewNamedTL
3300 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3301 NewNamedTL.copy(OldNamedTL);
3302 }
3303 else {
3304 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3305 if (NamedT.isNull())
3306 return QualType();
3307 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003308
John McCall550e0c22009-10-21 00:40:46 +00003309 QualType Result = TL.getType();
3310 if (getDerived().AlwaysRebuild() ||
3311 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003312 NamedT != T->getNamedType()) {
3313 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003314 if (Result.isNull())
3315 return QualType();
3316 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317
Abramo Bagnara6150c882010-05-11 21:36:43 +00003318 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003319 NewTL.setKeywordLoc(TL.getKeywordLoc());
3320 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003321
3322 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323}
Mike Stump11289f42009-09-09 15:08:12 +00003324
3325template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003326QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3327 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003328 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003329 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003330
Douglas Gregord6ff3322009-08-04 16:50:30 +00003331 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003332 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3333 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003334 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003335 if (!NNS)
3336 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003337
John McCallc392f372010-06-11 00:33:02 +00003338 QualType Result
3339 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3340 T->getIdentifier(),
3341 TL.getKeywordLoc(),
3342 TL.getQualifierRange(),
3343 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003344 if (Result.isNull())
3345 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003346
Abramo Bagnarad7548482010-05-19 21:37:53 +00003347 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3348 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003349 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3350
Abramo Bagnarad7548482010-05-19 21:37:53 +00003351 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3352 NewTL.setKeywordLoc(TL.getKeywordLoc());
3353 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003354 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003355 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3356 NewTL.setKeywordLoc(TL.getKeywordLoc());
3357 NewTL.setQualifierRange(TL.getQualifierRange());
3358 NewTL.setNameLoc(TL.getNameLoc());
3359 }
John McCall550e0c22009-10-21 00:40:46 +00003360 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003361}
Mike Stump11289f42009-09-09 15:08:12 +00003362
Douglas Gregord6ff3322009-08-04 16:50:30 +00003363template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003364QualType TreeTransform<Derived>::
3365 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3366 DependentTemplateSpecializationTypeLoc TL,
3367 QualType ObjectType) {
3368 DependentTemplateSpecializationType *T = TL.getTypePtr();
3369
3370 NestedNameSpecifier *NNS
3371 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3372 TL.getQualifierRange(),
3373 ObjectType);
3374 if (!NNS)
3375 return QualType();
3376
3377 TemplateArgumentListInfo NewTemplateArgs;
3378 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3379 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3380
3381 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3382 TemplateArgumentLoc Loc;
3383 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3384 return QualType();
3385 NewTemplateArgs.addArgument(Loc);
3386 }
3387
Douglas Gregora5614c52010-09-08 23:56:00 +00003388 QualType Result
3389 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3390 NNS,
3391 TL.getQualifierRange(),
3392 T->getIdentifier(),
3393 TL.getNameLoc(),
3394 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003395 if (Result.isNull())
3396 return QualType();
3397
3398 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3399 QualType NamedT = ElabT->getNamedType();
3400
3401 // Copy information relevant to the template specialization.
3402 TemplateSpecializationTypeLoc NamedTL
3403 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3404 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3405 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3406 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3407 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3408
3409 // Copy information relevant to the elaborated type.
3410 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3411 NewTL.setKeywordLoc(TL.getKeywordLoc());
3412 NewTL.setQualifierRange(TL.getQualifierRange());
3413 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003414 TypeLoc NewTL(Result, TL.getOpaqueData());
3415 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003416 }
3417 return Result;
3418}
3419
3420template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003421QualType
3422TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003423 ObjCInterfaceTypeLoc TL,
3424 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003425 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003426 TLB.pushFullCopy(TL);
3427 return TL.getType();
3428}
3429
3430template<typename Derived>
3431QualType
3432TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3433 ObjCObjectTypeLoc TL,
3434 QualType ObjectType) {
3435 // ObjCObjectType is never dependent.
3436 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003437 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003438}
Mike Stump11289f42009-09-09 15:08:12 +00003439
3440template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003441QualType
3442TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003443 ObjCObjectPointerTypeLoc TL,
3444 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003445 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003446 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003447 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003448}
3449
Douglas Gregord6ff3322009-08-04 16:50:30 +00003450//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003451// Statement transformation
3452//===----------------------------------------------------------------------===//
3453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003454StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003455TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3456 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003457}
3458
3459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003460StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003461TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3462 return getDerived().TransformCompoundStmt(S, false);
3463}
3464
3465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003466StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003467TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003468 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003469 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003470 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003471 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003472 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3473 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003474 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003475 if (Result.isInvalid()) {
3476 // Immediately fail if this was a DeclStmt, since it's very
3477 // likely that this will cause problems for future statements.
3478 if (isa<DeclStmt>(*B))
3479 return StmtError();
3480
3481 // Otherwise, just keep processing substatements and fail later.
3482 SubStmtInvalid = true;
3483 continue;
3484 }
Mike Stump11289f42009-09-09 15:08:12 +00003485
Douglas Gregorebe10102009-08-20 07:17:43 +00003486 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3487 Statements.push_back(Result.takeAs<Stmt>());
3488 }
Mike Stump11289f42009-09-09 15:08:12 +00003489
John McCall1ababa62010-08-27 19:56:05 +00003490 if (SubStmtInvalid)
3491 return StmtError();
3492
Douglas Gregorebe10102009-08-20 07:17:43 +00003493 if (!getDerived().AlwaysRebuild() &&
3494 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003495 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003496
3497 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3498 move_arg(Statements),
3499 S->getRBracLoc(),
3500 IsStmtExpr);
3501}
Mike Stump11289f42009-09-09 15:08:12 +00003502
Douglas Gregorebe10102009-08-20 07:17:43 +00003503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003504StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003505TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003506 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003507 {
3508 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003509 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003510
Eli Friedman06577382009-11-19 03:14:00 +00003511 // Transform the left-hand case value.
3512 LHS = getDerived().TransformExpr(S->getLHS());
3513 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003514 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003515
Eli Friedman06577382009-11-19 03:14:00 +00003516 // Transform the right-hand case value (for the GNU case-range extension).
3517 RHS = getDerived().TransformExpr(S->getRHS());
3518 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003519 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003520 }
Mike Stump11289f42009-09-09 15:08:12 +00003521
Douglas Gregorebe10102009-08-20 07:17:43 +00003522 // Build the case statement.
3523 // Case statements are always rebuilt so that they will attached to their
3524 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003525 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003526 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003527 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003528 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003529 S->getColonLoc());
3530 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003531 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003532
Douglas Gregorebe10102009-08-20 07:17:43 +00003533 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003534 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003535 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003536 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003537
Douglas Gregorebe10102009-08-20 07:17:43 +00003538 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003539 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003540}
3541
3542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003543StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003544TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003546 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003547 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003548 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003549
Douglas Gregorebe10102009-08-20 07:17:43 +00003550 // Default statements are always rebuilt
3551 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003552 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003553}
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregorebe10102009-08-20 07:17:43 +00003555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003556StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003557TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003558 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003559 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003560 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003561
Douglas Gregorebe10102009-08-20 07:17:43 +00003562 // FIXME: Pass the real colon location in.
3563 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3564 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00003565 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003566}
Mike Stump11289f42009-09-09 15:08:12 +00003567
Douglas Gregorebe10102009-08-20 07:17:43 +00003568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003569StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003570TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003571 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003572 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003573 VarDecl *ConditionVar = 0;
3574 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003575 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003576 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003577 getDerived().TransformDefinition(
3578 S->getConditionVariable()->getLocation(),
3579 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003580 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003581 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003582 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003583 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003584
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003585 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003586 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003587
3588 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003589 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003590 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003591 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003592 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003593 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003594 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003595
John McCallb268a282010-08-23 23:25:46 +00003596 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003597 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003598 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003599
John McCallb268a282010-08-23 23:25:46 +00003600 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3601 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003602 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003603
Douglas Gregorebe10102009-08-20 07:17:43 +00003604 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003605 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003607 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003608
Douglas Gregorebe10102009-08-20 07:17:43 +00003609 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003610 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003612 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003613
Douglas Gregorebe10102009-08-20 07:17:43 +00003614 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003615 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003616 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003617 Then.get() == S->getThen() &&
3618 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003619 return SemaRef.Owned(S->Retain());
3620
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003621 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003622 Then.get(),
3623 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003624}
3625
3626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003627StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003628TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003629 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003630 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003631 VarDecl *ConditionVar = 0;
3632 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003633 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003634 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003635 getDerived().TransformDefinition(
3636 S->getConditionVariable()->getLocation(),
3637 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003638 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003639 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003640 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003641 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003642
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003643 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003644 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003645 }
Mike Stump11289f42009-09-09 15:08:12 +00003646
Douglas Gregorebe10102009-08-20 07:17:43 +00003647 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003648 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003649 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003650 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003651 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003652 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregorebe10102009-08-20 07:17:43 +00003654 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003655 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003656 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003657 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003658
Douglas Gregorebe10102009-08-20 07:17:43 +00003659 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003660 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3661 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003662}
Mike Stump11289f42009-09-09 15:08:12 +00003663
Douglas Gregorebe10102009-08-20 07:17:43 +00003664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003665StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003666TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003667 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003668 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003669 VarDecl *ConditionVar = 0;
3670 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003671 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003672 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003673 getDerived().TransformDefinition(
3674 S->getConditionVariable()->getLocation(),
3675 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003676 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003677 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003678 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003679 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003680
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003681 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003682 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003683
3684 if (S->getCond()) {
3685 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003686 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003687 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003688 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003689 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003690 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003691 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003692 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003693 }
Mike Stump11289f42009-09-09 15:08:12 +00003694
John McCallb268a282010-08-23 23:25:46 +00003695 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3696 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003697 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003698
Douglas Gregorebe10102009-08-20 07:17:43 +00003699 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003700 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003701 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003702 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003705 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003706 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003707 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003708 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003709
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003710 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003711 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003712}
Mike Stump11289f42009-09-09 15:08:12 +00003713
Douglas Gregorebe10102009-08-20 07:17:43 +00003714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003715StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003716TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003717 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003718 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003719 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003720 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003721
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003722 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003723 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003724 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003725 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003726
Douglas Gregorebe10102009-08-20 07:17:43 +00003727 if (!getDerived().AlwaysRebuild() &&
3728 Cond.get() == S->getCond() &&
3729 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003730 return SemaRef.Owned(S->Retain());
3731
John McCallb268a282010-08-23 23:25:46 +00003732 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3733 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003734 S->getRParenLoc());
3735}
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregorebe10102009-08-20 07:17:43 +00003737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003738StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003739TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003740 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003741 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003742 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003743 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003744
Douglas Gregorebe10102009-08-20 07:17:43 +00003745 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003746 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003747 VarDecl *ConditionVar = 0;
3748 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003749 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003750 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003751 getDerived().TransformDefinition(
3752 S->getConditionVariable()->getLocation(),
3753 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003754 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003755 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003756 } else {
3757 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003758
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003759 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003760 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003761
3762 if (S->getCond()) {
3763 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003764 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003765 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003766 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003767 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003768 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003769
John McCallb268a282010-08-23 23:25:46 +00003770 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003771 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003772 }
Mike Stump11289f42009-09-09 15:08:12 +00003773
John McCallb268a282010-08-23 23:25:46 +00003774 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3775 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003776 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003777
Douglas Gregorebe10102009-08-20 07:17:43 +00003778 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003779 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003780 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003781 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003782
John McCallb268a282010-08-23 23:25:46 +00003783 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3784 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003785 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003786
Douglas Gregorebe10102009-08-20 07:17:43 +00003787 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003788 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003789 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003790 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003791
Douglas Gregorebe10102009-08-20 07:17:43 +00003792 if (!getDerived().AlwaysRebuild() &&
3793 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003794 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003795 Inc.get() == S->getInc() &&
3796 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003797 return SemaRef.Owned(S->Retain());
3798
Douglas Gregorebe10102009-08-20 07:17:43 +00003799 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003800 Init.get(), FullCond, ConditionVar,
3801 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003802}
3803
3804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003805StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003806TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003807 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003808 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003809 S->getLabel());
3810}
3811
3812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003813StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003814TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003815 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003816 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003817 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003818
Douglas Gregorebe10102009-08-20 07:17:43 +00003819 if (!getDerived().AlwaysRebuild() &&
3820 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003821 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003822
3823 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003824 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003825}
3826
3827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003828StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003829TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3830 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003831}
Mike Stump11289f42009-09-09 15:08:12 +00003832
Douglas Gregorebe10102009-08-20 07:17:43 +00003833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003834StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003835TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3836 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003837}
Mike Stump11289f42009-09-09 15:08:12 +00003838
Douglas Gregorebe10102009-08-20 07:17:43 +00003839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003840StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003841TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003842 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003843 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003844 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003845
Mike Stump11289f42009-09-09 15:08:12 +00003846 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003847 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003848 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003849}
Mike Stump11289f42009-09-09 15:08:12 +00003850
Douglas Gregorebe10102009-08-20 07:17:43 +00003851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003852StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003853TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003854 bool DeclChanged = false;
3855 llvm::SmallVector<Decl *, 4> Decls;
3856 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3857 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003858 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3859 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003860 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003861 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003862
Douglas Gregorebe10102009-08-20 07:17:43 +00003863 if (Transformed != *D)
3864 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003865
Douglas Gregorebe10102009-08-20 07:17:43 +00003866 Decls.push_back(Transformed);
3867 }
Mike Stump11289f42009-09-09 15:08:12 +00003868
Douglas Gregorebe10102009-08-20 07:17:43 +00003869 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003870 return SemaRef.Owned(S->Retain());
3871
3872 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003873 S->getStartLoc(), S->getEndLoc());
3874}
Mike Stump11289f42009-09-09 15:08:12 +00003875
Douglas Gregorebe10102009-08-20 07:17:43 +00003876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003877StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003878TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003879 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003880 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003881}
3882
3883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003884StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003885TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003886
John McCall37ad5512010-08-23 06:44:23 +00003887 ASTOwningVector<Expr*> Constraints(getSema());
3888 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003889 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003890
John McCalldadc5752010-08-24 06:29:42 +00003891 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003892 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003893
3894 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003895
Anders Carlssonaaeef072010-01-24 05:50:09 +00003896 // Go through the outputs.
3897 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003898 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003899
Anders Carlssonaaeef072010-01-24 05:50:09 +00003900 // No need to transform the constraint literal.
3901 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003902
Anders Carlssonaaeef072010-01-24 05:50:09 +00003903 // Transform the output expr.
3904 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003905 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003906 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003907 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003908
Anders Carlssonaaeef072010-01-24 05:50:09 +00003909 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003910
John McCallb268a282010-08-23 23:25:46 +00003911 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003912 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003913
Anders Carlssonaaeef072010-01-24 05:50:09 +00003914 // Go through the inputs.
3915 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003916 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003917
Anders Carlssonaaeef072010-01-24 05:50:09 +00003918 // No need to transform the constraint literal.
3919 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003920
Anders Carlssonaaeef072010-01-24 05:50:09 +00003921 // Transform the input expr.
3922 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003923 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003924 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003925 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003926
Anders Carlssonaaeef072010-01-24 05:50:09 +00003927 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003928
John McCallb268a282010-08-23 23:25:46 +00003929 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003930 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003931
Anders Carlssonaaeef072010-01-24 05:50:09 +00003932 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3933 return SemaRef.Owned(S->Retain());
3934
3935 // Go through the clobbers.
3936 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3937 Clobbers.push_back(S->getClobber(I)->Retain());
3938
3939 // No need to transform the asm string literal.
3940 AsmString = SemaRef.Owned(S->getAsmString());
3941
3942 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3943 S->isSimple(),
3944 S->isVolatile(),
3945 S->getNumOutputs(),
3946 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003947 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003948 move_arg(Constraints),
3949 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003950 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003951 move_arg(Clobbers),
3952 S->getRParenLoc(),
3953 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003954}
3955
3956
3957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003958StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003959TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003960 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00003961 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003962 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003963 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003964
Douglas Gregor96c79492010-04-23 22:50:49 +00003965 // Transform the @catch statements (if present).
3966 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003967 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00003968 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00003969 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003970 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003971 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003972 if (Catch.get() != S->getCatchStmt(I))
3973 AnyCatchChanged = true;
3974 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003975 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003976
Douglas Gregor306de2f2010-04-22 23:59:56 +00003977 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00003978 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00003979 if (S->getFinallyStmt()) {
3980 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3981 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003982 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00003983 }
3984
3985 // If nothing changed, just retain this statement.
3986 if (!getDerived().AlwaysRebuild() &&
3987 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003988 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003989 Finally.get() == S->getFinallyStmt())
3990 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003991
Douglas Gregor306de2f2010-04-22 23:59:56 +00003992 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00003993 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3994 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003995}
Mike Stump11289f42009-09-09 15:08:12 +00003996
Douglas Gregorebe10102009-08-20 07:17:43 +00003997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003998StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003999TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004000 // Transform the @catch parameter, if there is one.
4001 VarDecl *Var = 0;
4002 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4003 TypeSourceInfo *TSInfo = 0;
4004 if (FromVar->getTypeSourceInfo()) {
4005 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4006 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004007 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004008 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004009
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004010 QualType T;
4011 if (TSInfo)
4012 T = TSInfo->getType();
4013 else {
4014 T = getDerived().TransformType(FromVar->getType());
4015 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004016 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004017 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004018
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004019 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4020 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004021 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004022 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004023
John McCalldadc5752010-08-24 06:29:42 +00004024 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004025 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004026 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004027
4028 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004029 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004030 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004031}
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregorebe10102009-08-20 07:17:43 +00004033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004034StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004035TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004036 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004037 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004038 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004039 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004040
Douglas Gregor306de2f2010-04-22 23:59:56 +00004041 // If nothing changed, just retain this statement.
4042 if (!getDerived().AlwaysRebuild() &&
4043 Body.get() == S->getFinallyBody())
4044 return SemaRef.Owned(S->Retain());
4045
4046 // Build a new statement.
4047 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004048 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004049}
Mike Stump11289f42009-09-09 15:08:12 +00004050
Douglas Gregorebe10102009-08-20 07:17:43 +00004051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004052StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004053TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004054 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004055 if (S->getThrowExpr()) {
4056 Operand = getDerived().TransformExpr(S->getThrowExpr());
4057 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004058 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004059 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004060
Douglas Gregor2900c162010-04-22 21:44:01 +00004061 if (!getDerived().AlwaysRebuild() &&
4062 Operand.get() == S->getThrowExpr())
4063 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004064
John McCallb268a282010-08-23 23:25:46 +00004065 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004066}
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregorebe10102009-08-20 07:17:43 +00004068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004069StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004070TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004071 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004072 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004073 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004074 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004075 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004076
Douglas Gregor6148de72010-04-22 22:01:21 +00004077 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004078 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004079 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004080 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004081
Douglas Gregor6148de72010-04-22 22:01:21 +00004082 // If nothing change, just retain the current statement.
4083 if (!getDerived().AlwaysRebuild() &&
4084 Object.get() == S->getSynchExpr() &&
4085 Body.get() == S->getSynchBody())
4086 return SemaRef.Owned(S->Retain());
4087
4088 // Build a new statement.
4089 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004090 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004091}
4092
4093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004094StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004095TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004096 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004097 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004098 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004099 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004100 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004101
Douglas Gregorf68a5082010-04-22 23:10:45 +00004102 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004103 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004104 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004105 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004106
Douglas Gregorf68a5082010-04-22 23:10:45 +00004107 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004108 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004109 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004110 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004111
Douglas Gregorf68a5082010-04-22 23:10:45 +00004112 // If nothing changed, just retain this statement.
4113 if (!getDerived().AlwaysRebuild() &&
4114 Element.get() == S->getElement() &&
4115 Collection.get() == S->getCollection() &&
4116 Body.get() == S->getBody())
4117 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004118
Douglas Gregorf68a5082010-04-22 23:10:45 +00004119 // Build a new statement.
4120 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4121 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004122 Element.get(),
4123 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004124 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004125 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004126}
4127
4128
4129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004130StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004131TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4132 // Transform the exception declaration, if any.
4133 VarDecl *Var = 0;
4134 if (S->getExceptionDecl()) {
4135 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004136 TypeSourceInfo *T = getDerived().TransformType(
4137 ExceptionDecl->getTypeSourceInfo());
4138 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004139 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004141 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004142 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004143 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004144 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004145 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004146 }
Mike Stump11289f42009-09-09 15:08:12 +00004147
Douglas Gregorebe10102009-08-20 07:17:43 +00004148 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004149 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004150 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004151 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004152
Douglas Gregorebe10102009-08-20 07:17:43 +00004153 if (!getDerived().AlwaysRebuild() &&
4154 !Var &&
4155 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004156 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004157
4158 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4159 Var,
John McCallb268a282010-08-23 23:25:46 +00004160 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004161}
Mike Stump11289f42009-09-09 15:08:12 +00004162
Douglas Gregorebe10102009-08-20 07:17:43 +00004163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004164StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004165TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4166 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004167 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004168 = getDerived().TransformCompoundStmt(S->getTryBlock());
4169 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004170 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004171
Douglas Gregorebe10102009-08-20 07:17:43 +00004172 // Transform the handlers.
4173 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004174 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004175 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004176 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004177 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4178 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004179 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004180
Douglas Gregorebe10102009-08-20 07:17:43 +00004181 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4182 Handlers.push_back(Handler.takeAs<Stmt>());
4183 }
Mike Stump11289f42009-09-09 15:08:12 +00004184
Douglas Gregorebe10102009-08-20 07:17:43 +00004185 if (!getDerived().AlwaysRebuild() &&
4186 TryBlock.get() == S->getTryBlock() &&
4187 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004188 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004189
John McCallb268a282010-08-23 23:25:46 +00004190 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004191 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004192}
Mike Stump11289f42009-09-09 15:08:12 +00004193
Douglas Gregorebe10102009-08-20 07:17:43 +00004194//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004195// Expression transformation
4196//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004198ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004199TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004200 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004201}
Mike Stump11289f42009-09-09 15:08:12 +00004202
4203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004204ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004205TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004206 NestedNameSpecifier *Qualifier = 0;
4207 if (E->getQualifier()) {
4208 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004209 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004210 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004211 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004212 }
John McCallce546572009-12-08 09:08:17 +00004213
4214 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004215 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4216 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004217 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004218 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004219
John McCall815039a2010-08-17 21:27:17 +00004220 DeclarationNameInfo NameInfo = E->getNameInfo();
4221 if (NameInfo.getName()) {
4222 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4223 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004224 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004225 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004226
4227 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004228 Qualifier == E->getQualifier() &&
4229 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004230 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004231 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004232
4233 // Mark it referenced in the new context regardless.
4234 // FIXME: this is a bit instantiation-specific.
4235 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4236
Mike Stump11289f42009-09-09 15:08:12 +00004237 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004238 }
John McCallce546572009-12-08 09:08:17 +00004239
4240 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004241 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004242 TemplateArgs = &TransArgs;
4243 TransArgs.setLAngleLoc(E->getLAngleLoc());
4244 TransArgs.setRAngleLoc(E->getRAngleLoc());
4245 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4246 TemplateArgumentLoc Loc;
4247 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004248 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004249 TransArgs.addArgument(Loc);
4250 }
4251 }
4252
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004253 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004254 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004255}
Mike Stump11289f42009-09-09 15:08:12 +00004256
Douglas Gregora16548e2009-08-11 05:31:07 +00004257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004259TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004260 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004261}
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregora16548e2009-08-11 05:31:07 +00004263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004265TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004266 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004267}
Mike Stump11289f42009-09-09 15:08:12 +00004268
Douglas Gregora16548e2009-08-11 05:31:07 +00004269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004270ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004271TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004272 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004273}
Mike Stump11289f42009-09-09 15:08:12 +00004274
Douglas Gregora16548e2009-08-11 05:31:07 +00004275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004276ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004277TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004278 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004279}
Mike Stump11289f42009-09-09 15:08:12 +00004280
Douglas Gregora16548e2009-08-11 05:31:07 +00004281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004283TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004284 return SemaRef.Owned(E->Retain());
4285}
4286
4287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004289TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004290 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregora16548e2009-08-11 05:31:07 +00004294 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004295 return SemaRef.Owned(E->Retain());
4296
John McCallb268a282010-08-23 23:25:46 +00004297 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004298 E->getRParen());
4299}
4300
Mike Stump11289f42009-09-09 15:08:12 +00004301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004303TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004304 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004305 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004306 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004307
Douglas Gregora16548e2009-08-11 05:31:07 +00004308 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004309 return SemaRef.Owned(E->Retain());
4310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4312 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004313 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004314}
Mike Stump11289f42009-09-09 15:08:12 +00004315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004317ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004318TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4319 // Transform the type.
4320 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4321 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004322 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004323
Douglas Gregor882211c2010-04-28 22:16:22 +00004324 // Transform all of the components into components similar to what the
4325 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004326 // FIXME: It would be slightly more efficient in the non-dependent case to
4327 // just map FieldDecls, rather than requiring the rebuilder to look for
4328 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004329 // template code that we don't care.
4330 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004331 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004332 typedef OffsetOfExpr::OffsetOfNode Node;
4333 llvm::SmallVector<Component, 4> Components;
4334 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4335 const Node &ON = E->getComponent(I);
4336 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004337 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004338 Comp.LocStart = ON.getRange().getBegin();
4339 Comp.LocEnd = ON.getRange().getEnd();
4340 switch (ON.getKind()) {
4341 case Node::Array: {
4342 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004343 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004344 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004345 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004346
Douglas Gregor882211c2010-04-28 22:16:22 +00004347 ExprChanged = ExprChanged || Index.get() != FromIndex;
4348 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004349 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004350 break;
4351 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004352
Douglas Gregor882211c2010-04-28 22:16:22 +00004353 case Node::Field:
4354 case Node::Identifier:
4355 Comp.isBrackets = false;
4356 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004357 if (!Comp.U.IdentInfo)
4358 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004359
Douglas Gregor882211c2010-04-28 22:16:22 +00004360 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004361
Douglas Gregord1702062010-04-29 00:18:15 +00004362 case Node::Base:
4363 // Will be recomputed during the rebuild.
4364 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004365 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004366
Douglas Gregor882211c2010-04-28 22:16:22 +00004367 Components.push_back(Comp);
4368 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004369
Douglas Gregor882211c2010-04-28 22:16:22 +00004370 // If nothing changed, retain the existing expression.
4371 if (!getDerived().AlwaysRebuild() &&
4372 Type == E->getTypeSourceInfo() &&
4373 !ExprChanged)
4374 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004375
Douglas Gregor882211c2010-04-28 22:16:22 +00004376 // Build a new offsetof expression.
4377 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4378 Components.data(), Components.size(),
4379 E->getRParenLoc());
4380}
4381
4382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004384TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004385 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004386 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004387
John McCallbcd03502009-12-07 02:54:59 +00004388 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004389 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004390 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004391
John McCall4c98fd82009-11-04 07:28:41 +00004392 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004394
John McCall4c98fd82009-11-04 07:28:41 +00004395 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004396 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 E->getSourceRange());
4398 }
Mike Stump11289f42009-09-09 15:08:12 +00004399
John McCalldadc5752010-08-24 06:29:42 +00004400 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004401 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 // C++0x [expr.sizeof]p1:
4403 // The operand is either an expression, which is an unevaluated operand
4404 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004405 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004406
Douglas Gregora16548e2009-08-11 05:31:07 +00004407 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4408 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004410
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4412 return SemaRef.Owned(E->Retain());
4413 }
Mike Stump11289f42009-09-09 15:08:12 +00004414
John McCallb268a282010-08-23 23:25:46 +00004415 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 E->isSizeOf(),
4417 E->getSourceRange());
4418}
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregora16548e2009-08-11 05:31:07 +00004420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004422TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004423 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004424 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004426
John McCalldadc5752010-08-24 06:29:42 +00004427 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004430
4431
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 if (!getDerived().AlwaysRebuild() &&
4433 LHS.get() == E->getLHS() &&
4434 RHS.get() == E->getRHS())
4435 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004436
John McCallb268a282010-08-23 23:25:46 +00004437 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004439 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 E->getRBracketLoc());
4441}
Mike Stump11289f42009-09-09 15:08:12 +00004442
4443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004444ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004445TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004447 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004449 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004450
4451 // Transform arguments.
4452 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004453 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004454 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004455 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004458
Mike Stump11289f42009-09-09 15:08:12 +00004459 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004460 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 }
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 if (!getDerived().AlwaysRebuild() &&
4464 Callee.get() == E->getCallee() &&
4465 !ArgChanged)
4466 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004467
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004469 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004471 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004472 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004473 E->getRParenLoc());
4474}
Mike Stump11289f42009-09-09 15:08:12 +00004475
4476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004478TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004479 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004480 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004483 NestedNameSpecifier *Qualifier = 0;
4484 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004485 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004486 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004487 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004488 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004489 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004490 }
Mike Stump11289f42009-09-09 15:08:12 +00004491
Eli Friedman2cfcef62009-12-04 06:40:45 +00004492 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004493 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4494 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004495 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004497
John McCall16df1e52010-03-30 21:47:33 +00004498 NamedDecl *FoundDecl = E->getFoundDecl();
4499 if (FoundDecl == E->getMemberDecl()) {
4500 FoundDecl = Member;
4501 } else {
4502 FoundDecl = cast_or_null<NamedDecl>(
4503 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4504 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004505 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004506 }
4507
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 if (!getDerived().AlwaysRebuild() &&
4509 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004510 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004511 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004512 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004513 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004514
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004515 // Mark it referenced in the new context regardless.
4516 // FIXME: this is a bit instantiation-specific.
4517 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004518 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004519 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004520
John McCall6b51f282009-11-23 01:53:49 +00004521 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004522 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004523 TransArgs.setLAngleLoc(E->getLAngleLoc());
4524 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004525 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004526 TemplateArgumentLoc Loc;
4527 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004528 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004529 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004530 }
4531 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004532
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 // FIXME: Bogus source location for the operator
4534 SourceLocation FakeOperatorLoc
4535 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4536
John McCall38836f02010-01-15 08:34:02 +00004537 // FIXME: to do this check properly, we will need to preserve the
4538 // first-qualifier-in-scope here, just in case we had a dependent
4539 // base (and therefore couldn't do the check) and a
4540 // nested-name-qualifier (and therefore could do the lookup).
4541 NamedDecl *FirstQualifierInScope = 0;
4542
John McCallb268a282010-08-23 23:25:46 +00004543 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004545 Qualifier,
4546 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004547 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004548 Member,
John McCall16df1e52010-03-30 21:47:33 +00004549 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004550 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004551 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004552 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004553}
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregora16548e2009-08-11 05:31:07 +00004555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004556ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004557TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004558 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004561
John McCalldadc5752010-08-24 06:29:42 +00004562 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 if (!getDerived().AlwaysRebuild() &&
4567 LHS.get() == E->getLHS() &&
4568 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004569 return SemaRef.Owned(E->Retain());
4570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004572 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004573}
4574
Mike Stump11289f42009-09-09 15:08:12 +00004575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004576ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004577TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004578 CompoundAssignOperator *E) {
4579 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004580}
Mike Stump11289f42009-09-09 15:08:12 +00004581
Douglas Gregora16548e2009-08-11 05:31:07 +00004582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004583ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004584TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004585 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004586 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004588
John McCalldadc5752010-08-24 06:29:42 +00004589 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004592
John McCalldadc5752010-08-24 06:29:42 +00004593 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004594 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004596
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 if (!getDerived().AlwaysRebuild() &&
4598 Cond.get() == E->getCond() &&
4599 LHS.get() == E->getLHS() &&
4600 RHS.get() == E->getRHS())
4601 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004602
John McCallb268a282010-08-23 23:25:46 +00004603 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004604 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004605 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004606 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004607 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004608}
Mike Stump11289f42009-09-09 15:08:12 +00004609
4610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004611ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004612TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004613 // Implicit casts are eliminated during transformation, since they
4614 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004615 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004616}
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregora16548e2009-08-11 05:31:07 +00004618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004620TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004621 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4622 if (!Type)
4623 return ExprError();
4624
John McCalldadc5752010-08-24 06:29:42 +00004625 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004626 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004628 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004629
Douglas Gregora16548e2009-08-11 05:31:07 +00004630 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004631 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004632 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004633 return SemaRef.Owned(E->Retain());
4634
John McCall97513962010-01-15 18:39:57 +00004635 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004636 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004637 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004638 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004639}
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregora16548e2009-08-11 05:31:07 +00004641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004642ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004643TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004644 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4645 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4646 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004648
John McCalldadc5752010-08-24 06:29:42 +00004649 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004652
Douglas Gregora16548e2009-08-11 05:31:07 +00004653 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004654 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004656 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004657
John McCall5d7aa7f2010-01-19 22:33:45 +00004658 // Note: the expression type doesn't necessarily match the
4659 // type-as-written, but that's okay, because it should always be
4660 // derivable from the initializer.
4661
John McCalle15bbff2010-01-18 19:35:47 +00004662 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004663 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004664 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004665}
Mike Stump11289f42009-09-09 15:08:12 +00004666
Douglas Gregora16548e2009-08-11 05:31:07 +00004667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004669TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004670 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004673
Douglas Gregora16548e2009-08-11 05:31:07 +00004674 if (!getDerived().AlwaysRebuild() &&
4675 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004676 return SemaRef.Owned(E->Retain());
4677
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004679 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004680 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004681 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 E->getAccessorLoc(),
4683 E->getAccessor());
4684}
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregora16548e2009-08-11 05:31:07 +00004686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004687ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004688TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004690
John McCall37ad5512010-08-23 06:44:23 +00004691 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004693 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004694 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004698 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 }
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004702 return SemaRef.Owned(E->Retain());
4703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004705 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004706}
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregora16548e2009-08-11 05:31:07 +00004708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004709ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004710TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregorebe10102009-08-20 07:17:43 +00004713 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004714 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004715 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregorebe10102009-08-20 07:17:43 +00004718 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004719 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004720 bool ExprChanged = false;
4721 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4722 DEnd = E->designators_end();
4723 D != DEnd; ++D) {
4724 if (D->isFieldDesignator()) {
4725 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4726 D->getDotLoc(),
4727 D->getFieldLoc()));
4728 continue;
4729 }
Mike Stump11289f42009-09-09 15:08:12 +00004730
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004732 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004733 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004735
4736 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregora16548e2009-08-11 05:31:07 +00004739 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4740 ArrayExprs.push_back(Index.release());
4741 continue;
4742 }
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004745 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004746 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4747 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004749
John McCalldadc5752010-08-24 06:29:42 +00004750 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004753
4754 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 End.get(),
4756 D->getLBracketLoc(),
4757 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4760 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 ArrayExprs.push_back(Start.release());
4763 ArrayExprs.push_back(End.release());
4764 }
Mike Stump11289f42009-09-09 15:08:12 +00004765
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 if (!getDerived().AlwaysRebuild() &&
4767 Init.get() == E->getInit() &&
4768 !ExprChanged)
4769 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4772 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004773 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004774}
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregora16548e2009-08-11 05:31:07 +00004776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004777ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004778TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004779 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004780 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004781
Douglas Gregor3da3c062009-10-28 00:29:27 +00004782 // FIXME: Will we ever have proper type location here? Will we actually
4783 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 QualType T = getDerived().TransformType(E->getType());
4785 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 if (!getDerived().AlwaysRebuild() &&
4789 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004790 return SemaRef.Owned(E->Retain());
4791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 return getDerived().RebuildImplicitValueInitExpr(T);
4793}
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004796ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004797TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004798 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4799 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004800 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004801
John McCalldadc5752010-08-24 06:29:42 +00004802 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004807 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004808 SubExpr.get() == E->getSubExpr())
4809 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004810
John McCallb268a282010-08-23 23:25:46 +00004811 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004812 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004813}
4814
4815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004816ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004817TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004819 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004821 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004822 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004823 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004824
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004826 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 }
Mike Stump11289f42009-09-09 15:08:12 +00004828
Douglas Gregora16548e2009-08-11 05:31:07 +00004829 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4830 move_arg(Inits),
4831 E->getRParenLoc());
4832}
Mike Stump11289f42009-09-09 15:08:12 +00004833
Douglas Gregora16548e2009-08-11 05:31:07 +00004834/// \brief Transform an address-of-label expression.
4835///
4836/// By default, the transformation of an address-of-label expression always
4837/// rebuilds the expression, so that the label identifier can be resolved to
4838/// the corresponding label statement by semantic analysis.
4839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004841TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4843 E->getLabel());
4844}
Mike Stump11289f42009-09-09 15:08:12 +00004845
4846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004847ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004848TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004849 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004850 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4851 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 if (!getDerived().AlwaysRebuild() &&
4855 SubStmt.get() == E->getSubStmt())
4856 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004857
4858 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004859 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004860 E->getRParenLoc());
4861}
Mike Stump11289f42009-09-09 15:08:12 +00004862
Douglas Gregora16548e2009-08-11 05:31:07 +00004863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004865TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004866 TypeSourceInfo *TInfo1;
4867 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004868
4869 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4870 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregor7058c262010-08-10 14:27:00 +00004873 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4874 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004875 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004876
4877 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004878 TInfo1 == E->getArgTInfo1() &&
4879 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004880 return SemaRef.Owned(E->Retain());
4881
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004883 TInfo1, TInfo2,
4884 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004885}
Mike Stump11289f42009-09-09 15:08:12 +00004886
Douglas Gregora16548e2009-08-11 05:31:07 +00004887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004888ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004889TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004890 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004891 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004893
John McCalldadc5752010-08-24 06:29:42 +00004894 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004897
John McCalldadc5752010-08-24 06:29:42 +00004898 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004901
Douglas Gregora16548e2009-08-11 05:31:07 +00004902 if (!getDerived().AlwaysRebuild() &&
4903 Cond.get() == E->getCond() &&
4904 LHS.get() == E->getLHS() &&
4905 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004906 return SemaRef.Owned(E->Retain());
4907
Douglas Gregora16548e2009-08-11 05:31:07 +00004908 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004909 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004910 E->getRParenLoc());
4911}
Mike Stump11289f42009-09-09 15:08:12 +00004912
Douglas Gregora16548e2009-08-11 05:31:07 +00004913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004915TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004916 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004917}
4918
4919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004920ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004921TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004922 switch (E->getOperator()) {
4923 case OO_New:
4924 case OO_Delete:
4925 case OO_Array_New:
4926 case OO_Array_Delete:
4927 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004928 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004929
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004930 case OO_Call: {
4931 // This is a call to an object's operator().
4932 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4933
4934 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004935 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004936 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004937 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004938
4939 // FIXME: Poor location information
4940 SourceLocation FakeLParenLoc
4941 = SemaRef.PP.getLocForEndOfToken(
4942 static_cast<Expr *>(Object.get())->getLocEnd());
4943
4944 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004945 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004946 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004947 if (getDerived().DropCallArgument(E->getArg(I)))
4948 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004949
John McCalldadc5752010-08-24 06:29:42 +00004950 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004951 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004952 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004953
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004954 Args.push_back(Arg.release());
4955 }
4956
John McCallb268a282010-08-23 23:25:46 +00004957 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004958 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004959 E->getLocEnd());
4960 }
4961
4962#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4963 case OO_##Name:
4964#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4965#include "clang/Basic/OperatorKinds.def"
4966 case OO_Subscript:
4967 // Handled below.
4968 break;
4969
4970 case OO_Conditional:
4971 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00004972 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004973
4974 case OO_None:
4975 case NUM_OVERLOADED_OPERATORS:
4976 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00004977 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004978 }
4979
John McCalldadc5752010-08-24 06:29:42 +00004980 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004981 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004983
John McCalldadc5752010-08-24 06:29:42 +00004984 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004985 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004986 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004987
John McCalldadc5752010-08-24 06:29:42 +00004988 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00004989 if (E->getNumArgs() == 2) {
4990 Second = getDerived().TransformExpr(E->getArg(1));
4991 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004992 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004993 }
Mike Stump11289f42009-09-09 15:08:12 +00004994
Douglas Gregora16548e2009-08-11 05:31:07 +00004995 if (!getDerived().AlwaysRebuild() &&
4996 Callee.get() == E->getCallee() &&
4997 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004998 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4999 return SemaRef.Owned(E->Retain());
5000
Douglas Gregora16548e2009-08-11 05:31:07 +00005001 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5002 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005003 Callee.get(),
5004 First.get(),
5005 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005006}
Mike Stump11289f42009-09-09 15:08:12 +00005007
Douglas Gregora16548e2009-08-11 05:31:07 +00005008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005010TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5011 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005012}
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregora16548e2009-08-11 05:31:07 +00005014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005015ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005016TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005017 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5018 if (!Type)
5019 return ExprError();
5020
John McCalldadc5752010-08-24 06:29:42 +00005021 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005022 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005024 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005027 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005029 return SemaRef.Owned(E->Retain());
5030
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005032 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005033 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5034 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5035 SourceLocation FakeRParenLoc
5036 = SemaRef.PP.getLocForEndOfToken(
5037 E->getSubExpr()->getSourceRange().getEnd());
5038 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005039 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005041 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 FakeRAngleLoc,
5043 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005044 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 FakeRParenLoc);
5046}
Mike Stump11289f42009-09-09 15:08:12 +00005047
Douglas Gregora16548e2009-08-11 05:31:07 +00005048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005049ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005050TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5051 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005052}
Mike Stump11289f42009-09-09 15:08:12 +00005053
5054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005056TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5057 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005058}
5059
Douglas Gregora16548e2009-08-11 05:31:07 +00005060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005061ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005062TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005063 CXXReinterpretCastExpr *E) {
5064 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005065}
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005069TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5070 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005071}
Mike Stump11289f42009-09-09 15:08:12 +00005072
Douglas Gregora16548e2009-08-11 05:31:07 +00005073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005074ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005075TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005076 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005077 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5078 if (!Type)
5079 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005080
John McCalldadc5752010-08-24 06:29:42 +00005081 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005082 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005083 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005084 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005087 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005088 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005089 return SemaRef.Owned(E->Retain());
5090
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005091 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005092 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005093 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 E->getRParenLoc());
5095}
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>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005101 TypeSourceInfo *TInfo
5102 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5103 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005107 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005108 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005109
Douglas Gregor9da64192010-04-26 22:37:10 +00005110 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5111 E->getLocStart(),
5112 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 E->getLocEnd());
5114 }
Mike Stump11289f42009-09-09 15:08:12 +00005115
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 // We don't know whether the expression is potentially evaluated until
5117 // after we perform semantic analysis, so the expression is potentially
5118 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005119 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005120 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005121
John McCalldadc5752010-08-24 06:29:42 +00005122 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005125
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 if (!getDerived().AlwaysRebuild() &&
5127 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005128 return SemaRef.Owned(E->Retain());
5129
Douglas Gregor9da64192010-04-26 22:37:10 +00005130 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5131 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005132 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 E->getLocEnd());
5134}
5135
5136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005137ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005138TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5139 if (E->isTypeOperand()) {
5140 TypeSourceInfo *TInfo
5141 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5142 if (!TInfo)
5143 return ExprError();
5144
5145 if (!getDerived().AlwaysRebuild() &&
5146 TInfo == E->getTypeOperandSourceInfo())
5147 return SemaRef.Owned(E->Retain());
5148
5149 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5150 E->getLocStart(),
5151 TInfo,
5152 E->getLocEnd());
5153 }
5154
5155 // We don't know whether the expression is potentially evaluated until
5156 // after we perform semantic analysis, so the expression is potentially
5157 // potentially evaluated.
5158 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5159
5160 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5161 if (SubExpr.isInvalid())
5162 return ExprError();
5163
5164 if (!getDerived().AlwaysRebuild() &&
5165 SubExpr.get() == E->getExprOperand())
5166 return SemaRef.Owned(E->Retain());
5167
5168 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5169 E->getLocStart(),
5170 SubExpr.get(),
5171 E->getLocEnd());
5172}
5173
5174template<typename Derived>
5175ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005176TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005177 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005178}
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregora16548e2009-08-11 05:31:07 +00005180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005181ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005182TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005183 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005184 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005185}
Mike Stump11289f42009-09-09 15:08:12 +00005186
Douglas Gregora16548e2009-08-11 05:31:07 +00005187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005188ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005189TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005190 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5191 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5192 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005193
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005194 if (!getDerived().AlwaysRebuild() && T == E->getType())
Douglas Gregora16548e2009-08-11 05:31:07 +00005195 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregorb15af892010-01-07 23:12:05 +00005197 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005198}
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregora16548e2009-08-11 05:31:07 +00005200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005202TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005203 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005206
Douglas Gregora16548e2009-08-11 05:31:07 +00005207 if (!getDerived().AlwaysRebuild() &&
5208 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005209 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005210
John McCallb268a282010-08-23 23:25:46 +00005211 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005212}
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregora16548e2009-08-11 05:31:07 +00005214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005216TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005217 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005218 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5219 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005220 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005221 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005222
Chandler Carruth794da4c2010-02-08 06:42:49 +00005223 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005224 Param == E->getParam())
5225 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregor033f6752009-12-23 23:03:06 +00005227 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
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
Douglas Gregor2b88c112010-09-08 00:15:04 +00005232TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5233 CXXScalarValueInitExpr *E) {
5234 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5235 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005236 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005237
Douglas Gregora16548e2009-08-11 05:31:07 +00005238 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005239 T == E->getTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005240 return SemaRef.Owned(E->Retain());
5241
Douglas Gregor2b88c112010-09-08 00:15:04 +00005242 return getDerived().RebuildCXXScalarValueInitExpr(T,
5243 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005244 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005245}
Mike Stump11289f42009-09-09 15:08:12 +00005246
Douglas Gregora16548e2009-08-11 05:31:07 +00005247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005249TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005250 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005251 TypeSourceInfo *AllocTypeInfo
5252 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5253 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005255
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005257 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregora16548e2009-08-11 05:31:07 +00005261 // Transform the placement arguments (if any).
5262 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005263 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005264 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005265 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005266 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005267 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005268
Douglas Gregora16548e2009-08-11 05:31:07 +00005269 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5270 PlacementArgs.push_back(Arg.take());
5271 }
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregorebe10102009-08-20 07:17:43 +00005273 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005274 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005275 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005276 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5277 break;
5278
John McCalldadc5752010-08-24 06:29:42 +00005279 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005280 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregora16548e2009-08-11 05:31:07 +00005283 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5284 ConstructorArgs.push_back(Arg.take());
5285 }
Mike Stump11289f42009-09-09 15:08:12 +00005286
Douglas Gregord2d9da02010-02-26 00:38:10 +00005287 // Transform constructor, new operator, and delete operator.
5288 CXXConstructorDecl *Constructor = 0;
5289 if (E->getConstructor()) {
5290 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005291 getDerived().TransformDecl(E->getLocStart(),
5292 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005293 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005295 }
5296
5297 FunctionDecl *OperatorNew = 0;
5298 if (E->getOperatorNew()) {
5299 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005300 getDerived().TransformDecl(E->getLocStart(),
5301 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005302 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005303 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005304 }
5305
5306 FunctionDecl *OperatorDelete = 0;
5307 if (E->getOperatorDelete()) {
5308 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005309 getDerived().TransformDecl(E->getLocStart(),
5310 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005311 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005312 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005313 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005314
Douglas Gregora16548e2009-08-11 05:31:07 +00005315 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005316 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005318 Constructor == E->getConstructor() &&
5319 OperatorNew == E->getOperatorNew() &&
5320 OperatorDelete == E->getOperatorDelete() &&
5321 !ArgumentChanged) {
5322 // Mark any declarations we need as referenced.
5323 // FIXME: instantiation-specific.
5324 if (Constructor)
5325 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5326 if (OperatorNew)
5327 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5328 if (OperatorDelete)
5329 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005330 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005331 }
Mike Stump11289f42009-09-09 15:08:12 +00005332
Douglas Gregor0744ef62010-09-07 21:49:58 +00005333 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005334 if (!ArraySize.get()) {
5335 // If no array size was specified, but the new expression was
5336 // instantiated with an array type (e.g., "new T" where T is
5337 // instantiated with "int[4]"), extract the outer bound from the
5338 // array type as our array size. We do this with constant and
5339 // dependently-sized array types.
5340 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5341 if (!ArrayT) {
5342 // Do nothing
5343 } else if (const ConstantArrayType *ConsArrayT
5344 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005345 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005346 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5347 ConsArrayT->getSize(),
5348 SemaRef.Context.getSizeType(),
5349 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005350 AllocType = ConsArrayT->getElementType();
5351 } else if (const DependentSizedArrayType *DepArrayT
5352 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5353 if (DepArrayT->getSizeExpr()) {
5354 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5355 AllocType = DepArrayT->getElementType();
5356 }
5357 }
5358 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005359
Douglas Gregora16548e2009-08-11 05:31:07 +00005360 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5361 E->isGlobalNew(),
5362 /*FIXME:*/E->getLocStart(),
5363 move_arg(PlacementArgs),
5364 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005365 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005366 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005367 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005368 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005369 /*FIXME:*/E->getLocStart(),
5370 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005371 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005372}
Mike Stump11289f42009-09-09 15:08:12 +00005373
Douglas Gregora16548e2009-08-11 05:31:07 +00005374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005376TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005377 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005378 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005380
Douglas Gregord2d9da02010-02-26 00:38:10 +00005381 // Transform the delete operator, if known.
5382 FunctionDecl *OperatorDelete = 0;
5383 if (E->getOperatorDelete()) {
5384 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005385 getDerived().TransformDecl(E->getLocStart(),
5386 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005387 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005388 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005389 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005390
Douglas Gregora16548e2009-08-11 05:31:07 +00005391 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005392 Operand.get() == E->getArgument() &&
5393 OperatorDelete == E->getOperatorDelete()) {
5394 // Mark any declarations we need as referenced.
5395 // FIXME: instantiation-specific.
5396 if (OperatorDelete)
5397 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005398 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005399 }
Mike Stump11289f42009-09-09 15:08:12 +00005400
Douglas Gregora16548e2009-08-11 05:31:07 +00005401 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5402 E->isGlobalDelete(),
5403 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005404 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005405}
Mike Stump11289f42009-09-09 15:08:12 +00005406
Douglas Gregora16548e2009-08-11 05:31:07 +00005407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005408ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005409TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005410 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005411 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005412 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005413 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005414
John McCallba7bf592010-08-24 05:47:05 +00005415 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005416 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005417 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005418 E->getOperatorLoc(),
5419 E->isArrow()? tok::arrow : tok::period,
5420 ObjectTypePtr,
5421 MayBePseudoDestructor);
5422 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005424
John McCallba7bf592010-08-24 05:47:05 +00005425 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005426 NestedNameSpecifier *Qualifier
5427 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005428 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005429 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005430 if (E->getQualifier() && !Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005432
Douglas Gregor678f90d2010-02-25 01:56:36 +00005433 PseudoDestructorTypeStorage Destroyed;
5434 if (E->getDestroyedTypeInfo()) {
5435 TypeSourceInfo *DestroyedTypeInfo
5436 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5437 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005438 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005439 Destroyed = DestroyedTypeInfo;
5440 } else if (ObjectType->isDependentType()) {
5441 // We aren't likely to be able to resolve the identifier down to a type
5442 // now anyway, so just retain the identifier.
5443 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5444 E->getDestroyedTypeLoc());
5445 } else {
5446 // Look for a destructor known with the given name.
5447 CXXScopeSpec SS;
5448 if (Qualifier) {
5449 SS.setScopeRep(Qualifier);
5450 SS.setRange(E->getQualifierRange());
5451 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005452
John McCallba7bf592010-08-24 05:47:05 +00005453 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005454 *E->getDestroyedTypeIdentifier(),
5455 E->getDestroyedTypeLoc(),
5456 /*Scope=*/0,
5457 SS, ObjectTypePtr,
5458 false);
5459 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005460 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005461
Douglas Gregor678f90d2010-02-25 01:56:36 +00005462 Destroyed
5463 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5464 E->getDestroyedTypeLoc());
5465 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005466
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005467 TypeSourceInfo *ScopeTypeInfo = 0;
5468 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005469 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005470 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005471 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005472 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005473 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005474
John McCallb268a282010-08-23 23:25:46 +00005475 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005476 E->getOperatorLoc(),
5477 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005478 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005479 E->getQualifierRange(),
5480 ScopeTypeInfo,
5481 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005482 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005483 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005484}
Mike Stump11289f42009-09-09 15:08:12 +00005485
Douglas Gregorad8a3362009-09-04 17:36:40 +00005486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005487ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005488TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005489 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005490 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5491
5492 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5493 Sema::LookupOrdinaryName);
5494
5495 // Transform all the decls.
5496 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5497 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005498 NamedDecl *InstD = static_cast<NamedDecl*>(
5499 getDerived().TransformDecl(Old->getNameLoc(),
5500 *I));
John McCall84d87672009-12-10 09:41:52 +00005501 if (!InstD) {
5502 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5503 // This can happen because of dependent hiding.
5504 if (isa<UsingShadowDecl>(*I))
5505 continue;
5506 else
John McCallfaf5fb42010-08-26 23:41:50 +00005507 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005508 }
John McCalle66edc12009-11-24 19:00:30 +00005509
5510 // Expand using declarations.
5511 if (isa<UsingDecl>(InstD)) {
5512 UsingDecl *UD = cast<UsingDecl>(InstD);
5513 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5514 E = UD->shadow_end(); I != E; ++I)
5515 R.addDecl(*I);
5516 continue;
5517 }
5518
5519 R.addDecl(InstD);
5520 }
5521
5522 // Resolve a kind, but don't do any further analysis. If it's
5523 // ambiguous, the callee needs to deal with it.
5524 R.resolveKind();
5525
5526 // Rebuild the nested-name qualifier, if present.
5527 CXXScopeSpec SS;
5528 NestedNameSpecifier *Qualifier = 0;
5529 if (Old->getQualifier()) {
5530 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005531 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005532 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005533 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005534
John McCalle66edc12009-11-24 19:00:30 +00005535 SS.setScopeRep(Qualifier);
5536 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005537 }
5538
Douglas Gregor9262f472010-04-27 18:19:34 +00005539 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005540 CXXRecordDecl *NamingClass
5541 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5542 Old->getNameLoc(),
5543 Old->getNamingClass()));
5544 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005546
Douglas Gregorda7be082010-04-27 16:10:10 +00005547 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005548 }
5549
5550 // If we have no template arguments, it's a normal declaration name.
5551 if (!Old->hasExplicitTemplateArgs())
5552 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5553
5554 // If we have template arguments, rebuild them, then rebuild the
5555 // templateid expression.
5556 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5557 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5558 TemplateArgumentLoc Loc;
5559 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005560 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005561 TransArgs.addArgument(Loc);
5562 }
5563
5564 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5565 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005566}
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005569ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005570TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005571 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5572 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005574
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005576 T == E->getQueriedTypeSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005578
Mike Stump11289f42009-09-09 15:08:12 +00005579 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005580 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 T,
5582 E->getLocEnd());
5583}
Mike Stump11289f42009-09-09 15:08:12 +00005584
Douglas Gregora16548e2009-08-11 05:31:07 +00005585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005586ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005587TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005588 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005589 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005590 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005591 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005592 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005593 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005594
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005595 DeclarationNameInfo NameInfo
5596 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5597 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005599
John McCalle66edc12009-11-24 19:00:30 +00005600 if (!E->hasExplicitTemplateArgs()) {
5601 if (!getDerived().AlwaysRebuild() &&
5602 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005603 // Note: it is sufficient to compare the Name component of NameInfo:
5604 // if name has not changed, DNLoc has not changed either.
5605 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005606 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005607
John McCalle66edc12009-11-24 19:00:30 +00005608 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5609 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005610 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005611 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005612 }
John McCall6b51f282009-11-23 01:53:49 +00005613
5614 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005615 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005616 TemplateArgumentLoc Loc;
5617 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005618 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005619 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005620 }
5621
John McCalle66edc12009-11-24 19:00:30 +00005622 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5623 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005624 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005625 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005626}
5627
5628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005629ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005630TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005631 // CXXConstructExprs are always implicit, so when we have a
5632 // 1-argument construction we just transform that argument.
5633 if (E->getNumArgs() == 1 ||
5634 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5635 return getDerived().TransformExpr(E->getArg(0));
5636
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5638
5639 QualType T = getDerived().TransformType(E->getType());
5640 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005641 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005642
5643 CXXConstructorDecl *Constructor
5644 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005645 getDerived().TransformDecl(E->getLocStart(),
5646 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005647 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005651 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005652 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005653 ArgEnd = E->arg_end();
5654 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005655 if (getDerived().DropCallArgument(*Arg)) {
5656 ArgumentChanged = true;
5657 break;
5658 }
5659
John McCalldadc5752010-08-24 06:29:42 +00005660 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005661 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005665 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 }
5667
5668 if (!getDerived().AlwaysRebuild() &&
5669 T == E->getType() &&
5670 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005671 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005672 // Mark the constructor as referenced.
5673 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005674 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005676 }
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregordb121ba2009-12-14 16:27:04 +00005678 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5679 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005680 move_arg(Args),
5681 E->requiresZeroInitialization(),
5682 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005683}
Mike Stump11289f42009-09-09 15:08:12 +00005684
Douglas Gregora16548e2009-08-11 05:31:07 +00005685/// \brief Transform a C++ temporary-binding expression.
5686///
Douglas Gregor363b1512009-12-24 18:51:59 +00005687/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5688/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005690ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005691TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005692 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005693}
Mike Stump11289f42009-09-09 15:08:12 +00005694
5695/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005696/// be destroyed after the expression is evaluated.
5697///
Douglas Gregor363b1512009-12-24 18:51:59 +00005698/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5699/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005700template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005701ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005702TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005703 CXXExprWithTemporaries *E) {
5704 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005705}
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregora16548e2009-08-11 05:31:07 +00005707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005708ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005709TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005710 CXXTemporaryObjectExpr *E) {
5711 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5712 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregora16548e2009-08-11 05:31:07 +00005715 CXXConstructorDecl *Constructor
5716 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005717 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005718 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005720 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregora16548e2009-08-11 05:31:07 +00005722 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005723 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005724 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005725 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 ArgEnd = E->arg_end();
5727 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005728 if (getDerived().DropCallArgument(*Arg)) {
5729 ArgumentChanged = true;
5730 break;
5731 }
5732
John McCalldadc5752010-08-24 06:29:42 +00005733 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005736
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5738 Args.push_back((Expr *)TransArg.release());
5739 }
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005742 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005743 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005744 !ArgumentChanged) {
5745 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005746 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005747 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005748 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005749
5750 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5751 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005752 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 E->getLocEnd());
5754}
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>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005759 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005760 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 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005765 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005766 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5767 ArgEnd = E->arg_end();
5768 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005769 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005771 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005772
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005774 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005775 }
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005778 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005780 return SemaRef.Owned(E->Retain());
5781
Douglas Gregora16548e2009-08-11 05:31:07 +00005782 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005783 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005784 E->getLParenLoc(),
5785 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005786 E->getRParenLoc());
5787}
Mike Stump11289f42009-09-09 15:08:12 +00005788
Douglas Gregora16548e2009-08-11 05:31:07 +00005789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005790ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005791TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005792 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005794 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005795 Expr *OldBase;
5796 QualType BaseType;
5797 QualType ObjectType;
5798 if (!E->isImplicitAccess()) {
5799 OldBase = E->getBase();
5800 Base = getDerived().TransformExpr(OldBase);
5801 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005803
John McCall2d74de92009-12-01 22:10:20 +00005804 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005805 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005806 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005807 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005808 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005809 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005810 ObjectTy,
5811 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005812 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005813 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005814
John McCallba7bf592010-08-24 05:47:05 +00005815 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005816 BaseType = ((Expr*) Base.get())->getType();
5817 } else {
5818 OldBase = 0;
5819 BaseType = getDerived().TransformType(E->getBaseType());
5820 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5821 }
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005823 // Transform the first part of the nested-name-specifier that qualifies
5824 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005825 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005826 = getDerived().TransformFirstQualifierInScope(
5827 E->getFirstQualifierFoundInScope(),
5828 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005829
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005830 NestedNameSpecifier *Qualifier = 0;
5831 if (E->getQualifier()) {
5832 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5833 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005834 ObjectType,
5835 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005836 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005837 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005838 }
Mike Stump11289f42009-09-09 15:08:12 +00005839
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005840 DeclarationNameInfo NameInfo
5841 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5842 ObjectType);
5843 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005845
John McCall2d74de92009-12-01 22:10:20 +00005846 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005847 // This is a reference to a member without an explicitly-specified
5848 // template argument list. Optimize for this common case.
5849 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005850 Base.get() == OldBase &&
5851 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005852 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005853 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005854 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005855 return SemaRef.Owned(E->Retain());
5856
John McCallb268a282010-08-23 23:25:46 +00005857 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005858 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005859 E->isArrow(),
5860 E->getOperatorLoc(),
5861 Qualifier,
5862 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005863 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005864 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005865 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005866 }
5867
John McCall6b51f282009-11-23 01:53:49 +00005868 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005869 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005870 TemplateArgumentLoc Loc;
5871 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005872 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005873 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005874 }
Mike Stump11289f42009-09-09 15:08:12 +00005875
John McCallb268a282010-08-23 23:25:46 +00005876 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005877 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005878 E->isArrow(),
5879 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005880 Qualifier,
5881 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005882 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005883 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005884 &TransArgs);
5885}
5886
5887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005888ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005889TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005890 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005891 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005892 QualType BaseType;
5893 if (!Old->isImplicitAccess()) {
5894 Base = getDerived().TransformExpr(Old->getBase());
5895 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005896 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005897 BaseType = ((Expr*) Base.get())->getType();
5898 } else {
5899 BaseType = getDerived().TransformType(Old->getBaseType());
5900 }
John McCall10eae182009-11-30 22:42:35 +00005901
5902 NestedNameSpecifier *Qualifier = 0;
5903 if (Old->getQualifier()) {
5904 Qualifier
5905 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005906 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005907 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005908 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005909 }
5910
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005911 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005912 Sema::LookupOrdinaryName);
5913
5914 // Transform all the decls.
5915 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5916 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005917 NamedDecl *InstD = static_cast<NamedDecl*>(
5918 getDerived().TransformDecl(Old->getMemberLoc(),
5919 *I));
John McCall84d87672009-12-10 09:41:52 +00005920 if (!InstD) {
5921 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5922 // This can happen because of dependent hiding.
5923 if (isa<UsingShadowDecl>(*I))
5924 continue;
5925 else
John McCallfaf5fb42010-08-26 23:41:50 +00005926 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005927 }
John McCall10eae182009-11-30 22:42:35 +00005928
5929 // Expand using declarations.
5930 if (isa<UsingDecl>(InstD)) {
5931 UsingDecl *UD = cast<UsingDecl>(InstD);
5932 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5933 E = UD->shadow_end(); I != E; ++I)
5934 R.addDecl(*I);
5935 continue;
5936 }
5937
5938 R.addDecl(InstD);
5939 }
5940
5941 R.resolveKind();
5942
Douglas Gregor9262f472010-04-27 18:19:34 +00005943 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005944 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005945 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005946 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005947 Old->getMemberLoc(),
5948 Old->getNamingClass()));
5949 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005950 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005951
Douglas Gregorda7be082010-04-27 16:10:10 +00005952 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005953 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005954
John McCall10eae182009-11-30 22:42:35 +00005955 TemplateArgumentListInfo TransArgs;
5956 if (Old->hasExplicitTemplateArgs()) {
5957 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5958 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5959 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5960 TemplateArgumentLoc Loc;
5961 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5962 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005964 TransArgs.addArgument(Loc);
5965 }
5966 }
John McCall38836f02010-01-15 08:34:02 +00005967
5968 // FIXME: to do this check properly, we will need to preserve the
5969 // first-qualifier-in-scope here, just in case we had a dependent
5970 // base (and therefore couldn't do the check) and a
5971 // nested-name-qualifier (and therefore could do the lookup).
5972 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005973
John McCallb268a282010-08-23 23:25:46 +00005974 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005975 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005976 Old->getOperatorLoc(),
5977 Old->isArrow(),
5978 Qualifier,
5979 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005980 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005981 R,
5982 (Old->hasExplicitTemplateArgs()
5983 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005984}
5985
5986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005987ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00005988TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
5989 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
5990 if (SubExpr.isInvalid())
5991 return ExprError();
5992
5993 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
5994 return SemaRef.Owned(E->Retain());
5995
5996 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
5997}
5998
5999template<typename Derived>
6000ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006001TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006002 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006003}
6004
Mike Stump11289f42009-09-09 15:08:12 +00006005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006006ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006008 TypeSourceInfo *EncodedTypeInfo
6009 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6010 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006012
Douglas Gregora16548e2009-08-11 05:31:07 +00006013 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006014 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006015 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006016
6017 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006018 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 E->getRParenLoc());
6020}
Mike Stump11289f42009-09-09 15:08:12 +00006021
Douglas Gregora16548e2009-08-11 05:31:07 +00006022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006024TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006025 // Transform arguments.
6026 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006027 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006028 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006029 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006030 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006031 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006032
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006033 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006034 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006035 }
6036
6037 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6038 // Class message: transform the receiver type.
6039 TypeSourceInfo *ReceiverTypeInfo
6040 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6041 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006043
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006044 // If nothing changed, just retain the existing message send.
6045 if (!getDerived().AlwaysRebuild() &&
6046 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6047 return SemaRef.Owned(E->Retain());
6048
6049 // Build a new class message send.
6050 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6051 E->getSelector(),
6052 E->getMethodDecl(),
6053 E->getLeftLoc(),
6054 move_arg(Args),
6055 E->getRightLoc());
6056 }
6057
6058 // Instance message: transform the receiver
6059 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6060 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006061 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006062 = getDerived().TransformExpr(E->getInstanceReceiver());
6063 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006064 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006065
6066 // If nothing changed, just retain the existing message send.
6067 if (!getDerived().AlwaysRebuild() &&
6068 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6069 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006070
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006071 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006072 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006073 E->getSelector(),
6074 E->getMethodDecl(),
6075 E->getLeftLoc(),
6076 move_arg(Args),
6077 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006078}
6079
Mike Stump11289f42009-09-09 15:08:12 +00006080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006081ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006082TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006083 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006084}
6085
Mike Stump11289f42009-09-09 15:08:12 +00006086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006088TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006089 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006090}
6091
Mike Stump11289f42009-09-09 15:08:12 +00006092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006093ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006094TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006095 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006096 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006097 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006098 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006099
6100 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006101
Douglas Gregord51d90d2010-04-26 20:11:03 +00006102 // If nothing changed, just retain the existing expression.
6103 if (!getDerived().AlwaysRebuild() &&
6104 Base.get() == E->getBase())
6105 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006106
John McCallb268a282010-08-23 23:25:46 +00006107 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006108 E->getLocation(),
6109 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006110}
6111
Mike Stump11289f42009-09-09 15:08:12 +00006112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006114TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006115 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006116 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006117 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006119
Douglas Gregor9faee212010-04-26 20:47:02 +00006120 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006121
Douglas Gregor9faee212010-04-26 20:47:02 +00006122 // If nothing changed, just retain the existing expression.
6123 if (!getDerived().AlwaysRebuild() &&
6124 Base.get() == E->getBase())
6125 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006126
John McCallb268a282010-08-23 23:25:46 +00006127 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006128 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006129}
6130
Mike Stump11289f42009-09-09 15:08:12 +00006131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006132ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006133TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006134 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006135 // If this implicit setter/getter refers to class methods, it cannot have any
6136 // dependent parts. Just retain the existing declaration.
6137 if (E->getInterfaceDecl())
6138 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006139
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006140 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006141 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006142 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006144
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006145 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006146
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006147 // If nothing changed, just retain the existing expression.
6148 if (!getDerived().AlwaysRebuild() &&
6149 Base.get() == E->getBase())
6150 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006151
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006152 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6153 E->getGetterMethod(),
6154 E->getType(),
6155 E->getSetterMethod(),
6156 E->getLocation(),
John McCallb268a282010-08-23 23:25:46 +00006157 Base.get());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006158
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>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006164 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006165 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006166}
6167
Mike Stump11289f42009-09-09 15:08:12 +00006168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006169ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006170TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006171 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006172 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006173 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006174 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006175
Douglas Gregord51d90d2010-04-26 20:11:03 +00006176 // If nothing changed, just retain the existing expression.
6177 if (!getDerived().AlwaysRebuild() &&
6178 Base.get() == E->getBase())
6179 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006180
John McCallb268a282010-08-23 23:25:46 +00006181 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006182 E->isArrow());
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
John McCall47f29ea2009-12-08 09:21:05 +00006187TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006188 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006189 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006190 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006191 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006192 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregora16548e2009-08-11 05:31:07 +00006195 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006196 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006197 }
Mike Stump11289f42009-09-09 15:08:12 +00006198
Douglas Gregora16548e2009-08-11 05:31:07 +00006199 if (!getDerived().AlwaysRebuild() &&
6200 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006201 return SemaRef.Owned(E->Retain());
6202
Douglas Gregora16548e2009-08-11 05:31:07 +00006203 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6204 move_arg(SubExprs),
6205 E->getRParenLoc());
6206}
6207
Mike Stump11289f42009-09-09 15:08:12 +00006208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006209ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006210TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006211 SourceLocation CaretLoc(E->getExprLoc());
6212
6213 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6214 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6215 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6216 llvm::SmallVector<ParmVarDecl*, 4> Params;
6217 llvm::SmallVector<QualType, 4> ParamTypes;
6218
6219 // Parameter substitution.
6220 const BlockDecl *BD = E->getBlockDecl();
6221 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6222 EN = BD->param_end(); P != EN; ++P) {
6223 ParmVarDecl *OldParm = (*P);
6224 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6225 QualType NewType = NewParm->getType();
6226 Params.push_back(NewParm);
6227 ParamTypes.push_back(NewParm->getType());
6228 }
6229
6230 const FunctionType *BExprFunctionType = E->getFunctionType();
6231 QualType BExprResultType = BExprFunctionType->getResultType();
6232 if (!BExprResultType.isNull()) {
6233 if (!BExprResultType->isDependentType())
6234 CurBlock->ReturnType = BExprResultType;
6235 else if (BExprResultType != SemaRef.Context.DependentTy)
6236 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6237 }
6238
6239 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006240 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006241 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006242 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006243 // Set the parameters on the block decl.
6244 if (!Params.empty())
6245 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6246
6247 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6248 CurBlock->ReturnType,
6249 ParamTypes.data(),
6250 ParamTypes.size(),
6251 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006252 0,
6253 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006254
6255 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006256 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006257}
6258
Mike Stump11289f42009-09-09 15:08:12 +00006259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006260ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006261TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006262 NestedNameSpecifier *Qualifier = 0;
6263
6264 ValueDecl *ND
6265 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6266 E->getDecl()));
6267 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006268 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006269
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006270 if (!getDerived().AlwaysRebuild() &&
6271 ND == E->getDecl()) {
6272 // Mark it referenced in the new context regardless.
6273 // FIXME: this is a bit instantiation-specific.
6274 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6275
6276 return SemaRef.Owned(E->Retain());
6277 }
6278
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006279 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006280 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006281 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006282}
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregora16548e2009-08-11 05:31:07 +00006284//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006285// Type reconstruction
6286//===----------------------------------------------------------------------===//
6287
Mike Stump11289f42009-09-09 15:08:12 +00006288template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006289QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6290 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006291 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006292 getDerived().getBaseEntity());
6293}
6294
Mike Stump11289f42009-09-09 15:08:12 +00006295template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006296QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6297 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006298 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006299 getDerived().getBaseEntity());
6300}
6301
Mike Stump11289f42009-09-09 15:08:12 +00006302template<typename Derived>
6303QualType
John McCall70dd5f62009-10-30 00:06:24 +00006304TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6305 bool WrittenAsLValue,
6306 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006307 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006308 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006309}
6310
6311template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006312QualType
John McCall70dd5f62009-10-30 00:06:24 +00006313TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6314 QualType ClassType,
6315 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006316 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006317 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006318}
6319
6320template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006321QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006322TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6323 ArrayType::ArraySizeModifier SizeMod,
6324 const llvm::APInt *Size,
6325 Expr *SizeExpr,
6326 unsigned IndexTypeQuals,
6327 SourceRange BracketsRange) {
6328 if (SizeExpr || !Size)
6329 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6330 IndexTypeQuals, BracketsRange,
6331 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006332
6333 QualType Types[] = {
6334 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6335 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6336 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006337 };
6338 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6339 QualType SizeType;
6340 for (unsigned I = 0; I != NumTypes; ++I)
6341 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6342 SizeType = Types[I];
6343 break;
6344 }
Mike Stump11289f42009-09-09 15:08:12 +00006345
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006346 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6347 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006348 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006349 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006350 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006351}
Mike Stump11289f42009-09-09 15:08:12 +00006352
Douglas Gregord6ff3322009-08-04 16:50:30 +00006353template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006354QualType
6355TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006356 ArrayType::ArraySizeModifier SizeMod,
6357 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006358 unsigned IndexTypeQuals,
6359 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006360 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006361 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006362}
6363
6364template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006365QualType
Mike Stump11289f42009-09-09 15:08:12 +00006366TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006367 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006368 unsigned IndexTypeQuals,
6369 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006370 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006371 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006372}
Mike Stump11289f42009-09-09 15:08:12 +00006373
Douglas Gregord6ff3322009-08-04 16:50:30 +00006374template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006375QualType
6376TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006377 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006378 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006379 unsigned IndexTypeQuals,
6380 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006381 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006382 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006383 IndexTypeQuals, BracketsRange);
6384}
6385
6386template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006387QualType
6388TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006389 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006390 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391 unsigned IndexTypeQuals,
6392 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006393 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006394 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006395 IndexTypeQuals, BracketsRange);
6396}
6397
6398template<typename Derived>
6399QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006400 unsigned NumElements,
6401 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006402 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006403 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006404}
Mike Stump11289f42009-09-09 15:08:12 +00006405
Douglas Gregord6ff3322009-08-04 16:50:30 +00006406template<typename Derived>
6407QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6408 unsigned NumElements,
6409 SourceLocation AttributeLoc) {
6410 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6411 NumElements, true);
6412 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006413 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6414 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006415 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006416}
Mike Stump11289f42009-09-09 15:08:12 +00006417
Douglas Gregord6ff3322009-08-04 16:50:30 +00006418template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006419QualType
6420TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006421 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006422 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006423 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006424}
Mike Stump11289f42009-09-09 15:08:12 +00006425
Douglas Gregord6ff3322009-08-04 16:50:30 +00006426template<typename Derived>
6427QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006428 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006429 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006430 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006431 unsigned Quals,
6432 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006433 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006434 Quals,
6435 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006436 getDerived().getBaseEntity(),
6437 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438}
Mike Stump11289f42009-09-09 15:08:12 +00006439
Douglas Gregord6ff3322009-08-04 16:50:30 +00006440template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006441QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6442 return SemaRef.Context.getFunctionNoProtoType(T);
6443}
6444
6445template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006446QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6447 assert(D && "no decl found");
6448 if (D->isInvalidDecl()) return QualType();
6449
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006450 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006451 TypeDecl *Ty;
6452 if (isa<UsingDecl>(D)) {
6453 UsingDecl *Using = cast<UsingDecl>(D);
6454 assert(Using->isTypeName() &&
6455 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6456
6457 // A valid resolved using typename decl points to exactly one type decl.
6458 assert(++Using->shadow_begin() == Using->shadow_end());
6459 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006460
John McCallb96ec562009-12-04 22:46:56 +00006461 } else {
6462 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6463 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6464 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6465 }
6466
6467 return SemaRef.Context.getTypeDeclType(Ty);
6468}
6469
6470template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006471QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6472 return SemaRef.BuildTypeofExprType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006473}
6474
6475template<typename Derived>
6476QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6477 return SemaRef.Context.getTypeOfType(Underlying);
6478}
6479
6480template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006481QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6482 return SemaRef.BuildDecltypeType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006483}
6484
6485template<typename Derived>
6486QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006487 TemplateName Template,
6488 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006489 const TemplateArgumentListInfo &TemplateArgs) {
6490 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006491}
Mike Stump11289f42009-09-09 15:08:12 +00006492
Douglas Gregor1135c352009-08-06 05:28:30 +00006493template<typename Derived>
6494NestedNameSpecifier *
6495TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6496 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006497 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006498 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006499 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006500 CXXScopeSpec SS;
6501 // FIXME: The source location information is all wrong.
6502 SS.setRange(Range);
6503 SS.setScopeRep(Prefix);
6504 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006505 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006506 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006507 ObjectType,
6508 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006509 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006510}
6511
6512template<typename Derived>
6513NestedNameSpecifier *
6514TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6515 SourceRange Range,
6516 NamespaceDecl *NS) {
6517 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6518}
6519
6520template<typename Derived>
6521NestedNameSpecifier *
6522TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6523 SourceRange Range,
6524 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006525 QualType T) {
6526 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006527 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006528 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006529 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6530 T.getTypePtr());
6531 }
Mike Stump11289f42009-09-09 15:08:12 +00006532
Douglas Gregor1135c352009-08-06 05:28:30 +00006533 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6534 return 0;
6535}
Mike Stump11289f42009-09-09 15:08:12 +00006536
Douglas Gregor71dc5092009-08-06 06:41:21 +00006537template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006538TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006539TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6540 bool TemplateKW,
6541 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006542 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006543 Template);
6544}
6545
6546template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006547TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006548TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006549 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006550 const IdentifierInfo &II,
6551 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006552 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006553 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006554 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006555 UnqualifiedId Name;
6556 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006557 Sema::TemplateTy Template;
6558 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6559 /*FIXME:*/getDerived().getBaseLocation(),
6560 SS,
6561 Name,
John McCallba7bf592010-08-24 05:47:05 +00006562 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006563 /*EnteringContext=*/false,
6564 Template);
6565 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006566}
Mike Stump11289f42009-09-09 15:08:12 +00006567
Douglas Gregora16548e2009-08-11 05:31:07 +00006568template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006569TemplateName
6570TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6571 OverloadedOperatorKind Operator,
6572 QualType ObjectType) {
6573 CXXScopeSpec SS;
6574 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6575 SS.setScopeRep(Qualifier);
6576 UnqualifiedId Name;
6577 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6578 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6579 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006580 Sema::TemplateTy Template;
6581 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006582 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006583 SS,
6584 Name,
John McCallba7bf592010-08-24 05:47:05 +00006585 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006586 /*EnteringContext=*/false,
6587 Template);
6588 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006589}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006590
Douglas Gregor71395fa2009-11-04 00:56:37 +00006591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006592ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006593TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6594 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006595 Expr *OrigCallee,
6596 Expr *First,
6597 Expr *Second) {
6598 Expr *Callee = OrigCallee->IgnoreParenCasts();
6599 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006600
Douglas Gregora16548e2009-08-11 05:31:07 +00006601 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006602 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006603 if (!First->getType()->isOverloadableType() &&
6604 !Second->getType()->isOverloadableType())
6605 return getSema().CreateBuiltinArraySubscriptExpr(First,
6606 Callee->getLocStart(),
6607 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006608 } else if (Op == OO_Arrow) {
6609 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006610 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6611 } else if (Second == 0 || isPostIncDec) {
6612 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006613 // The argument is not of overloadable type, so try to create a
6614 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006615 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006616 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006617
John McCallb268a282010-08-23 23:25:46 +00006618 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006619 }
6620 } else {
John McCallb268a282010-08-23 23:25:46 +00006621 if (!First->getType()->isOverloadableType() &&
6622 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006623 // Neither of the arguments is an overloadable type, so try to
6624 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006625 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006626 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006627 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006628 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006630
Douglas Gregora16548e2009-08-11 05:31:07 +00006631 return move(Result);
6632 }
6633 }
Mike Stump11289f42009-09-09 15:08:12 +00006634
6635 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006636 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006637 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006638
John McCallb268a282010-08-23 23:25:46 +00006639 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006640 assert(ULE->requiresADL());
6641
6642 // FIXME: Do we have to check
6643 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006644 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006645 } else {
John McCallb268a282010-08-23 23:25:46 +00006646 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006647 }
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregora16548e2009-08-11 05:31:07 +00006649 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006650 Expr *Args[2] = { First, Second };
6651 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006652
Douglas Gregora16548e2009-08-11 05:31:07 +00006653 // Create the overloaded operator invocation for unary operators.
6654 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006655 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006656 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006657 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006658 }
Mike Stump11289f42009-09-09 15:08:12 +00006659
Sebastian Redladba46e2009-10-29 20:17:01 +00006660 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006661 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006662 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006663 First,
6664 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006665
Douglas Gregora16548e2009-08-11 05:31:07 +00006666 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006667 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006668 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006669 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6670 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006672
Mike Stump11289f42009-09-09 15:08:12 +00006673 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006674}
Mike Stump11289f42009-09-09 15:08:12 +00006675
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006677ExprResult
John McCallb268a282010-08-23 23:25:46 +00006678TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006679 SourceLocation OperatorLoc,
6680 bool isArrow,
6681 NestedNameSpecifier *Qualifier,
6682 SourceRange QualifierRange,
6683 TypeSourceInfo *ScopeType,
6684 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006685 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006686 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006687 CXXScopeSpec SS;
6688 if (Qualifier) {
6689 SS.setRange(QualifierRange);
6690 SS.setScopeRep(Qualifier);
6691 }
6692
John McCallb268a282010-08-23 23:25:46 +00006693 QualType BaseType = Base->getType();
6694 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006695 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006696 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006697 !BaseType->getAs<PointerType>()->getPointeeType()
6698 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006699 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006700 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006701 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006702 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006703 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006704 /*FIXME?*/true);
6705 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006706
Douglas Gregor678f90d2010-02-25 01:56:36 +00006707 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006708 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6709 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6710 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6711 NameInfo.setNamedTypeInfo(DestroyedType);
6712
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006713 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006714
John McCallb268a282010-08-23 23:25:46 +00006715 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006716 OperatorLoc, isArrow,
6717 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006718 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006719 /*TemplateArgs*/ 0);
6720}
6721
Douglas Gregord6ff3322009-08-04 16:50:30 +00006722} // end namespace clang
6723
6724#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H