blob: 655980c85a48bb6abb51867206266c19409aee8a [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,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000443 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000444
Douglas Gregord6ff3322009-08-04 16:50:30 +0000445 /// \brief Build a new extended vector type given the element type and
446 /// number of elements.
447 ///
448 /// By default, performs semantic analysis when building the vector type.
449 /// Subclasses may override this routine to provide different behavior.
450 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
451 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000452
453 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000454 /// given the element type and number of elements.
455 ///
456 /// By default, performs semantic analysis when building the vector type.
457 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000458 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000459 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000460 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000461
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 /// \brief Build a new function type.
463 ///
464 /// By default, performs semantic analysis when building the function type.
465 /// Subclasses may override this routine to provide different behavior.
466 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000467 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000468 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000469 bool Variadic, unsigned Quals,
470 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000471
John McCall550e0c22009-10-21 00:40:46 +0000472 /// \brief Build a new unprototyped function type.
473 QualType RebuildFunctionNoProtoType(QualType ResultType);
474
John McCallb96ec562009-12-04 22:46:56 +0000475 /// \brief Rebuild an unresolved typename type, given the decl that
476 /// the UnresolvedUsingTypenameDecl was transformed to.
477 QualType RebuildUnresolvedUsingType(Decl *D);
478
Douglas Gregord6ff3322009-08-04 16:50:30 +0000479 /// \brief Build a new typedef type.
480 QualType RebuildTypedefType(TypedefDecl *Typedef) {
481 return SemaRef.Context.getTypeDeclType(Typedef);
482 }
483
484 /// \brief Build a new class/struct/union type.
485 QualType RebuildRecordType(RecordDecl *Record) {
486 return SemaRef.Context.getTypeDeclType(Record);
487 }
488
489 /// \brief Build a new Enum type.
490 QualType RebuildEnumType(EnumDecl *Enum) {
491 return SemaRef.Context.getTypeDeclType(Enum);
492 }
John McCallfcc33b02009-09-05 00:15:47 +0000493
Mike Stump11289f42009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000495 ///
496 /// By default, performs semantic analysis when building the typeof type.
497 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, builds a new TypeOfType with the given underlying type.
503 QualType RebuildTypeOfType(QualType Underlying);
504
Mike Stump11289f42009-09-09 15:08:12 +0000505 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 ///
507 /// By default, performs semantic analysis when building the decltype type.
508 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000509 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000510
Douglas Gregord6ff3322009-08-04 16:50:30 +0000511 /// \brief Build a new template specialization type.
512 ///
513 /// By default, performs semantic analysis when building the template
514 /// specialization type. Subclasses may override this routine to provide
515 /// different behavior.
516 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000517 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000518 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000519
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 /// \brief Build a new qualified name type.
521 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000522 /// By default, builds a new ElaboratedType type from the keyword,
523 /// the nested-name-specifier and the named type.
524 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000525 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
526 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000527 NestedNameSpecifier *NNS, QualType Named) {
528 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000529 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to a template-id.
532 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000533 /// By default, builds a new DependentNameType type from the
534 /// nested-name-specifier and the given type. Subclasses may override
535 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000536 QualType RebuildDependentTemplateSpecializationType(
537 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000538 NestedNameSpecifier *Qualifier,
539 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000540 const IdentifierInfo *Name,
541 SourceLocation NameLoc,
542 const TemplateArgumentListInfo &Args) {
543 // Rebuild the template name.
544 // TODO: avoid TemplateName abstraction
545 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000546 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
547 QualType());
John McCallc392f372010-06-11 00:33:02 +0000548
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000549 if (InstName.isNull())
550 return QualType();
551
John McCallc392f372010-06-11 00:33:02 +0000552 // If it's still dependent, make a dependent specialization.
553 if (InstName.getAsDependentTemplateName())
554 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000555 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000556
557 // Otherwise, make an elaborated type wrapping a non-dependent
558 // specialization.
559 QualType T =
560 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
561 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000562
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000563 // NOTE: NNS is already recorded in template specialization type T.
564 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000565 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000566
567 /// \brief Build a new typename type that refers to an identifier.
568 ///
569 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000570 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000573 NestedNameSpecifier *NNS,
574 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000575 SourceLocation KeywordLoc,
576 SourceRange NNSRange,
577 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000578 CXXScopeSpec SS;
579 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000580 SS.setRange(NNSRange);
581
Douglas Gregore677daf2010-03-31 22:19:08 +0000582 if (NNS->isDependent()) {
583 // If the name is still dependent, just build a new dependent name type.
584 if (!SemaRef.computeDeclContext(SS))
585 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
586 }
587
Abramo Bagnara6150c882010-05-11 21:36:43 +0000588 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000589 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
590 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000591
592 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
593
Abramo Bagnarad7548482010-05-19 21:37:53 +0000594 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000595 // into a non-dependent elaborated-type-specifier. Find the tag we're
596 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000597 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000598 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
599 if (!DC)
600 return QualType();
601
John McCallbf8c5192010-05-27 06:40:31 +0000602 if (SemaRef.RequireCompleteDeclContext(SS, DC))
603 return QualType();
604
Douglas Gregore677daf2010-03-31 22:19:08 +0000605 TagDecl *Tag = 0;
606 SemaRef.LookupQualifiedName(Result, DC);
607 switch (Result.getResultKind()) {
608 case LookupResult::NotFound:
609 case LookupResult::NotFoundInCurrentInstantiation:
610 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000611
Douglas Gregore677daf2010-03-31 22:19:08 +0000612 case LookupResult::Found:
613 Tag = Result.getAsSingle<TagDecl>();
614 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000615
Douglas Gregore677daf2010-03-31 22:19:08 +0000616 case LookupResult::FoundOverloaded:
617 case LookupResult::FoundUnresolvedValue:
618 llvm_unreachable("Tag lookup cannot find non-tags");
619 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000620
Douglas Gregore677daf2010-03-31 22:19:08 +0000621 case LookupResult::Ambiguous:
622 // Let the LookupResult structure handle ambiguities.
623 return QualType();
624 }
625
626 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000627 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000628 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000629 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000630 return QualType();
631 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000632
Abramo Bagnarad7548482010-05-19 21:37:53 +0000633 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
634 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000635 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
636 return QualType();
637 }
638
639 // Build the elaborated-type-specifier type.
640 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000641 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000642 }
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregor1135c352009-08-06 05:28:30 +0000644 /// \brief Build a new nested-name-specifier given the prefix and an
645 /// identifier that names the next step in the nested-name-specifier.
646 ///
647 /// By default, performs semantic analysis when building the new
648 /// nested-name-specifier. Subclasses may override this routine to provide
649 /// different behavior.
650 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
651 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000652 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000653 QualType ObjectType,
654 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000655
656 /// \brief Build a new nested-name-specifier given the prefix and the
657 /// namespace named in the next step in the nested-name-specifier.
658 ///
659 /// By default, performs semantic analysis when building the new
660 /// nested-name-specifier. Subclasses may override this routine to provide
661 /// different behavior.
662 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
663 SourceRange Range,
664 NamespaceDecl *NS);
665
666 /// \brief Build a new nested-name-specifier given the prefix and the
667 /// type named in the next step in the nested-name-specifier.
668 ///
669 /// By default, performs semantic analysis when building the new
670 /// nested-name-specifier. Subclasses may override this routine to provide
671 /// different behavior.
672 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
673 SourceRange Range,
674 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000675 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000676
677 /// \brief Build a new template name given a nested name specifier, a flag
678 /// indicating whether the "template" keyword was provided, and the template
679 /// that the template name refers to.
680 ///
681 /// By default, builds the new template name directly. Subclasses may override
682 /// this routine to provide different behavior.
683 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
684 bool TemplateKW,
685 TemplateDecl *Template);
686
Douglas Gregor71dc5092009-08-06 06:41:21 +0000687 /// \brief Build a new template name given a nested name specifier and the
688 /// name that is referred to as a template.
689 ///
690 /// By default, performs semantic analysis to determine whether the name can
691 /// be resolved to a specific template, then builds the appropriate kind of
692 /// template name. Subclasses may override this routine to provide different
693 /// behavior.
694 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000695 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000696 const IdentifierInfo &II,
697 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000698
Douglas Gregor71395fa2009-11-04 00:56:37 +0000699 /// \brief Build a new template name given a nested name specifier and the
700 /// overloaded operator name that is referred to as a template.
701 ///
702 /// By default, performs semantic analysis to determine whether the name can
703 /// be resolved to a specific template, then builds the appropriate kind of
704 /// template name. Subclasses may override this routine to provide different
705 /// behavior.
706 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
707 OverloadedOperatorKind Operator,
708 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000709
Douglas Gregorebe10102009-08-20 07:17:43 +0000710 /// \brief Build a new compound statement.
711 ///
712 /// By default, performs semantic analysis to build the new statement.
713 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000714 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000715 MultiStmtArg Statements,
716 SourceLocation RBraceLoc,
717 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000718 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000719 IsStmtExpr);
720 }
721
722 /// \brief Build a new case statement.
723 ///
724 /// By default, performs semantic analysis to build the new statement.
725 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000726 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000727 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000729 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000730 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000731 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000732 ColonLoc);
733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Attach the body to a new case statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000739 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000740 getSema().ActOnCaseStmtBody(S, Body);
741 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000742 }
Mike Stump11289f42009-09-09 15:08:12 +0000743
Douglas Gregorebe10102009-08-20 07:17:43 +0000744 /// \brief Build a new default statement.
745 ///
746 /// By default, performs semantic analysis to build the new statement.
747 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000748 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000749 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000750 Stmt *SubStmt) {
751 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 /*CurScope=*/0);
753 }
Mike Stump11289f42009-09-09 15:08:12 +0000754
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /// \brief Build a new label statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000759 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000760 IdentifierInfo *Id,
761 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000762 Stmt *SubStmt, bool HasUnusedAttr) {
763 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
764 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 }
Mike Stump11289f42009-09-09 15:08:12 +0000766
Douglas Gregorebe10102009-08-20 07:17:43 +0000767 /// \brief Build a new "if" statement.
768 ///
769 /// By default, performs semantic analysis to build the new statement.
770 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000771 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000772 VarDecl *CondVar, Stmt *Then,
773 SourceLocation ElseLoc, Stmt *Else) {
774 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 }
Mike Stump11289f42009-09-09 15:08:12 +0000776
Douglas Gregorebe10102009-08-20 07:17:43 +0000777 /// \brief Start building a new switch statement.
778 ///
779 /// By default, performs semantic analysis to build the new statement.
780 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000781 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000782 Expr *Cond, VarDecl *CondVar) {
783 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000784 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 }
Mike Stump11289f42009-09-09 15:08:12 +0000786
Douglas Gregorebe10102009-08-20 07:17:43 +0000787 /// \brief Attach the body to the switch statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000791 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000792 Stmt *Switch, Stmt *Body) {
793 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000794 }
795
796 /// \brief Build a new while statement.
797 ///
798 /// By default, performs semantic analysis to build the new statement.
799 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000800 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000801 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000802 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000803 Stmt *Body) {
804 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 }
Mike Stump11289f42009-09-09 15:08:12 +0000806
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 /// \brief Build a new do-while statement.
808 ///
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000811 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000812 SourceLocation WhileLoc,
813 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000814 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000815 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000816 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
817 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 }
819
820 /// \brief Build a new for statement.
821 ///
822 /// By default, performs semantic analysis to build the new statement.
823 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000824 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000825 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000826 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000827 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000828 SourceLocation RParenLoc, Stmt *Body) {
829 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000830 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000831 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 }
Mike Stump11289f42009-09-09 15:08:12 +0000833
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 /// \brief Build a new goto statement.
835 ///
836 /// By default, performs semantic analysis to build the new statement.
837 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000838 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000839 SourceLocation LabelLoc,
840 LabelStmt *Label) {
841 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
842 }
843
844 /// \brief Build a new indirect goto statement.
845 ///
846 /// By default, performs semantic analysis to build the new statement.
847 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000848 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000849 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000850 Expr *Target) {
851 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 }
Mike Stump11289f42009-09-09 15:08:12 +0000853
Douglas Gregorebe10102009-08-20 07:17:43 +0000854 /// \brief Build a new return statement.
855 ///
856 /// By default, performs semantic analysis to build the new statement.
857 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000858 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000859 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000860
John McCallb268a282010-08-23 23:25:46 +0000861 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 }
Mike Stump11289f42009-09-09 15:08:12 +0000863
Douglas Gregorebe10102009-08-20 07:17:43 +0000864 /// \brief Build a new declaration statement.
865 ///
866 /// By default, performs semantic analysis to build the new statement.
867 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000868 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000869 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000870 SourceLocation EndLoc) {
871 return getSema().Owned(
872 new (getSema().Context) DeclStmt(
873 DeclGroupRef::Create(getSema().Context,
874 Decls, NumDecls),
875 StartLoc, EndLoc));
876 }
Mike Stump11289f42009-09-09 15:08:12 +0000877
Anders Carlssonaaeef072010-01-24 05:50:09 +0000878 /// \brief Build a new inline asm statement.
879 ///
880 /// By default, performs semantic analysis to build the new statement.
881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000882 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000883 bool IsSimple,
884 bool IsVolatile,
885 unsigned NumOutputs,
886 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000887 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000888 MultiExprArg Constraints,
889 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000890 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000891 MultiExprArg Clobbers,
892 SourceLocation RParenLoc,
893 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000894 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000895 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000896 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000897 RParenLoc, MSAsm);
898 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000899
900 /// \brief Build a new Objective-C @try statement.
901 ///
902 /// By default, performs semantic analysis to build the new statement.
903 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000904 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000905 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000906 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000907 Stmt *Finally) {
908 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
909 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000910 }
911
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000912 /// \brief Rebuild an Objective-C exception declaration.
913 ///
914 /// By default, performs semantic analysis to build the new declaration.
915 /// Subclasses may override this routine to provide different behavior.
916 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
917 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000918 return getSema().BuildObjCExceptionDecl(TInfo, T,
919 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000920 ExceptionDecl->getLocation());
921 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000922
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 /// \brief Build a new Objective-C @catch statement.
924 ///
925 /// By default, performs semantic analysis to build the new statement.
926 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000927 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000928 SourceLocation RParenLoc,
929 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000930 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000931 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000932 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000933 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000934
Douglas Gregor306de2f2010-04-22 23:59:56 +0000935 /// \brief Build a new Objective-C @finally statement.
936 ///
937 /// By default, performs semantic analysis to build the new statement.
938 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000939 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000940 Stmt *Body) {
941 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000942 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000943
Douglas Gregor6148de72010-04-22 22:01:21 +0000944 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000945 ///
946 /// By default, performs semantic analysis to build the new statement.
947 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000948 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000949 Expr *Operand) {
950 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000951 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000952
Douglas Gregor6148de72010-04-22 22:01:21 +0000953 /// \brief Build a new Objective-C @synchronized statement.
954 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000955 /// By default, performs semantic analysis to build the new statement.
956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000957 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000958 Expr *Object,
959 Stmt *Body) {
960 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
961 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000962 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000963
964 /// \brief Build a new Objective-C fast enumeration statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000968 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000969 SourceLocation LParenLoc,
970 Stmt *Element,
971 Expr *Collection,
972 SourceLocation RParenLoc,
973 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000974 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000975 Element,
976 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000977 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000979 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000980
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 /// \brief Build a new C++ exception declaration.
982 ///
983 /// By default, performs semantic analysis to build the new decaration.
984 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000985 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +0000986 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000988 SourceLocation Loc) {
989 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000990 }
991
992 /// \brief Build a new C++ catch statement.
993 ///
994 /// By default, performs semantic analysis to build the new statement.
995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000996 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000997 VarDecl *ExceptionDecl,
998 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +0000999 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1000 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /// \brief Build a new C++ try statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001007 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001008 Stmt *TryBlock,
1009 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001010 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 }
Mike Stump11289f42009-09-09 15:08:12 +00001012
Douglas Gregora16548e2009-08-11 05:31:07 +00001013 /// \brief Build a new expression that references a declaration.
1014 ///
1015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001017 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001018 LookupResult &R,
1019 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001020 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1021 }
1022
1023
1024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001028 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001029 SourceRange QualifierRange,
1030 ValueDecl *VD,
1031 const DeclarationNameInfo &NameInfo,
1032 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001033 CXXScopeSpec SS;
1034 SS.setScopeRep(Qualifier);
1035 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001036
1037 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001038
1039 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001040 }
Mike Stump11289f42009-09-09 15:08:12 +00001041
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001043 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 /// By default, performs semantic analysis to build the new expression.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001048 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 }
1050
Douglas Gregorad8a3362009-09-04 17:36:40 +00001051 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001052 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001053 /// By default, performs semantic analysis to build the new expression.
1054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001055 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001056 SourceLocation OperatorLoc,
1057 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001058 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001059 SourceRange QualifierRange,
1060 TypeSourceInfo *ScopeType,
1061 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001062 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001063 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001064
Douglas Gregora16548e2009-08-11 05:31:07 +00001065 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001066 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001067 /// By default, performs semantic analysis to build the new expression.
1068 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001069 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001070 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001071 Expr *SubExpr) {
1072 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregor882211c2010-04-28 22:16:22 +00001075 /// \brief Build a new builtin offsetof expression.
1076 ///
1077 /// By default, performs semantic analysis to build the new expression.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001080 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001081 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001082 unsigned NumComponents,
1083 SourceLocation RParenLoc) {
1084 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1085 NumComponents, RParenLoc);
1086 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001087
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001089 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 /// By default, performs semantic analysis to build the new expression.
1091 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001092 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001093 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001095 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 }
1097
Mike Stump11289f42009-09-09 15:08:12 +00001098 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001100 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001103 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001105 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001106 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 return move(Result);
1111 }
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001114 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 /// By default, performs semantic analysis to build the new expression.
1116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001117 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001119 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001121 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1122 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 RBracketLoc);
1124 }
1125
1126 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001127 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001130 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001131 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001133 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001134 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 }
1136
1137 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001138 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001141 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001142 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001143 NestedNameSpecifier *Qualifier,
1144 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001145 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001146 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001147 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001148 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001149 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001150 if (!Member->getDeclName()) {
1151 // We have a reference to an unnamed field.
1152 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001153
John McCallb268a282010-08-23 23:25:46 +00001154 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001155 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001156 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001157
Mike Stump11289f42009-09-09 15:08:12 +00001158 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001159 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001160 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001161 cast<FieldDecl>(Member)->getType());
1162 return getSema().Owned(ME);
1163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001165 CXXScopeSpec SS;
1166 if (Qualifier) {
1167 SS.setRange(QualifierRange);
1168 SS.setScopeRep(Qualifier);
1169 }
1170
John McCallb268a282010-08-23 23:25:46 +00001171 getSema().DefaultFunctionArrayConversion(Base);
1172 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001173
John McCall16df1e52010-03-30 21:47:33 +00001174 // FIXME: this involves duplicating earlier analysis in a lot of
1175 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001176 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001177 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001178 R.resolveKind();
1179
John McCallb268a282010-08-23 23:25:46 +00001180 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001181 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001182 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001186 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 /// By default, performs semantic analysis to build the new expression.
1188 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001189 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001190 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001191 Expr *LHS, Expr *RHS) {
1192 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 }
1194
1195 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001196 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 /// By default, performs semantic analysis to build the new expression.
1198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001199 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001201 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001203 Expr *RHS) {
1204 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1205 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 }
1207
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001209 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 /// By default, performs semantic analysis to build the new expression.
1211 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001212 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001213 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001215 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001216 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001217 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001224 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001225 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001227 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001228 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001229 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001233 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001236 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 SourceLocation OpLoc,
1238 SourceLocation AccessorLoc,
1239 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001240
John McCall10eae182009-11-30 22:42:35 +00001241 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001242 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001243 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001244 OpLoc, /*IsArrow*/ false,
1245 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001246 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001247 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 }
Mike Stump11289f42009-09-09 15:08:12 +00001249
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001251 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 /// By default, performs semantic analysis to build the new expression.
1253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001254 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001256 SourceLocation RBraceLoc,
1257 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001258 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001259 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1260 if (Result.isInvalid() || ResultTy->isDependentType())
1261 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001262
Douglas Gregord3d93062009-11-09 17:16:50 +00001263 // Patch in the result type we were given, which may have been computed
1264 // when the initial InitListExpr was built.
1265 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1266 ILE->setType(ResultTy);
1267 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001271 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 /// By default, performs semantic analysis to build the new expression.
1273 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001274 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 MultiExprArg ArrayExprs,
1276 SourceLocation EqualOrColonLoc,
1277 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001278 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001279 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001281 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001283 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001284
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 ArrayExprs.release();
1286 return move(Result);
1287 }
Mike Stump11289f42009-09-09 15:08:12 +00001288
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001290 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 /// By default, builds the implicit value initialization without performing
1292 /// any semantic analysis. Subclasses may override this routine to provide
1293 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001294 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001295 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1296 }
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001299 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001302 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001303 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001304 SourceLocation RParenLoc) {
1305 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001306 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001307 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 }
1309
1310 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001314 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 MultiExprArg SubExprs,
1316 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001317 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001318 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 }
Mike Stump11289f42009-09-09 15:08:12 +00001320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001322 ///
1323 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// rather than attempting to map the label statement itself.
1325 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001326 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 SourceLocation LabelLoc,
1328 LabelStmt *Label) {
1329 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001336 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001337 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001339 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new __builtin_types_compatible_p expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001346 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001347 TypeSourceInfo *TInfo1,
1348 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001350 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1351 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 RParenLoc);
1353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new __builtin_choose_expr expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001359 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001360 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 SourceLocation RParenLoc) {
1362 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001363 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 RParenLoc);
1365 }
Mike Stump11289f42009-09-09 15:08:12 +00001366
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 /// \brief Build a new overloaded operator call expression.
1368 ///
1369 /// By default, performs semantic analysis to build the new expression.
1370 /// The semantic analysis provides the behavior of template instantiation,
1371 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001372 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 /// argument-dependent lookup, etc. Subclasses may override this routine to
1374 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001375 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001377 Expr *Callee,
1378 Expr *First,
1379 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001380
1381 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// reinterpret_cast.
1383 ///
1384 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001385 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001387 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 Stmt::StmtClass Class,
1389 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001390 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 SourceLocation RAngleLoc,
1392 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001393 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 SourceLocation RParenLoc) {
1395 switch (Class) {
1396 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001397 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001398 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001399 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001400
1401 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001402 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001403 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001404 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001405
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001407 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001408 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001409 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001413 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001414 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001415 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 default:
1418 assert(false && "Invalid C++ named cast");
1419 break;
1420 }
Mike Stump11289f42009-09-09 15:08:12 +00001421
John McCallfaf5fb42010-08-26 23:41:50 +00001422 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 }
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// \brief Build a new C++ static_cast expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001429 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001431 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 SourceLocation RAngleLoc,
1433 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001434 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001436 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001437 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001438 SourceRange(LAngleLoc, RAngleLoc),
1439 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 }
1441
1442 /// \brief Build a new C++ dynamic_cast expression.
1443 ///
1444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001446 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001448 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 SourceLocation RAngleLoc,
1450 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001451 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001453 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001454 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001455 SourceRange(LAngleLoc, RAngleLoc),
1456 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new C++ reinterpret_cast expression.
1460 ///
1461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001463 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001465 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 SourceLocation RAngleLoc,
1467 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001468 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001470 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001471 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001472 SourceRange(LAngleLoc, RAngleLoc),
1473 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 }
1475
1476 /// \brief Build a new C++ const_cast expression.
1477 ///
1478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001480 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001482 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 SourceLocation RAngleLoc,
1484 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001485 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001487 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001488 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001489 SourceRange(LAngleLoc, RAngleLoc),
1490 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 }
Mike Stump11289f42009-09-09 15:08:12 +00001492
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 /// \brief Build a new C++ functional-style cast expression.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001497 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1498 SourceLocation LParenLoc,
1499 Expr *Sub,
1500 SourceLocation RParenLoc) {
1501 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001502 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 RParenLoc);
1504 }
Mike Stump11289f42009-09-09 15:08:12 +00001505
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 /// \brief Build a new C++ typeid(type) expression.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001510 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001511 SourceLocation TypeidLoc,
1512 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001514 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001515 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 }
Mike Stump11289f42009-09-09 15:08:12 +00001517
Francois Pichet9f4f2072010-09-08 12:20:18 +00001518
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 /// \brief Build a new C++ typeid(expr) expression.
1520 ///
1521 /// By default, performs semantic analysis to build the new expression.
1522 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001523 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001524 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001525 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001527 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001528 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001529 }
1530
Francois Pichet9f4f2072010-09-08 12:20:18 +00001531 /// \brief Build a new C++ __uuidof(type) expression.
1532 ///
1533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
1535 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1536 SourceLocation TypeidLoc,
1537 TypeSourceInfo *Operand,
1538 SourceLocation RParenLoc) {
1539 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1540 RParenLoc);
1541 }
1542
1543 /// \brief Build a new C++ __uuidof(expr) expression.
1544 ///
1545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
1547 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1548 SourceLocation TypeidLoc,
1549 Expr *Operand,
1550 SourceLocation RParenLoc) {
1551 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1552 RParenLoc);
1553 }
1554
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 /// \brief Build a new C++ "this" expression.
1556 ///
1557 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001558 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001560 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001561 QualType ThisType,
1562 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001564 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1565 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 }
1567
1568 /// \brief Build a new C++ throw expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001572 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001573 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 }
1575
1576 /// \brief Build a new C++ default-argument expression.
1577 ///
1578 /// By default, builds a new default-argument expression, which does not
1579 /// require any semantic analysis. Subclasses may override this routine to
1580 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001581 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001582 ParmVarDecl *Param) {
1583 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1584 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 }
1586
1587 /// \brief Build a new C++ zero-initialization expression.
1588 ///
1589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001591 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1592 SourceLocation LParenLoc,
1593 SourceLocation RParenLoc) {
1594 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001595 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001596 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 }
Mike Stump11289f42009-09-09 15:08:12 +00001598
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// \brief Build a new C++ "new" expression.
1600 ///
1601 /// By default, performs semantic analysis to build the new expression.
1602 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001603 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001604 bool UseGlobal,
1605 SourceLocation PlacementLParen,
1606 MultiExprArg PlacementArgs,
1607 SourceLocation PlacementRParen,
1608 SourceRange TypeIdParens,
1609 QualType AllocatedType,
1610 TypeSourceInfo *AllocatedTypeInfo,
1611 Expr *ArraySize,
1612 SourceLocation ConstructorLParen,
1613 MultiExprArg ConstructorArgs,
1614 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001615 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 PlacementLParen,
1617 move(PlacementArgs),
1618 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001619 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001620 AllocatedType,
1621 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001622 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 ConstructorLParen,
1624 move(ConstructorArgs),
1625 ConstructorRParen);
1626 }
Mike Stump11289f42009-09-09 15:08:12 +00001627
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// \brief Build a new C++ "delete" expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001632 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 bool IsGlobalDelete,
1634 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001635 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001637 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 }
Mike Stump11289f42009-09-09 15:08:12 +00001639
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 /// \brief Build a new unary type trait expression.
1641 ///
1642 /// By default, performs semantic analysis to build the new expression.
1643 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001644 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001645 SourceLocation StartLoc,
1646 TypeSourceInfo *T,
1647 SourceLocation RParenLoc) {
1648 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 }
1650
Mike Stump11289f42009-09-09 15:08:12 +00001651 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 /// expression.
1653 ///
1654 /// By default, performs semantic analysis to build the new expression.
1655 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001656 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001658 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001659 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 CXXScopeSpec SS;
1661 SS.setRange(QualifierRange);
1662 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001663
1664 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001665 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001666 *TemplateArgs);
1667
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001668 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 }
1670
1671 /// \brief Build a new template-id expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001675 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001676 LookupResult &R,
1677 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001678 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001679 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 }
1681
1682 /// \brief Build a new object-construction expression.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001686 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001687 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 CXXConstructorDecl *Constructor,
1689 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001690 MultiExprArg Args,
1691 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001692 CXXConstructExpr::ConstructionKind ConstructKind,
1693 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001694 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001695 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001696 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001697 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001698
Douglas Gregordb121ba2009-12-14 16:27:04 +00001699 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001700 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001701 RequiresZeroInit, ConstructKind,
1702 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 }
1704
1705 /// \brief Build a new object-construction expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001709 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1710 SourceLocation LParenLoc,
1711 MultiExprArg Args,
1712 SourceLocation RParenLoc) {
1713 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 LParenLoc,
1715 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 RParenLoc);
1717 }
1718
1719 /// \brief Build a new object-construction expression.
1720 ///
1721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001723 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1724 SourceLocation LParenLoc,
1725 MultiExprArg Args,
1726 SourceLocation RParenLoc) {
1727 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 LParenLoc,
1729 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 RParenLoc);
1731 }
Mike Stump11289f42009-09-09 15:08:12 +00001732
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 /// \brief Build a new member reference expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001737 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001738 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 bool IsArrow,
1740 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001741 NestedNameSpecifier *Qualifier,
1742 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001743 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001744 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001745 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001747 SS.setRange(QualifierRange);
1748 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001749
John McCallb268a282010-08-23 23:25:46 +00001750 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001751 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001752 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001753 MemberNameInfo,
1754 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 }
1756
John McCall10eae182009-11-30 22:42:35 +00001757 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001758 ///
1759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001761 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001762 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001763 SourceLocation OperatorLoc,
1764 bool IsArrow,
1765 NestedNameSpecifier *Qualifier,
1766 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001767 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001768 LookupResult &R,
1769 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001770 CXXScopeSpec SS;
1771 SS.setRange(QualifierRange);
1772 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001773
John McCallb268a282010-08-23 23:25:46 +00001774 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001775 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001776 SS, FirstQualifierInScope,
1777 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001778 }
Mike Stump11289f42009-09-09 15:08:12 +00001779
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001780 /// \brief Build a new noexcept expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
1784 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1785 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1786 }
1787
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 /// \brief Build a new Objective-C @encode expression.
1789 ///
1790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001793 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001795 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001797 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001798
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001799 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001800 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001801 Selector Sel,
1802 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001803 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001804 MultiExprArg Args,
1805 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001806 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1807 ReceiverTypeInfo->getType(),
1808 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001809 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001810 move(Args));
1811 }
1812
1813 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001814 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001815 Selector Sel,
1816 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001817 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001818 MultiExprArg Args,
1819 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001820 return SemaRef.BuildInstanceMessage(Receiver,
1821 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001822 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001823 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001824 move(Args));
1825 }
1826
Douglas Gregord51d90d2010-04-26 20:11:03 +00001827 /// \brief Build a new Objective-C ivar reference expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001831 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001832 SourceLocation IvarLoc,
1833 bool IsArrow, bool IsFreeIvar) {
1834 // FIXME: We lose track of the IsFreeIvar bit.
1835 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001836 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001837 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1838 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001840 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001841 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001842 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001843 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001844 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001845
Douglas Gregord51d90d2010-04-26 20:11:03 +00001846 if (Result.get())
1847 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001848
John McCallb268a282010-08-23 23:25:46 +00001849 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001850 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001851 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001852 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001853 /*TemplateArgs=*/0);
1854 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001855
1856 /// \brief Build a new Objective-C property reference expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001861 ObjCPropertyDecl *Property,
1862 SourceLocation PropertyLoc) {
1863 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001864 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001865 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1866 Sema::LookupMemberName);
1867 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001868 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001869 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001870 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001871 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001872 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001873
Douglas Gregor9faee212010-04-26 20:47:02 +00001874 if (Result.get())
1875 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001876
John McCallb268a282010-08-23 23:25:46 +00001877 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001878 /*FIXME:*/PropertyLoc, IsArrow,
1879 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001880 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001881 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001882 /*TemplateArgs=*/0);
1883 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001884
1885 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001886 /// expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001889 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001890 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001891 ObjCMethodDecl *Getter,
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001892 QualType T,
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001893 ObjCMethodDecl *Setter,
1894 SourceLocation NameLoc,
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001895 Expr *Base,
1896 SourceLocation SuperLoc,
1897 QualType SuperTy,
1898 bool Super) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001899 // Since these expressions can only be value-dependent, we do not need to
1900 // perform semantic analysis again.
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001901 if (Super)
1902 return Owned(
1903 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1904 Setter,
1905 NameLoc,
1906 SuperLoc,
1907 SuperTy));
1908 else
1909 return Owned(
1910 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(
1911 Getter, T,
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001912 Setter,
1913 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001914 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001915 }
1916
Douglas Gregord51d90d2010-04-26 20:11:03 +00001917 /// \brief Build a new Objective-C "isa" expression.
1918 ///
1919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001921 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001922 bool IsArrow) {
1923 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001924 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001925 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1926 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001927 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001928 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001929 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001930 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001931 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001932
Douglas Gregord51d90d2010-04-26 20:11:03 +00001933 if (Result.get())
1934 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001935
John McCallb268a282010-08-23 23:25:46 +00001936 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001937 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001938 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001939 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001940 /*TemplateArgs=*/0);
1941 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// \brief Build a new shuffle vector expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001947 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 MultiExprArg SubExprs,
1949 SourceLocation RParenLoc) {
1950 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001951 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1953 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1954 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1955 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 // Build a reference to the __builtin_shufflevector builtin
1958 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001959 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001961 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001963
1964 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 unsigned NumSubExprs = SubExprs.size();
1966 Expr **Subs = (Expr **)SubExprs.release();
1967 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1968 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001969 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001971 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001972
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001974 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001976 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001979 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001981};
Douglas Gregora16548e2009-08-11 05:31:07 +00001982
Douglas Gregorebe10102009-08-20 07:17:43 +00001983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001984StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001985 if (!S)
1986 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregorebe10102009-08-20 07:17:43 +00001988 switch (S->getStmtClass()) {
1989 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001990
Douglas Gregorebe10102009-08-20 07:17:43 +00001991 // Transform individual statement nodes
1992#define STMT(Node, Parent) \
1993 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1994#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001995#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001996
Douglas Gregorebe10102009-08-20 07:17:43 +00001997 // Transform expressions by calling TransformExpr.
1998#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001999#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002000#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002001#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002002 {
John McCalldadc5752010-08-24 06:29:42 +00002003 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002004 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002005 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002006
John McCallb268a282010-08-23 23:25:46 +00002007 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009 }
2010
John McCallc3007a22010-10-26 07:05:15 +00002011 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002012}
Mike Stump11289f42009-09-09 15:08:12 +00002013
2014
Douglas Gregore922c772009-08-04 22:27:00 +00002015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002016ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 if (!E)
2018 return SemaRef.Owned(E);
2019
2020 switch (E->getStmtClass()) {
2021 case Stmt::NoStmtClass: break;
2022#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002023#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002024#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002025 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002026#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002027 }
2028
John McCallc3007a22010-10-26 07:05:15 +00002029 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002030}
2031
2032template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002033NestedNameSpecifier *
2034TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002035 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002036 QualType ObjectType,
2037 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002038 if (!NNS)
2039 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregorebe10102009-08-20 07:17:43 +00002041 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002042 NestedNameSpecifier *Prefix = NNS->getPrefix();
2043 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002044 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002045 ObjectType,
2046 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002047 if (!Prefix)
2048 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002049
2050 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002051 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002052 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002053 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002054 }
Mike Stump11289f42009-09-09 15:08:12 +00002055
Douglas Gregor1135c352009-08-06 05:28:30 +00002056 switch (NNS->getKind()) {
2057 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002058 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002059 "Identifier nested-name-specifier with no prefix or object type");
2060 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2061 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002062 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002063
2064 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002065 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002066 ObjectType,
2067 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregor1135c352009-08-06 05:28:30 +00002069 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002070 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002071 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002072 getDerived().TransformDecl(Range.getBegin(),
2073 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002075 Prefix == NNS->getPrefix() &&
2076 NS == NNS->getAsNamespace())
2077 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002078
Douglas Gregor1135c352009-08-06 05:28:30 +00002079 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2080 }
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregor1135c352009-08-06 05:28:30 +00002082 case NestedNameSpecifier::Global:
2083 // There is no meaningful transformation that one could perform on the
2084 // global scope.
2085 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregor1135c352009-08-06 05:28:30 +00002087 case NestedNameSpecifier::TypeSpecWithTemplate:
2088 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002089 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002090 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2091 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002092 if (T.isNull())
2093 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002094
Douglas Gregor1135c352009-08-06 05:28:30 +00002095 if (!getDerived().AlwaysRebuild() &&
2096 Prefix == NNS->getPrefix() &&
2097 T == QualType(NNS->getAsType(), 0))
2098 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002099
2100 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2101 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002102 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002103 }
2104 }
Mike Stump11289f42009-09-09 15:08:12 +00002105
Douglas Gregor1135c352009-08-06 05:28:30 +00002106 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002107 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002108}
2109
2110template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002111DeclarationNameInfo
2112TreeTransform<Derived>
2113::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2114 QualType ObjectType) {
2115 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002116 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002117 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002118
2119 switch (Name.getNameKind()) {
2120 case DeclarationName::Identifier:
2121 case DeclarationName::ObjCZeroArgSelector:
2122 case DeclarationName::ObjCOneArgSelector:
2123 case DeclarationName::ObjCMultiArgSelector:
2124 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002125 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002126 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002127 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002128
Douglas Gregorf816bd72009-09-03 22:13:48 +00002129 case DeclarationName::CXXConstructorName:
2130 case DeclarationName::CXXDestructorName:
2131 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002132 TypeSourceInfo *NewTInfo;
2133 CanQualType NewCanTy;
2134 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2135 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2136 if (!NewTInfo)
2137 return DeclarationNameInfo();
2138 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2139 }
2140 else {
2141 NewTInfo = 0;
2142 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2143 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2144 ObjectType);
2145 if (NewT.isNull())
2146 return DeclarationNameInfo();
2147 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2148 }
Mike Stump11289f42009-09-09 15:08:12 +00002149
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002150 DeclarationName NewName
2151 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2152 NewCanTy);
2153 DeclarationNameInfo NewNameInfo(NameInfo);
2154 NewNameInfo.setName(NewName);
2155 NewNameInfo.setNamedTypeInfo(NewTInfo);
2156 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002157 }
Mike Stump11289f42009-09-09 15:08:12 +00002158 }
2159
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002160 assert(0 && "Unknown name kind.");
2161 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002162}
2163
2164template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002165TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002166TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2167 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002168 SourceLocation Loc = getDerived().getBaseLocation();
2169
Douglas Gregor71dc5092009-08-06 06:41:21 +00002170 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002171 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002172 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002173 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2174 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002175 if (!NNS)
2176 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregor71dc5092009-08-06 06:41:21 +00002178 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002179 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002180 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002181 if (!TransTemplate)
2182 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 if (!getDerived().AlwaysRebuild() &&
2185 NNS == QTN->getQualifier() &&
2186 TransTemplate == Template)
2187 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregor71dc5092009-08-06 06:41:21 +00002189 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2190 TransTemplate);
2191 }
Mike Stump11289f42009-09-09 15:08:12 +00002192
John McCalle66edc12009-11-24 19:00:30 +00002193 // These should be getting filtered out before they make it into the AST.
2194 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002195 }
Mike Stump11289f42009-09-09 15:08:12 +00002196
Douglas Gregor71dc5092009-08-06 06:41:21 +00002197 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002198 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002199 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002200 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2201 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002202 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002203 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002204
Douglas Gregor71dc5092009-08-06 06:41:21 +00002205 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002206 NNS == DTN->getQualifier() &&
2207 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002208 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregora5614c52010-09-08 23:56:00 +00002210 if (DTN->isIdentifier()) {
2211 // FIXME: Bad range
2212 SourceRange QualifierRange(getDerived().getBaseLocation());
2213 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2214 *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002215 ObjectType);
Douglas Gregora5614c52010-09-08 23:56:00 +00002216 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002217
2218 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002219 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002220 }
Mike Stump11289f42009-09-09 15:08:12 +00002221
Douglas Gregor71dc5092009-08-06 06:41:21 +00002222 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002223 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002224 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002225 if (!TransTemplate)
2226 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002227
Douglas Gregor71dc5092009-08-06 06:41:21 +00002228 if (!getDerived().AlwaysRebuild() &&
2229 TransTemplate == Template)
2230 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002231
Douglas Gregor71dc5092009-08-06 06:41:21 +00002232 return TemplateName(TransTemplate);
2233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
John McCalle66edc12009-11-24 19:00:30 +00002235 // These should be getting filtered out before they reach the AST.
2236 assert(false && "overloaded function decl survived to here");
2237 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002238}
2239
2240template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002241void TreeTransform<Derived>::InventTemplateArgumentLoc(
2242 const TemplateArgument &Arg,
2243 TemplateArgumentLoc &Output) {
2244 SourceLocation Loc = getDerived().getBaseLocation();
2245 switch (Arg.getKind()) {
2246 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002247 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002248 break;
2249
2250 case TemplateArgument::Type:
2251 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002252 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002253
John McCall0ad16662009-10-29 08:12:44 +00002254 break;
2255
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002256 case TemplateArgument::Template:
2257 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2258 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002259
John McCall0ad16662009-10-29 08:12:44 +00002260 case TemplateArgument::Expression:
2261 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2262 break;
2263
2264 case TemplateArgument::Declaration:
2265 case TemplateArgument::Integral:
2266 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002267 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002268 break;
2269 }
2270}
2271
2272template<typename Derived>
2273bool TreeTransform<Derived>::TransformTemplateArgument(
2274 const TemplateArgumentLoc &Input,
2275 TemplateArgumentLoc &Output) {
2276 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002277 switch (Arg.getKind()) {
2278 case TemplateArgument::Null:
2279 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002280 Output = Input;
2281 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregore922c772009-08-04 22:27:00 +00002283 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002284 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002285 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002286 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002287
2288 DI = getDerived().TransformType(DI);
2289 if (!DI) return true;
2290
2291 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2292 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002293 }
Mike Stump11289f42009-09-09 15:08:12 +00002294
Douglas Gregore922c772009-08-04 22:27:00 +00002295 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002296 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002297 DeclarationName Name;
2298 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2299 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002300 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002301 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002302 if (!D) return true;
2303
John McCall0d07eb32009-10-29 18:45:58 +00002304 Expr *SourceExpr = Input.getSourceDeclExpression();
2305 if (SourceExpr) {
2306 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002307 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002308 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002309 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002310 }
2311
2312 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002313 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002314 }
Mike Stump11289f42009-09-09 15:08:12 +00002315
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002316 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002317 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002318 TemplateName Template
2319 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2320 if (Template.isNull())
2321 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002322
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002323 Output = TemplateArgumentLoc(TemplateArgument(Template),
2324 Input.getTemplateQualifierRange(),
2325 Input.getTemplateNameLoc());
2326 return false;
2327 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002328
Douglas Gregore922c772009-08-04 22:27:00 +00002329 case TemplateArgument::Expression: {
2330 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002331 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002332 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002333
John McCall0ad16662009-10-29 08:12:44 +00002334 Expr *InputExpr = Input.getSourceExpression();
2335 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2336
John McCalldadc5752010-08-24 06:29:42 +00002337 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002338 = getDerived().TransformExpr(InputExpr);
2339 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002340 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002341 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002342 }
Mike Stump11289f42009-09-09 15:08:12 +00002343
Douglas Gregore922c772009-08-04 22:27:00 +00002344 case TemplateArgument::Pack: {
2345 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2346 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002347 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002348 AEnd = Arg.pack_end();
2349 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002350
John McCall0ad16662009-10-29 08:12:44 +00002351 // FIXME: preserve source information here when we start
2352 // caring about parameter packs.
2353
John McCall0d07eb32009-10-29 18:45:58 +00002354 TemplateArgumentLoc InputArg;
2355 TemplateArgumentLoc OutputArg;
2356 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2357 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002358 return true;
2359
John McCall0d07eb32009-10-29 18:45:58 +00002360 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002361 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002362
2363 TemplateArgument *TransformedArgsPtr
2364 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2365 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2366 TransformedArgsPtr);
2367 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2368 TransformedArgs.size()),
2369 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002370 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002371 }
2372 }
Mike Stump11289f42009-09-09 15:08:12 +00002373
Douglas Gregore922c772009-08-04 22:27:00 +00002374 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002375 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002376}
2377
Douglas Gregord6ff3322009-08-04 16:50:30 +00002378//===----------------------------------------------------------------------===//
2379// Type transformation
2380//===----------------------------------------------------------------------===//
2381
2382template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002383QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002384 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002385 if (getDerived().AlreadyTransformed(T))
2386 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002387
John McCall550e0c22009-10-21 00:40:46 +00002388 // Temporary workaround. All of these transformations should
2389 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002390 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002391 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002392
Douglas Gregorfe17d252010-02-16 19:09:40 +00002393 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002394
John McCall550e0c22009-10-21 00:40:46 +00002395 if (!NewDI)
2396 return QualType();
2397
2398 return NewDI->getType();
2399}
2400
2401template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002402TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2403 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002404 if (getDerived().AlreadyTransformed(DI->getType()))
2405 return DI;
2406
2407 TypeLocBuilder TLB;
2408
2409 TypeLoc TL = DI->getTypeLoc();
2410 TLB.reserve(TL.getFullDataSize());
2411
Douglas Gregorfe17d252010-02-16 19:09:40 +00002412 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002413 if (Result.isNull())
2414 return 0;
2415
John McCallbcd03502009-12-07 02:54:59 +00002416 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002417}
2418
2419template<typename Derived>
2420QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002421TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2422 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002423 switch (T.getTypeLocClass()) {
2424#define ABSTRACT_TYPELOC(CLASS, PARENT)
2425#define TYPELOC(CLASS, PARENT) \
2426 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002427 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2428 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002429#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002430 }
Mike Stump11289f42009-09-09 15:08:12 +00002431
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002432 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002433 return QualType();
2434}
2435
2436/// FIXME: By default, this routine adds type qualifiers only to types
2437/// that can have qualifiers, and silently suppresses those qualifiers
2438/// that are not permitted (e.g., qualifiers on reference or function
2439/// types). This is the right thing for template instantiation, but
2440/// probably not for other clients.
2441template<typename Derived>
2442QualType
2443TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002444 QualifiedTypeLoc T,
2445 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002446 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002447
Douglas Gregorfe17d252010-02-16 19:09:40 +00002448 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2449 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002450 if (Result.isNull())
2451 return QualType();
2452
2453 // Silently suppress qualifiers if the result type can't be qualified.
2454 // FIXME: this is the right thing for template instantiation, but
2455 // probably not for other clients.
2456 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002457 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002458
John McCallcb0f89a2010-06-05 06:41:15 +00002459 if (!Quals.empty()) {
2460 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2461 TLB.push<QualifiedTypeLoc>(Result);
2462 // No location information to preserve.
2463 }
John McCall550e0c22009-10-21 00:40:46 +00002464
2465 return Result;
2466}
2467
2468template <class TyLoc> static inline
2469QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2470 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2471 NewT.setNameLoc(T.getNameLoc());
2472 return T.getType();
2473}
2474
John McCall550e0c22009-10-21 00:40:46 +00002475template<typename Derived>
2476QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002477 BuiltinTypeLoc T,
2478 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002479 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2480 NewT.setBuiltinLoc(T.getBuiltinLoc());
2481 if (T.needsExtraLocalData())
2482 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2483 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002484}
Mike Stump11289f42009-09-09 15:08:12 +00002485
Douglas Gregord6ff3322009-08-04 16:50:30 +00002486template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002487QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002488 ComplexTypeLoc T,
2489 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002490 // FIXME: recurse?
2491 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002492}
Mike Stump11289f42009-09-09 15:08:12 +00002493
Douglas Gregord6ff3322009-08-04 16:50:30 +00002494template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002495QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002496 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002497 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002498 QualType PointeeType
2499 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002500 if (PointeeType.isNull())
2501 return QualType();
2502
2503 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002504 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002505 // A dependent pointer type 'T *' has is being transformed such
2506 // that an Objective-C class type is being replaced for 'T'. The
2507 // resulting pointer type is an ObjCObjectPointerType, not a
2508 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002509 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002510
John McCall8b07ec22010-05-15 11:32:37 +00002511 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2512 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002513 return Result;
2514 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002515
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002516 if (getDerived().AlwaysRebuild() ||
2517 PointeeType != TL.getPointeeLoc().getType()) {
2518 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2519 if (Result.isNull())
2520 return QualType();
2521 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002522
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002523 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2524 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002526}
Mike Stump11289f42009-09-09 15:08:12 +00002527
2528template<typename Derived>
2529QualType
John McCall550e0c22009-10-21 00:40:46 +00002530TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002531 BlockPointerTypeLoc TL,
2532 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002533 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002534 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2535 if (PointeeType.isNull())
2536 return QualType();
2537
2538 QualType Result = TL.getType();
2539 if (getDerived().AlwaysRebuild() ||
2540 PointeeType != TL.getPointeeLoc().getType()) {
2541 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002542 TL.getSigilLoc());
2543 if (Result.isNull())
2544 return QualType();
2545 }
2546
Douglas Gregor049211a2010-04-22 16:50:51 +00002547 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002548 NewT.setSigilLoc(TL.getSigilLoc());
2549 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002550}
2551
John McCall70dd5f62009-10-30 00:06:24 +00002552/// Transforms a reference type. Note that somewhat paradoxically we
2553/// don't care whether the type itself is an l-value type or an r-value
2554/// type; we only care if the type was *written* as an l-value type
2555/// or an r-value type.
2556template<typename Derived>
2557QualType
2558TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002559 ReferenceTypeLoc TL,
2560 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002561 const ReferenceType *T = TL.getTypePtr();
2562
2563 // Note that this works with the pointee-as-written.
2564 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2565 if (PointeeType.isNull())
2566 return QualType();
2567
2568 QualType Result = TL.getType();
2569 if (getDerived().AlwaysRebuild() ||
2570 PointeeType != T->getPointeeTypeAsWritten()) {
2571 Result = getDerived().RebuildReferenceType(PointeeType,
2572 T->isSpelledAsLValue(),
2573 TL.getSigilLoc());
2574 if (Result.isNull())
2575 return QualType();
2576 }
2577
2578 // r-value references can be rebuilt as l-value references.
2579 ReferenceTypeLoc NewTL;
2580 if (isa<LValueReferenceType>(Result))
2581 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2582 else
2583 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2584 NewTL.setSigilLoc(TL.getSigilLoc());
2585
2586 return Result;
2587}
2588
Mike Stump11289f42009-09-09 15:08:12 +00002589template<typename Derived>
2590QualType
John McCall550e0c22009-10-21 00:40:46 +00002591TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002592 LValueReferenceTypeLoc TL,
2593 QualType ObjectType) {
2594 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002595}
2596
Mike Stump11289f42009-09-09 15:08:12 +00002597template<typename Derived>
2598QualType
John McCall550e0c22009-10-21 00:40:46 +00002599TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002600 RValueReferenceTypeLoc TL,
2601 QualType ObjectType) {
2602 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002603}
Mike Stump11289f42009-09-09 15:08:12 +00002604
Douglas Gregord6ff3322009-08-04 16:50:30 +00002605template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002606QualType
John McCall550e0c22009-10-21 00:40:46 +00002607TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002608 MemberPointerTypeLoc TL,
2609 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002610 MemberPointerType *T = TL.getTypePtr();
2611
2612 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002613 if (PointeeType.isNull())
2614 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002615
John McCall550e0c22009-10-21 00:40:46 +00002616 // TODO: preserve source information for this.
2617 QualType ClassType
2618 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002619 if (ClassType.isNull())
2620 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002621
John McCall550e0c22009-10-21 00:40:46 +00002622 QualType Result = TL.getType();
2623 if (getDerived().AlwaysRebuild() ||
2624 PointeeType != T->getPointeeType() ||
2625 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002626 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2627 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002628 if (Result.isNull())
2629 return QualType();
2630 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002631
John McCall550e0c22009-10-21 00:40:46 +00002632 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2633 NewTL.setSigilLoc(TL.getSigilLoc());
2634
2635 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002636}
2637
Mike Stump11289f42009-09-09 15:08:12 +00002638template<typename Derived>
2639QualType
John McCall550e0c22009-10-21 00:40:46 +00002640TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002641 ConstantArrayTypeLoc TL,
2642 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002643 ConstantArrayType *T = TL.getTypePtr();
2644 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645 if (ElementType.isNull())
2646 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002647
John McCall550e0c22009-10-21 00:40:46 +00002648 QualType Result = TL.getType();
2649 if (getDerived().AlwaysRebuild() ||
2650 ElementType != T->getElementType()) {
2651 Result = getDerived().RebuildConstantArrayType(ElementType,
2652 T->getSizeModifier(),
2653 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002654 T->getIndexTypeCVRQualifiers(),
2655 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002656 if (Result.isNull())
2657 return QualType();
2658 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002659
John McCall550e0c22009-10-21 00:40:46 +00002660 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2661 NewTL.setLBracketLoc(TL.getLBracketLoc());
2662 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002663
John McCall550e0c22009-10-21 00:40:46 +00002664 Expr *Size = TL.getSizeExpr();
2665 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002666 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002667 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2668 }
2669 NewTL.setSizeExpr(Size);
2670
2671 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002672}
Mike Stump11289f42009-09-09 15:08:12 +00002673
Douglas Gregord6ff3322009-08-04 16:50:30 +00002674template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002675QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002676 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002677 IncompleteArrayTypeLoc TL,
2678 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002679 IncompleteArrayType *T = TL.getTypePtr();
2680 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002681 if (ElementType.isNull())
2682 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002683
John McCall550e0c22009-10-21 00:40:46 +00002684 QualType Result = TL.getType();
2685 if (getDerived().AlwaysRebuild() ||
2686 ElementType != T->getElementType()) {
2687 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002688 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002689 T->getIndexTypeCVRQualifiers(),
2690 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002691 if (Result.isNull())
2692 return QualType();
2693 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002694
John McCall550e0c22009-10-21 00:40:46 +00002695 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2696 NewTL.setLBracketLoc(TL.getLBracketLoc());
2697 NewTL.setRBracketLoc(TL.getRBracketLoc());
2698 NewTL.setSizeExpr(0);
2699
2700 return Result;
2701}
2702
2703template<typename Derived>
2704QualType
2705TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002706 VariableArrayTypeLoc TL,
2707 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002708 VariableArrayType *T = TL.getTypePtr();
2709 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2710 if (ElementType.isNull())
2711 return QualType();
2712
2713 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002714 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002715
John McCalldadc5752010-08-24 06:29:42 +00002716 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002717 = getDerived().TransformExpr(T->getSizeExpr());
2718 if (SizeResult.isInvalid())
2719 return QualType();
2720
John McCallb268a282010-08-23 23:25:46 +00002721 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002722
2723 QualType Result = TL.getType();
2724 if (getDerived().AlwaysRebuild() ||
2725 ElementType != T->getElementType() ||
2726 Size != T->getSizeExpr()) {
2727 Result = getDerived().RebuildVariableArrayType(ElementType,
2728 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002729 Size,
John McCall550e0c22009-10-21 00:40:46 +00002730 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002731 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002732 if (Result.isNull())
2733 return QualType();
2734 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002735
John McCall550e0c22009-10-21 00:40:46 +00002736 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2737 NewTL.setLBracketLoc(TL.getLBracketLoc());
2738 NewTL.setRBracketLoc(TL.getRBracketLoc());
2739 NewTL.setSizeExpr(Size);
2740
2741 return Result;
2742}
2743
2744template<typename Derived>
2745QualType
2746TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002747 DependentSizedArrayTypeLoc TL,
2748 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002749 DependentSizedArrayType *T = TL.getTypePtr();
2750 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2751 if (ElementType.isNull())
2752 return QualType();
2753
2754 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002755 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002756
John McCalldadc5752010-08-24 06:29:42 +00002757 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002758 = getDerived().TransformExpr(T->getSizeExpr());
2759 if (SizeResult.isInvalid())
2760 return QualType();
2761
2762 Expr *Size = static_cast<Expr*>(SizeResult.get());
2763
2764 QualType Result = TL.getType();
2765 if (getDerived().AlwaysRebuild() ||
2766 ElementType != T->getElementType() ||
2767 Size != T->getSizeExpr()) {
2768 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2769 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002770 Size,
John McCall550e0c22009-10-21 00:40:46 +00002771 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002772 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002773 if (Result.isNull())
2774 return QualType();
2775 }
2776 else SizeResult.take();
2777
2778 // We might have any sort of array type now, but fortunately they
2779 // all have the same location layout.
2780 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2781 NewTL.setLBracketLoc(TL.getLBracketLoc());
2782 NewTL.setRBracketLoc(TL.getRBracketLoc());
2783 NewTL.setSizeExpr(Size);
2784
2785 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002786}
Mike Stump11289f42009-09-09 15:08:12 +00002787
2788template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002789QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002790 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002791 DependentSizedExtVectorTypeLoc TL,
2792 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002793 DependentSizedExtVectorType *T = TL.getTypePtr();
2794
2795 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002796 QualType ElementType = getDerived().TransformType(T->getElementType());
2797 if (ElementType.isNull())
2798 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002799
Douglas Gregore922c772009-08-04 22:27:00 +00002800 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002801 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002802
John McCalldadc5752010-08-24 06:29:42 +00002803 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002804 if (Size.isInvalid())
2805 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002806
John McCall550e0c22009-10-21 00:40:46 +00002807 QualType Result = TL.getType();
2808 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002809 ElementType != T->getElementType() ||
2810 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002811 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002812 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002813 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002814 if (Result.isNull())
2815 return QualType();
2816 }
John McCall550e0c22009-10-21 00:40:46 +00002817
2818 // Result might be dependent or not.
2819 if (isa<DependentSizedExtVectorType>(Result)) {
2820 DependentSizedExtVectorTypeLoc NewTL
2821 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2822 NewTL.setNameLoc(TL.getNameLoc());
2823 } else {
2824 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2825 NewTL.setNameLoc(TL.getNameLoc());
2826 }
2827
2828 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002829}
Mike Stump11289f42009-09-09 15:08:12 +00002830
2831template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002832QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002833 VectorTypeLoc TL,
2834 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002835 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002836 QualType ElementType = getDerived().TransformType(T->getElementType());
2837 if (ElementType.isNull())
2838 return QualType();
2839
John McCall550e0c22009-10-21 00:40:46 +00002840 QualType Result = TL.getType();
2841 if (getDerived().AlwaysRebuild() ||
2842 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002843 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00002844 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00002845 if (Result.isNull())
2846 return QualType();
2847 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002848
John McCall550e0c22009-10-21 00:40:46 +00002849 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2850 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002851
John McCall550e0c22009-10-21 00:40:46 +00002852 return Result;
2853}
2854
2855template<typename Derived>
2856QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002857 ExtVectorTypeLoc TL,
2858 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002859 VectorType *T = TL.getTypePtr();
2860 QualType ElementType = getDerived().TransformType(T->getElementType());
2861 if (ElementType.isNull())
2862 return QualType();
2863
2864 QualType Result = TL.getType();
2865 if (getDerived().AlwaysRebuild() ||
2866 ElementType != T->getElementType()) {
2867 Result = getDerived().RebuildExtVectorType(ElementType,
2868 T->getNumElements(),
2869 /*FIXME*/ SourceLocation());
2870 if (Result.isNull())
2871 return QualType();
2872 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002873
John McCall550e0c22009-10-21 00:40:46 +00002874 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2875 NewTL.setNameLoc(TL.getNameLoc());
2876
2877 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002878}
Mike Stump11289f42009-09-09 15:08:12 +00002879
2880template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002881ParmVarDecl *
2882TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2883 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2884 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2885 if (!NewDI)
2886 return 0;
2887
2888 if (NewDI == OldDI)
2889 return OldParm;
2890 else
2891 return ParmVarDecl::Create(SemaRef.Context,
2892 OldParm->getDeclContext(),
2893 OldParm->getLocation(),
2894 OldParm->getIdentifier(),
2895 NewDI->getType(),
2896 NewDI,
2897 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002898 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002899 /* DefArg */ NULL);
2900}
2901
2902template<typename Derived>
2903bool TreeTransform<Derived>::
2904 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2905 llvm::SmallVectorImpl<QualType> &PTypes,
2906 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2907 FunctionProtoType *T = TL.getTypePtr();
2908
2909 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2910 ParmVarDecl *OldParm = TL.getArg(i);
2911
2912 QualType NewType;
2913 ParmVarDecl *NewParm;
2914
2915 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002916 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2917 if (!NewParm)
2918 return true;
2919 NewType = NewParm->getType();
2920
2921 // Deal with the possibility that we don't have a parameter
2922 // declaration for this parameter.
2923 } else {
2924 NewParm = 0;
2925
2926 QualType OldType = T->getArgType(i);
2927 NewType = getDerived().TransformType(OldType);
2928 if (NewType.isNull())
2929 return true;
2930 }
2931
2932 PTypes.push_back(NewType);
2933 PVars.push_back(NewParm);
2934 }
2935
2936 return false;
2937}
2938
2939template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002940QualType
John McCall550e0c22009-10-21 00:40:46 +00002941TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002942 FunctionProtoTypeLoc TL,
2943 QualType ObjectType) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00002944 // Transform the parameters and return type.
2945 //
2946 // We instantiate in source order, with the return type first followed by
2947 // the parameters, because users tend to expect this (even if they shouldn't
2948 // rely on it!).
2949 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00002950 // When the function has a trailing return type, we instantiate the
2951 // parameters before the return type, since the return type can then refer
2952 // to the parameters themselves (via decltype, sizeof, etc.).
2953 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00002954 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002955 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00002956 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00002957
Douglas Gregor7fb25412010-10-01 18:44:50 +00002958 QualType ResultType;
2959
2960 if (TL.getTrailingReturn()) {
2961 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2962 return QualType();
2963
2964 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2965 if (ResultType.isNull())
2966 return QualType();
2967 }
2968 else {
2969 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2970 if (ResultType.isNull())
2971 return QualType();
2972
2973 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2974 return QualType();
2975 }
2976
John McCall550e0c22009-10-21 00:40:46 +00002977 QualType Result = TL.getType();
2978 if (getDerived().AlwaysRebuild() ||
2979 ResultType != T->getResultType() ||
2980 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2981 Result = getDerived().RebuildFunctionProtoType(ResultType,
2982 ParamTypes.data(),
2983 ParamTypes.size(),
2984 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002985 T->getTypeQuals(),
2986 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002987 if (Result.isNull())
2988 return QualType();
2989 }
Mike Stump11289f42009-09-09 15:08:12 +00002990
John McCall550e0c22009-10-21 00:40:46 +00002991 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2992 NewTL.setLParenLoc(TL.getLParenLoc());
2993 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00002994 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00002995 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2996 NewTL.setArg(i, ParamDecls[i]);
2997
2998 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002999}
Mike Stump11289f42009-09-09 15:08:12 +00003000
Douglas Gregord6ff3322009-08-04 16:50:30 +00003001template<typename Derived>
3002QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003003 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003004 FunctionNoProtoTypeLoc TL,
3005 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003006 FunctionNoProtoType *T = TL.getTypePtr();
3007 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3008 if (ResultType.isNull())
3009 return QualType();
3010
3011 QualType Result = TL.getType();
3012 if (getDerived().AlwaysRebuild() ||
3013 ResultType != T->getResultType())
3014 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3015
3016 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3017 NewTL.setLParenLoc(TL.getLParenLoc());
3018 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003019 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003020
3021 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003022}
Mike Stump11289f42009-09-09 15:08:12 +00003023
John McCallb96ec562009-12-04 22:46:56 +00003024template<typename Derived> QualType
3025TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003026 UnresolvedUsingTypeLoc TL,
3027 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00003028 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003029 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003030 if (!D)
3031 return QualType();
3032
3033 QualType Result = TL.getType();
3034 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3035 Result = getDerived().RebuildUnresolvedUsingType(D);
3036 if (Result.isNull())
3037 return QualType();
3038 }
3039
3040 // We might get an arbitrary type spec type back. We should at
3041 // least always get a type spec type, though.
3042 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3043 NewTL.setNameLoc(TL.getNameLoc());
3044
3045 return Result;
3046}
3047
Douglas Gregord6ff3322009-08-04 16:50:30 +00003048template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003049QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003050 TypedefTypeLoc TL,
3051 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003052 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003053 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003054 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3055 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003056 if (!Typedef)
3057 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003058
John McCall550e0c22009-10-21 00:40:46 +00003059 QualType Result = TL.getType();
3060 if (getDerived().AlwaysRebuild() ||
3061 Typedef != T->getDecl()) {
3062 Result = getDerived().RebuildTypedefType(Typedef);
3063 if (Result.isNull())
3064 return QualType();
3065 }
Mike Stump11289f42009-09-09 15:08:12 +00003066
John McCall550e0c22009-10-21 00:40:46 +00003067 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3068 NewTL.setNameLoc(TL.getNameLoc());
3069
3070 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003071}
Mike Stump11289f42009-09-09 15:08:12 +00003072
Douglas Gregord6ff3322009-08-04 16:50:30 +00003073template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003074QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003075 TypeOfExprTypeLoc TL,
3076 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003077 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003078 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003079
John McCalldadc5752010-08-24 06:29:42 +00003080 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003081 if (E.isInvalid())
3082 return QualType();
3083
John McCall550e0c22009-10-21 00:40:46 +00003084 QualType Result = TL.getType();
3085 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003086 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003087 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003088 if (Result.isNull())
3089 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003090 }
John McCall550e0c22009-10-21 00:40:46 +00003091 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003092
John McCall550e0c22009-10-21 00:40:46 +00003093 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003094 NewTL.setTypeofLoc(TL.getTypeofLoc());
3095 NewTL.setLParenLoc(TL.getLParenLoc());
3096 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003097
3098 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003099}
Mike Stump11289f42009-09-09 15:08:12 +00003100
3101template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003102QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003103 TypeOfTypeLoc TL,
3104 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003105 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3106 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3107 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003108 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003109
John McCall550e0c22009-10-21 00:40:46 +00003110 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003111 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3112 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003113 if (Result.isNull())
3114 return QualType();
3115 }
Mike Stump11289f42009-09-09 15:08:12 +00003116
John McCall550e0c22009-10-21 00:40:46 +00003117 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003118 NewTL.setTypeofLoc(TL.getTypeofLoc());
3119 NewTL.setLParenLoc(TL.getLParenLoc());
3120 NewTL.setRParenLoc(TL.getRParenLoc());
3121 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003122
3123 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003124}
Mike Stump11289f42009-09-09 15:08:12 +00003125
3126template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003127QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003128 DecltypeTypeLoc TL,
3129 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003130 DecltypeType *T = TL.getTypePtr();
3131
Douglas Gregore922c772009-08-04 22:27:00 +00003132 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003133 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003134
John McCalldadc5752010-08-24 06:29:42 +00003135 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003136 if (E.isInvalid())
3137 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003138
John McCall550e0c22009-10-21 00:40:46 +00003139 QualType Result = TL.getType();
3140 if (getDerived().AlwaysRebuild() ||
3141 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003142 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003143 if (Result.isNull())
3144 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003145 }
John McCall550e0c22009-10-21 00:40:46 +00003146 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003147
John McCall550e0c22009-10-21 00:40:46 +00003148 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3149 NewTL.setNameLoc(TL.getNameLoc());
3150
3151 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152}
3153
3154template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003155QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003156 RecordTypeLoc TL,
3157 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003158 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003159 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003160 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3161 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003162 if (!Record)
3163 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003164
John McCall550e0c22009-10-21 00:40:46 +00003165 QualType Result = TL.getType();
3166 if (getDerived().AlwaysRebuild() ||
3167 Record != T->getDecl()) {
3168 Result = getDerived().RebuildRecordType(Record);
3169 if (Result.isNull())
3170 return QualType();
3171 }
Mike Stump11289f42009-09-09 15:08:12 +00003172
John McCall550e0c22009-10-21 00:40:46 +00003173 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3174 NewTL.setNameLoc(TL.getNameLoc());
3175
3176 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003177}
Mike Stump11289f42009-09-09 15:08:12 +00003178
3179template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003180QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003181 EnumTypeLoc TL,
3182 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003183 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003184 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003185 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3186 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003187 if (!Enum)
3188 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003189
John McCall550e0c22009-10-21 00:40:46 +00003190 QualType Result = TL.getType();
3191 if (getDerived().AlwaysRebuild() ||
3192 Enum != T->getDecl()) {
3193 Result = getDerived().RebuildEnumType(Enum);
3194 if (Result.isNull())
3195 return QualType();
3196 }
Mike Stump11289f42009-09-09 15:08:12 +00003197
John McCall550e0c22009-10-21 00:40:46 +00003198 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3199 NewTL.setNameLoc(TL.getNameLoc());
3200
3201 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003202}
John McCallfcc33b02009-09-05 00:15:47 +00003203
John McCalle78aac42010-03-10 03:28:59 +00003204template<typename Derived>
3205QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3206 TypeLocBuilder &TLB,
3207 InjectedClassNameTypeLoc TL,
3208 QualType ObjectType) {
3209 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3210 TL.getTypePtr()->getDecl());
3211 if (!D) return QualType();
3212
3213 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3214 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3215 return T;
3216}
3217
Mike Stump11289f42009-09-09 15:08:12 +00003218
Douglas Gregord6ff3322009-08-04 16:50:30 +00003219template<typename Derived>
3220QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003221 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003222 TemplateTypeParmTypeLoc TL,
3223 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003224 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003225}
3226
Mike Stump11289f42009-09-09 15:08:12 +00003227template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003228QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003229 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003230 SubstTemplateTypeParmTypeLoc TL,
3231 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003232 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003233}
3234
3235template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003236QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3237 const TemplateSpecializationType *TST,
3238 QualType ObjectType) {
3239 // FIXME: this entire method is a temporary workaround; callers
3240 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003241
John McCall0ad16662009-10-29 08:12:44 +00003242 // Fake up a TemplateSpecializationTypeLoc.
3243 TypeLocBuilder TLB;
3244 TemplateSpecializationTypeLoc TL
3245 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3246
John McCall0d07eb32009-10-29 18:45:58 +00003247 SourceLocation BaseLoc = getDerived().getBaseLocation();
3248
3249 TL.setTemplateNameLoc(BaseLoc);
3250 TL.setLAngleLoc(BaseLoc);
3251 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003252 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3253 const TemplateArgument &TA = TST->getArg(i);
3254 TemplateArgumentLoc TAL;
3255 getDerived().InventTemplateArgumentLoc(TA, TAL);
3256 TL.setArgLocInfo(i, TAL.getLocInfo());
3257 }
3258
3259 TypeLocBuilder IgnoredTLB;
3260 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003261}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003262
Douglas Gregorc59e5612009-10-19 22:04:39 +00003263template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003264QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003265 TypeLocBuilder &TLB,
3266 TemplateSpecializationTypeLoc TL,
3267 QualType ObjectType) {
3268 const TemplateSpecializationType *T = TL.getTypePtr();
3269
Mike Stump11289f42009-09-09 15:08:12 +00003270 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003271 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003272 if (Template.isNull())
3273 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003274
John McCall6b51f282009-11-23 01:53:49 +00003275 TemplateArgumentListInfo NewTemplateArgs;
3276 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3277 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3278
3279 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3280 TemplateArgumentLoc Loc;
3281 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003283 NewTemplateArgs.addArgument(Loc);
3284 }
Mike Stump11289f42009-09-09 15:08:12 +00003285
John McCall0ad16662009-10-29 08:12:44 +00003286 // FIXME: maybe don't rebuild if all the template arguments are the same.
3287
3288 QualType Result =
3289 getDerived().RebuildTemplateSpecializationType(Template,
3290 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003291 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003292
3293 if (!Result.isNull()) {
3294 TemplateSpecializationTypeLoc NewTL
3295 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3296 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3297 NewTL.setLAngleLoc(TL.getLAngleLoc());
3298 NewTL.setRAngleLoc(TL.getRAngleLoc());
3299 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3300 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003301 }
Mike Stump11289f42009-09-09 15:08:12 +00003302
John McCall0ad16662009-10-29 08:12:44 +00003303 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304}
Mike Stump11289f42009-09-09 15:08:12 +00003305
3306template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003307QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003308TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3309 ElaboratedTypeLoc TL,
3310 QualType ObjectType) {
3311 ElaboratedType *T = TL.getTypePtr();
3312
3313 NestedNameSpecifier *NNS = 0;
3314 // NOTE: the qualifier in an ElaboratedType is optional.
3315 if (T->getQualifier() != 0) {
3316 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003317 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003318 ObjectType);
3319 if (!NNS)
3320 return QualType();
3321 }
Mike Stump11289f42009-09-09 15:08:12 +00003322
Abramo Bagnarad7548482010-05-19 21:37:53 +00003323 QualType NamedT;
3324 // FIXME: this test is meant to workaround a problem (failing assertion)
3325 // occurring if directly executing the code in the else branch.
3326 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3327 TemplateSpecializationTypeLoc OldNamedTL
3328 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3329 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003330 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003331 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3332 if (NamedT.isNull())
3333 return QualType();
3334 TemplateSpecializationTypeLoc NewNamedTL
3335 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3336 NewNamedTL.copy(OldNamedTL);
3337 }
3338 else {
3339 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3340 if (NamedT.isNull())
3341 return QualType();
3342 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003343
John McCall550e0c22009-10-21 00:40:46 +00003344 QualType Result = TL.getType();
3345 if (getDerived().AlwaysRebuild() ||
3346 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003347 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003348 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3349 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003350 if (Result.isNull())
3351 return QualType();
3352 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003353
Abramo Bagnara6150c882010-05-11 21:36:43 +00003354 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003355 NewTL.setKeywordLoc(TL.getKeywordLoc());
3356 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003357
3358 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003359}
Mike Stump11289f42009-09-09 15:08:12 +00003360
3361template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003362QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3363 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003364 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003365 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003366
Douglas Gregord6ff3322009-08-04 16:50:30 +00003367 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003368 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3369 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003370 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003371 if (!NNS)
3372 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003373
John McCallc392f372010-06-11 00:33:02 +00003374 QualType Result
3375 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3376 T->getIdentifier(),
3377 TL.getKeywordLoc(),
3378 TL.getQualifierRange(),
3379 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003380 if (Result.isNull())
3381 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003382
Abramo Bagnarad7548482010-05-19 21:37:53 +00003383 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3384 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003385 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3386
Abramo Bagnarad7548482010-05-19 21:37:53 +00003387 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3388 NewTL.setKeywordLoc(TL.getKeywordLoc());
3389 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003390 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003391 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3392 NewTL.setKeywordLoc(TL.getKeywordLoc());
3393 NewTL.setQualifierRange(TL.getQualifierRange());
3394 NewTL.setNameLoc(TL.getNameLoc());
3395 }
John McCall550e0c22009-10-21 00:40:46 +00003396 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003397}
Mike Stump11289f42009-09-09 15:08:12 +00003398
Douglas Gregord6ff3322009-08-04 16:50:30 +00003399template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003400QualType TreeTransform<Derived>::
3401 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3402 DependentTemplateSpecializationTypeLoc TL,
3403 QualType ObjectType) {
3404 DependentTemplateSpecializationType *T = TL.getTypePtr();
3405
3406 NestedNameSpecifier *NNS
3407 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3408 TL.getQualifierRange(),
3409 ObjectType);
3410 if (!NNS)
3411 return QualType();
3412
3413 TemplateArgumentListInfo NewTemplateArgs;
3414 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3415 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3416
3417 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3418 TemplateArgumentLoc Loc;
3419 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3420 return QualType();
3421 NewTemplateArgs.addArgument(Loc);
3422 }
3423
Douglas Gregora5614c52010-09-08 23:56:00 +00003424 QualType Result
3425 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3426 NNS,
3427 TL.getQualifierRange(),
3428 T->getIdentifier(),
3429 TL.getNameLoc(),
3430 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003431 if (Result.isNull())
3432 return QualType();
3433
3434 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3435 QualType NamedT = ElabT->getNamedType();
3436
3437 // Copy information relevant to the template specialization.
3438 TemplateSpecializationTypeLoc NamedTL
3439 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3440 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3441 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3442 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3443 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3444
3445 // Copy information relevant to the elaborated type.
3446 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3447 NewTL.setKeywordLoc(TL.getKeywordLoc());
3448 NewTL.setQualifierRange(TL.getQualifierRange());
3449 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003450 TypeLoc NewTL(Result, TL.getOpaqueData());
3451 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003452 }
3453 return Result;
3454}
3455
3456template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003457QualType
3458TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003459 ObjCInterfaceTypeLoc TL,
3460 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003461 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003462 TLB.pushFullCopy(TL);
3463 return TL.getType();
3464}
3465
3466template<typename Derived>
3467QualType
3468TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3469 ObjCObjectTypeLoc TL,
3470 QualType ObjectType) {
3471 // ObjCObjectType is never dependent.
3472 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003473 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003474}
Mike Stump11289f42009-09-09 15:08:12 +00003475
3476template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003477QualType
3478TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003479 ObjCObjectPointerTypeLoc TL,
3480 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003481 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003482 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003483 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003484}
3485
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003487// Statement transformation
3488//===----------------------------------------------------------------------===//
3489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003490StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003491TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003492 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003493}
3494
3495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003496StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003497TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3498 return getDerived().TransformCompoundStmt(S, false);
3499}
3500
3501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003502StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003503TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003504 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003505 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003506 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003507 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003508 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3509 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003510 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003511 if (Result.isInvalid()) {
3512 // Immediately fail if this was a DeclStmt, since it's very
3513 // likely that this will cause problems for future statements.
3514 if (isa<DeclStmt>(*B))
3515 return StmtError();
3516
3517 // Otherwise, just keep processing substatements and fail later.
3518 SubStmtInvalid = true;
3519 continue;
3520 }
Mike Stump11289f42009-09-09 15:08:12 +00003521
Douglas Gregorebe10102009-08-20 07:17:43 +00003522 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3523 Statements.push_back(Result.takeAs<Stmt>());
3524 }
Mike Stump11289f42009-09-09 15:08:12 +00003525
John McCall1ababa62010-08-27 19:56:05 +00003526 if (SubStmtInvalid)
3527 return StmtError();
3528
Douglas Gregorebe10102009-08-20 07:17:43 +00003529 if (!getDerived().AlwaysRebuild() &&
3530 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003531 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003532
3533 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3534 move_arg(Statements),
3535 S->getRBracLoc(),
3536 IsStmtExpr);
3537}
Mike Stump11289f42009-09-09 15:08:12 +00003538
Douglas Gregorebe10102009-08-20 07:17:43 +00003539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003540StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003541TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003542 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003543 {
3544 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003545 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003546
Eli Friedman06577382009-11-19 03:14:00 +00003547 // Transform the left-hand case value.
3548 LHS = getDerived().TransformExpr(S->getLHS());
3549 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003550 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003551
Eli Friedman06577382009-11-19 03:14:00 +00003552 // Transform the right-hand case value (for the GNU case-range extension).
3553 RHS = getDerived().TransformExpr(S->getRHS());
3554 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003555 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003556 }
Mike Stump11289f42009-09-09 15:08:12 +00003557
Douglas Gregorebe10102009-08-20 07:17:43 +00003558 // Build the case statement.
3559 // Case statements are always rebuilt so that they will attached to their
3560 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003561 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003562 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003563 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003564 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003565 S->getColonLoc());
3566 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003567 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003568
Douglas Gregorebe10102009-08-20 07:17:43 +00003569 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003570 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003571 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003572 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003573
Douglas Gregorebe10102009-08-20 07:17:43 +00003574 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003575 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003576}
3577
3578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003579StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003580TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003581 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003582 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003583 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003584 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregorebe10102009-08-20 07:17:43 +00003586 // Default statements are always rebuilt
3587 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003588 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003589}
Mike Stump11289f42009-09-09 15:08:12 +00003590
Douglas Gregorebe10102009-08-20 07:17:43 +00003591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003592StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003593TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003594 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003595 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003596 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003597
Douglas Gregorebe10102009-08-20 07:17:43 +00003598 // FIXME: Pass the real colon location in.
3599 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3600 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003601 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003602}
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregorebe10102009-08-20 07:17:43 +00003604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003605StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003606TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003607 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003608 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003609 VarDecl *ConditionVar = 0;
3610 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003611 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003612 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003613 getDerived().TransformDefinition(
3614 S->getConditionVariable()->getLocation(),
3615 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003616 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003617 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003618 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003619 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003620
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003621 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003622 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003623
3624 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003625 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003626 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003627 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003628 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003629 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003630 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003631
John McCallb268a282010-08-23 23:25:46 +00003632 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003633 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003634 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003635
John McCallb268a282010-08-23 23:25:46 +00003636 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3637 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003638 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003639
Douglas Gregorebe10102009-08-20 07:17:43 +00003640 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003641 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003642 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003643 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003644
Douglas Gregorebe10102009-08-20 07:17:43 +00003645 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003646 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003647 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003648 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003649
Douglas Gregorebe10102009-08-20 07:17:43 +00003650 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003651 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003652 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003653 Then.get() == S->getThen() &&
3654 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003655 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003656
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003657 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003658 Then.get(),
3659 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003660}
3661
3662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003663StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003664TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003665 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003666 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003667 VarDecl *ConditionVar = 0;
3668 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003669 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003670 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003671 getDerived().TransformDefinition(
3672 S->getConditionVariable()->getLocation(),
3673 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003674 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003675 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003676 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003677 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003678
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003679 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003680 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003681 }
Mike Stump11289f42009-09-09 15:08:12 +00003682
Douglas Gregorebe10102009-08-20 07:17:43 +00003683 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003684 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003685 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003686 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003687 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003688 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003689
Douglas Gregorebe10102009-08-20 07:17:43 +00003690 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003691 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003692 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003693 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003694
Douglas Gregorebe10102009-08-20 07:17:43 +00003695 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003696 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3697 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003698}
Mike Stump11289f42009-09-09 15:08:12 +00003699
Douglas Gregorebe10102009-08-20 07:17:43 +00003700template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003701StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003702TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003703 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003704 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003705 VarDecl *ConditionVar = 0;
3706 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003707 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003708 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003709 getDerived().TransformDefinition(
3710 S->getConditionVariable()->getLocation(),
3711 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003712 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003713 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003714 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003715 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003716
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003717 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003718 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003719
3720 if (S->getCond()) {
3721 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003722 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003723 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003724 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003725 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003726 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003727 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003728 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003729 }
Mike Stump11289f42009-09-09 15:08:12 +00003730
John McCallb268a282010-08-23 23:25:46 +00003731 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3732 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003733 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003734
Douglas Gregorebe10102009-08-20 07:17:43 +00003735 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003736 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003737 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003738 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregorebe10102009-08-20 07:17:43 +00003740 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003741 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003742 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003743 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003744 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003745
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003746 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003747 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003748}
Mike Stump11289f42009-09-09 15:08:12 +00003749
Douglas Gregorebe10102009-08-20 07:17:43 +00003750template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003751StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003752TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003753 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003754 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003755 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003756 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003757
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003758 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003759 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003760 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003761 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003762
Douglas Gregorebe10102009-08-20 07:17:43 +00003763 if (!getDerived().AlwaysRebuild() &&
3764 Cond.get() == S->getCond() &&
3765 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003766 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003767
John McCallb268a282010-08-23 23:25:46 +00003768 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3769 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 S->getRParenLoc());
3771}
Mike Stump11289f42009-09-09 15:08:12 +00003772
Douglas Gregorebe10102009-08-20 07:17:43 +00003773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003774StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003775TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003776 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003777 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003778 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003779 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003780
Douglas Gregorebe10102009-08-20 07:17:43 +00003781 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003782 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003783 VarDecl *ConditionVar = 0;
3784 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003785 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003786 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003787 getDerived().TransformDefinition(
3788 S->getConditionVariable()->getLocation(),
3789 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003790 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003791 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003792 } else {
3793 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003794
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003795 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003796 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003797
3798 if (S->getCond()) {
3799 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003800 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003801 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003802 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003803 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003804 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003805
John McCallb268a282010-08-23 23:25:46 +00003806 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003807 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003808 }
Mike Stump11289f42009-09-09 15:08:12 +00003809
John McCallb268a282010-08-23 23:25:46 +00003810 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3811 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003812 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003813
Douglas Gregorebe10102009-08-20 07:17:43 +00003814 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003815 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003816 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003817 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003818
John McCallb268a282010-08-23 23:25:46 +00003819 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3820 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003821 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003822
Douglas Gregorebe10102009-08-20 07:17:43 +00003823 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003824 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003825 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003826 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003827
Douglas Gregorebe10102009-08-20 07:17:43 +00003828 if (!getDerived().AlwaysRebuild() &&
3829 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003830 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003831 Inc.get() == S->getInc() &&
3832 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003833 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003834
Douglas Gregorebe10102009-08-20 07:17:43 +00003835 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003836 Init.get(), FullCond, ConditionVar,
3837 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003838}
3839
3840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003841StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003842TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003843 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003844 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003845 S->getLabel());
3846}
3847
3848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003849StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003850TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003851 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003852 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003853 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003854
Douglas Gregorebe10102009-08-20 07:17:43 +00003855 if (!getDerived().AlwaysRebuild() &&
3856 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003857 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003858
3859 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003860 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003861}
3862
3863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003864StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003865TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003866 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003867}
Mike Stump11289f42009-09-09 15:08:12 +00003868
Douglas Gregorebe10102009-08-20 07:17:43 +00003869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003870StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003871TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003872 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003873}
Mike Stump11289f42009-09-09 15:08:12 +00003874
Douglas Gregorebe10102009-08-20 07:17:43 +00003875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003876StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003877TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003878 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003879 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003880 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003881
Mike Stump11289f42009-09-09 15:08:12 +00003882 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003883 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003884 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003885}
Mike Stump11289f42009-09-09 15:08:12 +00003886
Douglas Gregorebe10102009-08-20 07:17:43 +00003887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003888StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003889TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003890 bool DeclChanged = false;
3891 llvm::SmallVector<Decl *, 4> Decls;
3892 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3893 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003894 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3895 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003896 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003897 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003898
Douglas Gregorebe10102009-08-20 07:17:43 +00003899 if (Transformed != *D)
3900 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregorebe10102009-08-20 07:17:43 +00003902 Decls.push_back(Transformed);
3903 }
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregorebe10102009-08-20 07:17:43 +00003905 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00003906 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003907
3908 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003909 S->getStartLoc(), S->getEndLoc());
3910}
Mike Stump11289f42009-09-09 15:08:12 +00003911
Douglas Gregorebe10102009-08-20 07:17:43 +00003912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003913StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003914TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003915 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00003916 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003917}
3918
3919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003920StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003921TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003922
John McCall37ad5512010-08-23 06:44:23 +00003923 ASTOwningVector<Expr*> Constraints(getSema());
3924 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003925 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003926
John McCalldadc5752010-08-24 06:29:42 +00003927 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003928 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003929
3930 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003931
Anders Carlssonaaeef072010-01-24 05:50:09 +00003932 // Go through the outputs.
3933 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003934 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003935
Anders Carlssonaaeef072010-01-24 05:50:09 +00003936 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003937 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003938
Anders Carlssonaaeef072010-01-24 05:50:09 +00003939 // Transform the output expr.
3940 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003941 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003942 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003943 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003944
Anders Carlssonaaeef072010-01-24 05:50:09 +00003945 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003946
John McCallb268a282010-08-23 23:25:46 +00003947 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003948 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003949
Anders Carlssonaaeef072010-01-24 05:50:09 +00003950 // Go through the inputs.
3951 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003952 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003953
Anders Carlssonaaeef072010-01-24 05:50:09 +00003954 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003955 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003956
Anders Carlssonaaeef072010-01-24 05:50:09 +00003957 // Transform the input expr.
3958 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003959 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003960 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003961 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003962
Anders Carlssonaaeef072010-01-24 05:50:09 +00003963 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003964
John McCallb268a282010-08-23 23:25:46 +00003965 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003966 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003967
Anders Carlssonaaeef072010-01-24 05:50:09 +00003968 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00003969 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003970
3971 // Go through the clobbers.
3972 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00003973 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00003974
3975 // No need to transform the asm string literal.
3976 AsmString = SemaRef.Owned(S->getAsmString());
3977
3978 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3979 S->isSimple(),
3980 S->isVolatile(),
3981 S->getNumOutputs(),
3982 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003983 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003984 move_arg(Constraints),
3985 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003986 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003987 move_arg(Clobbers),
3988 S->getRParenLoc(),
3989 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003990}
3991
3992
3993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003994StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003995TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003996 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00003997 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003998 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003999 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004000
Douglas Gregor96c79492010-04-23 22:50:49 +00004001 // Transform the @catch statements (if present).
4002 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004003 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004004 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004005 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004006 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004007 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004008 if (Catch.get() != S->getCatchStmt(I))
4009 AnyCatchChanged = true;
4010 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004011 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004012
Douglas Gregor306de2f2010-04-22 23:59:56 +00004013 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004014 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004015 if (S->getFinallyStmt()) {
4016 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4017 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004018 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004019 }
4020
4021 // If nothing changed, just retain this statement.
4022 if (!getDerived().AlwaysRebuild() &&
4023 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004024 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004025 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004026 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004027
Douglas Gregor306de2f2010-04-22 23:59:56 +00004028 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004029 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4030 move_arg(CatchStmts), Finally.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>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004036 // Transform the @catch parameter, if there is one.
4037 VarDecl *Var = 0;
4038 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4039 TypeSourceInfo *TSInfo = 0;
4040 if (FromVar->getTypeSourceInfo()) {
4041 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4042 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004043 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004044 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004045
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004046 QualType T;
4047 if (TSInfo)
4048 T = TSInfo->getType();
4049 else {
4050 T = getDerived().TransformType(FromVar->getType());
4051 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004052 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004053 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004054
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004055 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4056 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004057 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004058 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004059
John McCalldadc5752010-08-24 06:29:42 +00004060 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004061 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004062 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004063
4064 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004065 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004066 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004067}
Mike Stump11289f42009-09-09 15:08:12 +00004068
Douglas Gregorebe10102009-08-20 07:17:43 +00004069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004070StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004071TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004072 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004073 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004074 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004075 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004076
Douglas Gregor306de2f2010-04-22 23:59:56 +00004077 // If nothing changed, just retain this statement.
4078 if (!getDerived().AlwaysRebuild() &&
4079 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004080 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004081
4082 // Build a new statement.
4083 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004084 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004085}
Mike Stump11289f42009-09-09 15:08:12 +00004086
Douglas Gregorebe10102009-08-20 07:17:43 +00004087template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004088StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004089TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004090 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004091 if (S->getThrowExpr()) {
4092 Operand = getDerived().TransformExpr(S->getThrowExpr());
4093 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004094 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004095 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004096
Douglas Gregor2900c162010-04-22 21:44:01 +00004097 if (!getDerived().AlwaysRebuild() &&
4098 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004099 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004100
John McCallb268a282010-08-23 23:25:46 +00004101 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004102}
Mike Stump11289f42009-09-09 15:08:12 +00004103
Douglas Gregorebe10102009-08-20 07:17:43 +00004104template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004105StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004106TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004107 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004108 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004109 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004110 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004111 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004112
Douglas Gregor6148de72010-04-22 22:01:21 +00004113 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004114 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004115 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004116 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004117
Douglas Gregor6148de72010-04-22 22:01:21 +00004118 // If nothing change, just retain the current statement.
4119 if (!getDerived().AlwaysRebuild() &&
4120 Object.get() == S->getSynchExpr() &&
4121 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004122 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004123
4124 // Build a new statement.
4125 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004126 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004127}
4128
4129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004130StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004131TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004132 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004133 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004134 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004135 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004136 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004137
Douglas Gregorf68a5082010-04-22 23:10:45 +00004138 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004139 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004140 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004141 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004142
Douglas Gregorf68a5082010-04-22 23:10:45 +00004143 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004144 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004145 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004146 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004147
Douglas Gregorf68a5082010-04-22 23:10:45 +00004148 // If nothing changed, just retain this statement.
4149 if (!getDerived().AlwaysRebuild() &&
4150 Element.get() == S->getElement() &&
4151 Collection.get() == S->getCollection() &&
4152 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004153 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004154
Douglas Gregorf68a5082010-04-22 23:10:45 +00004155 // Build a new statement.
4156 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4157 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004158 Element.get(),
4159 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004160 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004161 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004162}
4163
4164
4165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004166StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004167TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4168 // Transform the exception declaration, if any.
4169 VarDecl *Var = 0;
4170 if (S->getExceptionDecl()) {
4171 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004172 TypeSourceInfo *T = getDerived().TransformType(
4173 ExceptionDecl->getTypeSourceInfo());
4174 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004175 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004176
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004177 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004178 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004179 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004180 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004181 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004182 }
Mike Stump11289f42009-09-09 15:08:12 +00004183
Douglas Gregorebe10102009-08-20 07:17:43 +00004184 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004185 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004186 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004187 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004188
Douglas Gregorebe10102009-08-20 07:17:43 +00004189 if (!getDerived().AlwaysRebuild() &&
4190 !Var &&
4191 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004192 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004193
4194 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4195 Var,
John McCallb268a282010-08-23 23:25:46 +00004196 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004197}
Mike Stump11289f42009-09-09 15:08:12 +00004198
Douglas Gregorebe10102009-08-20 07:17:43 +00004199template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004200StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004201TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4202 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004203 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004204 = getDerived().TransformCompoundStmt(S->getTryBlock());
4205 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004206 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004207
Douglas Gregorebe10102009-08-20 07:17:43 +00004208 // Transform the handlers.
4209 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004210 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004211 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004212 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004213 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4214 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004215 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004216
Douglas Gregorebe10102009-08-20 07:17:43 +00004217 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4218 Handlers.push_back(Handler.takeAs<Stmt>());
4219 }
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregorebe10102009-08-20 07:17:43 +00004221 if (!getDerived().AlwaysRebuild() &&
4222 TryBlock.get() == S->getTryBlock() &&
4223 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004224 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004225
John McCallb268a282010-08-23 23:25:46 +00004226 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004227 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004228}
Mike Stump11289f42009-09-09 15:08:12 +00004229
Douglas Gregorebe10102009-08-20 07:17:43 +00004230//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004231// Expression transformation
4232//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004235TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004236 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004237}
Mike Stump11289f42009-09-09 15:08:12 +00004238
4239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004241TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004242 NestedNameSpecifier *Qualifier = 0;
4243 if (E->getQualifier()) {
4244 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004245 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004246 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004247 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004248 }
John McCallce546572009-12-08 09:08:17 +00004249
4250 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004251 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4252 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004253 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004255
John McCall815039a2010-08-17 21:27:17 +00004256 DeclarationNameInfo NameInfo = E->getNameInfo();
4257 if (NameInfo.getName()) {
4258 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4259 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004260 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004261 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004262
4263 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004264 Qualifier == E->getQualifier() &&
4265 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004266 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004267 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004268
4269 // Mark it referenced in the new context regardless.
4270 // FIXME: this is a bit instantiation-specific.
4271 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4272
John McCallc3007a22010-10-26 07:05:15 +00004273 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004274 }
John McCallce546572009-12-08 09:08:17 +00004275
4276 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004277 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004278 TemplateArgs = &TransArgs;
4279 TransArgs.setLAngleLoc(E->getLAngleLoc());
4280 TransArgs.setRAngleLoc(E->getRAngleLoc());
4281 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4282 TemplateArgumentLoc Loc;
4283 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004284 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004285 TransArgs.addArgument(Loc);
4286 }
4287 }
4288
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004289 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004290 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004291}
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004295TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004296 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004297}
Mike Stump11289f42009-09-09 15:08:12 +00004298
Douglas Gregora16548e2009-08-11 05:31:07 +00004299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004300ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004301TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004302 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004303}
Mike Stump11289f42009-09-09 15:08:12 +00004304
Douglas Gregora16548e2009-08-11 05:31:07 +00004305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004307TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004308 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004313TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004314 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004315}
Mike Stump11289f42009-09-09 15:08:12 +00004316
Douglas Gregora16548e2009-08-11 05:31:07 +00004317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004319TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004320 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004321}
4322
4323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004324ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004325TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004326 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004327 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004329
Douglas Gregora16548e2009-08-11 05:31:07 +00004330 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004331 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004332
John McCallb268a282010-08-23 23:25:46 +00004333 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 E->getRParen());
4335}
4336
Mike Stump11289f42009-09-09 15:08:12 +00004337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004339TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004340 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004345 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004346
Douglas Gregora16548e2009-08-11 05:31:07 +00004347 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4348 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004349 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004350}
Mike Stump11289f42009-09-09 15:08:12 +00004351
Douglas Gregora16548e2009-08-11 05:31:07 +00004352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004353ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004354TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4355 // Transform the type.
4356 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4357 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004358 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004359
Douglas Gregor882211c2010-04-28 22:16:22 +00004360 // Transform all of the components into components similar to what the
4361 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004362 // FIXME: It would be slightly more efficient in the non-dependent case to
4363 // just map FieldDecls, rather than requiring the rebuilder to look for
4364 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004365 // template code that we don't care.
4366 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004367 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004368 typedef OffsetOfExpr::OffsetOfNode Node;
4369 llvm::SmallVector<Component, 4> Components;
4370 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4371 const Node &ON = E->getComponent(I);
4372 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004373 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004374 Comp.LocStart = ON.getRange().getBegin();
4375 Comp.LocEnd = ON.getRange().getEnd();
4376 switch (ON.getKind()) {
4377 case Node::Array: {
4378 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004379 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004380 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004381 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004382
Douglas Gregor882211c2010-04-28 22:16:22 +00004383 ExprChanged = ExprChanged || Index.get() != FromIndex;
4384 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004385 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004386 break;
4387 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004388
Douglas Gregor882211c2010-04-28 22:16:22 +00004389 case Node::Field:
4390 case Node::Identifier:
4391 Comp.isBrackets = false;
4392 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004393 if (!Comp.U.IdentInfo)
4394 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004395
Douglas Gregor882211c2010-04-28 22:16:22 +00004396 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004397
Douglas Gregord1702062010-04-29 00:18:15 +00004398 case Node::Base:
4399 // Will be recomputed during the rebuild.
4400 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004401 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004402
Douglas Gregor882211c2010-04-28 22:16:22 +00004403 Components.push_back(Comp);
4404 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004405
Douglas Gregor882211c2010-04-28 22:16:22 +00004406 // If nothing changed, retain the existing expression.
4407 if (!getDerived().AlwaysRebuild() &&
4408 Type == E->getTypeSourceInfo() &&
4409 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004410 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004411
Douglas Gregor882211c2010-04-28 22:16:22 +00004412 // Build a new offsetof expression.
4413 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4414 Components.data(), Components.size(),
4415 E->getRParenLoc());
4416}
4417
4418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004420TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004421 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004422 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004423
John McCallbcd03502009-12-07 02:54:59 +00004424 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004425 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004427
John McCall4c98fd82009-11-04 07:28:41 +00004428 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004429 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004430
John McCall4c98fd82009-11-04 07:28:41 +00004431 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004432 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 E->getSourceRange());
4434 }
Mike Stump11289f42009-09-09 15:08:12 +00004435
John McCalldadc5752010-08-24 06:29:42 +00004436 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004437 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 // C++0x [expr.sizeof]p1:
4439 // The operand is either an expression, which is an unevaluated operand
4440 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004441 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4444 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004445 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregora16548e2009-08-11 05:31:07 +00004447 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004448 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004449 }
Mike Stump11289f42009-09-09 15:08:12 +00004450
John McCallb268a282010-08-23 23:25:46 +00004451 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 E->isSizeOf(),
4453 E->getSourceRange());
4454}
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004457ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004458TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004459 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004462
John McCalldadc5752010-08-24 06:29:42 +00004463 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004465 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004466
4467
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 if (!getDerived().AlwaysRebuild() &&
4469 LHS.get() == E->getLHS() &&
4470 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004471 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004472
John McCallb268a282010-08-23 23:25:46 +00004473 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004475 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 E->getRBracketLoc());
4477}
Mike Stump11289f42009-09-09 15:08:12 +00004478
4479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004480ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004481TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004482 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004483 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004484 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004485 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004486
4487 // Transform arguments.
4488 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004489 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004490 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004491 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004493 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004494
Mike Stump11289f42009-09-09 15:08:12 +00004495 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004496 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 }
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregora16548e2009-08-11 05:31:07 +00004499 if (!getDerived().AlwaysRebuild() &&
4500 Callee.get() == E->getCallee() &&
4501 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004502 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004503
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004505 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004507 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 E->getRParenLoc());
4510}
Mike Stump11289f42009-09-09 15:08:12 +00004511
4512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004513ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004514TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004515 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004516 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004518
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004519 NestedNameSpecifier *Qualifier = 0;
4520 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004521 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004522 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004523 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004524 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004525 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004526 }
Mike Stump11289f42009-09-09 15:08:12 +00004527
Eli Friedman2cfcef62009-12-04 06:40:45 +00004528 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004529 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4530 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004532 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004533
John McCall16df1e52010-03-30 21:47:33 +00004534 NamedDecl *FoundDecl = E->getFoundDecl();
4535 if (FoundDecl == E->getMemberDecl()) {
4536 FoundDecl = Member;
4537 } else {
4538 FoundDecl = cast_or_null<NamedDecl>(
4539 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4540 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004541 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004542 }
4543
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 if (!getDerived().AlwaysRebuild() &&
4545 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004546 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004547 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004548 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004549 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004550
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004551 // Mark it referenced in the new context regardless.
4552 // FIXME: this is a bit instantiation-specific.
4553 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004554 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004555 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004556
John McCall6b51f282009-11-23 01:53:49 +00004557 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004558 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004559 TransArgs.setLAngleLoc(E->getLAngleLoc());
4560 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004561 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004562 TemplateArgumentLoc Loc;
4563 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004564 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004565 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004566 }
4567 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004568
Douglas Gregora16548e2009-08-11 05:31:07 +00004569 // FIXME: Bogus source location for the operator
4570 SourceLocation FakeOperatorLoc
4571 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4572
John McCall38836f02010-01-15 08:34:02 +00004573 // FIXME: to do this check properly, we will need to preserve the
4574 // first-qualifier-in-scope here, just in case we had a dependent
4575 // base (and therefore couldn't do the check) and a
4576 // nested-name-qualifier (and therefore could do the lookup).
4577 NamedDecl *FirstQualifierInScope = 0;
4578
John McCallb268a282010-08-23 23:25:46 +00004579 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004580 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004581 Qualifier,
4582 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004583 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004584 Member,
John McCall16df1e52010-03-30 21:47:33 +00004585 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004586 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004587 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004588 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004589}
Mike Stump11289f42009-09-09 15:08:12 +00004590
Douglas Gregora16548e2009-08-11 05:31:07 +00004591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004593TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004594 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004597
John McCalldadc5752010-08-24 06:29:42 +00004598 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004599 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregora16548e2009-08-11 05:31:07 +00004602 if (!getDerived().AlwaysRebuild() &&
4603 LHS.get() == E->getLHS() &&
4604 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004605 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004606
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004608 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004609}
4610
Mike Stump11289f42009-09-09 15:08:12 +00004611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004612ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004613TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004614 CompoundAssignOperator *E) {
4615 return getDerived().TransformBinaryOperator(E);
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>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004621 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004624
John McCalldadc5752010-08-24 06:29:42 +00004625 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004626 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004627 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004628
John McCalldadc5752010-08-24 06:29:42 +00004629 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004630 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004632
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 if (!getDerived().AlwaysRebuild() &&
4634 Cond.get() == E->getCond() &&
4635 LHS.get() == E->getLHS() &&
4636 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004637 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004638
John McCallb268a282010-08-23 23:25:46 +00004639 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004640 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004641 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004642 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004643 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004644}
Mike Stump11289f42009-09-09 15:08:12 +00004645
4646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004647ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004648TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004649 // Implicit casts are eliminated during transformation, since they
4650 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004651 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004652}
Mike Stump11289f42009-09-09 15:08:12 +00004653
Douglas Gregora16548e2009-08-11 05:31:07 +00004654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004655ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004656TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004657 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4658 if (!Type)
4659 return ExprError();
4660
John McCalldadc5752010-08-24 06:29:42 +00004661 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004662 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004663 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004664 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004667 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004669 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004670
John McCall97513962010-01-15 18:39:57 +00004671 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004672 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004674 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004675}
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregora16548e2009-08-11 05:31:07 +00004677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004678ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004679TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004680 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4681 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4682 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004684
John McCalldadc5752010-08-24 06:29:42 +00004685 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004687 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004690 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004691 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004692 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004693
John McCall5d7aa7f2010-01-19 22:33:45 +00004694 // Note: the expression type doesn't necessarily match the
4695 // type-as-written, but that's okay, because it should always be
4696 // derivable from the initializer.
4697
John McCalle15bbff2010-01-18 19:35:47 +00004698 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004700 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004701}
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregora16548e2009-08-11 05:31:07 +00004703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004704ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004705TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004706 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004708 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 if (!getDerived().AlwaysRebuild() &&
4711 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004712 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004715 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004717 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 E->getAccessorLoc(),
4719 E->getAccessor());
4720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004724TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004726
John McCall37ad5512010-08-23 06:44:23 +00004727 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004729 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004730 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregora16548e2009-08-11 05:31:07 +00004733 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004734 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004735 }
Mike Stump11289f42009-09-09 15:08:12 +00004736
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004738 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004739
Douglas Gregora16548e2009-08-11 05:31:07 +00004740 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004741 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004742}
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004745ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004746TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004748
Douglas Gregorebe10102009-08-20 07:17:43 +00004749 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004750 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregorebe10102009-08-20 07:17:43 +00004754 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004755 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004756 bool ExprChanged = false;
4757 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4758 DEnd = E->designators_end();
4759 D != DEnd; ++D) {
4760 if (D->isFieldDesignator()) {
4761 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4762 D->getDotLoc(),
4763 D->getFieldLoc()));
4764 continue;
4765 }
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregora16548e2009-08-11 05:31:07 +00004767 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004768 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004771
4772 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4776 ArrayExprs.push_back(Index.release());
4777 continue;
4778 }
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004781 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4783 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004785
John McCalldadc5752010-08-24 06:29:42 +00004786 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004789
4790 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 End.get(),
4792 D->getLBracketLoc(),
4793 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4796 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004797
Douglas Gregora16548e2009-08-11 05:31:07 +00004798 ArrayExprs.push_back(Start.release());
4799 ArrayExprs.push_back(End.release());
4800 }
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregora16548e2009-08-11 05:31:07 +00004802 if (!getDerived().AlwaysRebuild() &&
4803 Init.get() == E->getInit() &&
4804 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004805 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4808 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004809 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004810}
Mike Stump11289f42009-09-09 15:08:12 +00004811
Douglas Gregora16548e2009-08-11 05:31:07 +00004812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004813ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004814TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004815 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004816 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004817
Douglas Gregor3da3c062009-10-28 00:29:27 +00004818 // FIXME: Will we ever have proper type location here? Will we actually
4819 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 QualType T = getDerived().TransformType(E->getType());
4821 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004822 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 if (!getDerived().AlwaysRebuild() &&
4825 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004826 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004827
Douglas Gregora16548e2009-08-11 05:31:07 +00004828 return getDerived().RebuildImplicitValueInitExpr(T);
4829}
Mike Stump11289f42009-09-09 15:08:12 +00004830
Douglas Gregora16548e2009-08-11 05:31:07 +00004831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004832ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004833TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004834 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4835 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004836 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004837
John McCalldadc5752010-08-24 06:29:42 +00004838 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004839 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004841
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004843 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004845 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004846
John McCallb268a282010-08-23 23:25:46 +00004847 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004848 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004849}
4850
4851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004853TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004855 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004856 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004857 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004858 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004862 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004863 }
Mike Stump11289f42009-09-09 15:08:12 +00004864
Douglas Gregora16548e2009-08-11 05:31:07 +00004865 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4866 move_arg(Inits),
4867 E->getRParenLoc());
4868}
Mike Stump11289f42009-09-09 15:08:12 +00004869
Douglas Gregora16548e2009-08-11 05:31:07 +00004870/// \brief Transform an address-of-label expression.
4871///
4872/// By default, the transformation of an address-of-label expression always
4873/// rebuilds the expression, so that the label identifier can be resolved to
4874/// the corresponding label statement by semantic analysis.
4875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004876ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004877TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4879 E->getLabel());
4880}
Mike Stump11289f42009-09-09 15:08:12 +00004881
4882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004883ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004884TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004885 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004886 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4887 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregora16548e2009-08-11 05:31:07 +00004890 if (!getDerived().AlwaysRebuild() &&
4891 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00004892 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004893
4894 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004895 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 E->getRParenLoc());
4897}
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregora16548e2009-08-11 05:31:07 +00004899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004900ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004901TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004902 TypeSourceInfo *TInfo1;
4903 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004904
4905 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4906 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004907 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004908
Douglas Gregor7058c262010-08-10 14:27:00 +00004909 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4910 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004911 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004912
4913 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004914 TInfo1 == E->getArgTInfo1() &&
4915 TInfo2 == E->getArgTInfo2())
John McCallc3007a22010-10-26 07:05:15 +00004916 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004917
Douglas Gregora16548e2009-08-11 05:31:07 +00004918 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004919 TInfo1, TInfo2,
4920 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004921}
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregora16548e2009-08-11 05:31:07 +00004923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004924ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004925TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004926 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004927 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004928 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004929
John McCalldadc5752010-08-24 06:29:42 +00004930 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004931 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004932 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004933
John McCalldadc5752010-08-24 06:29:42 +00004934 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 if (!getDerived().AlwaysRebuild() &&
4939 Cond.get() == E->getCond() &&
4940 LHS.get() == E->getLHS() &&
4941 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004942 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004943
Douglas Gregora16548e2009-08-11 05:31:07 +00004944 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004945 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004946 E->getRParenLoc());
4947}
Mike Stump11289f42009-09-09 15:08:12 +00004948
Douglas Gregora16548e2009-08-11 05:31:07 +00004949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004950ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004951TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004952 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004953}
4954
4955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004956ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004957TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004958 switch (E->getOperator()) {
4959 case OO_New:
4960 case OO_Delete:
4961 case OO_Array_New:
4962 case OO_Array_Delete:
4963 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004964 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004965
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004966 case OO_Call: {
4967 // This is a call to an object's operator().
4968 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4969
4970 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004971 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004972 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004973 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004974
4975 // FIXME: Poor location information
4976 SourceLocation FakeLParenLoc
4977 = SemaRef.PP.getLocForEndOfToken(
4978 static_cast<Expr *>(Object.get())->getLocEnd());
4979
4980 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004981 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004982 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004983 if (getDerived().DropCallArgument(E->getArg(I)))
4984 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004985
John McCalldadc5752010-08-24 06:29:42 +00004986 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004987 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004988 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004989
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004990 Args.push_back(Arg.release());
4991 }
4992
John McCallb268a282010-08-23 23:25:46 +00004993 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004994 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004995 E->getLocEnd());
4996 }
4997
4998#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4999 case OO_##Name:
5000#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5001#include "clang/Basic/OperatorKinds.def"
5002 case OO_Subscript:
5003 // Handled below.
5004 break;
5005
5006 case OO_Conditional:
5007 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005008 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005009
5010 case OO_None:
5011 case NUM_OVERLOADED_OPERATORS:
5012 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005014 }
5015
John McCalldadc5752010-08-24 06:29:42 +00005016 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005018 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005019
John McCalldadc5752010-08-24 06:29:42 +00005020 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005022 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005023
John McCalldadc5752010-08-24 06:29:42 +00005024 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005025 if (E->getNumArgs() == 2) {
5026 Second = getDerived().TransformExpr(E->getArg(1));
5027 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005028 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005029 }
Mike Stump11289f42009-09-09 15:08:12 +00005030
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 if (!getDerived().AlwaysRebuild() &&
5032 Callee.get() == E->getCallee() &&
5033 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005034 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005035 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005036
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5038 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005039 Callee.get(),
5040 First.get(),
5041 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005042}
Mike Stump11289f42009-09-09 15:08:12 +00005043
Douglas Gregora16548e2009-08-11 05:31:07 +00005044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005046TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5047 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005048}
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregora16548e2009-08-11 05:31:07 +00005050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005052TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005053 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5054 if (!Type)
5055 return ExprError();
5056
John McCalldadc5752010-08-24 06:29:42 +00005057 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005058 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005060 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005063 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005064 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005065 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005068 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005069 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5070 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5071 SourceLocation FakeRParenLoc
5072 = SemaRef.PP.getLocForEndOfToken(
5073 E->getSubExpr()->getSourceRange().getEnd());
5074 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005075 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005077 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005078 FakeRAngleLoc,
5079 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005080 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005081 FakeRParenLoc);
5082}
Mike Stump11289f42009-09-09 15:08:12 +00005083
Douglas Gregora16548e2009-08-11 05:31:07 +00005084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005085ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005086TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5087 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005088}
Mike Stump11289f42009-09-09 15:08:12 +00005089
5090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005091ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005092TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5093 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005094}
5095
Douglas Gregora16548e2009-08-11 05:31:07 +00005096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005097ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005098TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005099 CXXReinterpretCastExpr *E) {
5100 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005101}
Mike Stump11289f42009-09-09 15:08:12 +00005102
Douglas Gregora16548e2009-08-11 05:31:07 +00005103template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005104ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005105TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5106 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005107}
Mike Stump11289f42009-09-09 15:08:12 +00005108
Douglas Gregora16548e2009-08-11 05:31:07 +00005109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005110ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005111TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005112 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005113 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5114 if (!Type)
5115 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005116
John McCalldadc5752010-08-24 06:29:42 +00005117 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005118 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005119 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005123 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005125 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005127 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005129 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 E->getRParenLoc());
5131}
Mike Stump11289f42009-09-09 15:08:12 +00005132
Douglas Gregora16548e2009-08-11 05:31:07 +00005133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005134ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005135TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005136 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005137 TypeSourceInfo *TInfo
5138 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5139 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005140 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005141
Douglas Gregora16548e2009-08-11 05:31:07 +00005142 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005143 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005144 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregor9da64192010-04-26 22:37:10 +00005146 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5147 E->getLocStart(),
5148 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 E->getLocEnd());
5150 }
Mike Stump11289f42009-09-09 15:08:12 +00005151
Douglas Gregora16548e2009-08-11 05:31:07 +00005152 // We don't know whether the expression is potentially evaluated until
5153 // after we perform semantic analysis, so the expression is potentially
5154 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005155 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005156 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005157
John McCalldadc5752010-08-24 06:29:42 +00005158 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005161
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 if (!getDerived().AlwaysRebuild() &&
5163 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005164 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005165
Douglas Gregor9da64192010-04-26 22:37:10 +00005166 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5167 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005168 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 E->getLocEnd());
5170}
5171
5172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005173ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005174TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5175 if (E->isTypeOperand()) {
5176 TypeSourceInfo *TInfo
5177 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5178 if (!TInfo)
5179 return ExprError();
5180
5181 if (!getDerived().AlwaysRebuild() &&
5182 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005183 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005184
5185 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5186 E->getLocStart(),
5187 TInfo,
5188 E->getLocEnd());
5189 }
5190
5191 // We don't know whether the expression is potentially evaluated until
5192 // after we perform semantic analysis, so the expression is potentially
5193 // potentially evaluated.
5194 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5195
5196 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5197 if (SubExpr.isInvalid())
5198 return ExprError();
5199
5200 if (!getDerived().AlwaysRebuild() &&
5201 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005202 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005203
5204 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5205 E->getLocStart(),
5206 SubExpr.get(),
5207 E->getLocEnd());
5208}
5209
5210template<typename Derived>
5211ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005212TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005213 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005214}
Mike Stump11289f42009-09-09 15:08:12 +00005215
Douglas Gregora16548e2009-08-11 05:31:07 +00005216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005217ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005218TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005219 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005220 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005221}
Mike Stump11289f42009-09-09 15:08:12 +00005222
Douglas Gregora16548e2009-08-11 05:31:07 +00005223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005225TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005226 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5227 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5228 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005229
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005230 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005231 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregorb15af892010-01-07 23:12:05 +00005233 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005234}
Mike Stump11289f42009-09-09 15:08:12 +00005235
Douglas Gregora16548e2009-08-11 05:31:07 +00005236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005238TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005239 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005240 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005241 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 if (!getDerived().AlwaysRebuild() &&
5244 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005245 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005246
John McCallb268a282010-08-23 23:25:46 +00005247 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005248}
Mike Stump11289f42009-09-09 15:08:12 +00005249
Douglas Gregora16548e2009-08-11 05:31:07 +00005250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005251ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005252TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005253 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005254 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5255 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005257 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005258
Chandler Carruth794da4c2010-02-08 06:42:49 +00005259 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005260 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005261 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregor033f6752009-12-23 23:03:06 +00005263 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005264}
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregora16548e2009-08-11 05:31:07 +00005266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005267ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005268TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5269 CXXScalarValueInitExpr *E) {
5270 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5271 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005272 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005275 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005276 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregor2b88c112010-09-08 00:15:04 +00005278 return getDerived().RebuildCXXScalarValueInitExpr(T,
5279 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005280 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005281}
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregora16548e2009-08-11 05:31:07 +00005283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005284ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005285TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005287 TypeSourceInfo *AllocTypeInfo
5288 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5289 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005291
Douglas Gregora16548e2009-08-11 05:31:07 +00005292 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005293 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005296
Douglas Gregora16548e2009-08-11 05:31:07 +00005297 // Transform the placement arguments (if any).
5298 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005299 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005300 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005301 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5302 ArgumentChanged = true;
5303 break;
5304 }
5305
John McCalldadc5752010-08-24 06:29:42 +00005306 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005307 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005309
Douglas Gregora16548e2009-08-11 05:31:07 +00005310 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5311 PlacementArgs.push_back(Arg.take());
5312 }
Mike Stump11289f42009-09-09 15:08:12 +00005313
Douglas Gregorebe10102009-08-20 07:17:43 +00005314 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005315 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005316 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005317 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5318 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005319 break;
John McCall09d13692010-10-05 22:36:42 +00005320 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005321
John McCalldadc5752010-08-24 06:29:42 +00005322 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005323 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005324 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregora16548e2009-08-11 05:31:07 +00005326 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5327 ConstructorArgs.push_back(Arg.take());
5328 }
Mike Stump11289f42009-09-09 15:08:12 +00005329
Douglas Gregord2d9da02010-02-26 00:38:10 +00005330 // Transform constructor, new operator, and delete operator.
5331 CXXConstructorDecl *Constructor = 0;
5332 if (E->getConstructor()) {
5333 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005334 getDerived().TransformDecl(E->getLocStart(),
5335 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005336 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005337 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005338 }
5339
5340 FunctionDecl *OperatorNew = 0;
5341 if (E->getOperatorNew()) {
5342 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005343 getDerived().TransformDecl(E->getLocStart(),
5344 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005345 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005346 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005347 }
5348
5349 FunctionDecl *OperatorDelete = 0;
5350 if (E->getOperatorDelete()) {
5351 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005352 getDerived().TransformDecl(E->getLocStart(),
5353 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005354 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005355 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005356 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005357
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005359 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005360 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005361 Constructor == E->getConstructor() &&
5362 OperatorNew == E->getOperatorNew() &&
5363 OperatorDelete == E->getOperatorDelete() &&
5364 !ArgumentChanged) {
5365 // Mark any declarations we need as referenced.
5366 // FIXME: instantiation-specific.
5367 if (Constructor)
5368 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5369 if (OperatorNew)
5370 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5371 if (OperatorDelete)
5372 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005373 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005374 }
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregor0744ef62010-09-07 21:49:58 +00005376 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005377 if (!ArraySize.get()) {
5378 // If no array size was specified, but the new expression was
5379 // instantiated with an array type (e.g., "new T" where T is
5380 // instantiated with "int[4]"), extract the outer bound from the
5381 // array type as our array size. We do this with constant and
5382 // dependently-sized array types.
5383 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5384 if (!ArrayT) {
5385 // Do nothing
5386 } else if (const ConstantArrayType *ConsArrayT
5387 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005388 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005389 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5390 ConsArrayT->getSize(),
5391 SemaRef.Context.getSizeType(),
5392 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005393 AllocType = ConsArrayT->getElementType();
5394 } else if (const DependentSizedArrayType *DepArrayT
5395 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5396 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005397 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005398 AllocType = DepArrayT->getElementType();
5399 }
5400 }
5401 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005402
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5404 E->isGlobalNew(),
5405 /*FIXME:*/E->getLocStart(),
5406 move_arg(PlacementArgs),
5407 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005408 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005409 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005410 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005411 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005412 /*FIXME:*/E->getLocStart(),
5413 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005414 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005415}
Mike Stump11289f42009-09-09 15:08:12 +00005416
Douglas Gregora16548e2009-08-11 05:31:07 +00005417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005418ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005419TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005420 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005421 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005422 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005423
Douglas Gregord2d9da02010-02-26 00:38:10 +00005424 // Transform the delete operator, if known.
5425 FunctionDecl *OperatorDelete = 0;
5426 if (E->getOperatorDelete()) {
5427 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005428 getDerived().TransformDecl(E->getLocStart(),
5429 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005430 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005431 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005432 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005433
Douglas Gregora16548e2009-08-11 05:31:07 +00005434 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005435 Operand.get() == E->getArgument() &&
5436 OperatorDelete == E->getOperatorDelete()) {
5437 // Mark any declarations we need as referenced.
5438 // FIXME: instantiation-specific.
5439 if (OperatorDelete)
5440 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005441
5442 if (!E->getArgument()->isTypeDependent()) {
5443 QualType Destroyed = SemaRef.Context.getBaseElementType(
5444 E->getDestroyedType());
5445 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5446 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5447 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5448 SemaRef.LookupDestructor(Record));
5449 }
5450 }
5451
John McCallc3007a22010-10-26 07:05:15 +00005452 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005453 }
Mike Stump11289f42009-09-09 15:08:12 +00005454
Douglas Gregora16548e2009-08-11 05:31:07 +00005455 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5456 E->isGlobalDelete(),
5457 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005458 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005459}
Mike Stump11289f42009-09-09 15:08:12 +00005460
Douglas Gregora16548e2009-08-11 05:31:07 +00005461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005462ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005463TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005464 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005465 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005466 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005468
John McCallba7bf592010-08-24 05:47:05 +00005469 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005470 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005471 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005472 E->getOperatorLoc(),
5473 E->isArrow()? tok::arrow : tok::period,
5474 ObjectTypePtr,
5475 MayBePseudoDestructor);
5476 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005477 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005478
John McCallba7bf592010-08-24 05:47:05 +00005479 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005480 NestedNameSpecifier *Qualifier
5481 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005482 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005483 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005484 if (E->getQualifier() && !Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005486
Douglas Gregor678f90d2010-02-25 01:56:36 +00005487 PseudoDestructorTypeStorage Destroyed;
5488 if (E->getDestroyedTypeInfo()) {
5489 TypeSourceInfo *DestroyedTypeInfo
5490 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5491 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005493 Destroyed = DestroyedTypeInfo;
5494 } else if (ObjectType->isDependentType()) {
5495 // We aren't likely to be able to resolve the identifier down to a type
5496 // now anyway, so just retain the identifier.
5497 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5498 E->getDestroyedTypeLoc());
5499 } else {
5500 // Look for a destructor known with the given name.
5501 CXXScopeSpec SS;
5502 if (Qualifier) {
5503 SS.setScopeRep(Qualifier);
5504 SS.setRange(E->getQualifierRange());
5505 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005506
John McCallba7bf592010-08-24 05:47:05 +00005507 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005508 *E->getDestroyedTypeIdentifier(),
5509 E->getDestroyedTypeLoc(),
5510 /*Scope=*/0,
5511 SS, ObjectTypePtr,
5512 false);
5513 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005514 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005515
Douglas Gregor678f90d2010-02-25 01:56:36 +00005516 Destroyed
5517 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5518 E->getDestroyedTypeLoc());
5519 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005520
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005521 TypeSourceInfo *ScopeTypeInfo = 0;
5522 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005523 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005524 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005525 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005526 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005527 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005528
John McCallb268a282010-08-23 23:25:46 +00005529 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005530 E->getOperatorLoc(),
5531 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005532 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005533 E->getQualifierRange(),
5534 ScopeTypeInfo,
5535 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005536 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005537 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005538}
Mike Stump11289f42009-09-09 15:08:12 +00005539
Douglas Gregorad8a3362009-09-04 17:36:40 +00005540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005541ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005542TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005543 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005544 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5545
5546 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5547 Sema::LookupOrdinaryName);
5548
5549 // Transform all the decls.
5550 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5551 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005552 NamedDecl *InstD = static_cast<NamedDecl*>(
5553 getDerived().TransformDecl(Old->getNameLoc(),
5554 *I));
John McCall84d87672009-12-10 09:41:52 +00005555 if (!InstD) {
5556 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5557 // This can happen because of dependent hiding.
5558 if (isa<UsingShadowDecl>(*I))
5559 continue;
5560 else
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005562 }
John McCalle66edc12009-11-24 19:00:30 +00005563
5564 // Expand using declarations.
5565 if (isa<UsingDecl>(InstD)) {
5566 UsingDecl *UD = cast<UsingDecl>(InstD);
5567 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5568 E = UD->shadow_end(); I != E; ++I)
5569 R.addDecl(*I);
5570 continue;
5571 }
5572
5573 R.addDecl(InstD);
5574 }
5575
5576 // Resolve a kind, but don't do any further analysis. If it's
5577 // ambiguous, the callee needs to deal with it.
5578 R.resolveKind();
5579
5580 // Rebuild the nested-name qualifier, if present.
5581 CXXScopeSpec SS;
5582 NestedNameSpecifier *Qualifier = 0;
5583 if (Old->getQualifier()) {
5584 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005585 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005586 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005587 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005588
John McCalle66edc12009-11-24 19:00:30 +00005589 SS.setScopeRep(Qualifier);
5590 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005591 }
5592
Douglas Gregor9262f472010-04-27 18:19:34 +00005593 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005594 CXXRecordDecl *NamingClass
5595 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5596 Old->getNameLoc(),
5597 Old->getNamingClass()));
5598 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005599 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005600
Douglas Gregorda7be082010-04-27 16:10:10 +00005601 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005602 }
5603
5604 // If we have no template arguments, it's a normal declaration name.
5605 if (!Old->hasExplicitTemplateArgs())
5606 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5607
5608 // If we have template arguments, rebuild them, then rebuild the
5609 // templateid expression.
5610 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5611 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5612 TemplateArgumentLoc Loc;
5613 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005614 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005615 TransArgs.addArgument(Loc);
5616 }
5617
5618 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5619 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005620}
Mike Stump11289f42009-09-09 15:08:12 +00005621
Douglas Gregora16548e2009-08-11 05:31:07 +00005622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005624TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005625 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5626 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005627 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005628
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005630 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005631 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005632
Mike Stump11289f42009-09-09 15:08:12 +00005633 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 T,
5636 E->getLocEnd());
5637}
Mike Stump11289f42009-09-09 15:08:12 +00005638
Douglas Gregora16548e2009-08-11 05:31:07 +00005639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005640ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005641TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005642 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005644 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005645 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005648
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005649 DeclarationNameInfo NameInfo
5650 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5651 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005652 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005653
John McCalle66edc12009-11-24 19:00:30 +00005654 if (!E->hasExplicitTemplateArgs()) {
5655 if (!getDerived().AlwaysRebuild() &&
5656 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005657 // Note: it is sufficient to compare the Name component of NameInfo:
5658 // if name has not changed, DNLoc has not changed either.
5659 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005660 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005661
John McCalle66edc12009-11-24 19:00:30 +00005662 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5663 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005664 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005665 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005666 }
John McCall6b51f282009-11-23 01:53:49 +00005667
5668 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005670 TemplateArgumentLoc Loc;
5671 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005672 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005673 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005674 }
5675
John McCalle66edc12009-11-24 19:00:30 +00005676 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5677 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005678 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005679 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005680}
5681
5682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005684TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005685 // CXXConstructExprs are always implicit, so when we have a
5686 // 1-argument construction we just transform that argument.
5687 if (E->getNumArgs() == 1 ||
5688 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5689 return getDerived().TransformExpr(E->getArg(0));
5690
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5692
5693 QualType T = getDerived().TransformType(E->getType());
5694 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005695 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005696
5697 CXXConstructorDecl *Constructor
5698 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005699 getDerived().TransformDecl(E->getLocStart(),
5700 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005701 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregora16548e2009-08-11 05:31:07 +00005704 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005705 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005706 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 ArgEnd = E->arg_end();
5708 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005709 if (getDerived().DropCallArgument(*Arg)) {
5710 ArgumentChanged = true;
5711 break;
5712 }
5713
John McCalldadc5752010-08-24 06:29:42 +00005714 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005715 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005717
Douglas Gregora16548e2009-08-11 05:31:07 +00005718 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005719 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005720 }
5721
5722 if (!getDerived().AlwaysRebuild() &&
5723 T == E->getType() &&
5724 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005725 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005726 // Mark the constructor as referenced.
5727 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005728 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005729 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005730 }
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregordb121ba2009-12-14 16:27:04 +00005732 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5733 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005734 move_arg(Args),
5735 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005736 E->getConstructionKind(),
5737 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005738}
Mike Stump11289f42009-09-09 15:08:12 +00005739
Douglas Gregora16548e2009-08-11 05:31:07 +00005740/// \brief Transform a C++ temporary-binding expression.
5741///
Douglas Gregor363b1512009-12-24 18:51:59 +00005742/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5743/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005745ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005746TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005747 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005748}
Mike Stump11289f42009-09-09 15:08:12 +00005749
5750/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005751/// be destroyed after the expression is evaluated.
5752///
Douglas Gregor363b1512009-12-24 18:51:59 +00005753/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5754/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005756ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005757TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005758 CXXExprWithTemporaries *E) {
5759 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005760}
Mike Stump11289f42009-09-09 15:08:12 +00005761
Douglas Gregora16548e2009-08-11 05:31:07 +00005762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005763ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005764TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005765 CXXTemporaryObjectExpr *E) {
5766 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5767 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005769
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 CXXConstructorDecl *Constructor
5771 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005772 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005773 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005774 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005778 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005780 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 ArgEnd = E->arg_end();
5782 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005783 if (getDerived().DropCallArgument(*Arg)) {
5784 ArgumentChanged = true;
5785 break;
5786 }
5787
John McCalldadc5752010-08-24 06:29:42 +00005788 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5793 Args.push_back((Expr *)TransArg.release());
5794 }
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregora16548e2009-08-11 05:31:07 +00005796 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005797 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005798 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005799 !ArgumentChanged) {
5800 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005801 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005802 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005803 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005804
5805 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5806 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 E->getLocEnd());
5809}
Mike Stump11289f42009-09-09 15:08:12 +00005810
Douglas Gregora16548e2009-08-11 05:31:07 +00005811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005812ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005813TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005814 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005815 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5816 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005817 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005818
Douglas Gregora16548e2009-08-11 05:31:07 +00005819 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005820 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005821 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5822 ArgEnd = E->arg_end();
5823 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005824 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005825 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005829 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 }
Mike Stump11289f42009-09-09 15:08:12 +00005831
Douglas Gregora16548e2009-08-11 05:31:07 +00005832 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005833 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005834 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005835 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregora16548e2009-08-11 05:31:07 +00005837 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005838 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 E->getLParenLoc(),
5840 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 E->getRParenLoc());
5842}
Mike Stump11289f42009-09-09 15:08:12 +00005843
Douglas Gregora16548e2009-08-11 05:31:07 +00005844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005845ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005846TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005847 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005849 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005850 Expr *OldBase;
5851 QualType BaseType;
5852 QualType ObjectType;
5853 if (!E->isImplicitAccess()) {
5854 OldBase = E->getBase();
5855 Base = getDerived().TransformExpr(OldBase);
5856 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005857 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005858
John McCall2d74de92009-12-01 22:10:20 +00005859 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005860 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005861 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005862 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005863 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005864 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005865 ObjectTy,
5866 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005867 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005869
John McCallba7bf592010-08-24 05:47:05 +00005870 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005871 BaseType = ((Expr*) Base.get())->getType();
5872 } else {
5873 OldBase = 0;
5874 BaseType = getDerived().TransformType(E->getBaseType());
5875 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5876 }
Mike Stump11289f42009-09-09 15:08:12 +00005877
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005878 // Transform the first part of the nested-name-specifier that qualifies
5879 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005880 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005881 = getDerived().TransformFirstQualifierInScope(
5882 E->getFirstQualifierFoundInScope(),
5883 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005884
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005885 NestedNameSpecifier *Qualifier = 0;
5886 if (E->getQualifier()) {
5887 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5888 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005889 ObjectType,
5890 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005891 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005892 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005893 }
Mike Stump11289f42009-09-09 15:08:12 +00005894
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005895 DeclarationNameInfo NameInfo
5896 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5897 ObjectType);
5898 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005899 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005900
John McCall2d74de92009-12-01 22:10:20 +00005901 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005902 // This is a reference to a member without an explicitly-specified
5903 // template argument list. Optimize for this common case.
5904 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005905 Base.get() == OldBase &&
5906 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005907 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005908 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005909 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00005910 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005911
John McCallb268a282010-08-23 23:25:46 +00005912 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005913 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005914 E->isArrow(),
5915 E->getOperatorLoc(),
5916 Qualifier,
5917 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005918 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005919 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005920 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005921 }
5922
John McCall6b51f282009-11-23 01:53:49 +00005923 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005924 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005925 TemplateArgumentLoc Loc;
5926 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005927 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005928 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005929 }
Mike Stump11289f42009-09-09 15:08:12 +00005930
John McCallb268a282010-08-23 23:25:46 +00005931 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005932 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005933 E->isArrow(),
5934 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005935 Qualifier,
5936 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005937 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005938 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005939 &TransArgs);
5940}
5941
5942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005944TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005945 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005946 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005947 QualType BaseType;
5948 if (!Old->isImplicitAccess()) {
5949 Base = getDerived().TransformExpr(Old->getBase());
5950 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005951 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005952 BaseType = ((Expr*) Base.get())->getType();
5953 } else {
5954 BaseType = getDerived().TransformType(Old->getBaseType());
5955 }
John McCall10eae182009-11-30 22:42:35 +00005956
5957 NestedNameSpecifier *Qualifier = 0;
5958 if (Old->getQualifier()) {
5959 Qualifier
5960 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005961 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005962 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005964 }
5965
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005966 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005967 Sema::LookupOrdinaryName);
5968
5969 // Transform all the decls.
5970 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5971 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005972 NamedDecl *InstD = static_cast<NamedDecl*>(
5973 getDerived().TransformDecl(Old->getMemberLoc(),
5974 *I));
John McCall84d87672009-12-10 09:41:52 +00005975 if (!InstD) {
5976 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5977 // This can happen because of dependent hiding.
5978 if (isa<UsingShadowDecl>(*I))
5979 continue;
5980 else
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005982 }
John McCall10eae182009-11-30 22:42:35 +00005983
5984 // Expand using declarations.
5985 if (isa<UsingDecl>(InstD)) {
5986 UsingDecl *UD = cast<UsingDecl>(InstD);
5987 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5988 E = UD->shadow_end(); I != E; ++I)
5989 R.addDecl(*I);
5990 continue;
5991 }
5992
5993 R.addDecl(InstD);
5994 }
5995
5996 R.resolveKind();
5997
Douglas Gregor9262f472010-04-27 18:19:34 +00005998 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005999 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006000 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006001 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006002 Old->getMemberLoc(),
6003 Old->getNamingClass()));
6004 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006006
Douglas Gregorda7be082010-04-27 16:10:10 +00006007 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006008 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006009
John McCall10eae182009-11-30 22:42:35 +00006010 TemplateArgumentListInfo TransArgs;
6011 if (Old->hasExplicitTemplateArgs()) {
6012 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6013 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6014 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6015 TemplateArgumentLoc Loc;
6016 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6017 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006019 TransArgs.addArgument(Loc);
6020 }
6021 }
John McCall38836f02010-01-15 08:34:02 +00006022
6023 // FIXME: to do this check properly, we will need to preserve the
6024 // first-qualifier-in-scope here, just in case we had a dependent
6025 // base (and therefore couldn't do the check) and a
6026 // nested-name-qualifier (and therefore could do the lookup).
6027 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006028
John McCallb268a282010-08-23 23:25:46 +00006029 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006030 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006031 Old->getOperatorLoc(),
6032 Old->isArrow(),
6033 Qualifier,
6034 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006035 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006036 R,
6037 (Old->hasExplicitTemplateArgs()
6038 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006039}
6040
6041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006042ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006043TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6044 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6045 if (SubExpr.isInvalid())
6046 return ExprError();
6047
6048 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006049 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006050
6051 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6052}
6053
6054template<typename Derived>
6055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006056TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006057 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006058}
6059
Mike Stump11289f42009-09-09 15:08:12 +00006060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006061ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006062TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006063 TypeSourceInfo *EncodedTypeInfo
6064 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6065 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006067
Douglas Gregora16548e2009-08-11 05:31:07 +00006068 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006069 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006070 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006071
6072 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006073 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006074 E->getRParenLoc());
6075}
Mike Stump11289f42009-09-09 15:08:12 +00006076
Douglas Gregora16548e2009-08-11 05:31:07 +00006077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006080 // Transform arguments.
6081 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006082 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006083 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006084 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006085 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006087
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006088 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006089 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006090 }
6091
6092 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6093 // Class message: transform the receiver type.
6094 TypeSourceInfo *ReceiverTypeInfo
6095 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6096 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006098
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006099 // If nothing changed, just retain the existing message send.
6100 if (!getDerived().AlwaysRebuild() &&
6101 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006102 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006103
6104 // Build a new class message send.
6105 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6106 E->getSelector(),
6107 E->getMethodDecl(),
6108 E->getLeftLoc(),
6109 move_arg(Args),
6110 E->getRightLoc());
6111 }
6112
6113 // Instance message: transform the receiver
6114 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6115 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006116 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006117 = getDerived().TransformExpr(E->getInstanceReceiver());
6118 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006120
6121 // If nothing changed, just retain the existing message send.
6122 if (!getDerived().AlwaysRebuild() &&
6123 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006124 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006125
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006126 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006127 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006128 E->getSelector(),
6129 E->getMethodDecl(),
6130 E->getLeftLoc(),
6131 move_arg(Args),
6132 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006133}
6134
Mike Stump11289f42009-09-09 15:08:12 +00006135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006139}
6140
Mike Stump11289f42009-09-09 15:08:12 +00006141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006144 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006145}
6146
Mike Stump11289f42009-09-09 15:08:12 +00006147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006149TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006150 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006151 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006152 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006153 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006154
6155 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006156
Douglas Gregord51d90d2010-04-26 20:11:03 +00006157 // If nothing changed, just retain the existing expression.
6158 if (!getDerived().AlwaysRebuild() &&
6159 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006160 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006161
John McCallb268a282010-08-23 23:25:46 +00006162 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006163 E->getLocation(),
6164 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006165}
6166
Mike Stump11289f42009-09-09 15:08:12 +00006167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006168ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006170 // 'super' never changes. Property never changes. Just retain the existing
6171 // expression.
6172 if (E->isSuperReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006173 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006174
Douglas Gregor9faee212010-04-26 20:47:02 +00006175 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006176 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006177 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006178 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006179
Douglas Gregor9faee212010-04-26 20:47:02 +00006180 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006181
Douglas Gregor9faee212010-04-26 20:47:02 +00006182 // If nothing changed, just retain the existing expression.
6183 if (!getDerived().AlwaysRebuild() &&
6184 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006185 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006186
John McCallb268a282010-08-23 23:25:46 +00006187 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006188 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006189}
6190
Mike Stump11289f42009-09-09 15:08:12 +00006191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006192ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006193TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006194 ObjCImplicitSetterGetterRefExpr *E) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006195 // If this implicit setter/getter refers to super, it cannot have any
6196 // dependent parts. Just retain the existing declaration.
6197 if (E->isSuperReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006198 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006199
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006200 // If this implicit setter/getter refers to class methods, it cannot have any
6201 // dependent parts. Just retain the existing declaration.
6202 if (E->getInterfaceDecl())
John McCallc3007a22010-10-26 07:05:15 +00006203 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006204
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006205 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006206 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006207 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006209
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006210 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006211
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006212 // If nothing changed, just retain the existing expression.
6213 if (!getDerived().AlwaysRebuild() &&
6214 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006215 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006216
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006217 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6218 E->getGetterMethod(),
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006219 E->getType(),
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006220 E->getSetterMethod(),
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006221 E->getLocation(),
6222 Base.get(),
6223 E->getSuperLocation(),
6224 E->getSuperType(),
6225 E->isSuperReceiver());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006226
Douglas Gregora16548e2009-08-11 05:31:07 +00006227}
6228
Mike Stump11289f42009-09-09 15:08:12 +00006229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006231TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006232 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006233 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006234 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006235 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006236
Douglas Gregord51d90d2010-04-26 20:11:03 +00006237 // If nothing changed, just retain the existing expression.
6238 if (!getDerived().AlwaysRebuild() &&
6239 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006240 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006241
John McCallb268a282010-08-23 23:25:46 +00006242 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006243 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006244}
6245
Mike Stump11289f42009-09-09 15:08:12 +00006246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006248TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006249 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006250 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006251 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006252 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006253 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006255
Douglas Gregora16548e2009-08-11 05:31:07 +00006256 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006257 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006258 }
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregora16548e2009-08-11 05:31:07 +00006260 if (!getDerived().AlwaysRebuild() &&
6261 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006262 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006263
Douglas Gregora16548e2009-08-11 05:31:07 +00006264 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6265 move_arg(SubExprs),
6266 E->getRParenLoc());
6267}
6268
Mike Stump11289f42009-09-09 15:08:12 +00006269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006270ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006271TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006272 SourceLocation CaretLoc(E->getExprLoc());
6273
6274 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6275 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6276 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6277 llvm::SmallVector<ParmVarDecl*, 4> Params;
6278 llvm::SmallVector<QualType, 4> ParamTypes;
6279
6280 // Parameter substitution.
6281 const BlockDecl *BD = E->getBlockDecl();
6282 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6283 EN = BD->param_end(); P != EN; ++P) {
6284 ParmVarDecl *OldParm = (*P);
6285 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6286 QualType NewType = NewParm->getType();
6287 Params.push_back(NewParm);
6288 ParamTypes.push_back(NewParm->getType());
6289 }
6290
6291 const FunctionType *BExprFunctionType = E->getFunctionType();
6292 QualType BExprResultType = BExprFunctionType->getResultType();
6293 if (!BExprResultType.isNull()) {
6294 if (!BExprResultType->isDependentType())
6295 CurBlock->ReturnType = BExprResultType;
6296 else if (BExprResultType != SemaRef.Context.DependentTy)
6297 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6298 }
6299
6300 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006301 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006302 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006303 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006304 // Set the parameters on the block decl.
6305 if (!Params.empty())
6306 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6307
6308 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6309 CurBlock->ReturnType,
6310 ParamTypes.data(),
6311 ParamTypes.size(),
6312 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006313 0,
6314 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006315
6316 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006317 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006318}
6319
Mike Stump11289f42009-09-09 15:08:12 +00006320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006322TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006323 NestedNameSpecifier *Qualifier = 0;
6324
6325 ValueDecl *ND
6326 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6327 E->getDecl()));
6328 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006329 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006330
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006331 if (!getDerived().AlwaysRebuild() &&
6332 ND == E->getDecl()) {
6333 // Mark it referenced in the new context regardless.
6334 // FIXME: this is a bit instantiation-specific.
6335 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6336
John McCallc3007a22010-10-26 07:05:15 +00006337 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006338 }
6339
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006340 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006341 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006342 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006343}
Mike Stump11289f42009-09-09 15:08:12 +00006344
Douglas Gregora16548e2009-08-11 05:31:07 +00006345//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006346// Type reconstruction
6347//===----------------------------------------------------------------------===//
6348
Mike Stump11289f42009-09-09 15:08:12 +00006349template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006350QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6351 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006352 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006353 getDerived().getBaseEntity());
6354}
6355
Mike Stump11289f42009-09-09 15:08:12 +00006356template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006357QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6358 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006359 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006360 getDerived().getBaseEntity());
6361}
6362
Mike Stump11289f42009-09-09 15:08:12 +00006363template<typename Derived>
6364QualType
John McCall70dd5f62009-10-30 00:06:24 +00006365TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6366 bool WrittenAsLValue,
6367 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006368 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006369 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006370}
6371
6372template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006373QualType
John McCall70dd5f62009-10-30 00:06:24 +00006374TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6375 QualType ClassType,
6376 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006377 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006378 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006379}
6380
6381template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006382QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006383TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6384 ArrayType::ArraySizeModifier SizeMod,
6385 const llvm::APInt *Size,
6386 Expr *SizeExpr,
6387 unsigned IndexTypeQuals,
6388 SourceRange BracketsRange) {
6389 if (SizeExpr || !Size)
6390 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6391 IndexTypeQuals, BracketsRange,
6392 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006393
6394 QualType Types[] = {
6395 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6396 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6397 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006398 };
6399 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6400 QualType SizeType;
6401 for (unsigned I = 0; I != NumTypes; ++I)
6402 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6403 SizeType = Types[I];
6404 break;
6405 }
Mike Stump11289f42009-09-09 15:08:12 +00006406
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006407 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6408 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006409 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006410 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006411 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006415QualType
6416TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006417 ArrayType::ArraySizeModifier SizeMod,
6418 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006419 unsigned IndexTypeQuals,
6420 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006421 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006422 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006423}
6424
6425template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006426QualType
Mike Stump11289f42009-09-09 15:08:12 +00006427TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006428 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006429 unsigned IndexTypeQuals,
6430 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006431 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006432 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006433}
Mike Stump11289f42009-09-09 15:08:12 +00006434
Douglas Gregord6ff3322009-08-04 16:50:30 +00006435template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006436QualType
6437TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006439 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006440 unsigned IndexTypeQuals,
6441 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006442 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006443 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006444 IndexTypeQuals, BracketsRange);
6445}
6446
6447template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006448QualType
6449TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006450 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006451 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006452 unsigned IndexTypeQuals,
6453 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006454 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006455 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006456 IndexTypeQuals, BracketsRange);
6457}
6458
6459template<typename Derived>
6460QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006461 unsigned NumElements,
6462 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006463 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006464 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006465}
Mike Stump11289f42009-09-09 15:08:12 +00006466
Douglas Gregord6ff3322009-08-04 16:50:30 +00006467template<typename Derived>
6468QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6469 unsigned NumElements,
6470 SourceLocation AttributeLoc) {
6471 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6472 NumElements, true);
6473 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006474 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6475 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006476 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006477}
Mike Stump11289f42009-09-09 15:08:12 +00006478
Douglas Gregord6ff3322009-08-04 16:50:30 +00006479template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006480QualType
6481TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006482 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006483 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006484 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006485}
Mike Stump11289f42009-09-09 15:08:12 +00006486
Douglas Gregord6ff3322009-08-04 16:50:30 +00006487template<typename Derived>
6488QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006489 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006490 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006491 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006492 unsigned Quals,
6493 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006494 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006495 Quals,
6496 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006497 getDerived().getBaseEntity(),
6498 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006499}
Mike Stump11289f42009-09-09 15:08:12 +00006500
Douglas Gregord6ff3322009-08-04 16:50:30 +00006501template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006502QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6503 return SemaRef.Context.getFunctionNoProtoType(T);
6504}
6505
6506template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006507QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6508 assert(D && "no decl found");
6509 if (D->isInvalidDecl()) return QualType();
6510
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006511 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006512 TypeDecl *Ty;
6513 if (isa<UsingDecl>(D)) {
6514 UsingDecl *Using = cast<UsingDecl>(D);
6515 assert(Using->isTypeName() &&
6516 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6517
6518 // A valid resolved using typename decl points to exactly one type decl.
6519 assert(++Using->shadow_begin() == Using->shadow_end());
6520 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006521
John McCallb96ec562009-12-04 22:46:56 +00006522 } else {
6523 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6524 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6525 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6526 }
6527
6528 return SemaRef.Context.getTypeDeclType(Ty);
6529}
6530
6531template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006532QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6533 SourceLocation Loc) {
6534 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006535}
6536
6537template<typename Derived>
6538QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6539 return SemaRef.Context.getTypeOfType(Underlying);
6540}
6541
6542template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006543QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6544 SourceLocation Loc) {
6545 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006546}
6547
6548template<typename Derived>
6549QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006550 TemplateName Template,
6551 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006552 const TemplateArgumentListInfo &TemplateArgs) {
6553 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006554}
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregor1135c352009-08-06 05:28:30 +00006556template<typename Derived>
6557NestedNameSpecifier *
6558TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6559 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006560 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006561 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006562 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006563 CXXScopeSpec SS;
6564 // FIXME: The source location information is all wrong.
6565 SS.setRange(Range);
6566 SS.setScopeRep(Prefix);
6567 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006568 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006569 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006570 ObjectType,
6571 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006572 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006573}
6574
6575template<typename Derived>
6576NestedNameSpecifier *
6577TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6578 SourceRange Range,
6579 NamespaceDecl *NS) {
6580 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6581}
6582
6583template<typename Derived>
6584NestedNameSpecifier *
6585TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6586 SourceRange Range,
6587 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006588 QualType T) {
6589 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006590 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006591 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006592 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6593 T.getTypePtr());
6594 }
Mike Stump11289f42009-09-09 15:08:12 +00006595
Douglas Gregor1135c352009-08-06 05:28:30 +00006596 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6597 return 0;
6598}
Mike Stump11289f42009-09-09 15:08:12 +00006599
Douglas Gregor71dc5092009-08-06 06:41:21 +00006600template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006601TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006602TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6603 bool TemplateKW,
6604 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006605 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006606 Template);
6607}
6608
6609template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006610TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006611TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006612 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006613 const IdentifierInfo &II,
6614 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006615 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006616 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006617 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006618 UnqualifiedId Name;
6619 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006620 Sema::TemplateTy Template;
6621 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6622 /*FIXME:*/getDerived().getBaseLocation(),
6623 SS,
6624 Name,
John McCallba7bf592010-08-24 05:47:05 +00006625 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006626 /*EnteringContext=*/false,
6627 Template);
6628 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006629}
Mike Stump11289f42009-09-09 15:08:12 +00006630
Douglas Gregora16548e2009-08-11 05:31:07 +00006631template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006632TemplateName
6633TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6634 OverloadedOperatorKind Operator,
6635 QualType ObjectType) {
6636 CXXScopeSpec SS;
6637 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6638 SS.setScopeRep(Qualifier);
6639 UnqualifiedId Name;
6640 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6641 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6642 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006643 Sema::TemplateTy Template;
6644 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006645 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006646 SS,
6647 Name,
John McCallba7bf592010-08-24 05:47:05 +00006648 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006649 /*EnteringContext=*/false,
6650 Template);
6651 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006652}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006653
Douglas Gregor71395fa2009-11-04 00:56:37 +00006654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006655ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006656TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6657 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006658 Expr *OrigCallee,
6659 Expr *First,
6660 Expr *Second) {
6661 Expr *Callee = OrigCallee->IgnoreParenCasts();
6662 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006663
Douglas Gregora16548e2009-08-11 05:31:07 +00006664 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006665 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006666 if (!First->getType()->isOverloadableType() &&
6667 !Second->getType()->isOverloadableType())
6668 return getSema().CreateBuiltinArraySubscriptExpr(First,
6669 Callee->getLocStart(),
6670 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006671 } else if (Op == OO_Arrow) {
6672 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006673 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6674 } else if (Second == 0 || isPostIncDec) {
6675 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 // The argument is not of overloadable type, so try to create a
6677 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006678 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006679 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006680
John McCallb268a282010-08-23 23:25:46 +00006681 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 }
6683 } else {
John McCallb268a282010-08-23 23:25:46 +00006684 if (!First->getType()->isOverloadableType() &&
6685 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006686 // Neither of the arguments is an overloadable type, so try to
6687 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006688 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006689 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006690 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006691 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006693
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 return move(Result);
6695 }
6696 }
Mike Stump11289f42009-09-09 15:08:12 +00006697
6698 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006699 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006700 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006701
John McCallb268a282010-08-23 23:25:46 +00006702 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006703 assert(ULE->requiresADL());
6704
6705 // FIXME: Do we have to check
6706 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006707 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006708 } else {
John McCallb268a282010-08-23 23:25:46 +00006709 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006710 }
Mike Stump11289f42009-09-09 15:08:12 +00006711
Douglas Gregora16548e2009-08-11 05:31:07 +00006712 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006713 Expr *Args[2] = { First, Second };
6714 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006715
Douglas Gregora16548e2009-08-11 05:31:07 +00006716 // Create the overloaded operator invocation for unary operators.
6717 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006718 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006719 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006720 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006721 }
Mike Stump11289f42009-09-09 15:08:12 +00006722
Sebastian Redladba46e2009-10-29 20:17:01 +00006723 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006724 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006725 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006726 First,
6727 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006728
Douglas Gregora16548e2009-08-11 05:31:07 +00006729 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006730 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006731 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6733 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006735
Mike Stump11289f42009-09-09 15:08:12 +00006736 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006737}
Mike Stump11289f42009-09-09 15:08:12 +00006738
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006740ExprResult
John McCallb268a282010-08-23 23:25:46 +00006741TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006742 SourceLocation OperatorLoc,
6743 bool isArrow,
6744 NestedNameSpecifier *Qualifier,
6745 SourceRange QualifierRange,
6746 TypeSourceInfo *ScopeType,
6747 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006748 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006749 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006750 CXXScopeSpec SS;
6751 if (Qualifier) {
6752 SS.setRange(QualifierRange);
6753 SS.setScopeRep(Qualifier);
6754 }
6755
John McCallb268a282010-08-23 23:25:46 +00006756 QualType BaseType = Base->getType();
6757 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006758 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006759 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006760 !BaseType->getAs<PointerType>()->getPointeeType()
6761 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006762 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006763 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006764 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006765 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006766 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006767 /*FIXME?*/true);
6768 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006769
Douglas Gregor678f90d2010-02-25 01:56:36 +00006770 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006771 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6772 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6773 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6774 NameInfo.setNamedTypeInfo(DestroyedType);
6775
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006776 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006777
John McCallb268a282010-08-23 23:25:46 +00006778 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006779 OperatorLoc, isArrow,
6780 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006781 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006782 /*TemplateArgs*/ 0);
6783}
6784
Douglas Gregord6ff3322009-08-04 16:50:30 +00006785} // end namespace clang
6786
6787#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H