blob: fe1f6b96e866e45491de9ad88c8498ae83052813 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000016#include "clang/Sema/Sema.h"
17#include "clang/Sema/Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000020#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000027#include "clang/AST/TypeLocBuilder.h"
John McCall8b0666c2010-08-20 18:27:03 +000028#include "clang/Sema/Ownership.h"
29#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000030#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000031#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000032#include <algorithm>
33
34namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000035
Douglas Gregord6ff3322009-08-04 16:50:30 +000036/// \brief A semantic tree transformation that allows one to transform one
37/// abstract syntax tree into another.
38///
Mike Stump11289f42009-09-09 15:08:12 +000039/// A new tree transformation is defined by creating a new subclass \c X of
40/// \c TreeTransform<X> and then overriding certain operations to provide
41/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// instantiation is implemented as a tree transformation where the
43/// transformation of TemplateTypeParmType nodes involves substituting the
44/// template arguments for their corresponding template parameters; a similar
45/// transformation is performed for non-type template parameters and
46/// template template parameters.
47///
48/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000049/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000050/// override any of the transformation or rebuild operators by providing an
51/// operation with the same signature as the default implementation. The
52/// overridding function should not be virtual.
53///
54/// Semantic tree transformations are split into two stages, either of which
55/// can be replaced by a subclass. The "transform" step transforms an AST node
56/// or the parts of an AST node using the various transformation functions,
57/// then passes the pieces on to the "rebuild" step, which constructs a new AST
58/// node of the appropriate kind from the pieces. The default transformation
59/// routines recursively transform the operands to composite AST nodes (e.g.,
60/// the pointee type of a PointerType node) and, if any of those operand nodes
61/// were changed by the transformation, invokes the rebuild operation to create
62/// a new AST node.
63///
Mike Stump11289f42009-09-09 15:08:12 +000064/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000065/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000066/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
67/// TransformTemplateName(), or TransformTemplateArgument() with entirely
68/// new implementations.
69///
70/// For more fine-grained transformations, subclasses can replace any of the
71/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000072/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000074/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// parameters. Additionally, subclasses can override the \c RebuildXXX
76/// functions to control how AST nodes are rebuilt when their operands change.
77/// By default, \c TreeTransform will invoke semantic analysis to rebuild
78/// AST nodes. However, certain other tree transformations (e.g, cloning) may
79/// be able to use more efficient rebuild steps.
80///
81/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000082/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000083/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
84/// operands have not changed (\c AlwaysRebuild()), and customize the
85/// default locations and entity names used for type-checking
86/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000087template<typename Derived>
88class TreeTransform {
89protected:
90 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000091
92public:
Douglas Gregora16548e2009-08-11 05:31:07 +000093 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000094 typedef Sema::MultiStmtArg MultiStmtArg;
Alexis Hunta8136cc2010-05-05 15:23:54 +000095
Douglas Gregord6ff3322009-08-04 16:50:30 +000096 /// \brief Initializes a new tree transformer.
97 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000098
Douglas Gregord6ff3322009-08-04 16:50:30 +000099 /// \brief Retrieves a reference to the derived class.
100 Derived &getDerived() { return static_cast<Derived&>(*this); }
101
102 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000103 const Derived &getDerived() const {
104 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000105 }
106
John McCalldadc5752010-08-24 06:29:42 +0000107 static inline ExprResult Owned(Expr *E) { return E; }
108 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110 /// \brief Retrieves a reference to the semantic analysis object used for
111 /// this tree transform.
112 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000113
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Whether the transformation should always rebuild AST nodes, even
115 /// if none of the children have changed.
116 ///
117 /// Subclasses may override this function to specify when the transformation
118 /// should rebuild all AST nodes.
119 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000120
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Returns the location of the entity being transformed, if that
122 /// information was not available elsewhere in the AST.
123 ///
Mike Stump11289f42009-09-09 15:08:12 +0000124 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// provide an alternative implementation that provides better location
126 /// information.
127 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Returns the name of the entity being transformed, if that
130 /// information was not available elsewhere in the AST.
131 ///
132 /// By default, returns an empty name. Subclasses can provide an alternative
133 /// implementation with a more precise name.
134 DeclarationName getBaseEntity() { return DeclarationName(); }
135
Douglas Gregora16548e2009-08-11 05:31:07 +0000136 /// \brief Sets the "base" location and entity when that
137 /// information is known based on another transformation.
138 ///
139 /// By default, the source location and entity are ignored. Subclasses can
140 /// override this function to provide a customized implementation.
141 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000142
Douglas Gregora16548e2009-08-11 05:31:07 +0000143 /// \brief RAII object that temporarily sets the base location and entity
144 /// used for reporting diagnostics in types.
145 class TemporaryBase {
146 TreeTransform &Self;
147 SourceLocation OldLocation;
148 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregora16548e2009-08-11 05:31:07 +0000150 public:
151 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000152 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000153 OldLocation = Self.getDerived().getBaseLocation();
154 OldEntity = Self.getDerived().getBaseEntity();
155 Self.getDerived().setBase(Location, Entity);
156 }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregora16548e2009-08-11 05:31:07 +0000158 ~TemporaryBase() {
159 Self.getDerived().setBase(OldLocation, OldEntity);
160 }
161 };
Mike Stump11289f42009-09-09 15:08:12 +0000162
163 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000164 /// transformed.
165 ///
166 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000167 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000168 /// not change. For example, template instantiation need not traverse
169 /// non-dependent types.
170 bool AlreadyTransformed(QualType T) {
171 return T.isNull();
172 }
173
Douglas Gregord196a582009-12-14 19:27:10 +0000174 /// \brief Determine whether the given call argument should be dropped, e.g.,
175 /// because it is a default argument.
176 ///
177 /// Subclasses can provide an alternative implementation of this routine to
178 /// determine which kinds of call arguments get dropped. By default,
179 /// CXXDefaultArgument nodes are dropped (prior to transformation).
180 bool DropCallArgument(Expr *E) {
181 return E->isDefaultArgument();
182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000183
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// \brief Transforms the given type into another type.
185 ///
John McCall550e0c22009-10-21 00:40:46 +0000186 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000187 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000188 /// function. This is expensive, but we don't mind, because
189 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000190 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000191 ///
192 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000193 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000194
John McCall550e0c22009-10-21 00:40:46 +0000195 /// \brief Transforms the given type-with-location into a new
196 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000197 ///
John McCall550e0c22009-10-21 00:40:46 +0000198 /// By default, this routine transforms a type by delegating to the
199 /// appropriate TransformXXXType to build a new type. Subclasses
200 /// may override this function (to take over all type
201 /// transformations) or some set of the TransformXXXType functions
202 /// to alter the transformation.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000205
206 /// \brief Transform the given type-with-location into a new
207 /// type, collecting location information in the given builder
208 /// as necessary.
209 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000210 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000212
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000213 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000214 ///
Mike Stump11289f42009-09-09 15:08:12 +0000215 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000216 /// appropriate TransformXXXStmt function to transform a specific kind of
217 /// statement or the TransformExpr() function to transform an expression.
218 /// Subclasses may override this function to transform statements using some
219 /// other mechanism.
220 ///
221 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000222 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000223
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000224 /// \brief Transform the given expression.
225 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000226 /// By default, this routine transforms an expression by delegating to the
227 /// appropriate TransformXXXExpr function to build a new expression.
228 /// Subclasses may override this function to transform expressions using some
229 /// other mechanism.
230 ///
231 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000232 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000233
Douglas Gregord6ff3322009-08-04 16:50:30 +0000234 /// \brief Transform the given declaration, which is referenced from a type
235 /// or expression.
236 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000237 /// By default, acts as the identity function on declarations. Subclasses
238 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000239 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000240
241 /// \brief Transform the definition of the given declaration.
242 ///
Mike Stump11289f42009-09-09 15:08:12 +0000243 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000244 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000245 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
246 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000247 }
Mike Stump11289f42009-09-09 15:08:12 +0000248
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000249 /// \brief Transform the given declaration, which was the first part of a
250 /// nested-name-specifier in a member access expression.
251 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000252 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000253 /// identifier in a nested-name-specifier of a member access expression, e.g.,
254 /// the \c T in \c x->T::member
255 ///
256 /// By default, invokes TransformDecl() to transform the declaration.
257 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000258 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
259 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000260 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000261
Douglas Gregord6ff3322009-08-04 16:50:30 +0000262 /// \brief Transform the given nested-name-specifier.
263 ///
Mike Stump11289f42009-09-09 15:08:12 +0000264 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000265 /// nested-name-specifier. Subclasses may override this function to provide
266 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000267 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000268 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000269 QualType ObjectType = QualType(),
270 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000271
Douglas Gregorf816bd72009-09-03 22:13:48 +0000272 /// \brief Transform the given declaration name.
273 ///
274 /// By default, transforms the types of conversion function, constructor,
275 /// and destructor names and then (if needed) rebuilds the declaration name.
276 /// Identifiers and selectors are returned unmodified. Sublcasses may
277 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000278 DeclarationNameInfo
279 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
280 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000283 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000284 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000285 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000286 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000287 TemplateName TransformTemplateName(TemplateName Name,
288 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000289
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 /// \brief Transform the given template argument.
291 ///
Mike Stump11289f42009-09-09 15:08:12 +0000292 /// By default, this operation transforms the type, expression, or
293 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000294 /// new template argument from the transformed result. Subclasses may
295 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000296 ///
297 /// Returns true if there was an error.
298 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
299 TemplateArgumentLoc &Output);
300
301 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
302 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
303 TemplateArgumentLoc &ArgLoc);
304
John McCallbcd03502009-12-07 02:54:59 +0000305 /// \brief Fakes up a TypeSourceInfo for a type.
306 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
307 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000308 getDerived().getBaseLocation());
309 }
Mike Stump11289f42009-09-09 15:08:12 +0000310
John McCall550e0c22009-10-21 00:40:46 +0000311#define ABSTRACT_TYPELOC(CLASS, PARENT)
312#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000313 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
314 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000315#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000316
John McCall58f10c32010-03-11 09:03:00 +0000317 /// \brief Transforms the parameters of a function type into the
318 /// given vectors.
319 ///
320 /// The result vectors should be kept in sync; null entries in the
321 /// variables vector are acceptable.
322 ///
323 /// Return true on error.
324 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
325 llvm::SmallVectorImpl<QualType> &PTypes,
326 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
327
328 /// \brief Transforms a single function-type parameter. Return null
329 /// on error.
330 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
331
Alexis Hunta8136cc2010-05-05 15:23:54 +0000332 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000333 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000334
Alexis Hunta8136cc2010-05-05 15:23:54 +0000335 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000336 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
337 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000338
John McCalldadc5752010-08-24 06:29:42 +0000339 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
340 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000341
Douglas Gregorebe10102009-08-20 07:17:43 +0000342#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000343 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000344#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000345 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000346#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000347#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000348
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 /// \brief Build a new pointer type given its pointee type.
350 ///
351 /// By default, performs semantic analysis when building the pointer type.
352 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000353 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000354
355 /// \brief Build a new block pointer type given its pointee type.
356 ///
Mike Stump11289f42009-09-09 15:08:12 +0000357 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000358 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000359 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000360
John McCall70dd5f62009-10-30 00:06:24 +0000361 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000362 ///
John McCall70dd5f62009-10-30 00:06:24 +0000363 /// By default, performs semantic analysis when building the
364 /// reference type. Subclasses may override this routine to provide
365 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000366 ///
John McCall70dd5f62009-10-30 00:06:24 +0000367 /// \param LValue whether the type was written with an lvalue sigil
368 /// or an rvalue sigil.
369 QualType RebuildReferenceType(QualType ReferentType,
370 bool LValue,
371 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000372
Douglas Gregord6ff3322009-08-04 16:50:30 +0000373 /// \brief Build a new member pointer type given the pointee type and the
374 /// class type it refers into.
375 ///
376 /// By default, performs semantic analysis when building the member pointer
377 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000378 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
379 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000380
Douglas Gregord6ff3322009-08-04 16:50:30 +0000381 /// \brief Build a new array type given the element type, size
382 /// modifier, size of the array (if known), size expression, and index type
383 /// qualifiers.
384 ///
385 /// By default, performs semantic analysis when building the array type.
386 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000387 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000388 QualType RebuildArrayType(QualType ElementType,
389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt *Size,
391 Expr *SizeExpr,
392 unsigned IndexTypeQuals,
393 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000394
Douglas Gregord6ff3322009-08-04 16:50:30 +0000395 /// \brief Build a new constant array type given the element type, size
396 /// modifier, (known) size of the array, and index type qualifiers.
397 ///
398 /// By default, performs semantic analysis when building the array type.
399 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000400 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000401 ArrayType::ArraySizeModifier SizeMod,
402 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000403 unsigned IndexTypeQuals,
404 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406 /// \brief Build a new incomplete array type given the element type, size
407 /// modifier, and index type qualifiers.
408 ///
409 /// By default, performs semantic analysis when building the array type.
410 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000411 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000412 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000413 unsigned IndexTypeQuals,
414 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000415
Mike Stump11289f42009-09-09 15:08:12 +0000416 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// size modifier, size expression, and index type qualifiers.
418 ///
419 /// By default, performs semantic analysis when building the array type.
420 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000421 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000423 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424 unsigned IndexTypeQuals,
425 SourceRange BracketsRange);
426
Mike Stump11289f42009-09-09 15:08:12 +0000427 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000428 /// size modifier, size expression, and index type qualifiers.
429 ///
430 /// By default, performs semantic analysis when building the array type.
431 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000432 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000433 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000434 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000435 unsigned IndexTypeQuals,
436 SourceRange BracketsRange);
437
438 /// \brief Build a new vector type given the element type and
439 /// number of elements.
440 ///
441 /// By default, performs semantic analysis when building the vector type.
442 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000443 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner37141f42010-06-23 06:00:24 +0000444 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump11289f42009-09-09 15:08:12 +0000445
Douglas Gregord6ff3322009-08-04 16:50:30 +0000446 /// \brief Build a new extended vector type given the element type and
447 /// number of elements.
448 ///
449 /// By default, performs semantic analysis when building the vector type.
450 /// Subclasses may override this routine to provide different behavior.
451 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
452 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000453
454 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000455 /// given the element type and number of elements.
456 ///
457 /// By default, performs semantic analysis when building the vector type.
458 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000459 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000460 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000461 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000462
Douglas Gregord6ff3322009-08-04 16:50:30 +0000463 /// \brief Build a new function type.
464 ///
465 /// By default, performs semantic analysis when building the function type.
466 /// Subclasses may override this routine to provide different behavior.
467 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000468 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000469 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000470 bool Variadic, unsigned Quals,
471 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
Mike Stump11289f42009-09-09 15:08:12 +0000495 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 ///
497 /// By default, performs semantic analysis when building the typeof type.
498 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000499 QualType RebuildTypeOfExprType(Expr *Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500
Mike Stump11289f42009-09-09 15:08:12 +0000501 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000502 ///
503 /// By default, builds a new TypeOfType with the given underlying type.
504 QualType RebuildTypeOfType(QualType Underlying);
505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, performs semantic analysis when building the decltype type.
509 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000510 QualType RebuildDecltypeType(Expr *Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new template specialization type.
513 ///
514 /// By default, performs semantic analysis when building the template
515 /// specialization type. Subclasses may override this routine to provide
516 /// different behavior.
517 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000518 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000519 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000520
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 /// \brief Build a new qualified name type.
522 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000523 /// By default, builds a new ElaboratedType type from the keyword,
524 /// the nested-name-specifier and the named type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
527 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,
538 NestedNameSpecifier *NNS,
539 const IdentifierInfo *Name,
540 SourceLocation NameLoc,
541 const TemplateArgumentListInfo &Args) {
542 // Rebuild the template name.
543 // TODO: avoid TemplateName abstraction
544 TemplateName InstName =
545 getDerived().RebuildTemplateName(NNS, *Name, QualType());
546
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000547 if (InstName.isNull())
548 return QualType();
549
John McCallc392f372010-06-11 00:33:02 +0000550 // If it's still dependent, make a dependent specialization.
551 if (InstName.getAsDependentTemplateName())
552 return SemaRef.Context.getDependentTemplateSpecializationType(
553 Keyword, NNS, Name, Args);
554
555 // Otherwise, make an elaborated type wrapping a non-dependent
556 // specialization.
557 QualType T =
558 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
559 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000560
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000561 // NOTE: NNS is already recorded in template specialization type T.
562 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000563 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564
565 /// \brief Build a new typename type that refers to an identifier.
566 ///
567 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000568 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000569 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000570 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000571 NestedNameSpecifier *NNS,
572 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000573 SourceLocation KeywordLoc,
574 SourceRange NNSRange,
575 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000576 CXXScopeSpec SS;
577 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000578 SS.setRange(NNSRange);
579
Douglas Gregore677daf2010-03-31 22:19:08 +0000580 if (NNS->isDependent()) {
581 // If the name is still dependent, just build a new dependent name type.
582 if (!SemaRef.computeDeclContext(SS))
583 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
584 }
585
Abramo Bagnara6150c882010-05-11 21:36:43 +0000586 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000587 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
588 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000589
590 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
591
Abramo Bagnarad7548482010-05-19 21:37:53 +0000592 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000593 // into a non-dependent elaborated-type-specifier. Find the tag we're
594 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000595 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000596 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
597 if (!DC)
598 return QualType();
599
John McCallbf8c5192010-05-27 06:40:31 +0000600 if (SemaRef.RequireCompleteDeclContext(SS, DC))
601 return QualType();
602
Douglas Gregore677daf2010-03-31 22:19:08 +0000603 TagDecl *Tag = 0;
604 SemaRef.LookupQualifiedName(Result, DC);
605 switch (Result.getResultKind()) {
606 case LookupResult::NotFound:
607 case LookupResult::NotFoundInCurrentInstantiation:
608 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000609
Douglas Gregore677daf2010-03-31 22:19:08 +0000610 case LookupResult::Found:
611 Tag = Result.getAsSingle<TagDecl>();
612 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000613
Douglas Gregore677daf2010-03-31 22:19:08 +0000614 case LookupResult::FoundOverloaded:
615 case LookupResult::FoundUnresolvedValue:
616 llvm_unreachable("Tag lookup cannot find non-tags");
617 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000618
Douglas Gregore677daf2010-03-31 22:19:08 +0000619 case LookupResult::Ambiguous:
620 // Let the LookupResult structure handle ambiguities.
621 return QualType();
622 }
623
624 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000625 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000626 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000627 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000628 return QualType();
629 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000630
Abramo Bagnarad7548482010-05-19 21:37:53 +0000631 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
632 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000633 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
634 return QualType();
635 }
636
637 // Build the elaborated-type-specifier type.
638 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000639 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000640 }
Mike Stump11289f42009-09-09 15:08:12 +0000641
Douglas Gregor1135c352009-08-06 05:28:30 +0000642 /// \brief Build a new nested-name-specifier given the prefix and an
643 /// identifier that names the next step in the nested-name-specifier.
644 ///
645 /// By default, performs semantic analysis when building the new
646 /// nested-name-specifier. Subclasses may override this routine to provide
647 /// different behavior.
648 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
649 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000650 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000651 QualType ObjectType,
652 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000653
654 /// \brief Build a new nested-name-specifier given the prefix and the
655 /// namespace named in the next step in the nested-name-specifier.
656 ///
657 /// By default, performs semantic analysis when building the new
658 /// nested-name-specifier. Subclasses may override this routine to provide
659 /// different behavior.
660 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
661 SourceRange Range,
662 NamespaceDecl *NS);
663
664 /// \brief Build a new nested-name-specifier given the prefix and the
665 /// type named in the next step in the nested-name-specifier.
666 ///
667 /// By default, performs semantic analysis when building the new
668 /// nested-name-specifier. Subclasses may override this routine to provide
669 /// different behavior.
670 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
671 SourceRange Range,
672 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000673 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000674
675 /// \brief Build a new template name given a nested name specifier, a flag
676 /// indicating whether the "template" keyword was provided, and the template
677 /// that the template name refers to.
678 ///
679 /// By default, builds the new template name directly. Subclasses may override
680 /// this routine to provide different behavior.
681 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
682 bool TemplateKW,
683 TemplateDecl *Template);
684
Douglas Gregor71dc5092009-08-06 06:41:21 +0000685 /// \brief Build a new template name given a nested name specifier and the
686 /// name that is referred to as a template.
687 ///
688 /// By default, performs semantic analysis to determine whether the name can
689 /// be resolved to a specific template, then builds the appropriate kind of
690 /// template name. Subclasses may override this routine to provide different
691 /// behavior.
692 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000693 const IdentifierInfo &II,
694 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000695
Douglas Gregor71395fa2009-11-04 00:56:37 +0000696 /// \brief Build a new template name given a nested name specifier and the
697 /// overloaded operator name that is referred to as a template.
698 ///
699 /// By default, performs semantic analysis to determine whether the name can
700 /// be resolved to a specific template, then builds the appropriate kind of
701 /// template name. Subclasses may override this routine to provide different
702 /// behavior.
703 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
704 OverloadedOperatorKind Operator,
705 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000706
Douglas Gregorebe10102009-08-20 07:17:43 +0000707 /// \brief Build a new compound statement.
708 ///
709 /// By default, performs semantic analysis to build the new statement.
710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000711 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000712 MultiStmtArg Statements,
713 SourceLocation RBraceLoc,
714 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000715 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000716 IsStmtExpr);
717 }
718
719 /// \brief Build a new case statement.
720 ///
721 /// By default, performs semantic analysis to build the new statement.
722 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000723 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000724 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000725 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000726 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000728 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 ColonLoc);
730 }
Mike Stump11289f42009-09-09 15:08:12 +0000731
Douglas Gregorebe10102009-08-20 07:17:43 +0000732 /// \brief Attach the body to a new case statement.
733 ///
734 /// By default, performs semantic analysis to build the new statement.
735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000736 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000737 getSema().ActOnCaseStmtBody(S, Body);
738 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 }
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregorebe10102009-08-20 07:17:43 +0000741 /// \brief Build a new default statement.
742 ///
743 /// By default, performs semantic analysis to build the new statement.
744 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000745 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000747 Stmt *SubStmt) {
748 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000749 /*CurScope=*/0);
750 }
Mike Stump11289f42009-09-09 15:08:12 +0000751
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 /// \brief Build a new label statement.
753 ///
754 /// By default, performs semantic analysis to build the new statement.
755 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000756 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 IdentifierInfo *Id,
758 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000759 Stmt *SubStmt) {
760 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000761 }
Mike Stump11289f42009-09-09 15:08:12 +0000762
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 /// \brief Build a new "if" statement.
764 ///
765 /// By default, performs semantic analysis to build the new statement.
766 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000767 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000768 VarDecl *CondVar, Stmt *Then,
769 SourceLocation ElseLoc, Stmt *Else) {
770 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000771 }
Mike Stump11289f42009-09-09 15:08:12 +0000772
Douglas Gregorebe10102009-08-20 07:17:43 +0000773 /// \brief Start building a new switch statement.
774 ///
775 /// By default, performs semantic analysis to build the new statement.
776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000777 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000778 Expr *Cond, VarDecl *CondVar) {
779 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000780 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000781 }
Mike Stump11289f42009-09-09 15:08:12 +0000782
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 /// \brief Attach the body to the switch statement.
784 ///
785 /// By default, performs semantic analysis to build the new statement.
786 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000787 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000788 Stmt *Switch, Stmt *Body) {
789 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000790 }
791
792 /// \brief Build a new while statement.
793 ///
794 /// By default, performs semantic analysis to build the new statement.
795 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000796 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000797 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000798 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000799 Stmt *Body) {
800 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000801 }
Mike Stump11289f42009-09-09 15:08:12 +0000802
Douglas Gregorebe10102009-08-20 07:17:43 +0000803 /// \brief Build a new do-while statement.
804 ///
805 /// By default, performs semantic analysis to build the new statement.
806 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000807 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 SourceLocation WhileLoc,
809 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000810 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000811 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000812 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
813 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 }
815
816 /// \brief Build a new for statement.
817 ///
818 /// By default, performs semantic analysis to build the new statement.
819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000820 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000821 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000822 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000823 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000824 SourceLocation RParenLoc, Stmt *Body) {
825 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000826 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000827 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000828 }
Mike Stump11289f42009-09-09 15:08:12 +0000829
Douglas Gregorebe10102009-08-20 07:17:43 +0000830 /// \brief Build a new goto statement.
831 ///
832 /// By default, performs semantic analysis to build the new statement.
833 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000834 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000835 SourceLocation LabelLoc,
836 LabelStmt *Label) {
837 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
838 }
839
840 /// \brief Build a new indirect goto statement.
841 ///
842 /// By default, performs semantic analysis to build the new statement.
843 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000844 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000845 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000846 Expr *Target) {
847 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000848 }
Mike Stump11289f42009-09-09 15:08:12 +0000849
Douglas Gregorebe10102009-08-20 07:17:43 +0000850 /// \brief Build a new return statement.
851 ///
852 /// By default, performs semantic analysis to build the new statement.
853 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000854 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000855 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000856
John McCallb268a282010-08-23 23:25:46 +0000857 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000858 }
Mike Stump11289f42009-09-09 15:08:12 +0000859
Douglas Gregorebe10102009-08-20 07:17:43 +0000860 /// \brief Build a new declaration statement.
861 ///
862 /// By default, performs semantic analysis to build the new statement.
863 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000864 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000865 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000866 SourceLocation EndLoc) {
867 return getSema().Owned(
868 new (getSema().Context) DeclStmt(
869 DeclGroupRef::Create(getSema().Context,
870 Decls, NumDecls),
871 StartLoc, EndLoc));
872 }
Mike Stump11289f42009-09-09 15:08:12 +0000873
Anders Carlssonaaeef072010-01-24 05:50:09 +0000874 /// \brief Build a new inline asm statement.
875 ///
876 /// By default, performs semantic analysis to build the new statement.
877 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000878 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000879 bool IsSimple,
880 bool IsVolatile,
881 unsigned NumOutputs,
882 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000883 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000884 MultiExprArg Constraints,
885 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000886 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000887 MultiExprArg Clobbers,
888 SourceLocation RParenLoc,
889 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000890 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000891 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000892 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000893 RParenLoc, MSAsm);
894 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000895
896 /// \brief Build a new Objective-C @try statement.
897 ///
898 /// By default, performs semantic analysis to build the new statement.
899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000900 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000901 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000902 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000903 Stmt *Finally) {
904 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
905 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000906 }
907
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000908 /// \brief Rebuild an Objective-C exception declaration.
909 ///
910 /// By default, performs semantic analysis to build the new declaration.
911 /// Subclasses may override this routine to provide different behavior.
912 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
913 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000914 return getSema().BuildObjCExceptionDecl(TInfo, T,
915 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000916 ExceptionDecl->getLocation());
917 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000918
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000919 /// \brief Build a new Objective-C @catch statement.
920 ///
921 /// By default, performs semantic analysis to build the new statement.
922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000923 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000924 SourceLocation RParenLoc,
925 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000926 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000927 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000928 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000929 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000930
Douglas Gregor306de2f2010-04-22 23:59:56 +0000931 /// \brief Build a new Objective-C @finally statement.
932 ///
933 /// By default, performs semantic analysis to build the new statement.
934 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000935 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000936 Stmt *Body) {
937 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000938 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000939
Douglas Gregor6148de72010-04-22 22:01:21 +0000940 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000941 ///
942 /// By default, performs semantic analysis to build the new statement.
943 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000944 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000945 Expr *Operand) {
946 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000947 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000948
Douglas Gregor6148de72010-04-22 22:01:21 +0000949 /// \brief Build a new Objective-C @synchronized statement.
950 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000951 /// By default, performs semantic analysis to build the new statement.
952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000953 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000954 Expr *Object,
955 Stmt *Body) {
956 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
957 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000958 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000959
960 /// \brief Build a new Objective-C fast enumeration statement.
961 ///
962 /// By default, performs semantic analysis to build the new statement.
963 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000964 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000965 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000966 Stmt *Element,
967 Expr *Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000968 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000969 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000970 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000971 Element,
972 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000973 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000974 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000975 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000976
Douglas Gregorebe10102009-08-20 07:17:43 +0000977 /// \brief Build a new C++ exception declaration.
978 ///
979 /// By default, performs semantic analysis to build the new decaration.
980 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000981 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000982 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 IdentifierInfo *Name,
984 SourceLocation Loc,
985 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000986 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 TypeRange);
988 }
989
990 /// \brief Build a new C++ catch statement.
991 ///
992 /// By default, performs semantic analysis to build the new statement.
993 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000994 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000995 VarDecl *ExceptionDecl,
John McCallb268a282010-08-23 23:25:46 +0000996 Stmt *Handler) {
997 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
998 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 }
Mike Stump11289f42009-09-09 15:08:12 +00001000
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 /// \brief Build a new C++ try statement.
1002 ///
1003 /// By default, performs semantic analysis to build the new statement.
1004 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001005 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallb268a282010-08-23 23:25:46 +00001006 Stmt *TryBlock,
Douglas Gregorebe10102009-08-20 07:17:43 +00001007 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001008 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 }
Mike Stump11289f42009-09-09 15:08:12 +00001010
Douglas Gregora16548e2009-08-11 05:31:07 +00001011 /// \brief Build a new expression that references a declaration.
1012 ///
1013 /// By default, performs semantic analysis to build the new expression.
1014 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001015 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001016 LookupResult &R,
1017 bool RequiresADL) {
1018 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1019 }
1020
1021
1022 /// \brief Build a new expression that references a declaration.
1023 ///
1024 /// By default, performs semantic analysis to build the new expression.
1025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001026 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001027 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001028 ValueDecl *VD,
1029 const DeclarationNameInfo &NameInfo,
John McCallce546572009-12-08 09:08:17 +00001030 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001031 CXXScopeSpec SS;
1032 SS.setScopeRep(Qualifier);
1033 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001034
1035 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001036
1037 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001038 }
Mike Stump11289f42009-09-09 15:08:12 +00001039
Douglas Gregora16548e2009-08-11 05:31:07 +00001040 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001041 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 /// By default, performs semantic analysis to build the new expression.
1043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001044 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001046 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 }
1048
Douglas Gregorad8a3362009-09-04 17:36:40 +00001049 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001050 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001051 /// By default, performs semantic analysis to build the new expression.
1052 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001053 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001054 SourceLocation OperatorLoc,
1055 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001056 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001057 SourceRange QualifierRange,
1058 TypeSourceInfo *ScopeType,
1059 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001060 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001061 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001062
Douglas Gregora16548e2009-08-11 05:31:07 +00001063 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001064 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001065 /// By default, performs semantic analysis to build the new expression.
1066 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001067 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 UnaryOperator::Opcode Opc,
John McCallb268a282010-08-23 23:25:46 +00001069 Expr *SubExpr) {
1070 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Douglas Gregor882211c2010-04-28 22:16:22 +00001073 /// \brief Build a new builtin offsetof expression.
1074 ///
1075 /// By default, performs semantic analysis to build the new expression.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001078 TypeSourceInfo *Type,
1079 Action::OffsetOfComponent *Components,
1080 unsigned NumComponents,
1081 SourceLocation RParenLoc) {
1082 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1083 NumComponents, RParenLoc);
1084 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001085
Douglas Gregora16548e2009-08-11 05:31:07 +00001086 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001087 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// By default, performs semantic analysis to build the new expression.
1089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001090 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001091 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001092 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001093 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 }
1095
Mike Stump11289f42009-09-09 15:08:12 +00001096 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// By default, performs semantic analysis to build the new expression.
1100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001101 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001103 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001104 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 if (Result.isInvalid())
1106 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001107
Douglas Gregora16548e2009-08-11 05:31:07 +00001108 return move(Result);
1109 }
Mike Stump11289f42009-09-09 15:08:12 +00001110
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001112 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// By default, performs semantic analysis to build the new expression.
1114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001115 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001117 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001119 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1120 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 RBracketLoc);
1122 }
1123
1124 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// By default, performs semantic analysis to build the new expression.
1127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001128 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 MultiExprArg Args,
1130 SourceLocation *CommaLocs,
1131 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001132 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 move(Args), CommaLocs, RParenLoc);
1134 }
1135
1136 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001140 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001141 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001142 NestedNameSpecifier *Qualifier,
1143 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001144 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001145 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001146 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001147 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001148 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001149 if (!Member->getDeclName()) {
1150 // We have a reference to an unnamed field.
1151 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001152
John McCallb268a282010-08-23 23:25:46 +00001153 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001154 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001155 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001156
Mike Stump11289f42009-09-09 15:08:12 +00001157 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001158 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001159 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001160 cast<FieldDecl>(Member)->getType());
1161 return getSema().Owned(ME);
1162 }
Mike Stump11289f42009-09-09 15:08:12 +00001163
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001164 CXXScopeSpec SS;
1165 if (Qualifier) {
1166 SS.setRange(QualifierRange);
1167 SS.setScopeRep(Qualifier);
1168 }
1169
John McCallb268a282010-08-23 23:25:46 +00001170 getSema().DefaultFunctionArrayConversion(Base);
1171 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001172
John McCall16df1e52010-03-30 21:47:33 +00001173 // FIXME: this involves duplicating earlier analysis in a lot of
1174 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001175 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001176 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001177 R.resolveKind();
1178
John McCallb268a282010-08-23 23:25:46 +00001179 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001180 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001181 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001182 }
Mike Stump11289f42009-09-09 15:08:12 +00001183
Douglas Gregora16548e2009-08-11 05:31:07 +00001184 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001185 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001188 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001189 BinaryOperator::Opcode Opc,
John McCallb268a282010-08-23 23:25:46 +00001190 Expr *LHS, Expr *RHS) {
1191 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001192 }
1193
1194 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001195 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001198 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001200 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001201 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001202 Expr *RHS) {
1203 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1204 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001205 }
1206
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001208 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// By default, performs semantic analysis to build the new expression.
1210 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001211 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001212 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001214 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001215 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001216 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 }
Mike Stump11289f42009-09-09 15:08:12 +00001218
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001220 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// By default, performs semantic analysis to build the new expression.
1222 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001223 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001224 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001226 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001227 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001228 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 }
Mike Stump11289f42009-09-09 15:08:12 +00001230
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001232 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 /// By default, performs semantic analysis to build the new expression.
1234 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001235 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 SourceLocation OpLoc,
1237 SourceLocation AccessorLoc,
1238 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001239
John McCall10eae182009-11-30 22:42:35 +00001240 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001241 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001242 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001243 OpLoc, /*IsArrow*/ false,
1244 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001245 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001246 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 }
Mike Stump11289f42009-09-09 15:08:12 +00001248
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001250 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001253 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001255 SourceLocation RBraceLoc,
1256 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001257 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001258 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1259 if (Result.isInvalid() || ResultTy->isDependentType())
1260 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001261
Douglas Gregord3d93062009-11-09 17:16:50 +00001262 // Patch in the result type we were given, which may have been computed
1263 // when the initial InitListExpr was built.
1264 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1265 ILE->setType(ResultTy);
1266 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001267 }
Mike Stump11289f42009-09-09 15:08:12 +00001268
Douglas Gregora16548e2009-08-11 05:31:07 +00001269 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001270 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001273 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 MultiExprArg ArrayExprs,
1275 SourceLocation EqualOrColonLoc,
1276 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001277 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001278 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001280 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 if (Result.isInvalid())
1282 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001283
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 ArrayExprs.release();
1285 return move(Result);
1286 }
Mike Stump11289f42009-09-09 15:08:12 +00001287
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001289 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 /// By default, builds the implicit value initialization without performing
1291 /// any semantic analysis. Subclasses may override this routine to provide
1292 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001293 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1295 }
Mike Stump11289f42009-09-09 15:08:12 +00001296
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001298 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001301 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001302 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001303 SourceLocation RParenLoc) {
1304 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001305 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001306 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 }
1308
1309 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001310 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001313 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 MultiExprArg SubExprs,
1315 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001316 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001317 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 }
Mike Stump11289f42009-09-09 15:08:12 +00001319
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001321 ///
1322 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// rather than attempting to map the label statement itself.
1324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001325 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 SourceLocation LabelLoc,
1327 LabelStmt *Label) {
1328 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1329 }
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001336 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001338 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// \brief Build a new __builtin_types_compatible_p expression.
1342 ///
1343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001346 TypeSourceInfo *TInfo1,
1347 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001349 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1350 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 RParenLoc);
1352 }
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 /// \brief Build a new __builtin_choose_expr expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001358 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001359 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 SourceLocation RParenLoc) {
1361 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001362 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 RParenLoc);
1364 }
Mike Stump11289f42009-09-09 15:08:12 +00001365
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 /// \brief Build a new overloaded operator call expression.
1367 ///
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// The semantic analysis provides the behavior of template instantiation,
1370 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001371 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 /// argument-dependent lookup, etc. Subclasses may override this routine to
1373 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001376 Expr *Callee,
1377 Expr *First,
1378 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001379
1380 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 /// reinterpret_cast.
1382 ///
1383 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001384 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001386 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 Stmt::StmtClass Class,
1388 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001389 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 SourceLocation RAngleLoc,
1391 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001392 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 SourceLocation RParenLoc) {
1394 switch (Class) {
1395 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001396 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001397 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001398 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001399
1400 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001403 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001404
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001408 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001410
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001412 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001413 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001414 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001415
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 default:
1417 assert(false && "Invalid C++ named cast");
1418 break;
1419 }
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 return getSema().ExprError();
1422 }
Mike Stump11289f42009-09-09 15:08:12 +00001423
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// \brief Build a new C++ static_cast expression.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001428 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001430 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 SourceLocation RAngleLoc,
1432 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001433 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001435 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001436 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001437 SourceRange(LAngleLoc, RAngleLoc),
1438 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 }
1440
1441 /// \brief Build a new C++ dynamic_cast expression.
1442 ///
1443 /// By default, performs semantic analysis to build the new expression.
1444 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001445 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001447 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 SourceLocation RAngleLoc,
1449 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001450 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001452 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001453 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001454 SourceRange(LAngleLoc, RAngleLoc),
1455 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 }
1457
1458 /// \brief Build a new C++ reinterpret_cast expression.
1459 ///
1460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001462 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001464 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 SourceLocation RAngleLoc,
1466 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001467 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001468 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001469 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001470 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001471 SourceRange(LAngleLoc, RAngleLoc),
1472 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 }
1474
1475 /// \brief Build a new C++ const_cast expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001479 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001481 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 SourceLocation RAngleLoc,
1483 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001484 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001486 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001487 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001488 SourceRange(LAngleLoc, RAngleLoc),
1489 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 }
Mike Stump11289f42009-09-09 15:08:12 +00001491
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// \brief Build a new C++ functional-style cast expression.
1493 ///
1494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001496 ExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001497 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001499 Expr *Sub,
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCallba7bf592010-08-24 05:47:05 +00001502 ParsedType::make(TInfo->getType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001504 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001505 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 RParenLoc);
1507 }
Mike Stump11289f42009-09-09 15:08:12 +00001508
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 /// \brief Build a new C++ typeid(type) expression.
1510 ///
1511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001513 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001514 SourceLocation TypeidLoc,
1515 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001517 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001518 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 }
Mike Stump11289f42009-09-09 15:08:12 +00001520
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 /// \brief Build a new C++ typeid(expr) expression.
1522 ///
1523 /// By default, performs semantic analysis to build the new expression.
1524 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001525 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001526 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001527 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001529 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001530 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001531 }
1532
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 /// \brief Build a new C++ "this" expression.
1534 ///
1535 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001536 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001538 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001539 QualType ThisType,
1540 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001542 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1543 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 }
1545
1546 /// \brief Build a new C++ throw expression.
1547 ///
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001550 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001551 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 }
1553
1554 /// \brief Build a new C++ default-argument expression.
1555 ///
1556 /// By default, builds a new default-argument expression, which does not
1557 /// require any semantic analysis. Subclasses may override this routine to
1558 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001559 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001560 ParmVarDecl *Param) {
1561 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1562 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 }
1564
1565 /// \brief Build a new C++ zero-initialization expression.
1566 ///
1567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001569 ExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 SourceLocation LParenLoc,
1571 QualType T,
1572 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001573 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
John McCallba7bf592010-08-24 05:47:05 +00001574 ParsedType::make(T), LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001575 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 0, RParenLoc);
1577 }
Mike Stump11289f42009-09-09 15:08:12 +00001578
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 /// \brief Build a new C++ "new" expression.
1580 ///
1581 /// By default, performs semantic analysis to build the new expression.
1582 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001583 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 bool UseGlobal,
1585 SourceLocation PlacementLParen,
1586 MultiExprArg PlacementArgs,
1587 SourceLocation PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001588 SourceRange TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 QualType AllocType,
1590 SourceLocation TypeLoc,
1591 SourceRange TypeRange,
John McCallb268a282010-08-23 23:25:46 +00001592 Expr *ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 SourceLocation ConstructorLParen,
1594 MultiExprArg ConstructorArgs,
1595 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001596 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 PlacementLParen,
1598 move(PlacementArgs),
1599 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001600 TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 AllocType,
1602 TypeLoc,
1603 TypeRange,
John McCallb268a282010-08-23 23:25:46 +00001604 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 ConstructorLParen,
1606 move(ConstructorArgs),
1607 ConstructorRParen);
1608 }
Mike Stump11289f42009-09-09 15:08:12 +00001609
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// \brief Build a new C++ "delete" expression.
1611 ///
1612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001614 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 bool IsGlobalDelete,
1616 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001617 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001619 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 }
Mike Stump11289f42009-09-09 15:08:12 +00001621
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 /// \brief Build a new unary type trait expression.
1623 ///
1624 /// By default, performs semantic analysis to build the new expression.
1625 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001626 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 SourceLocation StartLoc,
1628 SourceLocation LParenLoc,
1629 QualType T,
1630 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001631 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallba7bf592010-08-24 05:47:05 +00001632 ParsedType::make(T), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 }
1634
Mike Stump11289f42009-09-09 15:08:12 +00001635 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001640 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001642 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001643 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 CXXScopeSpec SS;
1645 SS.setRange(QualifierRange);
1646 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001647
1648 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001649 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001650 *TemplateArgs);
1651
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001652 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 }
1654
1655 /// \brief Build a new template-id expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001659 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001660 LookupResult &R,
1661 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001662 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001663 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 }
1665
1666 /// \brief Build a new object-construction expression.
1667 ///
1668 /// By default, performs semantic analysis to build the new expression.
1669 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001670 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001671 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 CXXConstructorDecl *Constructor,
1673 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001674 MultiExprArg Args,
1675 bool RequiresZeroInit,
1676 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCall37ad5512010-08-23 06:44:23 +00001677 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001678 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001679 ConvertedArgs))
1680 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001681
Douglas Gregordb121ba2009-12-14 16:27:04 +00001682 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001683 move_arg(ConvertedArgs),
1684 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new object-construction expression.
1688 ///
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001691 ExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 QualType T,
1693 SourceLocation LParenLoc,
1694 MultiExprArg Args,
1695 SourceLocation *Commas,
1696 SourceLocation RParenLoc) {
1697 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
John McCallba7bf592010-08-24 05:47:05 +00001698 ParsedType::make(T),
Douglas Gregora16548e2009-08-11 05:31:07 +00001699 LParenLoc,
1700 move(Args),
1701 Commas,
1702 RParenLoc);
1703 }
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.
John McCalldadc5752010-08-24 06:29:42 +00001709 ExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 QualType T,
1711 SourceLocation LParenLoc,
1712 MultiExprArg Args,
1713 SourceLocation *Commas,
1714 SourceLocation RParenLoc) {
1715 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1716 /*FIXME*/LParenLoc),
John McCallba7bf592010-08-24 05:47:05 +00001717 ParsedType::make(T),
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 LParenLoc,
1719 move(Args),
1720 Commas,
1721 RParenLoc);
1722 }
Mike Stump11289f42009-09-09 15:08:12 +00001723
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 /// \brief Build a new member reference expression.
1725 ///
1726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001728 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001729 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 bool IsArrow,
1731 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001732 NestedNameSpecifier *Qualifier,
1733 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001734 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001735 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001736 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001738 SS.setRange(QualifierRange);
1739 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001740
John McCallb268a282010-08-23 23:25:46 +00001741 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001742 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001743 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001744 MemberNameInfo,
1745 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 }
1747
John McCall10eae182009-11-30 22:42:35 +00001748 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001752 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001753 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001754 SourceLocation OperatorLoc,
1755 bool IsArrow,
1756 NestedNameSpecifier *Qualifier,
1757 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001758 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001759 LookupResult &R,
1760 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001761 CXXScopeSpec SS;
1762 SS.setRange(QualifierRange);
1763 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001764
John McCallb268a282010-08-23 23:25:46 +00001765 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001766 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001767 SS, FirstQualifierInScope,
1768 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001769 }
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 /// \brief Build a new Objective-C @encode expression.
1772 ///
1773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001776 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001778 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001780 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001781
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001782 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001783 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001784 Selector Sel,
1785 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001786 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001787 MultiExprArg Args,
1788 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001789 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1790 ReceiverTypeInfo->getType(),
1791 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001792 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001793 move(Args));
1794 }
1795
1796 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001797 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001798 Selector Sel,
1799 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001800 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001801 MultiExprArg Args,
1802 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001803 return SemaRef.BuildInstanceMessage(Receiver,
1804 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001805 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001806 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001807 move(Args));
1808 }
1809
Douglas Gregord51d90d2010-04-26 20:11:03 +00001810 /// \brief Build a new Objective-C ivar reference expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001814 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001815 SourceLocation IvarLoc,
1816 bool IsArrow, bool IsFreeIvar) {
1817 // FIXME: We lose track of the IsFreeIvar bit.
1818 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001819 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001820 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1821 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001822 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001823 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001824 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001825 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001826 if (Result.isInvalid())
1827 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001828
Douglas Gregord51d90d2010-04-26 20:11:03 +00001829 if (Result.get())
1830 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001831
John McCallb268a282010-08-23 23:25:46 +00001832 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001833 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001834 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001835 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001836 /*TemplateArgs=*/0);
1837 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001838
1839 /// \brief Build a new Objective-C property reference expression.
1840 ///
1841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001843 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001844 ObjCPropertyDecl *Property,
1845 SourceLocation PropertyLoc) {
1846 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001847 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001848 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1849 Sema::LookupMemberName);
1850 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001851 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001852 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001853 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001854 if (Result.isInvalid())
1855 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001856
Douglas Gregor9faee212010-04-26 20:47:02 +00001857 if (Result.get())
1858 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001859
John McCallb268a282010-08-23 23:25:46 +00001860 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001861 /*FIXME:*/PropertyLoc, IsArrow,
1862 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001863 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001864 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001865 /*TemplateArgs=*/0);
1866 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001867
1868 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001869 /// expression.
1870 ///
1871 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001872 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001873 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001874 ObjCMethodDecl *Getter,
1875 QualType T,
1876 ObjCMethodDecl *Setter,
1877 SourceLocation NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001878 Expr *Base) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001879 // Since these expressions can only be value-dependent, we do not need to
1880 // perform semantic analysis again.
John McCallb268a282010-08-23 23:25:46 +00001881 return Owned(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001882 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1883 Setter,
1884 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001885 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001886 }
1887
Douglas Gregord51d90d2010-04-26 20:11:03 +00001888 /// \brief Build a new Objective-C "isa" expression.
1889 ///
1890 /// By default, performs semantic analysis to build the new expression.
1891 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001892 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001893 bool IsArrow) {
1894 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001895 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001896 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1897 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001898 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001899 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001900 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001901 if (Result.isInvalid())
1902 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001903
Douglas Gregord51d90d2010-04-26 20:11:03 +00001904 if (Result.get())
1905 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001906
John McCallb268a282010-08-23 23:25:46 +00001907 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001908 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001909 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001910 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001911 /*TemplateArgs=*/0);
1912 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001913
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// \brief Build a new shuffle vector expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001918 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 MultiExprArg SubExprs,
1920 SourceLocation RParenLoc) {
1921 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001922 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1924 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1925 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1926 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001927
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 // Build a reference to the __builtin_shufflevector builtin
1929 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001930 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001932 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001934
1935 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 unsigned NumSubExprs = SubExprs.size();
1937 Expr **Subs = (Expr **)SubExprs.release();
1938 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1939 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001940 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001942 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001943
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001945 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 if (Result.isInvalid())
1947 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001948
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001950 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001952};
Douglas Gregora16548e2009-08-11 05:31:07 +00001953
Douglas Gregorebe10102009-08-20 07:17:43 +00001954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001955StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001956 if (!S)
1957 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregorebe10102009-08-20 07:17:43 +00001959 switch (S->getStmtClass()) {
1960 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregorebe10102009-08-20 07:17:43 +00001962 // Transform individual statement nodes
1963#define STMT(Node, Parent) \
1964 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1965#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001966#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001967
Douglas Gregorebe10102009-08-20 07:17:43 +00001968 // Transform expressions by calling TransformExpr.
1969#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001970#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001971#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001972#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001973 {
John McCalldadc5752010-08-24 06:29:42 +00001974 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00001975 if (E.isInvalid())
1976 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001977
John McCallb268a282010-08-23 23:25:46 +00001978 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00001979 }
Mike Stump11289f42009-09-09 15:08:12 +00001980 }
1981
Douglas Gregorebe10102009-08-20 07:17:43 +00001982 return SemaRef.Owned(S->Retain());
1983}
Mike Stump11289f42009-09-09 15:08:12 +00001984
1985
Douglas Gregore922c772009-08-04 22:27:00 +00001986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001987ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 if (!E)
1989 return SemaRef.Owned(E);
1990
1991 switch (E->getStmtClass()) {
1992 case Stmt::NoStmtClass: break;
1993#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00001994#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00001995#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001996 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00001997#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001998 }
1999
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002001}
2002
2003template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002004NestedNameSpecifier *
2005TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002006 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002007 QualType ObjectType,
2008 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002009 if (!NNS)
2010 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002011
Douglas Gregorebe10102009-08-20 07:17:43 +00002012 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002013 NestedNameSpecifier *Prefix = NNS->getPrefix();
2014 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002015 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002016 ObjectType,
2017 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002018 if (!Prefix)
2019 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002020
2021 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002022 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002023 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002024 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002025 }
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregor1135c352009-08-06 05:28:30 +00002027 switch (NNS->getKind()) {
2028 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002029 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002030 "Identifier nested-name-specifier with no prefix or object type");
2031 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2032 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002033 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002034
2035 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002036 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002037 ObjectType,
2038 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregor1135c352009-08-06 05:28:30 +00002040 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002041 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002042 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002043 getDerived().TransformDecl(Range.getBegin(),
2044 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002045 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002046 Prefix == NNS->getPrefix() &&
2047 NS == NNS->getAsNamespace())
2048 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002049
Douglas Gregor1135c352009-08-06 05:28:30 +00002050 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2051 }
Mike Stump11289f42009-09-09 15:08:12 +00002052
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 case NestedNameSpecifier::Global:
2054 // There is no meaningful transformation that one could perform on the
2055 // global scope.
2056 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002057
Douglas Gregor1135c352009-08-06 05:28:30 +00002058 case NestedNameSpecifier::TypeSpecWithTemplate:
2059 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002060 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002061 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2062 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002063 if (T.isNull())
2064 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002065
Douglas Gregor1135c352009-08-06 05:28:30 +00002066 if (!getDerived().AlwaysRebuild() &&
2067 Prefix == NNS->getPrefix() &&
2068 T == QualType(NNS->getAsType(), 0))
2069 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002070
2071 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2072 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002073 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002074 }
2075 }
Mike Stump11289f42009-09-09 15:08:12 +00002076
Douglas Gregor1135c352009-08-06 05:28:30 +00002077 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002078 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002079}
2080
2081template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002082DeclarationNameInfo
2083TreeTransform<Derived>
2084::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2085 QualType ObjectType) {
2086 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002087 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002088 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002089
2090 switch (Name.getNameKind()) {
2091 case DeclarationName::Identifier:
2092 case DeclarationName::ObjCZeroArgSelector:
2093 case DeclarationName::ObjCOneArgSelector:
2094 case DeclarationName::ObjCMultiArgSelector:
2095 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002096 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002097 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002098 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002099
Douglas Gregorf816bd72009-09-03 22:13:48 +00002100 case DeclarationName::CXXConstructorName:
2101 case DeclarationName::CXXDestructorName:
2102 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002103 TypeSourceInfo *NewTInfo;
2104 CanQualType NewCanTy;
2105 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2106 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2107 if (!NewTInfo)
2108 return DeclarationNameInfo();
2109 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2110 }
2111 else {
2112 NewTInfo = 0;
2113 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2114 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2115 ObjectType);
2116 if (NewT.isNull())
2117 return DeclarationNameInfo();
2118 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2119 }
Mike Stump11289f42009-09-09 15:08:12 +00002120
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002121 DeclarationName NewName
2122 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2123 NewCanTy);
2124 DeclarationNameInfo NewNameInfo(NameInfo);
2125 NewNameInfo.setName(NewName);
2126 NewNameInfo.setNamedTypeInfo(NewTInfo);
2127 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002128 }
Mike Stump11289f42009-09-09 15:08:12 +00002129 }
2130
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002131 assert(0 && "Unknown name kind.");
2132 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002133}
2134
2135template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002136TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002137TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2138 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002139 SourceLocation Loc = getDerived().getBaseLocation();
2140
Douglas Gregor71dc5092009-08-06 06:41:21 +00002141 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002142 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002143 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002144 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2145 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002146 if (!NNS)
2147 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002148
Douglas Gregor71dc5092009-08-06 06:41:21 +00002149 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002150 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002151 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002152 if (!TransTemplate)
2153 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002154
Douglas Gregor71dc5092009-08-06 06:41:21 +00002155 if (!getDerived().AlwaysRebuild() &&
2156 NNS == QTN->getQualifier() &&
2157 TransTemplate == Template)
2158 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002159
Douglas Gregor71dc5092009-08-06 06:41:21 +00002160 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2161 TransTemplate);
2162 }
Mike Stump11289f42009-09-09 15:08:12 +00002163
John McCalle66edc12009-11-24 19:00:30 +00002164 // These should be getting filtered out before they make it into the AST.
2165 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002166 }
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregor71dc5092009-08-06 06:41:21 +00002168 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002169 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002170 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002171 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2172 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002173 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002174 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002175
Douglas Gregor71dc5092009-08-06 06:41:21 +00002176 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002177 NNS == DTN->getQualifier() &&
2178 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002179 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002180
Douglas Gregor71395fa2009-11-04 00:56:37 +00002181 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002182 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002183 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002184
2185 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002186 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187 }
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregor71dc5092009-08-06 06:41:21 +00002189 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002190 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002191 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002192 if (!TransTemplate)
2193 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002194
Douglas Gregor71dc5092009-08-06 06:41:21 +00002195 if (!getDerived().AlwaysRebuild() &&
2196 TransTemplate == Template)
2197 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002198
Douglas Gregor71dc5092009-08-06 06:41:21 +00002199 return TemplateName(TransTemplate);
2200 }
Mike Stump11289f42009-09-09 15:08:12 +00002201
John McCalle66edc12009-11-24 19:00:30 +00002202 // These should be getting filtered out before they reach the AST.
2203 assert(false && "overloaded function decl survived to here");
2204 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002205}
2206
2207template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002208void TreeTransform<Derived>::InventTemplateArgumentLoc(
2209 const TemplateArgument &Arg,
2210 TemplateArgumentLoc &Output) {
2211 SourceLocation Loc = getDerived().getBaseLocation();
2212 switch (Arg.getKind()) {
2213 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002214 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002215 break;
2216
2217 case TemplateArgument::Type:
2218 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002219 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002220
John McCall0ad16662009-10-29 08:12:44 +00002221 break;
2222
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002223 case TemplateArgument::Template:
2224 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2225 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002226
John McCall0ad16662009-10-29 08:12:44 +00002227 case TemplateArgument::Expression:
2228 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2229 break;
2230
2231 case TemplateArgument::Declaration:
2232 case TemplateArgument::Integral:
2233 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002234 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002235 break;
2236 }
2237}
2238
2239template<typename Derived>
2240bool TreeTransform<Derived>::TransformTemplateArgument(
2241 const TemplateArgumentLoc &Input,
2242 TemplateArgumentLoc &Output) {
2243 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002244 switch (Arg.getKind()) {
2245 case TemplateArgument::Null:
2246 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002247 Output = Input;
2248 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002249
Douglas Gregore922c772009-08-04 22:27:00 +00002250 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002251 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002252 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002253 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002254
2255 DI = getDerived().TransformType(DI);
2256 if (!DI) return true;
2257
2258 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2259 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002260 }
Mike Stump11289f42009-09-09 15:08:12 +00002261
Douglas Gregore922c772009-08-04 22:27:00 +00002262 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002263 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002264 DeclarationName Name;
2265 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2266 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002267 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002268 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002269 if (!D) return true;
2270
John McCall0d07eb32009-10-29 18:45:58 +00002271 Expr *SourceExpr = Input.getSourceDeclExpression();
2272 if (SourceExpr) {
2273 EnterExpressionEvaluationContext Unevaluated(getSema(),
2274 Action::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002275 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002276 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002277 }
2278
2279 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002280 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002281 }
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002283 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002284 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002285 TemplateName Template
2286 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2287 if (Template.isNull())
2288 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002289
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002290 Output = TemplateArgumentLoc(TemplateArgument(Template),
2291 Input.getTemplateQualifierRange(),
2292 Input.getTemplateNameLoc());
2293 return false;
2294 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002295
Douglas Gregore922c772009-08-04 22:27:00 +00002296 case TemplateArgument::Expression: {
2297 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002298 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002299 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002300
John McCall0ad16662009-10-29 08:12:44 +00002301 Expr *InputExpr = Input.getSourceExpression();
2302 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2303
John McCalldadc5752010-08-24 06:29:42 +00002304 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002305 = getDerived().TransformExpr(InputExpr);
2306 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002307 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002308 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002309 }
Mike Stump11289f42009-09-09 15:08:12 +00002310
Douglas Gregore922c772009-08-04 22:27:00 +00002311 case TemplateArgument::Pack: {
2312 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2313 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002314 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002315 AEnd = Arg.pack_end();
2316 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002317
John McCall0ad16662009-10-29 08:12:44 +00002318 // FIXME: preserve source information here when we start
2319 // caring about parameter packs.
2320
John McCall0d07eb32009-10-29 18:45:58 +00002321 TemplateArgumentLoc InputArg;
2322 TemplateArgumentLoc OutputArg;
2323 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2324 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002325 return true;
2326
John McCall0d07eb32009-10-29 18:45:58 +00002327 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002328 }
2329 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002330 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002331 true);
John McCall0d07eb32009-10-29 18:45:58 +00002332 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002333 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002334 }
2335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregore922c772009-08-04 22:27:00 +00002337 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002338 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002339}
2340
Douglas Gregord6ff3322009-08-04 16:50:30 +00002341//===----------------------------------------------------------------------===//
2342// Type transformation
2343//===----------------------------------------------------------------------===//
2344
2345template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002346QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002347 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002348 if (getDerived().AlreadyTransformed(T))
2349 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002350
John McCall550e0c22009-10-21 00:40:46 +00002351 // Temporary workaround. All of these transformations should
2352 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002353 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002354 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002355
Douglas Gregorfe17d252010-02-16 19:09:40 +00002356 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002357
John McCall550e0c22009-10-21 00:40:46 +00002358 if (!NewDI)
2359 return QualType();
2360
2361 return NewDI->getType();
2362}
2363
2364template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002365TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2366 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002367 if (getDerived().AlreadyTransformed(DI->getType()))
2368 return DI;
2369
2370 TypeLocBuilder TLB;
2371
2372 TypeLoc TL = DI->getTypeLoc();
2373 TLB.reserve(TL.getFullDataSize());
2374
Douglas Gregorfe17d252010-02-16 19:09:40 +00002375 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002376 if (Result.isNull())
2377 return 0;
2378
John McCallbcd03502009-12-07 02:54:59 +00002379 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002380}
2381
2382template<typename Derived>
2383QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002384TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2385 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002386 switch (T.getTypeLocClass()) {
2387#define ABSTRACT_TYPELOC(CLASS, PARENT)
2388#define TYPELOC(CLASS, PARENT) \
2389 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002390 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2391 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002392#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002393 }
Mike Stump11289f42009-09-09 15:08:12 +00002394
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002395 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002396 return QualType();
2397}
2398
2399/// FIXME: By default, this routine adds type qualifiers only to types
2400/// that can have qualifiers, and silently suppresses those qualifiers
2401/// that are not permitted (e.g., qualifiers on reference or function
2402/// types). This is the right thing for template instantiation, but
2403/// probably not for other clients.
2404template<typename Derived>
2405QualType
2406TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002407 QualifiedTypeLoc T,
2408 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002409 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002410
Douglas Gregorfe17d252010-02-16 19:09:40 +00002411 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2412 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002413 if (Result.isNull())
2414 return QualType();
2415
2416 // Silently suppress qualifiers if the result type can't be qualified.
2417 // FIXME: this is the right thing for template instantiation, but
2418 // probably not for other clients.
2419 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002420 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002421
John McCallcb0f89a2010-06-05 06:41:15 +00002422 if (!Quals.empty()) {
2423 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2424 TLB.push<QualifiedTypeLoc>(Result);
2425 // No location information to preserve.
2426 }
John McCall550e0c22009-10-21 00:40:46 +00002427
2428 return Result;
2429}
2430
2431template <class TyLoc> static inline
2432QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2433 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2434 NewT.setNameLoc(T.getNameLoc());
2435 return T.getType();
2436}
2437
John McCall550e0c22009-10-21 00:40:46 +00002438template<typename Derived>
2439QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002440 BuiltinTypeLoc T,
2441 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002442 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2443 NewT.setBuiltinLoc(T.getBuiltinLoc());
2444 if (T.needsExtraLocalData())
2445 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2446 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002447}
Mike Stump11289f42009-09-09 15:08:12 +00002448
Douglas Gregord6ff3322009-08-04 16:50:30 +00002449template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002450QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002451 ComplexTypeLoc T,
2452 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002453 // FIXME: recurse?
2454 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002455}
Mike Stump11289f42009-09-09 15:08:12 +00002456
Douglas Gregord6ff3322009-08-04 16:50:30 +00002457template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002458QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002459 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002460 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002461 QualType PointeeType
2462 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002463 if (PointeeType.isNull())
2464 return QualType();
2465
2466 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002467 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002468 // A dependent pointer type 'T *' has is being transformed such
2469 // that an Objective-C class type is being replaced for 'T'. The
2470 // resulting pointer type is an ObjCObjectPointerType, not a
2471 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002472 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002473
John McCall8b07ec22010-05-15 11:32:37 +00002474 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2475 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002476 return Result;
2477 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002478
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002479 if (getDerived().AlwaysRebuild() ||
2480 PointeeType != TL.getPointeeLoc().getType()) {
2481 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2482 if (Result.isNull())
2483 return QualType();
2484 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002485
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002486 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2487 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002488 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002489}
Mike Stump11289f42009-09-09 15:08:12 +00002490
2491template<typename Derived>
2492QualType
John McCall550e0c22009-10-21 00:40:46 +00002493TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002494 BlockPointerTypeLoc TL,
2495 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002496 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002497 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2498 if (PointeeType.isNull())
2499 return QualType();
2500
2501 QualType Result = TL.getType();
2502 if (getDerived().AlwaysRebuild() ||
2503 PointeeType != TL.getPointeeLoc().getType()) {
2504 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002505 TL.getSigilLoc());
2506 if (Result.isNull())
2507 return QualType();
2508 }
2509
Douglas Gregor049211a2010-04-22 16:50:51 +00002510 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002511 NewT.setSigilLoc(TL.getSigilLoc());
2512 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002513}
2514
John McCall70dd5f62009-10-30 00:06:24 +00002515/// Transforms a reference type. Note that somewhat paradoxically we
2516/// don't care whether the type itself is an l-value type or an r-value
2517/// type; we only care if the type was *written* as an l-value type
2518/// or an r-value type.
2519template<typename Derived>
2520QualType
2521TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002522 ReferenceTypeLoc TL,
2523 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002524 const ReferenceType *T = TL.getTypePtr();
2525
2526 // Note that this works with the pointee-as-written.
2527 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2528 if (PointeeType.isNull())
2529 return QualType();
2530
2531 QualType Result = TL.getType();
2532 if (getDerived().AlwaysRebuild() ||
2533 PointeeType != T->getPointeeTypeAsWritten()) {
2534 Result = getDerived().RebuildReferenceType(PointeeType,
2535 T->isSpelledAsLValue(),
2536 TL.getSigilLoc());
2537 if (Result.isNull())
2538 return QualType();
2539 }
2540
2541 // r-value references can be rebuilt as l-value references.
2542 ReferenceTypeLoc NewTL;
2543 if (isa<LValueReferenceType>(Result))
2544 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2545 else
2546 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2547 NewTL.setSigilLoc(TL.getSigilLoc());
2548
2549 return Result;
2550}
2551
Mike Stump11289f42009-09-09 15:08:12 +00002552template<typename Derived>
2553QualType
John McCall550e0c22009-10-21 00:40:46 +00002554TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002555 LValueReferenceTypeLoc TL,
2556 QualType ObjectType) {
2557 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002558}
2559
Mike Stump11289f42009-09-09 15:08:12 +00002560template<typename Derived>
2561QualType
John McCall550e0c22009-10-21 00:40:46 +00002562TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002563 RValueReferenceTypeLoc TL,
2564 QualType ObjectType) {
2565 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002566}
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregord6ff3322009-08-04 16:50:30 +00002568template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002569QualType
John McCall550e0c22009-10-21 00:40:46 +00002570TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002571 MemberPointerTypeLoc TL,
2572 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002573 MemberPointerType *T = TL.getTypePtr();
2574
2575 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002576 if (PointeeType.isNull())
2577 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002578
John McCall550e0c22009-10-21 00:40:46 +00002579 // TODO: preserve source information for this.
2580 QualType ClassType
2581 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002582 if (ClassType.isNull())
2583 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002584
John McCall550e0c22009-10-21 00:40:46 +00002585 QualType Result = TL.getType();
2586 if (getDerived().AlwaysRebuild() ||
2587 PointeeType != T->getPointeeType() ||
2588 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002589 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2590 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002591 if (Result.isNull())
2592 return QualType();
2593 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002594
John McCall550e0c22009-10-21 00:40:46 +00002595 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2596 NewTL.setSigilLoc(TL.getSigilLoc());
2597
2598 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002599}
2600
Mike Stump11289f42009-09-09 15:08:12 +00002601template<typename Derived>
2602QualType
John McCall550e0c22009-10-21 00:40:46 +00002603TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002604 ConstantArrayTypeLoc TL,
2605 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002606 ConstantArrayType *T = TL.getTypePtr();
2607 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608 if (ElementType.isNull())
2609 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002610
John McCall550e0c22009-10-21 00:40:46 +00002611 QualType Result = TL.getType();
2612 if (getDerived().AlwaysRebuild() ||
2613 ElementType != T->getElementType()) {
2614 Result = getDerived().RebuildConstantArrayType(ElementType,
2615 T->getSizeModifier(),
2616 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002617 T->getIndexTypeCVRQualifiers(),
2618 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002619 if (Result.isNull())
2620 return QualType();
2621 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002622
John McCall550e0c22009-10-21 00:40:46 +00002623 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2624 NewTL.setLBracketLoc(TL.getLBracketLoc());
2625 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002626
John McCall550e0c22009-10-21 00:40:46 +00002627 Expr *Size = TL.getSizeExpr();
2628 if (Size) {
2629 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2630 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2631 }
2632 NewTL.setSizeExpr(Size);
2633
2634 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635}
Mike Stump11289f42009-09-09 15:08:12 +00002636
Douglas Gregord6ff3322009-08-04 16:50:30 +00002637template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002638QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002639 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002640 IncompleteArrayTypeLoc TL,
2641 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002642 IncompleteArrayType *T = TL.getTypePtr();
2643 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002644 if (ElementType.isNull())
2645 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002646
John McCall550e0c22009-10-21 00:40:46 +00002647 QualType Result = TL.getType();
2648 if (getDerived().AlwaysRebuild() ||
2649 ElementType != T->getElementType()) {
2650 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002651 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002652 T->getIndexTypeCVRQualifiers(),
2653 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002654 if (Result.isNull())
2655 return QualType();
2656 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002657
John McCall550e0c22009-10-21 00:40:46 +00002658 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2659 NewTL.setLBracketLoc(TL.getLBracketLoc());
2660 NewTL.setRBracketLoc(TL.getRBracketLoc());
2661 NewTL.setSizeExpr(0);
2662
2663 return Result;
2664}
2665
2666template<typename Derived>
2667QualType
2668TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002669 VariableArrayTypeLoc TL,
2670 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002671 VariableArrayType *T = TL.getTypePtr();
2672 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2673 if (ElementType.isNull())
2674 return QualType();
2675
2676 // Array bounds are not potentially evaluated contexts
2677 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2678
John McCalldadc5752010-08-24 06:29:42 +00002679 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002680 = getDerived().TransformExpr(T->getSizeExpr());
2681 if (SizeResult.isInvalid())
2682 return QualType();
2683
John McCallb268a282010-08-23 23:25:46 +00002684 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002685
2686 QualType Result = TL.getType();
2687 if (getDerived().AlwaysRebuild() ||
2688 ElementType != T->getElementType() ||
2689 Size != T->getSizeExpr()) {
2690 Result = getDerived().RebuildVariableArrayType(ElementType,
2691 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002692 Size,
John McCall550e0c22009-10-21 00:40:46 +00002693 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002694 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002695 if (Result.isNull())
2696 return QualType();
2697 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002698
John McCall550e0c22009-10-21 00:40:46 +00002699 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2700 NewTL.setLBracketLoc(TL.getLBracketLoc());
2701 NewTL.setRBracketLoc(TL.getRBracketLoc());
2702 NewTL.setSizeExpr(Size);
2703
2704 return Result;
2705}
2706
2707template<typename Derived>
2708QualType
2709TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002710 DependentSizedArrayTypeLoc TL,
2711 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002712 DependentSizedArrayType *T = TL.getTypePtr();
2713 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2714 if (ElementType.isNull())
2715 return QualType();
2716
2717 // Array bounds are not potentially evaluated contexts
2718 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2719
John McCalldadc5752010-08-24 06:29:42 +00002720 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002721 = getDerived().TransformExpr(T->getSizeExpr());
2722 if (SizeResult.isInvalid())
2723 return QualType();
2724
2725 Expr *Size = static_cast<Expr*>(SizeResult.get());
2726
2727 QualType Result = TL.getType();
2728 if (getDerived().AlwaysRebuild() ||
2729 ElementType != T->getElementType() ||
2730 Size != T->getSizeExpr()) {
2731 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2732 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002733 Size,
John McCall550e0c22009-10-21 00:40:46 +00002734 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002735 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002736 if (Result.isNull())
2737 return QualType();
2738 }
2739 else SizeResult.take();
2740
2741 // We might have any sort of array type now, but fortunately they
2742 // all have the same location layout.
2743 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2744 NewTL.setLBracketLoc(TL.getLBracketLoc());
2745 NewTL.setRBracketLoc(TL.getRBracketLoc());
2746 NewTL.setSizeExpr(Size);
2747
2748 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749}
Mike Stump11289f42009-09-09 15:08:12 +00002750
2751template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002752QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002753 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002754 DependentSizedExtVectorTypeLoc TL,
2755 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002756 DependentSizedExtVectorType *T = TL.getTypePtr();
2757
2758 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759 QualType ElementType = getDerived().TransformType(T->getElementType());
2760 if (ElementType.isNull())
2761 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002762
Douglas Gregore922c772009-08-04 22:27:00 +00002763 // Vector sizes are not potentially evaluated contexts
2764 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2765
John McCalldadc5752010-08-24 06:29:42 +00002766 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002767 if (Size.isInvalid())
2768 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002769
John McCall550e0c22009-10-21 00:40:46 +00002770 QualType Result = TL.getType();
2771 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002772 ElementType != T->getElementType() ||
2773 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002774 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002775 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002776 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002777 if (Result.isNull())
2778 return QualType();
2779 }
John McCall550e0c22009-10-21 00:40:46 +00002780
2781 // Result might be dependent or not.
2782 if (isa<DependentSizedExtVectorType>(Result)) {
2783 DependentSizedExtVectorTypeLoc NewTL
2784 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2785 NewTL.setNameLoc(TL.getNameLoc());
2786 } else {
2787 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2788 NewTL.setNameLoc(TL.getNameLoc());
2789 }
2790
2791 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002792}
Mike Stump11289f42009-09-09 15:08:12 +00002793
2794template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002795QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002796 VectorTypeLoc TL,
2797 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002798 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002799 QualType ElementType = getDerived().TransformType(T->getElementType());
2800 if (ElementType.isNull())
2801 return QualType();
2802
John McCall550e0c22009-10-21 00:40:46 +00002803 QualType Result = TL.getType();
2804 if (getDerived().AlwaysRebuild() ||
2805 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002806 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002807 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002808 if (Result.isNull())
2809 return QualType();
2810 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002811
John McCall550e0c22009-10-21 00:40:46 +00002812 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2813 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002814
John McCall550e0c22009-10-21 00:40:46 +00002815 return Result;
2816}
2817
2818template<typename Derived>
2819QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002820 ExtVectorTypeLoc TL,
2821 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002822 VectorType *T = TL.getTypePtr();
2823 QualType ElementType = getDerived().TransformType(T->getElementType());
2824 if (ElementType.isNull())
2825 return QualType();
2826
2827 QualType Result = TL.getType();
2828 if (getDerived().AlwaysRebuild() ||
2829 ElementType != T->getElementType()) {
2830 Result = getDerived().RebuildExtVectorType(ElementType,
2831 T->getNumElements(),
2832 /*FIXME*/ SourceLocation());
2833 if (Result.isNull())
2834 return QualType();
2835 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002836
John McCall550e0c22009-10-21 00:40:46 +00002837 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2838 NewTL.setNameLoc(TL.getNameLoc());
2839
2840 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002841}
Mike Stump11289f42009-09-09 15:08:12 +00002842
2843template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002844ParmVarDecl *
2845TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2846 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2847 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2848 if (!NewDI)
2849 return 0;
2850
2851 if (NewDI == OldDI)
2852 return OldParm;
2853 else
2854 return ParmVarDecl::Create(SemaRef.Context,
2855 OldParm->getDeclContext(),
2856 OldParm->getLocation(),
2857 OldParm->getIdentifier(),
2858 NewDI->getType(),
2859 NewDI,
2860 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002861 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002862 /* DefArg */ NULL);
2863}
2864
2865template<typename Derived>
2866bool TreeTransform<Derived>::
2867 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2868 llvm::SmallVectorImpl<QualType> &PTypes,
2869 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2870 FunctionProtoType *T = TL.getTypePtr();
2871
2872 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2873 ParmVarDecl *OldParm = TL.getArg(i);
2874
2875 QualType NewType;
2876 ParmVarDecl *NewParm;
2877
2878 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002879 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2880 if (!NewParm)
2881 return true;
2882 NewType = NewParm->getType();
2883
2884 // Deal with the possibility that we don't have a parameter
2885 // declaration for this parameter.
2886 } else {
2887 NewParm = 0;
2888
2889 QualType OldType = T->getArgType(i);
2890 NewType = getDerived().TransformType(OldType);
2891 if (NewType.isNull())
2892 return true;
2893 }
2894
2895 PTypes.push_back(NewType);
2896 PVars.push_back(NewParm);
2897 }
2898
2899 return false;
2900}
2901
2902template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002903QualType
John McCall550e0c22009-10-21 00:40:46 +00002904TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002905 FunctionProtoTypeLoc TL,
2906 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002907 // Transform the parameters. We do this first for the benefit of template
2908 // instantiations, so that the ParmVarDecls get/ placed into the template
2909 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002910 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002911 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002912 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2913 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002914
Douglas Gregor14cf7522010-04-30 18:55:50 +00002915 FunctionProtoType *T = TL.getTypePtr();
2916 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2917 if (ResultType.isNull())
2918 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002919
John McCall550e0c22009-10-21 00:40:46 +00002920 QualType Result = TL.getType();
2921 if (getDerived().AlwaysRebuild() ||
2922 ResultType != T->getResultType() ||
2923 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2924 Result = getDerived().RebuildFunctionProtoType(ResultType,
2925 ParamTypes.data(),
2926 ParamTypes.size(),
2927 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002928 T->getTypeQuals(),
2929 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002930 if (Result.isNull())
2931 return QualType();
2932 }
Mike Stump11289f42009-09-09 15:08:12 +00002933
John McCall550e0c22009-10-21 00:40:46 +00002934 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2935 NewTL.setLParenLoc(TL.getLParenLoc());
2936 NewTL.setRParenLoc(TL.getRParenLoc());
2937 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2938 NewTL.setArg(i, ParamDecls[i]);
2939
2940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941}
Mike Stump11289f42009-09-09 15:08:12 +00002942
Douglas Gregord6ff3322009-08-04 16:50:30 +00002943template<typename Derived>
2944QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002945 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002946 FunctionNoProtoTypeLoc TL,
2947 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002948 FunctionNoProtoType *T = TL.getTypePtr();
2949 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2950 if (ResultType.isNull())
2951 return QualType();
2952
2953 QualType Result = TL.getType();
2954 if (getDerived().AlwaysRebuild() ||
2955 ResultType != T->getResultType())
2956 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2957
2958 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2959 NewTL.setLParenLoc(TL.getLParenLoc());
2960 NewTL.setRParenLoc(TL.getRParenLoc());
2961
2962 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002963}
Mike Stump11289f42009-09-09 15:08:12 +00002964
John McCallb96ec562009-12-04 22:46:56 +00002965template<typename Derived> QualType
2966TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002967 UnresolvedUsingTypeLoc TL,
2968 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002969 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002970 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002971 if (!D)
2972 return QualType();
2973
2974 QualType Result = TL.getType();
2975 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2976 Result = getDerived().RebuildUnresolvedUsingType(D);
2977 if (Result.isNull())
2978 return QualType();
2979 }
2980
2981 // We might get an arbitrary type spec type back. We should at
2982 // least always get a type spec type, though.
2983 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2984 NewTL.setNameLoc(TL.getNameLoc());
2985
2986 return Result;
2987}
2988
Douglas Gregord6ff3322009-08-04 16:50:30 +00002989template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002990QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002991 TypedefTypeLoc TL,
2992 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002993 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002994 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002995 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2996 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002997 if (!Typedef)
2998 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002999
John McCall550e0c22009-10-21 00:40:46 +00003000 QualType Result = TL.getType();
3001 if (getDerived().AlwaysRebuild() ||
3002 Typedef != T->getDecl()) {
3003 Result = getDerived().RebuildTypedefType(Typedef);
3004 if (Result.isNull())
3005 return QualType();
3006 }
Mike Stump11289f42009-09-09 15:08:12 +00003007
John McCall550e0c22009-10-21 00:40:46 +00003008 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3009 NewTL.setNameLoc(TL.getNameLoc());
3010
3011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003012}
Mike Stump11289f42009-09-09 15:08:12 +00003013
Douglas Gregord6ff3322009-08-04 16:50:30 +00003014template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003015QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003016 TypeOfExprTypeLoc TL,
3017 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003018 // typeof expressions are not potentially evaluated contexts
3019 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003020
John McCalldadc5752010-08-24 06:29:42 +00003021 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003022 if (E.isInvalid())
3023 return QualType();
3024
John McCall550e0c22009-10-21 00:40:46 +00003025 QualType Result = TL.getType();
3026 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003027 E.get() != TL.getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003028 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003029 if (Result.isNull())
3030 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003031 }
John McCall550e0c22009-10-21 00:40:46 +00003032 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003033
John McCall550e0c22009-10-21 00:40:46 +00003034 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003035 NewTL.setTypeofLoc(TL.getTypeofLoc());
3036 NewTL.setLParenLoc(TL.getLParenLoc());
3037 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003038
3039 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003040}
Mike Stump11289f42009-09-09 15:08:12 +00003041
3042template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003043QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003044 TypeOfTypeLoc TL,
3045 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003046 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3047 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3048 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003049 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003050
John McCall550e0c22009-10-21 00:40:46 +00003051 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003052 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3053 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003054 if (Result.isNull())
3055 return QualType();
3056 }
Mike Stump11289f42009-09-09 15:08:12 +00003057
John McCall550e0c22009-10-21 00:40:46 +00003058 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003059 NewTL.setTypeofLoc(TL.getTypeofLoc());
3060 NewTL.setLParenLoc(TL.getLParenLoc());
3061 NewTL.setRParenLoc(TL.getRParenLoc());
3062 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003063
3064 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003065}
Mike Stump11289f42009-09-09 15:08:12 +00003066
3067template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003068QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003069 DecltypeTypeLoc TL,
3070 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003071 DecltypeType *T = TL.getTypePtr();
3072
Douglas Gregore922c772009-08-04 22:27:00 +00003073 // decltype expressions are not potentially evaluated contexts
3074 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003075
John McCalldadc5752010-08-24 06:29:42 +00003076 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003077 if (E.isInvalid())
3078 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003079
John McCall550e0c22009-10-21 00:40:46 +00003080 QualType Result = TL.getType();
3081 if (getDerived().AlwaysRebuild() ||
3082 E.get() != T->getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003083 Result = getDerived().RebuildDecltypeType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003084 if (Result.isNull())
3085 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003086 }
John McCall550e0c22009-10-21 00:40:46 +00003087 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003088
John McCall550e0c22009-10-21 00:40:46 +00003089 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3090 NewTL.setNameLoc(TL.getNameLoc());
3091
3092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093}
3094
3095template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003096QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003097 RecordTypeLoc TL,
3098 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003099 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003101 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3102 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003103 if (!Record)
3104 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003105
John McCall550e0c22009-10-21 00:40:46 +00003106 QualType Result = TL.getType();
3107 if (getDerived().AlwaysRebuild() ||
3108 Record != T->getDecl()) {
3109 Result = getDerived().RebuildRecordType(Record);
3110 if (Result.isNull())
3111 return QualType();
3112 }
Mike Stump11289f42009-09-09 15:08:12 +00003113
John McCall550e0c22009-10-21 00:40:46 +00003114 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3115 NewTL.setNameLoc(TL.getNameLoc());
3116
3117 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003118}
Mike Stump11289f42009-09-09 15:08:12 +00003119
3120template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003121QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003122 EnumTypeLoc TL,
3123 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003124 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003125 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003126 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3127 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 if (!Enum)
3129 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003130
John McCall550e0c22009-10-21 00:40:46 +00003131 QualType Result = TL.getType();
3132 if (getDerived().AlwaysRebuild() ||
3133 Enum != T->getDecl()) {
3134 Result = getDerived().RebuildEnumType(Enum);
3135 if (Result.isNull())
3136 return QualType();
3137 }
Mike Stump11289f42009-09-09 15:08:12 +00003138
John McCall550e0c22009-10-21 00:40:46 +00003139 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3140 NewTL.setNameLoc(TL.getNameLoc());
3141
3142 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003143}
John McCallfcc33b02009-09-05 00:15:47 +00003144
John McCalle78aac42010-03-10 03:28:59 +00003145template<typename Derived>
3146QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3147 TypeLocBuilder &TLB,
3148 InjectedClassNameTypeLoc TL,
3149 QualType ObjectType) {
3150 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3151 TL.getTypePtr()->getDecl());
3152 if (!D) return QualType();
3153
3154 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3155 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3156 return T;
3157}
3158
Mike Stump11289f42009-09-09 15:08:12 +00003159
Douglas Gregord6ff3322009-08-04 16:50:30 +00003160template<typename Derived>
3161QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003162 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003163 TemplateTypeParmTypeLoc TL,
3164 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003165 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003166}
3167
Mike Stump11289f42009-09-09 15:08:12 +00003168template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003169QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003170 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003171 SubstTemplateTypeParmTypeLoc TL,
3172 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003173 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003174}
3175
3176template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003177QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3178 const TemplateSpecializationType *TST,
3179 QualType ObjectType) {
3180 // FIXME: this entire method is a temporary workaround; callers
3181 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003182
John McCall0ad16662009-10-29 08:12:44 +00003183 // Fake up a TemplateSpecializationTypeLoc.
3184 TypeLocBuilder TLB;
3185 TemplateSpecializationTypeLoc TL
3186 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3187
John McCall0d07eb32009-10-29 18:45:58 +00003188 SourceLocation BaseLoc = getDerived().getBaseLocation();
3189
3190 TL.setTemplateNameLoc(BaseLoc);
3191 TL.setLAngleLoc(BaseLoc);
3192 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003193 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3194 const TemplateArgument &TA = TST->getArg(i);
3195 TemplateArgumentLoc TAL;
3196 getDerived().InventTemplateArgumentLoc(TA, TAL);
3197 TL.setArgLocInfo(i, TAL.getLocInfo());
3198 }
3199
3200 TypeLocBuilder IgnoredTLB;
3201 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003202}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003203
Douglas Gregorc59e5612009-10-19 22:04:39 +00003204template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003205QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003206 TypeLocBuilder &TLB,
3207 TemplateSpecializationTypeLoc TL,
3208 QualType ObjectType) {
3209 const TemplateSpecializationType *T = TL.getTypePtr();
3210
Mike Stump11289f42009-09-09 15:08:12 +00003211 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003212 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003213 if (Template.isNull())
3214 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003215
John McCall6b51f282009-11-23 01:53:49 +00003216 TemplateArgumentListInfo NewTemplateArgs;
3217 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3218 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3219
3220 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3221 TemplateArgumentLoc Loc;
3222 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003223 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003224 NewTemplateArgs.addArgument(Loc);
3225 }
Mike Stump11289f42009-09-09 15:08:12 +00003226
John McCall0ad16662009-10-29 08:12:44 +00003227 // FIXME: maybe don't rebuild if all the template arguments are the same.
3228
3229 QualType Result =
3230 getDerived().RebuildTemplateSpecializationType(Template,
3231 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003232 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003233
3234 if (!Result.isNull()) {
3235 TemplateSpecializationTypeLoc NewTL
3236 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3237 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3238 NewTL.setLAngleLoc(TL.getLAngleLoc());
3239 NewTL.setRAngleLoc(TL.getRAngleLoc());
3240 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3241 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003242 }
Mike Stump11289f42009-09-09 15:08:12 +00003243
John McCall0ad16662009-10-29 08:12:44 +00003244 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003245}
Mike Stump11289f42009-09-09 15:08:12 +00003246
3247template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003248QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003249TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3250 ElaboratedTypeLoc TL,
3251 QualType ObjectType) {
3252 ElaboratedType *T = TL.getTypePtr();
3253
3254 NestedNameSpecifier *NNS = 0;
3255 // NOTE: the qualifier in an ElaboratedType is optional.
3256 if (T->getQualifier() != 0) {
3257 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003258 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003259 ObjectType);
3260 if (!NNS)
3261 return QualType();
3262 }
Mike Stump11289f42009-09-09 15:08:12 +00003263
Abramo Bagnarad7548482010-05-19 21:37:53 +00003264 QualType NamedT;
3265 // FIXME: this test is meant to workaround a problem (failing assertion)
3266 // occurring if directly executing the code in the else branch.
3267 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3268 TemplateSpecializationTypeLoc OldNamedTL
3269 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3270 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003271 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003272 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3273 if (NamedT.isNull())
3274 return QualType();
3275 TemplateSpecializationTypeLoc NewNamedTL
3276 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3277 NewNamedTL.copy(OldNamedTL);
3278 }
3279 else {
3280 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3281 if (NamedT.isNull())
3282 return QualType();
3283 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003284
John McCall550e0c22009-10-21 00:40:46 +00003285 QualType Result = TL.getType();
3286 if (getDerived().AlwaysRebuild() ||
3287 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003288 NamedT != T->getNamedType()) {
3289 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003290 if (Result.isNull())
3291 return QualType();
3292 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293
Abramo Bagnara6150c882010-05-11 21:36:43 +00003294 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003295 NewTL.setKeywordLoc(TL.getKeywordLoc());
3296 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003297
3298 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003299}
Mike Stump11289f42009-09-09 15:08:12 +00003300
3301template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003302QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3303 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003304 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003305 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003306
Douglas Gregord6ff3322009-08-04 16:50:30 +00003307 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003308 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3309 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003310 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003311 if (!NNS)
3312 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003313
John McCallc392f372010-06-11 00:33:02 +00003314 QualType Result
3315 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3316 T->getIdentifier(),
3317 TL.getKeywordLoc(),
3318 TL.getQualifierRange(),
3319 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003320 if (Result.isNull())
3321 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322
Abramo Bagnarad7548482010-05-19 21:37:53 +00003323 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3324 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003325 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3326
Abramo Bagnarad7548482010-05-19 21:37:53 +00003327 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3328 NewTL.setKeywordLoc(TL.getKeywordLoc());
3329 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003330 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003331 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3332 NewTL.setKeywordLoc(TL.getKeywordLoc());
3333 NewTL.setQualifierRange(TL.getQualifierRange());
3334 NewTL.setNameLoc(TL.getNameLoc());
3335 }
John McCall550e0c22009-10-21 00:40:46 +00003336 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003337}
Mike Stump11289f42009-09-09 15:08:12 +00003338
Douglas Gregord6ff3322009-08-04 16:50:30 +00003339template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003340QualType TreeTransform<Derived>::
3341 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3342 DependentTemplateSpecializationTypeLoc TL,
3343 QualType ObjectType) {
3344 DependentTemplateSpecializationType *T = TL.getTypePtr();
3345
3346 NestedNameSpecifier *NNS
3347 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3348 TL.getQualifierRange(),
3349 ObjectType);
3350 if (!NNS)
3351 return QualType();
3352
3353 TemplateArgumentListInfo NewTemplateArgs;
3354 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3355 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3356
3357 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3358 TemplateArgumentLoc Loc;
3359 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3360 return QualType();
3361 NewTemplateArgs.addArgument(Loc);
3362 }
3363
3364 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3365 T->getKeyword(),
3366 NNS,
3367 T->getIdentifier(),
3368 TL.getNameLoc(),
3369 NewTemplateArgs);
3370 if (Result.isNull())
3371 return QualType();
3372
3373 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3374 QualType NamedT = ElabT->getNamedType();
3375
3376 // Copy information relevant to the template specialization.
3377 TemplateSpecializationTypeLoc NamedTL
3378 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3379 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3380 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3381 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3382 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3383
3384 // Copy information relevant to the elaborated type.
3385 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3386 NewTL.setKeywordLoc(TL.getKeywordLoc());
3387 NewTL.setQualifierRange(TL.getQualifierRange());
3388 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003389 TypeLoc NewTL(Result, TL.getOpaqueData());
3390 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003391 }
3392 return Result;
3393}
3394
3395template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003396QualType
3397TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003398 ObjCInterfaceTypeLoc TL,
3399 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003400 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003401 TLB.pushFullCopy(TL);
3402 return TL.getType();
3403}
3404
3405template<typename Derived>
3406QualType
3407TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3408 ObjCObjectTypeLoc TL,
3409 QualType ObjectType) {
3410 // ObjCObjectType is never dependent.
3411 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003412 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003413}
Mike Stump11289f42009-09-09 15:08:12 +00003414
3415template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003416QualType
3417TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003418 ObjCObjectPointerTypeLoc TL,
3419 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003420 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003421 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003422 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003423}
3424
Douglas Gregord6ff3322009-08-04 16:50:30 +00003425//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003426// Statement transformation
3427//===----------------------------------------------------------------------===//
3428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003429StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003430TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3431 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003432}
3433
3434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003435StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003436TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3437 return getDerived().TransformCompoundStmt(S, false);
3438}
3439
3440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003441StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003442TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003443 bool IsStmtExpr) {
3444 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003445 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003446 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3447 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003448 StmtResult Result = getDerived().TransformStmt(*B);
Douglas Gregorebe10102009-08-20 07:17:43 +00003449 if (Result.isInvalid())
3450 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003451
Douglas Gregorebe10102009-08-20 07:17:43 +00003452 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3453 Statements.push_back(Result.takeAs<Stmt>());
3454 }
Mike Stump11289f42009-09-09 15:08:12 +00003455
Douglas Gregorebe10102009-08-20 07:17:43 +00003456 if (!getDerived().AlwaysRebuild() &&
3457 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003458 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003459
3460 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3461 move_arg(Statements),
3462 S->getRBracLoc(),
3463 IsStmtExpr);
3464}
Mike Stump11289f42009-09-09 15:08:12 +00003465
Douglas Gregorebe10102009-08-20 07:17:43 +00003466template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003467StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003468TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003469 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003470 {
3471 // The case value expressions are not potentially evaluated.
3472 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003473
Eli Friedman06577382009-11-19 03:14:00 +00003474 // Transform the left-hand case value.
3475 LHS = getDerived().TransformExpr(S->getLHS());
3476 if (LHS.isInvalid())
3477 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003478
Eli Friedman06577382009-11-19 03:14:00 +00003479 // Transform the right-hand case value (for the GNU case-range extension).
3480 RHS = getDerived().TransformExpr(S->getRHS());
3481 if (RHS.isInvalid())
3482 return SemaRef.StmtError();
3483 }
Mike Stump11289f42009-09-09 15:08:12 +00003484
Douglas Gregorebe10102009-08-20 07:17:43 +00003485 // Build the case statement.
3486 // Case statements are always rebuilt so that they will attached to their
3487 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003488 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003489 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003490 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003491 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003492 S->getColonLoc());
3493 if (Case.isInvalid())
3494 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregorebe10102009-08-20 07:17:43 +00003496 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003497 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003498 if (SubStmt.isInvalid())
3499 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003500
Douglas Gregorebe10102009-08-20 07:17:43 +00003501 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003502 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003503}
3504
3505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003506StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003507TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003508 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003509 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003510 if (SubStmt.isInvalid())
3511 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003512
Douglas Gregorebe10102009-08-20 07:17:43 +00003513 // Default statements are always rebuilt
3514 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003515 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003516}
Mike Stump11289f42009-09-09 15:08:12 +00003517
Douglas Gregorebe10102009-08-20 07:17:43 +00003518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003519StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003520TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003521 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003522 if (SubStmt.isInvalid())
3523 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregorebe10102009-08-20 07:17:43 +00003525 // FIXME: Pass the real colon location in.
3526 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3527 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00003528 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003529}
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregorebe10102009-08-20 07:17:43 +00003531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003532StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003533TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003534 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003535 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003536 VarDecl *ConditionVar = 0;
3537 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003538 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003539 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003540 getDerived().TransformDefinition(
3541 S->getConditionVariable()->getLocation(),
3542 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003543 if (!ConditionVar)
3544 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003545 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003546 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003547
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003548 if (Cond.isInvalid())
3549 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003550
3551 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003552 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003553 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003554 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003555 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003556 if (CondE.isInvalid())
3557 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003558
John McCallb268a282010-08-23 23:25:46 +00003559 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003560 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003561 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003562
John McCallb268a282010-08-23 23:25:46 +00003563 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3564 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003565 return SemaRef.StmtError();
3566
Douglas Gregorebe10102009-08-20 07:17:43 +00003567 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003568 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003569 if (Then.isInvalid())
3570 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003571
Douglas Gregorebe10102009-08-20 07:17:43 +00003572 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003573 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003574 if (Else.isInvalid())
3575 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003576
Douglas Gregorebe10102009-08-20 07:17:43 +00003577 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003578 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003579 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003580 Then.get() == S->getThen() &&
3581 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003582 return SemaRef.Owned(S->Retain());
3583
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003584 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003585 Then.get(),
3586 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003587}
3588
3589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003590StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003591TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003592 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003593 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003594 VarDecl *ConditionVar = 0;
3595 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003596 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003597 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003598 getDerived().TransformDefinition(
3599 S->getConditionVariable()->getLocation(),
3600 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003601 if (!ConditionVar)
3602 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003603 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003604 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003605
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003606 if (Cond.isInvalid())
3607 return SemaRef.StmtError();
3608 }
Mike Stump11289f42009-09-09 15:08:12 +00003609
Douglas Gregorebe10102009-08-20 07:17:43 +00003610 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003611 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003612 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003613 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003614 if (Switch.isInvalid())
3615 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregorebe10102009-08-20 07:17:43 +00003617 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003618 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003619 if (Body.isInvalid())
3620 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003621
Douglas Gregorebe10102009-08-20 07:17:43 +00003622 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003623 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3624 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003625}
Mike Stump11289f42009-09-09 15:08:12 +00003626
Douglas Gregorebe10102009-08-20 07:17:43 +00003627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003628StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003629TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003630 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003631 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003632 VarDecl *ConditionVar = 0;
3633 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003634 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003635 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003636 getDerived().TransformDefinition(
3637 S->getConditionVariable()->getLocation(),
3638 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003639 if (!ConditionVar)
3640 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003641 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003642 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003643
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003644 if (Cond.isInvalid())
3645 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003646
3647 if (S->getCond()) {
3648 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003649 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003650 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003651 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003652 if (CondE.isInvalid())
3653 return getSema().StmtError();
John McCallb268a282010-08-23 23:25:46 +00003654 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003655 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003656 }
Mike Stump11289f42009-09-09 15:08:12 +00003657
John McCallb268a282010-08-23 23:25:46 +00003658 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3659 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003660 return SemaRef.StmtError();
3661
Douglas Gregorebe10102009-08-20 07:17:43 +00003662 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003663 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003664 if (Body.isInvalid())
3665 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003666
Douglas Gregorebe10102009-08-20 07:17:43 +00003667 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003668 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003669 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003670 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003671 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003672
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003673 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003674 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003675}
Mike Stump11289f42009-09-09 15:08:12 +00003676
Douglas Gregorebe10102009-08-20 07:17:43 +00003677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003678StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003679TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003680 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003681 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003682 if (Body.isInvalid())
3683 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003684
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003685 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003686 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003687 if (Cond.isInvalid())
3688 return SemaRef.StmtError();
3689
Douglas Gregorebe10102009-08-20 07:17:43 +00003690 if (!getDerived().AlwaysRebuild() &&
3691 Cond.get() == S->getCond() &&
3692 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003693 return SemaRef.Owned(S->Retain());
3694
John McCallb268a282010-08-23 23:25:46 +00003695 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3696 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003697 S->getRParenLoc());
3698}
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>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003703 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003704 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003705 if (Init.isInvalid())
3706 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003707
Douglas Gregorebe10102009-08-20 07:17:43 +00003708 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003709 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003710 VarDecl *ConditionVar = 0;
3711 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003712 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003713 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003714 getDerived().TransformDefinition(
3715 S->getConditionVariable()->getLocation(),
3716 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003717 if (!ConditionVar)
3718 return SemaRef.StmtError();
3719 } else {
3720 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003721
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003722 if (Cond.isInvalid())
3723 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003724
3725 if (S->getCond()) {
3726 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003727 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003728 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003729 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003730 if (CondE.isInvalid())
3731 return getSema().StmtError();
3732
John McCallb268a282010-08-23 23:25:46 +00003733 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003734 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003735 }
Mike Stump11289f42009-09-09 15:08:12 +00003736
John McCallb268a282010-08-23 23:25:46 +00003737 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3738 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003739 return SemaRef.StmtError();
3740
Douglas Gregorebe10102009-08-20 07:17:43 +00003741 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003742 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003743 if (Inc.isInvalid())
3744 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003745
John McCallb268a282010-08-23 23:25:46 +00003746 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3747 if (S->getInc() && !FullInc.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003748 return SemaRef.StmtError();
3749
Douglas Gregorebe10102009-08-20 07:17:43 +00003750 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003751 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003752 if (Body.isInvalid())
3753 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003754
Douglas Gregorebe10102009-08-20 07:17:43 +00003755 if (!getDerived().AlwaysRebuild() &&
3756 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003757 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003758 Inc.get() == S->getInc() &&
3759 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003760 return SemaRef.Owned(S->Retain());
3761
Douglas Gregorebe10102009-08-20 07:17:43 +00003762 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003763 Init.get(), FullCond, ConditionVar,
3764 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003765}
3766
3767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003768StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003769TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003771 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003772 S->getLabel());
3773}
3774
3775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003776StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003777TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003778 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003779 if (Target.isInvalid())
3780 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003781
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 if (!getDerived().AlwaysRebuild() &&
3783 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003784 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003785
3786 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003787 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003788}
3789
3790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003792TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3793 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003794}
Mike Stump11289f42009-09-09 15:08:12 +00003795
Douglas Gregorebe10102009-08-20 07:17:43 +00003796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003797StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003798TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3799 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003800}
Mike Stump11289f42009-09-09 15:08:12 +00003801
Douglas Gregorebe10102009-08-20 07:17:43 +00003802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003803StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003804TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003805 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003806 if (Result.isInvalid())
3807 return SemaRef.StmtError();
3808
Mike Stump11289f42009-09-09 15:08:12 +00003809 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003810 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003811 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003812}
Mike Stump11289f42009-09-09 15:08:12 +00003813
Douglas Gregorebe10102009-08-20 07:17:43 +00003814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003815StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003816TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003817 bool DeclChanged = false;
3818 llvm::SmallVector<Decl *, 4> Decls;
3819 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3820 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003821 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3822 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003823 if (!Transformed)
3824 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003825
Douglas Gregorebe10102009-08-20 07:17:43 +00003826 if (Transformed != *D)
3827 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003828
Douglas Gregorebe10102009-08-20 07:17:43 +00003829 Decls.push_back(Transformed);
3830 }
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregorebe10102009-08-20 07:17:43 +00003832 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003833 return SemaRef.Owned(S->Retain());
3834
3835 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003836 S->getStartLoc(), S->getEndLoc());
3837}
Mike Stump11289f42009-09-09 15:08:12 +00003838
Douglas Gregorebe10102009-08-20 07:17:43 +00003839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003840StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003841TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003842 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003843 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003844}
3845
3846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003847StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003848TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003849
John McCall37ad5512010-08-23 06:44:23 +00003850 ASTOwningVector<Expr*> Constraints(getSema());
3851 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003852 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003853
John McCalldadc5752010-08-24 06:29:42 +00003854 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003855 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003856
3857 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003858
Anders Carlssonaaeef072010-01-24 05:50:09 +00003859 // Go through the outputs.
3860 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003861 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003862
Anders Carlssonaaeef072010-01-24 05:50:09 +00003863 // No need to transform the constraint literal.
3864 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003865
Anders Carlssonaaeef072010-01-24 05:50:09 +00003866 // Transform the output expr.
3867 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003868 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003869 if (Result.isInvalid())
3870 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003871
Anders Carlssonaaeef072010-01-24 05:50:09 +00003872 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003873
John McCallb268a282010-08-23 23:25:46 +00003874 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003875 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003876
Anders Carlssonaaeef072010-01-24 05:50:09 +00003877 // Go through the inputs.
3878 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003879 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003880
Anders Carlssonaaeef072010-01-24 05:50:09 +00003881 // No need to transform the constraint literal.
3882 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003883
Anders Carlssonaaeef072010-01-24 05:50:09 +00003884 // Transform the input expr.
3885 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003886 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003887 if (Result.isInvalid())
3888 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003889
Anders Carlssonaaeef072010-01-24 05:50:09 +00003890 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003891
John McCallb268a282010-08-23 23:25:46 +00003892 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003893 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003894
Anders Carlssonaaeef072010-01-24 05:50:09 +00003895 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3896 return SemaRef.Owned(S->Retain());
3897
3898 // Go through the clobbers.
3899 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3900 Clobbers.push_back(S->getClobber(I)->Retain());
3901
3902 // No need to transform the asm string literal.
3903 AsmString = SemaRef.Owned(S->getAsmString());
3904
3905 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3906 S->isSimple(),
3907 S->isVolatile(),
3908 S->getNumOutputs(),
3909 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003910 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003911 move_arg(Constraints),
3912 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003913 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003914 move_arg(Clobbers),
3915 S->getRParenLoc(),
3916 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003917}
3918
3919
3920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003921StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003922TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003923 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00003924 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003925 if (TryBody.isInvalid())
3926 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003927
Douglas Gregor96c79492010-04-23 22:50:49 +00003928 // Transform the @catch statements (if present).
3929 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003930 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00003931 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00003932 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003933 if (Catch.isInvalid())
3934 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003935 if (Catch.get() != S->getCatchStmt(I))
3936 AnyCatchChanged = true;
3937 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003938 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003939
Douglas Gregor306de2f2010-04-22 23:59:56 +00003940 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00003941 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00003942 if (S->getFinallyStmt()) {
3943 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3944 if (Finally.isInvalid())
3945 return SemaRef.StmtError();
3946 }
3947
3948 // If nothing changed, just retain this statement.
3949 if (!getDerived().AlwaysRebuild() &&
3950 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003951 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003952 Finally.get() == S->getFinallyStmt())
3953 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003954
Douglas Gregor306de2f2010-04-22 23:59:56 +00003955 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00003956 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3957 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003958}
Mike Stump11289f42009-09-09 15:08:12 +00003959
Douglas Gregorebe10102009-08-20 07:17:43 +00003960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003961StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003962TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003963 // Transform the @catch parameter, if there is one.
3964 VarDecl *Var = 0;
3965 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3966 TypeSourceInfo *TSInfo = 0;
3967 if (FromVar->getTypeSourceInfo()) {
3968 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3969 if (!TSInfo)
3970 return SemaRef.StmtError();
3971 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003972
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003973 QualType T;
3974 if (TSInfo)
3975 T = TSInfo->getType();
3976 else {
3977 T = getDerived().TransformType(FromVar->getType());
3978 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003979 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003980 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003981
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003982 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3983 if (!Var)
3984 return SemaRef.StmtError();
3985 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003986
John McCalldadc5752010-08-24 06:29:42 +00003987 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003988 if (Body.isInvalid())
3989 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003990
3991 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003992 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003993 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003994}
Mike Stump11289f42009-09-09 15:08:12 +00003995
Douglas Gregorebe10102009-08-20 07:17:43 +00003996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003997StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003998TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003999 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004000 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004001 if (Body.isInvalid())
4002 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004003
Douglas Gregor306de2f2010-04-22 23:59:56 +00004004 // If nothing changed, just retain this statement.
4005 if (!getDerived().AlwaysRebuild() &&
4006 Body.get() == S->getFinallyBody())
4007 return SemaRef.Owned(S->Retain());
4008
4009 // Build a new statement.
4010 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004011 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004012}
Mike Stump11289f42009-09-09 15:08:12 +00004013
Douglas Gregorebe10102009-08-20 07:17:43 +00004014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004015StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004016TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004017 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004018 if (S->getThrowExpr()) {
4019 Operand = getDerived().TransformExpr(S->getThrowExpr());
4020 if (Operand.isInvalid())
4021 return getSema().StmtError();
4022 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004023
Douglas Gregor2900c162010-04-22 21:44:01 +00004024 if (!getDerived().AlwaysRebuild() &&
4025 Operand.get() == S->getThrowExpr())
4026 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004027
John McCallb268a282010-08-23 23:25:46 +00004028 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004029}
Mike Stump11289f42009-09-09 15:08:12 +00004030
Douglas Gregorebe10102009-08-20 07:17:43 +00004031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004032StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004033TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004034 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004035 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004036 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004037 if (Object.isInvalid())
4038 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004039
Douglas Gregor6148de72010-04-22 22:01:21 +00004040 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004041 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004042 if (Body.isInvalid())
4043 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004044
Douglas Gregor6148de72010-04-22 22:01:21 +00004045 // If nothing change, just retain the current statement.
4046 if (!getDerived().AlwaysRebuild() &&
4047 Object.get() == S->getSynchExpr() &&
4048 Body.get() == S->getSynchBody())
4049 return SemaRef.Owned(S->Retain());
4050
4051 // Build a new statement.
4052 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004053 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004054}
4055
4056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004057StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004058TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004059 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004060 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004061 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004062 if (Element.isInvalid())
4063 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004064
Douglas Gregorf68a5082010-04-22 23:10:45 +00004065 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004066 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004067 if (Collection.isInvalid())
4068 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004069
Douglas Gregorf68a5082010-04-22 23:10:45 +00004070 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004071 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004072 if (Body.isInvalid())
4073 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004074
Douglas Gregorf68a5082010-04-22 23:10:45 +00004075 // If nothing changed, just retain this statement.
4076 if (!getDerived().AlwaysRebuild() &&
4077 Element.get() == S->getElement() &&
4078 Collection.get() == S->getCollection() &&
4079 Body.get() == S->getBody())
4080 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004081
Douglas Gregorf68a5082010-04-22 23:10:45 +00004082 // Build a new statement.
4083 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4084 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004085 Element.get(),
4086 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004087 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004088 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004089}
4090
4091
4092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004093StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004094TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4095 // Transform the exception declaration, if any.
4096 VarDecl *Var = 0;
4097 if (S->getExceptionDecl()) {
4098 VarDecl *ExceptionDecl = S->getExceptionDecl();
4099 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4100 ExceptionDecl->getDeclName());
4101
4102 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4103 if (T.isNull())
4104 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregorebe10102009-08-20 07:17:43 +00004106 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4107 T,
John McCallbcd03502009-12-07 02:54:59 +00004108 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004109 ExceptionDecl->getIdentifier(),
4110 ExceptionDecl->getLocation(),
4111 /*FIXME: Inaccurate*/
4112 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004113 if (!Var || Var->isInvalidDecl())
Douglas Gregorebe10102009-08-20 07:17:43 +00004114 return SemaRef.StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004115 }
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregorebe10102009-08-20 07:17:43 +00004117 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004118 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004119 if (Handler.isInvalid())
Douglas Gregorebe10102009-08-20 07:17:43 +00004120 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004121
Douglas Gregorebe10102009-08-20 07:17:43 +00004122 if (!getDerived().AlwaysRebuild() &&
4123 !Var &&
4124 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004125 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004126
4127 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4128 Var,
John McCallb268a282010-08-23 23:25:46 +00004129 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004130}
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregorebe10102009-08-20 07:17:43 +00004132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004133StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004134TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4135 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004136 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004137 = getDerived().TransformCompoundStmt(S->getTryBlock());
4138 if (TryBlock.isInvalid())
4139 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregorebe10102009-08-20 07:17:43 +00004141 // Transform the handlers.
4142 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004143 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004144 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004145 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004146 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4147 if (Handler.isInvalid())
4148 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004149
Douglas Gregorebe10102009-08-20 07:17:43 +00004150 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4151 Handlers.push_back(Handler.takeAs<Stmt>());
4152 }
Mike Stump11289f42009-09-09 15:08:12 +00004153
Douglas Gregorebe10102009-08-20 07:17:43 +00004154 if (!getDerived().AlwaysRebuild() &&
4155 TryBlock.get() == S->getTryBlock() &&
4156 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004157 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004158
John McCallb268a282010-08-23 23:25:46 +00004159 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004160 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004161}
Mike Stump11289f42009-09-09 15:08:12 +00004162
Douglas Gregorebe10102009-08-20 07:17:43 +00004163//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004164// Expression transformation
4165//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004168TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004169 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004170}
Mike Stump11289f42009-09-09 15:08:12 +00004171
4172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004174TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004175 NestedNameSpecifier *Qualifier = 0;
4176 if (E->getQualifier()) {
4177 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004178 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004179 if (!Qualifier)
4180 return SemaRef.ExprError();
4181 }
John McCallce546572009-12-08 09:08:17 +00004182
4183 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004184 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4185 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 if (!ND)
4187 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004188
John McCall815039a2010-08-17 21:27:17 +00004189 DeclarationNameInfo NameInfo = E->getNameInfo();
4190 if (NameInfo.getName()) {
4191 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4192 if (!NameInfo.getName())
4193 return SemaRef.ExprError();
4194 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004195
4196 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004197 Qualifier == E->getQualifier() &&
4198 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004199 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004200 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004201
4202 // Mark it referenced in the new context regardless.
4203 // FIXME: this is a bit instantiation-specific.
4204 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4205
Mike Stump11289f42009-09-09 15:08:12 +00004206 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004207 }
John McCallce546572009-12-08 09:08:17 +00004208
4209 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004210 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004211 TemplateArgs = &TransArgs;
4212 TransArgs.setLAngleLoc(E->getLAngleLoc());
4213 TransArgs.setRAngleLoc(E->getRAngleLoc());
4214 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4215 TemplateArgumentLoc Loc;
4216 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4217 return SemaRef.ExprError();
4218 TransArgs.addArgument(Loc);
4219 }
4220 }
4221
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004222 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004223 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004224}
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregora16548e2009-08-11 05:31:07 +00004226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004228TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004229 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004230}
Mike Stump11289f42009-09-09 15:08:12 +00004231
Douglas Gregora16548e2009-08-11 05:31:07 +00004232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004234TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004235 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004236}
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregora16548e2009-08-11 05:31:07 +00004238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004240TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004241 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004242}
Mike Stump11289f42009-09-09 15:08:12 +00004243
Douglas Gregora16548e2009-08-11 05:31:07 +00004244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004245ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004246TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004247 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004248}
Mike Stump11289f42009-09-09 15:08:12 +00004249
Douglas Gregora16548e2009-08-11 05:31:07 +00004250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004251ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004252TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004253 return SemaRef.Owned(E->Retain());
4254}
4255
4256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004257ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004258TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004259 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004260 if (SubExpr.isInvalid())
4261 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregora16548e2009-08-11 05:31:07 +00004263 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004264 return SemaRef.Owned(E->Retain());
4265
John McCallb268a282010-08-23 23:25:46 +00004266 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004267 E->getRParen());
4268}
4269
Mike Stump11289f42009-09-09 15:08:12 +00004270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004271ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004272TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004273 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004274 if (SubExpr.isInvalid())
4275 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004278 return SemaRef.Owned(E->Retain());
4279
Douglas Gregora16548e2009-08-11 05:31:07 +00004280 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4281 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004282 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004283}
Mike Stump11289f42009-09-09 15:08:12 +00004284
Douglas Gregora16548e2009-08-11 05:31:07 +00004285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004286ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004287TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4288 // Transform the type.
4289 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4290 if (!Type)
4291 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004292
Douglas Gregor882211c2010-04-28 22:16:22 +00004293 // Transform all of the components into components similar to what the
4294 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004295 // FIXME: It would be slightly more efficient in the non-dependent case to
4296 // just map FieldDecls, rather than requiring the rebuilder to look for
4297 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004298 // template code that we don't care.
4299 bool ExprChanged = false;
4300 typedef Action::OffsetOfComponent Component;
4301 typedef OffsetOfExpr::OffsetOfNode Node;
4302 llvm::SmallVector<Component, 4> Components;
4303 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4304 const Node &ON = E->getComponent(I);
4305 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004306 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004307 Comp.LocStart = ON.getRange().getBegin();
4308 Comp.LocEnd = ON.getRange().getEnd();
4309 switch (ON.getKind()) {
4310 case Node::Array: {
4311 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004312 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004313 if (Index.isInvalid())
4314 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004315
Douglas Gregor882211c2010-04-28 22:16:22 +00004316 ExprChanged = ExprChanged || Index.get() != FromIndex;
4317 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004318 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004319 break;
4320 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004321
Douglas Gregor882211c2010-04-28 22:16:22 +00004322 case Node::Field:
4323 case Node::Identifier:
4324 Comp.isBrackets = false;
4325 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004326 if (!Comp.U.IdentInfo)
4327 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004328
Douglas Gregor882211c2010-04-28 22:16:22 +00004329 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004330
Douglas Gregord1702062010-04-29 00:18:15 +00004331 case Node::Base:
4332 // Will be recomputed during the rebuild.
4333 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004334 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004335
Douglas Gregor882211c2010-04-28 22:16:22 +00004336 Components.push_back(Comp);
4337 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004338
Douglas Gregor882211c2010-04-28 22:16:22 +00004339 // If nothing changed, retain the existing expression.
4340 if (!getDerived().AlwaysRebuild() &&
4341 Type == E->getTypeSourceInfo() &&
4342 !ExprChanged)
4343 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004344
Douglas Gregor882211c2010-04-28 22:16:22 +00004345 // Build a new offsetof expression.
4346 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4347 Components.data(), Components.size(),
4348 E->getRParenLoc());
4349}
4350
4351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004352ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004353TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004355 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004356
John McCallbcd03502009-12-07 02:54:59 +00004357 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004358 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004359 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004360
John McCall4c98fd82009-11-04 07:28:41 +00004361 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004362 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004363
John McCall4c98fd82009-11-04 07:28:41 +00004364 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004365 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004366 E->getSourceRange());
4367 }
Mike Stump11289f42009-09-09 15:08:12 +00004368
John McCalldadc5752010-08-24 06:29:42 +00004369 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004370 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 // C++0x [expr.sizeof]p1:
4372 // The operand is either an expression, which is an unevaluated operand
4373 // [...]
4374 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004375
Douglas Gregora16548e2009-08-11 05:31:07 +00004376 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4377 if (SubExpr.isInvalid())
4378 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004379
Douglas Gregora16548e2009-08-11 05:31:07 +00004380 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4381 return SemaRef.Owned(E->Retain());
4382 }
Mike Stump11289f42009-09-09 15:08:12 +00004383
John McCallb268a282010-08-23 23:25:46 +00004384 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004385 E->isSizeOf(),
4386 E->getSourceRange());
4387}
Mike Stump11289f42009-09-09 15:08:12 +00004388
Douglas Gregora16548e2009-08-11 05:31:07 +00004389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004390ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004391TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004392 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 if (LHS.isInvalid())
4394 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004395
John McCalldadc5752010-08-24 06:29:42 +00004396 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 if (RHS.isInvalid())
4398 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004399
4400
Douglas Gregora16548e2009-08-11 05:31:07 +00004401 if (!getDerived().AlwaysRebuild() &&
4402 LHS.get() == E->getLHS() &&
4403 RHS.get() == E->getRHS())
4404 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004405
John McCallb268a282010-08-23 23:25:46 +00004406 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004407 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004408 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004409 E->getRBracketLoc());
4410}
Mike Stump11289f42009-09-09 15:08:12 +00004411
4412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004414TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004415 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004416 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 if (Callee.isInvalid())
4418 return SemaRef.ExprError();
4419
4420 // Transform arguments.
4421 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004422 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4424 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004425 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004426 if (Arg.isInvalid())
4427 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004428
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 // FIXME: Wrong source location information for the ','.
4430 FakeCommaLocs.push_back(
4431 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004432
4433 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004434 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 }
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 if (!getDerived().AlwaysRebuild() &&
4438 Callee.get() == E->getCallee() &&
4439 !ArgChanged)
4440 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004441
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004443 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004444 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004445 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 move_arg(Args),
4447 FakeCommaLocs.data(),
4448 E->getRParenLoc());
4449}
Mike Stump11289f42009-09-09 15:08:12 +00004450
4451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004452ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004453TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004454 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 if (Base.isInvalid())
4456 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004458 NestedNameSpecifier *Qualifier = 0;
4459 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004460 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004461 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004462 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004463 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004464 return SemaRef.ExprError();
4465 }
Mike Stump11289f42009-09-09 15:08:12 +00004466
Eli Friedman2cfcef62009-12-04 06:40:45 +00004467 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004468 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4469 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 if (!Member)
4471 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004472
John McCall16df1e52010-03-30 21:47:33 +00004473 NamedDecl *FoundDecl = E->getFoundDecl();
4474 if (FoundDecl == E->getMemberDecl()) {
4475 FoundDecl = Member;
4476 } else {
4477 FoundDecl = cast_or_null<NamedDecl>(
4478 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4479 if (!FoundDecl)
4480 return SemaRef.ExprError();
4481 }
4482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483 if (!getDerived().AlwaysRebuild() &&
4484 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004485 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004486 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004487 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004488 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004489
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004490 // Mark it referenced in the new context regardless.
4491 // FIXME: this is a bit instantiation-specific.
4492 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004493 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004494 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004495
John McCall6b51f282009-11-23 01:53:49 +00004496 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004497 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004498 TransArgs.setLAngleLoc(E->getLAngleLoc());
4499 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004500 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004501 TemplateArgumentLoc Loc;
4502 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004503 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004504 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004505 }
4506 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004507
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 // FIXME: Bogus source location for the operator
4509 SourceLocation FakeOperatorLoc
4510 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4511
John McCall38836f02010-01-15 08:34:02 +00004512 // FIXME: to do this check properly, we will need to preserve the
4513 // first-qualifier-in-scope here, just in case we had a dependent
4514 // base (and therefore couldn't do the check) and a
4515 // nested-name-qualifier (and therefore could do the lookup).
4516 NamedDecl *FirstQualifierInScope = 0;
4517
John McCallb268a282010-08-23 23:25:46 +00004518 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004520 Qualifier,
4521 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004522 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004523 Member,
John McCall16df1e52010-03-30 21:47:33 +00004524 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004525 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004526 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004527 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004528}
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregora16548e2009-08-11 05:31:07 +00004530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004531ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004532TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004533 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 if (LHS.isInvalid())
4535 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004536
John McCalldadc5752010-08-24 06:29:42 +00004537 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004538 if (RHS.isInvalid())
4539 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregora16548e2009-08-11 05:31:07 +00004541 if (!getDerived().AlwaysRebuild() &&
4542 LHS.get() == E->getLHS() &&
4543 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004544 return SemaRef.Owned(E->Retain());
4545
Douglas Gregora16548e2009-08-11 05:31:07 +00004546 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004547 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004548}
4549
Mike Stump11289f42009-09-09 15:08:12 +00004550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004551ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004552TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004553 CompoundAssignOperator *E) {
4554 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004555}
Mike Stump11289f42009-09-09 15:08:12 +00004556
Douglas Gregora16548e2009-08-11 05:31:07 +00004557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004558ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004559TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004560 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 if (Cond.isInvalid())
4562 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004563
John McCalldadc5752010-08-24 06:29:42 +00004564 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004565 if (LHS.isInvalid())
4566 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004567
John McCalldadc5752010-08-24 06:29:42 +00004568 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004569 if (RHS.isInvalid())
4570 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 if (!getDerived().AlwaysRebuild() &&
4573 Cond.get() == E->getCond() &&
4574 LHS.get() == E->getLHS() &&
4575 RHS.get() == E->getRHS())
4576 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004577
John McCallb268a282010-08-23 23:25:46 +00004578 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004579 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004580 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004581 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004582 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
4585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004587TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004588 // Implicit casts are eliminated during transformation, since they
4589 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004590 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004591}
Mike Stump11289f42009-09-09 15:08:12 +00004592
Douglas Gregora16548e2009-08-11 05:31:07 +00004593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004595TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004596 TypeSourceInfo *OldT;
4597 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004598 {
4599 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004600 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4602 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004603
John McCall97513962010-01-15 18:39:57 +00004604 OldT = E->getTypeInfoAsWritten();
4605 NewT = getDerived().TransformType(OldT);
4606 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 return SemaRef.ExprError();
4608 }
Mike Stump11289f42009-09-09 15:08:12 +00004609
John McCalldadc5752010-08-24 06:29:42 +00004610 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004611 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004612 if (SubExpr.isInvalid())
4613 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004614
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004616 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004617 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004618 return SemaRef.Owned(E->Retain());
4619
John McCall97513962010-01-15 18:39:57 +00004620 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4621 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004623 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004624}
Mike Stump11289f42009-09-09 15:08:12 +00004625
Douglas Gregora16548e2009-08-11 05:31:07 +00004626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004627ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004628TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004629 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4630 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4631 if (!NewT)
4632 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004633
John McCalldadc5752010-08-24 06:29:42 +00004634 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 if (Init.isInvalid())
4636 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004637
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004639 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004640 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004641 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004642
John McCall5d7aa7f2010-01-19 22:33:45 +00004643 // Note: the expression type doesn't necessarily match the
4644 // type-as-written, but that's okay, because it should always be
4645 // derivable from the initializer.
4646
John McCalle15bbff2010-01-18 19:35:47 +00004647 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004649 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004650}
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregora16548e2009-08-11 05:31:07 +00004652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004654TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004655 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004656 if (Base.isInvalid())
4657 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004658
Douglas Gregora16548e2009-08-11 05:31:07 +00004659 if (!getDerived().AlwaysRebuild() &&
4660 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004661 return SemaRef.Owned(E->Retain());
4662
Douglas Gregora16548e2009-08-11 05:31:07 +00004663 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004664 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004666 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 E->getAccessorLoc(),
4668 E->getAccessor());
4669}
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004673TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004674 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004675
John McCall37ad5512010-08-23 06:44:23 +00004676 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004678 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004679 if (Init.isInvalid())
4680 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004681
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004683 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 }
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004687 return SemaRef.Owned(E->Retain());
4688
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004690 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004691}
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregora16548e2009-08-11 05:31:07 +00004693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004694ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004695TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004696 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregorebe10102009-08-20 07:17:43 +00004698 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004699 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 if (Init.isInvalid())
4701 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregorebe10102009-08-20 07:17:43 +00004703 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004704 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004705 bool ExprChanged = false;
4706 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4707 DEnd = E->designators_end();
4708 D != DEnd; ++D) {
4709 if (D->isFieldDesignator()) {
4710 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4711 D->getDotLoc(),
4712 D->getFieldLoc()));
4713 continue;
4714 }
Mike Stump11289f42009-09-09 15:08:12 +00004715
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004717 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 if (Index.isInvalid())
4719 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004720
4721 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004723
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4725 ArrayExprs.push_back(Index.release());
4726 continue;
4727 }
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004730 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4732 if (Start.isInvalid())
4733 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004734
John McCalldadc5752010-08-24 06:29:42 +00004735 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 if (End.isInvalid())
4737 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004738
4739 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004740 End.get(),
4741 D->getLBracketLoc(),
4742 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4745 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 ArrayExprs.push_back(Start.release());
4748 ArrayExprs.push_back(End.release());
4749 }
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 if (!getDerived().AlwaysRebuild() &&
4752 Init.get() == E->getInit() &&
4753 !ExprChanged)
4754 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregora16548e2009-08-11 05:31:07 +00004756 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4757 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004758 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004759}
Mike Stump11289f42009-09-09 15:08:12 +00004760
Douglas Gregora16548e2009-08-11 05:31:07 +00004761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004762ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004763TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004764 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004765 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004766
Douglas Gregor3da3c062009-10-28 00:29:27 +00004767 // FIXME: Will we ever have proper type location here? Will we actually
4768 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 QualType T = getDerived().TransformType(E->getType());
4770 if (T.isNull())
4771 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 if (!getDerived().AlwaysRebuild() &&
4774 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004775 return SemaRef.Owned(E->Retain());
4776
Douglas Gregora16548e2009-08-11 05:31:07 +00004777 return getDerived().RebuildImplicitValueInitExpr(T);
4778}
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004782TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004783 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4784 if (!TInfo)
4785 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004786
John McCalldadc5752010-08-24 06:29:42 +00004787 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 if (SubExpr.isInvalid())
4789 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004790
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004792 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004793 SubExpr.get() == E->getSubExpr())
4794 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004795
John McCallb268a282010-08-23 23:25:46 +00004796 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004797 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004798}
4799
4800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004801ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004802TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004804 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004806 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 if (Init.isInvalid())
4808 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004809
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004811 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 }
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4815 move_arg(Inits),
4816 E->getRParenLoc());
4817}
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregora16548e2009-08-11 05:31:07 +00004819/// \brief Transform an address-of-label expression.
4820///
4821/// By default, the transformation of an address-of-label expression always
4822/// rebuilds the expression, so that the label identifier can be resolved to
4823/// the corresponding label statement by semantic analysis.
4824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004826TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4828 E->getLabel());
4829}
Mike Stump11289f42009-09-09 15:08:12 +00004830
4831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004832ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004833TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004834 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4836 if (SubStmt.isInvalid())
4837 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004838
Douglas Gregora16548e2009-08-11 05:31:07 +00004839 if (!getDerived().AlwaysRebuild() &&
4840 SubStmt.get() == E->getSubStmt())
4841 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004842
4843 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004844 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004845 E->getRParenLoc());
4846}
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregora16548e2009-08-11 05:31:07 +00004848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004849ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004850TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004851 TypeSourceInfo *TInfo1;
4852 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004853
4854 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4855 if (!TInfo1)
4856 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004857
Douglas Gregor7058c262010-08-10 14:27:00 +00004858 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4859 if (!TInfo2)
4860 return SemaRef.ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004861
4862 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004863 TInfo1 == E->getArgTInfo1() &&
4864 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004865 return SemaRef.Owned(E->Retain());
4866
Douglas Gregora16548e2009-08-11 05:31:07 +00004867 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004868 TInfo1, TInfo2,
4869 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004870}
Mike Stump11289f42009-09-09 15:08:12 +00004871
Douglas Gregora16548e2009-08-11 05:31:07 +00004872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004874TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004875 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004876 if (Cond.isInvalid())
4877 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004878
John McCalldadc5752010-08-24 06:29:42 +00004879 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004880 if (LHS.isInvalid())
4881 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004882
John McCalldadc5752010-08-24 06:29:42 +00004883 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004884 if (RHS.isInvalid())
4885 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004886
Douglas Gregora16548e2009-08-11 05:31:07 +00004887 if (!getDerived().AlwaysRebuild() &&
4888 Cond.get() == E->getCond() &&
4889 LHS.get() == E->getLHS() &&
4890 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004891 return SemaRef.Owned(E->Retain());
4892
Douglas Gregora16548e2009-08-11 05:31:07 +00004893 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004894 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 E->getRParenLoc());
4896}
Mike Stump11289f42009-09-09 15:08:12 +00004897
Douglas Gregora16548e2009-08-11 05:31:07 +00004898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004900TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004901 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004902}
4903
4904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004906TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004907 switch (E->getOperator()) {
4908 case OO_New:
4909 case OO_Delete:
4910 case OO_Array_New:
4911 case OO_Array_Delete:
4912 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4913 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004914
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004915 case OO_Call: {
4916 // This is a call to an object's operator().
4917 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4918
4919 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004920 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004921 if (Object.isInvalid())
4922 return SemaRef.ExprError();
4923
4924 // FIXME: Poor location information
4925 SourceLocation FakeLParenLoc
4926 = SemaRef.PP.getLocForEndOfToken(
4927 static_cast<Expr *>(Object.get())->getLocEnd());
4928
4929 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004930 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004931 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4932 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004933 if (getDerived().DropCallArgument(E->getArg(I)))
4934 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004935
John McCalldadc5752010-08-24 06:29:42 +00004936 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004937 if (Arg.isInvalid())
4938 return SemaRef.ExprError();
4939
4940 // FIXME: Poor source location information.
4941 SourceLocation FakeCommaLoc
4942 = SemaRef.PP.getLocForEndOfToken(
4943 static_cast<Expr *>(Arg.get())->getLocEnd());
4944 FakeCommaLocs.push_back(FakeCommaLoc);
4945 Args.push_back(Arg.release());
4946 }
4947
John McCallb268a282010-08-23 23:25:46 +00004948 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004949 move_arg(Args),
4950 FakeCommaLocs.data(),
4951 E->getLocEnd());
4952 }
4953
4954#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4955 case OO_##Name:
4956#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4957#include "clang/Basic/OperatorKinds.def"
4958 case OO_Subscript:
4959 // Handled below.
4960 break;
4961
4962 case OO_Conditional:
4963 llvm_unreachable("conditional operator is not actually overloadable");
4964 return SemaRef.ExprError();
4965
4966 case OO_None:
4967 case NUM_OVERLOADED_OPERATORS:
4968 llvm_unreachable("not an overloaded operator?");
4969 return SemaRef.ExprError();
4970 }
4971
John McCalldadc5752010-08-24 06:29:42 +00004972 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004973 if (Callee.isInvalid())
4974 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004975
John McCalldadc5752010-08-24 06:29:42 +00004976 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004977 if (First.isInvalid())
4978 return SemaRef.ExprError();
4979
John McCalldadc5752010-08-24 06:29:42 +00004980 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00004981 if (E->getNumArgs() == 2) {
4982 Second = getDerived().TransformExpr(E->getArg(1));
4983 if (Second.isInvalid())
4984 return SemaRef.ExprError();
4985 }
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregora16548e2009-08-11 05:31:07 +00004987 if (!getDerived().AlwaysRebuild() &&
4988 Callee.get() == E->getCallee() &&
4989 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004990 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4991 return SemaRef.Owned(E->Retain());
4992
Douglas Gregora16548e2009-08-11 05:31:07 +00004993 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4994 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00004995 Callee.get(),
4996 First.get(),
4997 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004998}
Mike Stump11289f42009-09-09 15:08:12 +00004999
Douglas Gregora16548e2009-08-11 05:31:07 +00005000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005002TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5003 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005004}
Mike Stump11289f42009-09-09 15:08:12 +00005005
Douglas Gregora16548e2009-08-11 05:31:07 +00005006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005007ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005008TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005009 TypeSourceInfo *OldT;
5010 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 {
5012 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005013 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005014 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5015 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005016
John McCall97513962010-01-15 18:39:57 +00005017 OldT = E->getTypeInfoAsWritten();
5018 NewT = getDerived().TransformType(OldT);
5019 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 return SemaRef.ExprError();
5021 }
Mike Stump11289f42009-09-09 15:08:12 +00005022
John McCalldadc5752010-08-24 06:29:42 +00005023 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005024 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005025 if (SubExpr.isInvalid())
5026 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005027
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005029 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005030 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005031 return SemaRef.Owned(E->Retain());
5032
Douglas Gregora16548e2009-08-11 05:31:07 +00005033 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005034 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005035 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5036 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5037 SourceLocation FakeRParenLoc
5038 = SemaRef.PP.getLocForEndOfToken(
5039 E->getSubExpr()->getSourceRange().getEnd());
5040 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005041 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005043 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 FakeRAngleLoc,
5045 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005046 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005047 FakeRParenLoc);
5048}
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>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5053 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005054}
Mike Stump11289f42009-09-09 15:08:12 +00005055
5056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005058TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5059 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005060}
5061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005063ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005064TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005065 CXXReinterpretCastExpr *E) {
5066 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005067}
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregora16548e2009-08-11 05:31:07 +00005069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005070ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005071TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5072 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005073}
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregora16548e2009-08-11 05:31:07 +00005075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005076ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005077TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005078 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005079 TypeSourceInfo *OldT;
5080 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005081 {
5082 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005083
John McCall97513962010-01-15 18:39:57 +00005084 OldT = E->getTypeInfoAsWritten();
5085 NewT = getDerived().TransformType(OldT);
5086 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005087 return SemaRef.ExprError();
5088 }
Mike Stump11289f42009-09-09 15:08:12 +00005089
John McCalldadc5752010-08-24 06:29:42 +00005090 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005091 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005092 if (SubExpr.isInvalid())
5093 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005094
Douglas Gregora16548e2009-08-11 05:31:07 +00005095 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005096 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005097 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005098 return SemaRef.Owned(E->Retain());
5099
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 // FIXME: The end of the type's source range is wrong
5101 return getDerived().RebuildCXXFunctionalCastExpr(
5102 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005103 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005105 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 E->getRParenLoc());
5107}
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
John McCall47f29ea2009-12-08 09:21:05 +00005111TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005113 TypeSourceInfo *TInfo
5114 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5115 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005119 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005120 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregor9da64192010-04-26 22:37:10 +00005122 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5123 E->getLocStart(),
5124 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 E->getLocEnd());
5126 }
Mike Stump11289f42009-09-09 15:08:12 +00005127
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 // We don't know whether the expression is potentially evaluated until
5129 // after we perform semantic analysis, so the expression is potentially
5130 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005131 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005132 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005133
John McCalldadc5752010-08-24 06:29:42 +00005134 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 if (SubExpr.isInvalid())
5136 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005137
Douglas Gregora16548e2009-08-11 05:31:07 +00005138 if (!getDerived().AlwaysRebuild() &&
5139 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005140 return SemaRef.Owned(E->Retain());
5141
Douglas Gregor9da64192010-04-26 22:37:10 +00005142 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5143 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005144 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 E->getLocEnd());
5146}
5147
5148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005150TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005151 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005152}
Mike Stump11289f42009-09-09 15:08:12 +00005153
Douglas Gregora16548e2009-08-11 05:31:07 +00005154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005155ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005156TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005157 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005158 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005159}
Mike Stump11289f42009-09-09 15:08:12 +00005160
Douglas Gregora16548e2009-08-11 05:31:07 +00005161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005163TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005165
Douglas Gregora16548e2009-08-11 05:31:07 +00005166 QualType T = getDerived().TransformType(E->getType());
5167 if (T.isNull())
5168 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 if (!getDerived().AlwaysRebuild() &&
5171 T == E->getType())
5172 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005173
Douglas Gregorb15af892010-01-07 23:12:05 +00005174 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005175}
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregora16548e2009-08-11 05:31:07 +00005177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005178ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005179TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005180 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 if (SubExpr.isInvalid())
5182 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005183
Douglas Gregora16548e2009-08-11 05:31:07 +00005184 if (!getDerived().AlwaysRebuild() &&
5185 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005186 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005187
John McCallb268a282010-08-23 23:25:46 +00005188 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005189}
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregora16548e2009-08-11 05:31:07 +00005191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005192ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005193TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005194 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005195 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5196 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005197 if (!Param)
5198 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005199
Chandler Carruth794da4c2010-02-08 06:42:49 +00005200 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005201 Param == E->getParam())
5202 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005203
Douglas Gregor033f6752009-12-23 23:03:06 +00005204 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005205}
Mike Stump11289f42009-09-09 15:08:12 +00005206
Douglas Gregora16548e2009-08-11 05:31:07 +00005207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005208ExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005209TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005210 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5211
5212 QualType T = getDerived().TransformType(E->getType());
5213 if (T.isNull())
5214 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005215
Douglas Gregora16548e2009-08-11 05:31:07 +00005216 if (!getDerived().AlwaysRebuild() &&
5217 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005218 return SemaRef.Owned(E->Retain());
5219
Douglas Gregor747eb782010-07-08 06:14:04 +00005220 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5221 /*FIXME:*/E->getTypeBeginLoc(),
5222 T,
5223 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005224}
Mike Stump11289f42009-09-09 15:08:12 +00005225
Douglas Gregora16548e2009-08-11 05:31:07 +00005226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005228TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005229 // Transform the type that we're allocating
5230 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5231 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5232 if (AllocType.isNull())
5233 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005234
Douglas Gregora16548e2009-08-11 05:31:07 +00005235 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005236 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005237 if (ArraySize.isInvalid())
5238 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005239
Douglas Gregora16548e2009-08-11 05:31:07 +00005240 // Transform the placement arguments (if any).
5241 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005242 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005244 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005245 if (Arg.isInvalid())
5246 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005247
Douglas Gregora16548e2009-08-11 05:31:07 +00005248 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5249 PlacementArgs.push_back(Arg.take());
5250 }
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregorebe10102009-08-20 07:17:43 +00005252 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005253 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005254 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005255 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5256 break;
5257
John McCalldadc5752010-08-24 06:29:42 +00005258 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 if (Arg.isInvalid())
5260 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005261
Douglas Gregora16548e2009-08-11 05:31:07 +00005262 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5263 ConstructorArgs.push_back(Arg.take());
5264 }
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregord2d9da02010-02-26 00:38:10 +00005266 // Transform constructor, new operator, and delete operator.
5267 CXXConstructorDecl *Constructor = 0;
5268 if (E->getConstructor()) {
5269 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005270 getDerived().TransformDecl(E->getLocStart(),
5271 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005272 if (!Constructor)
5273 return SemaRef.ExprError();
5274 }
5275
5276 FunctionDecl *OperatorNew = 0;
5277 if (E->getOperatorNew()) {
5278 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005279 getDerived().TransformDecl(E->getLocStart(),
5280 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005281 if (!OperatorNew)
5282 return SemaRef.ExprError();
5283 }
5284
5285 FunctionDecl *OperatorDelete = 0;
5286 if (E->getOperatorDelete()) {
5287 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005288 getDerived().TransformDecl(E->getLocStart(),
5289 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005290 if (!OperatorDelete)
5291 return SemaRef.ExprError();
5292 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005293
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 if (!getDerived().AlwaysRebuild() &&
5295 AllocType == E->getAllocatedType() &&
5296 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005297 Constructor == E->getConstructor() &&
5298 OperatorNew == E->getOperatorNew() &&
5299 OperatorDelete == E->getOperatorDelete() &&
5300 !ArgumentChanged) {
5301 // Mark any declarations we need as referenced.
5302 // FIXME: instantiation-specific.
5303 if (Constructor)
5304 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5305 if (OperatorNew)
5306 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5307 if (OperatorDelete)
5308 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005309 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005310 }
Mike Stump11289f42009-09-09 15:08:12 +00005311
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005312 if (!ArraySize.get()) {
5313 // If no array size was specified, but the new expression was
5314 // instantiated with an array type (e.g., "new T" where T is
5315 // instantiated with "int[4]"), extract the outer bound from the
5316 // array type as our array size. We do this with constant and
5317 // dependently-sized array types.
5318 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5319 if (!ArrayT) {
5320 // Do nothing
5321 } else if (const ConstantArrayType *ConsArrayT
5322 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005324 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005325 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005326 SemaRef.Context.getSizeType(),
5327 /*FIXME:*/E->getLocStart()));
5328 AllocType = ConsArrayT->getElementType();
5329 } else if (const DependentSizedArrayType *DepArrayT
5330 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5331 if (DepArrayT->getSizeExpr()) {
5332 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5333 AllocType = DepArrayT->getElementType();
5334 }
5335 }
5336 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005337 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5338 E->isGlobalNew(),
5339 /*FIXME:*/E->getLocStart(),
5340 move_arg(PlacementArgs),
5341 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005342 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005343 AllocType,
5344 /*FIXME:*/E->getLocStart(),
5345 /*FIXME:*/SourceRange(),
John McCallb268a282010-08-23 23:25:46 +00005346 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005347 /*FIXME:*/E->getLocStart(),
5348 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005349 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005350}
Mike Stump11289f42009-09-09 15:08:12 +00005351
Douglas Gregora16548e2009-08-11 05:31:07 +00005352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005354TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005355 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005356 if (Operand.isInvalid())
5357 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregord2d9da02010-02-26 00:38:10 +00005359 // Transform the delete operator, if known.
5360 FunctionDecl *OperatorDelete = 0;
5361 if (E->getOperatorDelete()) {
5362 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005363 getDerived().TransformDecl(E->getLocStart(),
5364 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005365 if (!OperatorDelete)
5366 return SemaRef.ExprError();
5367 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005368
Douglas Gregora16548e2009-08-11 05:31:07 +00005369 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005370 Operand.get() == E->getArgument() &&
5371 OperatorDelete == E->getOperatorDelete()) {
5372 // Mark any declarations we need as referenced.
5373 // FIXME: instantiation-specific.
5374 if (OperatorDelete)
5375 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005376 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005377 }
Mike Stump11289f42009-09-09 15:08:12 +00005378
Douglas Gregora16548e2009-08-11 05:31:07 +00005379 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5380 E->isGlobalDelete(),
5381 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005382 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005383}
Mike Stump11289f42009-09-09 15:08:12 +00005384
Douglas Gregora16548e2009-08-11 05:31:07 +00005385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005386ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005387TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005388 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005389 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005390 if (Base.isInvalid())
5391 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005392
John McCallba7bf592010-08-24 05:47:05 +00005393 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005394 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005395 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005396 E->getOperatorLoc(),
5397 E->isArrow()? tok::arrow : tok::period,
5398 ObjectTypePtr,
5399 MayBePseudoDestructor);
5400 if (Base.isInvalid())
5401 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005402
John McCallba7bf592010-08-24 05:47:05 +00005403 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005404 NestedNameSpecifier *Qualifier
5405 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005406 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005407 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005408 if (E->getQualifier() && !Qualifier)
5409 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregor678f90d2010-02-25 01:56:36 +00005411 PseudoDestructorTypeStorage Destroyed;
5412 if (E->getDestroyedTypeInfo()) {
5413 TypeSourceInfo *DestroyedTypeInfo
5414 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5415 if (!DestroyedTypeInfo)
5416 return SemaRef.ExprError();
5417 Destroyed = DestroyedTypeInfo;
5418 } else if (ObjectType->isDependentType()) {
5419 // We aren't likely to be able to resolve the identifier down to a type
5420 // now anyway, so just retain the identifier.
5421 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5422 E->getDestroyedTypeLoc());
5423 } else {
5424 // Look for a destructor known with the given name.
5425 CXXScopeSpec SS;
5426 if (Qualifier) {
5427 SS.setScopeRep(Qualifier);
5428 SS.setRange(E->getQualifierRange());
5429 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005430
John McCallba7bf592010-08-24 05:47:05 +00005431 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005432 *E->getDestroyedTypeIdentifier(),
5433 E->getDestroyedTypeLoc(),
5434 /*Scope=*/0,
5435 SS, ObjectTypePtr,
5436 false);
5437 if (!T)
5438 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005439
Douglas Gregor678f90d2010-02-25 01:56:36 +00005440 Destroyed
5441 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5442 E->getDestroyedTypeLoc());
5443 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005444
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005445 TypeSourceInfo *ScopeTypeInfo = 0;
5446 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005447 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005448 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005449 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005450 return SemaRef.ExprError();
5451 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005452
John McCallb268a282010-08-23 23:25:46 +00005453 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005454 E->getOperatorLoc(),
5455 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005456 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005457 E->getQualifierRange(),
5458 ScopeTypeInfo,
5459 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005460 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005461 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005462}
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregorad8a3362009-09-04 17:36:40 +00005464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005465ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005466TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005467 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005468 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5469
5470 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5471 Sema::LookupOrdinaryName);
5472
5473 // Transform all the decls.
5474 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5475 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005476 NamedDecl *InstD = static_cast<NamedDecl*>(
5477 getDerived().TransformDecl(Old->getNameLoc(),
5478 *I));
John McCall84d87672009-12-10 09:41:52 +00005479 if (!InstD) {
5480 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5481 // This can happen because of dependent hiding.
5482 if (isa<UsingShadowDecl>(*I))
5483 continue;
5484 else
5485 return SemaRef.ExprError();
5486 }
John McCalle66edc12009-11-24 19:00:30 +00005487
5488 // Expand using declarations.
5489 if (isa<UsingDecl>(InstD)) {
5490 UsingDecl *UD = cast<UsingDecl>(InstD);
5491 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5492 E = UD->shadow_end(); I != E; ++I)
5493 R.addDecl(*I);
5494 continue;
5495 }
5496
5497 R.addDecl(InstD);
5498 }
5499
5500 // Resolve a kind, but don't do any further analysis. If it's
5501 // ambiguous, the callee needs to deal with it.
5502 R.resolveKind();
5503
5504 // Rebuild the nested-name qualifier, if present.
5505 CXXScopeSpec SS;
5506 NestedNameSpecifier *Qualifier = 0;
5507 if (Old->getQualifier()) {
5508 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005509 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005510 if (!Qualifier)
5511 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005512
John McCalle66edc12009-11-24 19:00:30 +00005513 SS.setScopeRep(Qualifier);
5514 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005515 }
5516
Douglas Gregor9262f472010-04-27 18:19:34 +00005517 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005518 CXXRecordDecl *NamingClass
5519 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5520 Old->getNameLoc(),
5521 Old->getNamingClass()));
5522 if (!NamingClass)
5523 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005524
Douglas Gregorda7be082010-04-27 16:10:10 +00005525 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005526 }
5527
5528 // If we have no template arguments, it's a normal declaration name.
5529 if (!Old->hasExplicitTemplateArgs())
5530 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5531
5532 // If we have template arguments, rebuild them, then rebuild the
5533 // templateid expression.
5534 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5535 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5536 TemplateArgumentLoc Loc;
5537 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5538 return SemaRef.ExprError();
5539 TransArgs.addArgument(Loc);
5540 }
5541
5542 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5543 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005544}
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregora16548e2009-08-11 05:31:07 +00005546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005548TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005549 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005550
Douglas Gregora16548e2009-08-11 05:31:07 +00005551 QualType T = getDerived().TransformType(E->getQueriedType());
5552 if (T.isNull())
5553 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005554
Douglas Gregora16548e2009-08-11 05:31:07 +00005555 if (!getDerived().AlwaysRebuild() &&
5556 T == E->getQueriedType())
5557 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005558
Douglas Gregora16548e2009-08-11 05:31:07 +00005559 // FIXME: Bad location information
5560 SourceLocation FakeLParenLoc
5561 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005562
5563 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 E->getLocStart(),
5565 /*FIXME:*/FakeLParenLoc,
5566 T,
5567 E->getLocEnd());
5568}
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregora16548e2009-08-11 05:31:07 +00005570template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005571ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005572TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005573 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005574 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005575 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005576 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 if (!NNS)
5578 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005579
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005580 DeclarationNameInfo NameInfo
5581 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5582 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005583 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005584
John McCalle66edc12009-11-24 19:00:30 +00005585 if (!E->hasExplicitTemplateArgs()) {
5586 if (!getDerived().AlwaysRebuild() &&
5587 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005588 // Note: it is sufficient to compare the Name component of NameInfo:
5589 // if name has not changed, DNLoc has not changed either.
5590 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005591 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005592
John McCalle66edc12009-11-24 19:00:30 +00005593 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5594 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005595 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005596 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005597 }
John McCall6b51f282009-11-23 01:53:49 +00005598
5599 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005601 TemplateArgumentLoc Loc;
5602 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005604 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 }
5606
John McCalle66edc12009-11-24 19:00:30 +00005607 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5608 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005609 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005610 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005611}
5612
5613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005614ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005615TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005616 // CXXConstructExprs are always implicit, so when we have a
5617 // 1-argument construction we just transform that argument.
5618 if (E->getNumArgs() == 1 ||
5619 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5620 return getDerived().TransformExpr(E->getArg(0));
5621
Douglas Gregora16548e2009-08-11 05:31:07 +00005622 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5623
5624 QualType T = getDerived().TransformType(E->getType());
5625 if (T.isNull())
5626 return SemaRef.ExprError();
5627
5628 CXXConstructorDecl *Constructor
5629 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005630 getDerived().TransformDecl(E->getLocStart(),
5631 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 if (!Constructor)
5633 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005636 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005637 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 ArgEnd = E->arg_end();
5639 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005640 if (getDerived().DropCallArgument(*Arg)) {
5641 ArgumentChanged = true;
5642 break;
5643 }
5644
John McCalldadc5752010-08-24 06:29:42 +00005645 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 if (TransArg.isInvalid())
5647 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005650 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005651 }
5652
5653 if (!getDerived().AlwaysRebuild() &&
5654 T == E->getType() &&
5655 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005656 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005657 // Mark the constructor as referenced.
5658 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005659 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005661 }
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregordb121ba2009-12-14 16:27:04 +00005663 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5664 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005665 move_arg(Args),
5666 E->requiresZeroInitialization(),
5667 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005668}
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregora16548e2009-08-11 05:31:07 +00005670/// \brief Transform a C++ temporary-binding expression.
5671///
Douglas Gregor363b1512009-12-24 18:51:59 +00005672/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5673/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005676TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005677 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005678}
Mike Stump11289f42009-09-09 15:08:12 +00005679
Anders Carlssonba6c4372010-01-29 02:39:32 +00005680/// \brief Transform a C++ reference-binding expression.
5681///
5682/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5683/// transform the subexpression and return that.
5684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005685ExprResult
Anders Carlssonba6c4372010-01-29 02:39:32 +00005686TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5687 return getDerived().TransformExpr(E->getSubExpr());
5688}
5689
Mike Stump11289f42009-09-09 15:08:12 +00005690/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005691/// be destroyed after the expression is evaluated.
5692///
Douglas Gregor363b1512009-12-24 18:51:59 +00005693/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5694/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005696ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005697TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005698 CXXExprWithTemporaries *E) {
5699 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005700}
Mike Stump11289f42009-09-09 15:08:12 +00005701
Douglas Gregora16548e2009-08-11 05:31:07 +00005702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005703ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005704TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005705 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5707 QualType T = getDerived().TransformType(E->getType());
5708 if (T.isNull())
5709 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005710
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 CXXConstructorDecl *Constructor
5712 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005713 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005714 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005715 if (!Constructor)
5716 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005717
Douglas Gregora16548e2009-08-11 05:31:07 +00005718 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005719 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005720 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005721 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005722 ArgEnd = E->arg_end();
5723 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005724 if (getDerived().DropCallArgument(*Arg)) {
5725 ArgumentChanged = true;
5726 break;
5727 }
5728
John McCalldadc5752010-08-24 06:29:42 +00005729 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (TransArg.isInvalid())
5731 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5734 Args.push_back((Expr *)TransArg.release());
5735 }
Mike Stump11289f42009-09-09 15:08:12 +00005736
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 if (!getDerived().AlwaysRebuild() &&
5738 T == E->getType() &&
5739 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005740 !ArgumentChanged) {
5741 // FIXME: Instantiation-specific
5742 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005743 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005744 }
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregora16548e2009-08-11 05:31:07 +00005746 // FIXME: Bogus location information
5747 SourceLocation CommaLoc;
5748 if (Args.size() > 1) {
5749 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005750 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5752 }
5753 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5754 T,
5755 /*FIXME:*/E->getTypeBeginLoc(),
5756 move_arg(Args),
5757 &CommaLoc,
5758 E->getLocEnd());
5759}
Mike Stump11289f42009-09-09 15:08:12 +00005760
Douglas Gregora16548e2009-08-11 05:31:07 +00005761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005762ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005763TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005764 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005765 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5766 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5767 if (T.isNull())
5768 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005769
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005771 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005772 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5773 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5774 ArgEnd = E->arg_end();
5775 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005776 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 if (TransArg.isInvalid())
5778 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005779
Douglas Gregora16548e2009-08-11 05:31:07 +00005780 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5781 FakeCommaLocs.push_back(
5782 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
John McCallb268a282010-08-23 23:25:46 +00005783 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005784 }
Mike Stump11289f42009-09-09 15:08:12 +00005785
Douglas Gregora16548e2009-08-11 05:31:07 +00005786 if (!getDerived().AlwaysRebuild() &&
5787 T == E->getTypeAsWritten() &&
5788 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005789 return SemaRef.Owned(E->Retain());
5790
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 // FIXME: we're faking the locations of the commas
5792 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5793 T,
5794 E->getLParenLoc(),
5795 move_arg(Args),
5796 FakeCommaLocs.data(),
5797 E->getRParenLoc());
5798}
Mike Stump11289f42009-09-09 15:08:12 +00005799
Douglas Gregora16548e2009-08-11 05:31:07 +00005800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005801ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005802TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005803 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005804 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005805 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005806 Expr *OldBase;
5807 QualType BaseType;
5808 QualType ObjectType;
5809 if (!E->isImplicitAccess()) {
5810 OldBase = E->getBase();
5811 Base = getDerived().TransformExpr(OldBase);
5812 if (Base.isInvalid())
5813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005814
John McCall2d74de92009-12-01 22:10:20 +00005815 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005816 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005817 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005818 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005819 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005820 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005821 ObjectTy,
5822 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005823 if (Base.isInvalid())
5824 return SemaRef.ExprError();
5825
John McCallba7bf592010-08-24 05:47:05 +00005826 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005827 BaseType = ((Expr*) Base.get())->getType();
5828 } else {
5829 OldBase = 0;
5830 BaseType = getDerived().TransformType(E->getBaseType());
5831 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5832 }
Mike Stump11289f42009-09-09 15:08:12 +00005833
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005834 // Transform the first part of the nested-name-specifier that qualifies
5835 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005836 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005837 = getDerived().TransformFirstQualifierInScope(
5838 E->getFirstQualifierFoundInScope(),
5839 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005840
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005841 NestedNameSpecifier *Qualifier = 0;
5842 if (E->getQualifier()) {
5843 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5844 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005845 ObjectType,
5846 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005847 if (!Qualifier)
5848 return SemaRef.ExprError();
5849 }
Mike Stump11289f42009-09-09 15:08:12 +00005850
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005851 DeclarationNameInfo NameInfo
5852 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5853 ObjectType);
5854 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005855 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005856
John McCall2d74de92009-12-01 22:10:20 +00005857 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005858 // This is a reference to a member without an explicitly-specified
5859 // template argument list. Optimize for this common case.
5860 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005861 Base.get() == OldBase &&
5862 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005863 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005864 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005865 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005866 return SemaRef.Owned(E->Retain());
5867
John McCallb268a282010-08-23 23:25:46 +00005868 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005869 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005870 E->isArrow(),
5871 E->getOperatorLoc(),
5872 Qualifier,
5873 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005874 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005875 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005876 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005877 }
5878
John McCall6b51f282009-11-23 01:53:49 +00005879 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005880 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005881 TemplateArgumentLoc Loc;
5882 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005883 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005884 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005885 }
Mike Stump11289f42009-09-09 15:08:12 +00005886
John McCallb268a282010-08-23 23:25:46 +00005887 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005888 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 E->isArrow(),
5890 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005891 Qualifier,
5892 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005893 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005894 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005895 &TransArgs);
5896}
5897
5898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005900TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005901 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005902 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005903 QualType BaseType;
5904 if (!Old->isImplicitAccess()) {
5905 Base = getDerived().TransformExpr(Old->getBase());
5906 if (Base.isInvalid())
5907 return SemaRef.ExprError();
5908 BaseType = ((Expr*) Base.get())->getType();
5909 } else {
5910 BaseType = getDerived().TransformType(Old->getBaseType());
5911 }
John McCall10eae182009-11-30 22:42:35 +00005912
5913 NestedNameSpecifier *Qualifier = 0;
5914 if (Old->getQualifier()) {
5915 Qualifier
5916 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005917 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005918 if (Qualifier == 0)
5919 return SemaRef.ExprError();
5920 }
5921
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005922 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005923 Sema::LookupOrdinaryName);
5924
5925 // Transform all the decls.
5926 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5927 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005928 NamedDecl *InstD = static_cast<NamedDecl*>(
5929 getDerived().TransformDecl(Old->getMemberLoc(),
5930 *I));
John McCall84d87672009-12-10 09:41:52 +00005931 if (!InstD) {
5932 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5933 // This can happen because of dependent hiding.
5934 if (isa<UsingShadowDecl>(*I))
5935 continue;
5936 else
5937 return SemaRef.ExprError();
5938 }
John McCall10eae182009-11-30 22:42:35 +00005939
5940 // Expand using declarations.
5941 if (isa<UsingDecl>(InstD)) {
5942 UsingDecl *UD = cast<UsingDecl>(InstD);
5943 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5944 E = UD->shadow_end(); I != E; ++I)
5945 R.addDecl(*I);
5946 continue;
5947 }
5948
5949 R.addDecl(InstD);
5950 }
5951
5952 R.resolveKind();
5953
Douglas Gregor9262f472010-04-27 18:19:34 +00005954 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005955 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005956 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005957 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005958 Old->getMemberLoc(),
5959 Old->getNamingClass()));
5960 if (!NamingClass)
5961 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005962
Douglas Gregorda7be082010-04-27 16:10:10 +00005963 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005964 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005965
John McCall10eae182009-11-30 22:42:35 +00005966 TemplateArgumentListInfo TransArgs;
5967 if (Old->hasExplicitTemplateArgs()) {
5968 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5969 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5970 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5971 TemplateArgumentLoc Loc;
5972 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5973 Loc))
5974 return SemaRef.ExprError();
5975 TransArgs.addArgument(Loc);
5976 }
5977 }
John McCall38836f02010-01-15 08:34:02 +00005978
5979 // FIXME: to do this check properly, we will need to preserve the
5980 // first-qualifier-in-scope here, just in case we had a dependent
5981 // base (and therefore couldn't do the check) and a
5982 // nested-name-qualifier (and therefore could do the lookup).
5983 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005984
John McCallb268a282010-08-23 23:25:46 +00005985 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005986 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005987 Old->getOperatorLoc(),
5988 Old->isArrow(),
5989 Qualifier,
5990 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005991 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005992 R,
5993 (Old->hasExplicitTemplateArgs()
5994 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005995}
5996
5997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005998ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005999TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006000 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006001}
6002
Mike Stump11289f42009-09-09 15:08:12 +00006003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006004ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006005TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006006 TypeSourceInfo *EncodedTypeInfo
6007 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6008 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006009 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregora16548e2009-08-11 05:31:07 +00006011 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006012 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006013 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014
6015 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006016 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 E->getRParenLoc());
6018}
Mike Stump11289f42009-09-09 15:08:12 +00006019
Douglas Gregora16548e2009-08-11 05:31:07 +00006020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006021ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006022TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006023 // Transform arguments.
6024 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006025 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006026 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006027 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006028 if (Arg.isInvalid())
6029 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006030
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006031 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006032 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006033 }
6034
6035 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6036 // Class message: transform the receiver type.
6037 TypeSourceInfo *ReceiverTypeInfo
6038 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6039 if (!ReceiverTypeInfo)
6040 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006041
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006042 // If nothing changed, just retain the existing message send.
6043 if (!getDerived().AlwaysRebuild() &&
6044 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6045 return SemaRef.Owned(E->Retain());
6046
6047 // Build a new class message send.
6048 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6049 E->getSelector(),
6050 E->getMethodDecl(),
6051 E->getLeftLoc(),
6052 move_arg(Args),
6053 E->getRightLoc());
6054 }
6055
6056 // Instance message: transform the receiver
6057 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6058 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006059 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006060 = getDerived().TransformExpr(E->getInstanceReceiver());
6061 if (Receiver.isInvalid())
6062 return SemaRef.ExprError();
6063
6064 // If nothing changed, just retain the existing message send.
6065 if (!getDerived().AlwaysRebuild() &&
6066 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6067 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006068
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006069 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006070 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006071 E->getSelector(),
6072 E->getMethodDecl(),
6073 E->getLeftLoc(),
6074 move_arg(Args),
6075 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006076}
6077
Mike Stump11289f42009-09-09 15:08:12 +00006078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006079ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006080TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006081 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006082}
6083
Mike Stump11289f42009-09-09 15:08:12 +00006084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006085ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006086TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006087 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006088}
6089
Mike Stump11289f42009-09-09 15:08:12 +00006090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006091ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006092TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006093 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006094 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006095 if (Base.isInvalid())
6096 return SemaRef.ExprError();
6097
6098 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006099
Douglas Gregord51d90d2010-04-26 20:11:03 +00006100 // If nothing changed, just retain the existing expression.
6101 if (!getDerived().AlwaysRebuild() &&
6102 Base.get() == E->getBase())
6103 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006104
John McCallb268a282010-08-23 23:25:46 +00006105 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006106 E->getLocation(),
6107 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006108}
6109
Mike Stump11289f42009-09-09 15:08:12 +00006110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006112TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006113 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006114 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006115 if (Base.isInvalid())
6116 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006117
Douglas Gregor9faee212010-04-26 20:47:02 +00006118 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006119
Douglas Gregor9faee212010-04-26 20:47:02 +00006120 // If nothing changed, just retain the existing expression.
6121 if (!getDerived().AlwaysRebuild() &&
6122 Base.get() == E->getBase())
6123 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006124
John McCallb268a282010-08-23 23:25:46 +00006125 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006126 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006127}
6128
Mike Stump11289f42009-09-09 15:08:12 +00006129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006130ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006131TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006132 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006133 // If this implicit setter/getter refers to class methods, it cannot have any
6134 // dependent parts. Just retain the existing declaration.
6135 if (E->getInterfaceDecl())
6136 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006137
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006138 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006139 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006140 if (Base.isInvalid())
6141 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006142
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006143 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006144
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006145 // If nothing changed, just retain the existing expression.
6146 if (!getDerived().AlwaysRebuild() &&
6147 Base.get() == E->getBase())
6148 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006149
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006150 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6151 E->getGetterMethod(),
6152 E->getType(),
6153 E->getSetterMethod(),
6154 E->getLocation(),
John McCallb268a282010-08-23 23:25:46 +00006155 Base.get());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006156
Douglas Gregora16548e2009-08-11 05:31:07 +00006157}
6158
Mike Stump11289f42009-09-09 15:08:12 +00006159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006161TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006162 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006163 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006164}
6165
Mike Stump11289f42009-09-09 15:08:12 +00006166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006168TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006169 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006170 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006171 if (Base.isInvalid())
6172 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006173
Douglas Gregord51d90d2010-04-26 20:11:03 +00006174 // If nothing changed, just retain the existing expression.
6175 if (!getDerived().AlwaysRebuild() &&
6176 Base.get() == E->getBase())
6177 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006178
John McCallb268a282010-08-23 23:25:46 +00006179 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006180 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006181}
6182
Mike Stump11289f42009-09-09 15:08:12 +00006183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006184ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006185TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006186 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006187 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006188 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006189 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006190 if (SubExpr.isInvalid())
6191 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006192
Douglas Gregora16548e2009-08-11 05:31:07 +00006193 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006194 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006195 }
Mike Stump11289f42009-09-09 15:08:12 +00006196
Douglas Gregora16548e2009-08-11 05:31:07 +00006197 if (!getDerived().AlwaysRebuild() &&
6198 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006199 return SemaRef.Owned(E->Retain());
6200
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6202 move_arg(SubExprs),
6203 E->getRParenLoc());
6204}
6205
Mike Stump11289f42009-09-09 15:08:12 +00006206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006207ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006208TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006209 SourceLocation CaretLoc(E->getExprLoc());
6210
6211 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6212 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6213 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6214 llvm::SmallVector<ParmVarDecl*, 4> Params;
6215 llvm::SmallVector<QualType, 4> ParamTypes;
6216
6217 // Parameter substitution.
6218 const BlockDecl *BD = E->getBlockDecl();
6219 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6220 EN = BD->param_end(); P != EN; ++P) {
6221 ParmVarDecl *OldParm = (*P);
6222 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6223 QualType NewType = NewParm->getType();
6224 Params.push_back(NewParm);
6225 ParamTypes.push_back(NewParm->getType());
6226 }
6227
6228 const FunctionType *BExprFunctionType = E->getFunctionType();
6229 QualType BExprResultType = BExprFunctionType->getResultType();
6230 if (!BExprResultType.isNull()) {
6231 if (!BExprResultType->isDependentType())
6232 CurBlock->ReturnType = BExprResultType;
6233 else if (BExprResultType != SemaRef.Context.DependentTy)
6234 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6235 }
6236
6237 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006238 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006239 if (Body.isInvalid())
6240 return SemaRef.ExprError();
6241 // Set the parameters on the block decl.
6242 if (!Params.empty())
6243 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6244
6245 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6246 CurBlock->ReturnType,
6247 ParamTypes.data(),
6248 ParamTypes.size(),
6249 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006250 0,
6251 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006252
6253 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006254 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006255}
6256
Mike Stump11289f42009-09-09 15:08:12 +00006257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006259TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006260 NestedNameSpecifier *Qualifier = 0;
6261
6262 ValueDecl *ND
6263 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6264 E->getDecl()));
6265 if (!ND)
6266 return SemaRef.ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006267
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006268 if (!getDerived().AlwaysRebuild() &&
6269 ND == E->getDecl()) {
6270 // Mark it referenced in the new context regardless.
6271 // FIXME: this is a bit instantiation-specific.
6272 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6273
6274 return SemaRef.Owned(E->Retain());
6275 }
6276
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006277 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006278 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006279 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006280}
Mike Stump11289f42009-09-09 15:08:12 +00006281
Douglas Gregora16548e2009-08-11 05:31:07 +00006282//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006283// Type reconstruction
6284//===----------------------------------------------------------------------===//
6285
Mike Stump11289f42009-09-09 15:08:12 +00006286template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006287QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6288 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006289 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006290 getDerived().getBaseEntity());
6291}
6292
Mike Stump11289f42009-09-09 15:08:12 +00006293template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006294QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6295 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006296 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006297 getDerived().getBaseEntity());
6298}
6299
Mike Stump11289f42009-09-09 15:08:12 +00006300template<typename Derived>
6301QualType
John McCall70dd5f62009-10-30 00:06:24 +00006302TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6303 bool WrittenAsLValue,
6304 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006305 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006306 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006307}
6308
6309template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006310QualType
John McCall70dd5f62009-10-30 00:06:24 +00006311TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6312 QualType ClassType,
6313 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006314 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006315 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006316}
6317
6318template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006319QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006320TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6321 ArrayType::ArraySizeModifier SizeMod,
6322 const llvm::APInt *Size,
6323 Expr *SizeExpr,
6324 unsigned IndexTypeQuals,
6325 SourceRange BracketsRange) {
6326 if (SizeExpr || !Size)
6327 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6328 IndexTypeQuals, BracketsRange,
6329 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006330
6331 QualType Types[] = {
6332 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6333 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6334 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006335 };
6336 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6337 QualType SizeType;
6338 for (unsigned I = 0; I != NumTypes; ++I)
6339 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6340 SizeType = Types[I];
6341 break;
6342 }
Mike Stump11289f42009-09-09 15:08:12 +00006343
Douglas Gregord6ff3322009-08-04 16:50:30 +00006344 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006345 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006346 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006347 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006348}
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregord6ff3322009-08-04 16:50:30 +00006350template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006351QualType
6352TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006353 ArrayType::ArraySizeModifier SizeMod,
6354 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006355 unsigned IndexTypeQuals,
6356 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006357 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006358 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006359}
6360
6361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006362QualType
Mike Stump11289f42009-09-09 15:08:12 +00006363TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006364 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006365 unsigned IndexTypeQuals,
6366 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006367 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006368 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006369}
Mike Stump11289f42009-09-09 15:08:12 +00006370
Douglas Gregord6ff3322009-08-04 16:50:30 +00006371template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006372QualType
6373TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006374 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006375 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006376 unsigned IndexTypeQuals,
6377 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006378 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006379 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006380 IndexTypeQuals, BracketsRange);
6381}
6382
6383template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006384QualType
6385TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006386 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006387 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006388 unsigned IndexTypeQuals,
6389 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006390 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006391 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006392 IndexTypeQuals, BracketsRange);
6393}
6394
6395template<typename Derived>
6396QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006397 unsigned NumElements,
6398 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006399 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006400 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006401}
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregord6ff3322009-08-04 16:50:30 +00006403template<typename Derived>
6404QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6405 unsigned NumElements,
6406 SourceLocation AttributeLoc) {
6407 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6408 NumElements, true);
6409 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006410 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006411 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006412 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006413}
Mike Stump11289f42009-09-09 15:08:12 +00006414
Douglas Gregord6ff3322009-08-04 16:50:30 +00006415template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006416QualType
6417TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006418 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006419 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006420 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006421}
Mike Stump11289f42009-09-09 15:08:12 +00006422
Douglas Gregord6ff3322009-08-04 16:50:30 +00006423template<typename Derived>
6424QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006425 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006426 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006427 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006428 unsigned Quals,
6429 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006430 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006431 Quals,
6432 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006433 getDerived().getBaseEntity(),
6434 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006435}
Mike Stump11289f42009-09-09 15:08:12 +00006436
Douglas Gregord6ff3322009-08-04 16:50:30 +00006437template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006438QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6439 return SemaRef.Context.getFunctionNoProtoType(T);
6440}
6441
6442template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006443QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6444 assert(D && "no decl found");
6445 if (D->isInvalidDecl()) return QualType();
6446
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006447 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006448 TypeDecl *Ty;
6449 if (isa<UsingDecl>(D)) {
6450 UsingDecl *Using = cast<UsingDecl>(D);
6451 assert(Using->isTypeName() &&
6452 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6453
6454 // A valid resolved using typename decl points to exactly one type decl.
6455 assert(++Using->shadow_begin() == Using->shadow_end());
6456 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006457
John McCallb96ec562009-12-04 22:46:56 +00006458 } else {
6459 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6460 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6461 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6462 }
6463
6464 return SemaRef.Context.getTypeDeclType(Ty);
6465}
6466
6467template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006468QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6469 return SemaRef.BuildTypeofExprType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006470}
6471
6472template<typename Derived>
6473QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6474 return SemaRef.Context.getTypeOfType(Underlying);
6475}
6476
6477template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006478QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6479 return SemaRef.BuildDecltypeType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006480}
6481
6482template<typename Derived>
6483QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006484 TemplateName Template,
6485 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006486 const TemplateArgumentListInfo &TemplateArgs) {
6487 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006488}
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregor1135c352009-08-06 05:28:30 +00006490template<typename Derived>
6491NestedNameSpecifier *
6492TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6493 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006494 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006495 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006496 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006497 CXXScopeSpec SS;
6498 // FIXME: The source location information is all wrong.
6499 SS.setRange(Range);
6500 SS.setScopeRep(Prefix);
6501 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006502 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006503 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006504 ObjectType,
6505 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006506 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006507}
6508
6509template<typename Derived>
6510NestedNameSpecifier *
6511TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6512 SourceRange Range,
6513 NamespaceDecl *NS) {
6514 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6515}
6516
6517template<typename Derived>
6518NestedNameSpecifier *
6519TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6520 SourceRange Range,
6521 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006522 QualType T) {
6523 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006524 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006525 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006526 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6527 T.getTypePtr());
6528 }
Mike Stump11289f42009-09-09 15:08:12 +00006529
Douglas Gregor1135c352009-08-06 05:28:30 +00006530 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6531 return 0;
6532}
Mike Stump11289f42009-09-09 15:08:12 +00006533
Douglas Gregor71dc5092009-08-06 06:41:21 +00006534template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006535TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006536TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6537 bool TemplateKW,
6538 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006539 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006540 Template);
6541}
6542
6543template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006544TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006545TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006546 const IdentifierInfo &II,
6547 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006548 CXXScopeSpec SS;
6549 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006550 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006551 UnqualifiedId Name;
6552 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006553 Sema::TemplateTy Template;
6554 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6555 /*FIXME:*/getDerived().getBaseLocation(),
6556 SS,
6557 Name,
John McCallba7bf592010-08-24 05:47:05 +00006558 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006559 /*EnteringContext=*/false,
6560 Template);
6561 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006562}
Mike Stump11289f42009-09-09 15:08:12 +00006563
Douglas Gregora16548e2009-08-11 05:31:07 +00006564template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006565TemplateName
6566TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6567 OverloadedOperatorKind Operator,
6568 QualType ObjectType) {
6569 CXXScopeSpec SS;
6570 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6571 SS.setScopeRep(Qualifier);
6572 UnqualifiedId Name;
6573 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6574 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6575 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006576 Sema::TemplateTy Template;
6577 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006578 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006579 SS,
6580 Name,
John McCallba7bf592010-08-24 05:47:05 +00006581 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006582 /*EnteringContext=*/false,
6583 Template);
6584 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006585}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006586
Douglas Gregor71395fa2009-11-04 00:56:37 +00006587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006588ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006589TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6590 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006591 Expr *OrigCallee,
6592 Expr *First,
6593 Expr *Second) {
6594 Expr *Callee = OrigCallee->IgnoreParenCasts();
6595 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006596
Douglas Gregora16548e2009-08-11 05:31:07 +00006597 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006598 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006599 if (!First->getType()->isOverloadableType() &&
6600 !Second->getType()->isOverloadableType())
6601 return getSema().CreateBuiltinArraySubscriptExpr(First,
6602 Callee->getLocStart(),
6603 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006604 } else if (Op == OO_Arrow) {
6605 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006606 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6607 } else if (Second == 0 || isPostIncDec) {
6608 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006609 // The argument is not of overloadable type, so try to create a
6610 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006611 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006612 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006613
John McCallb268a282010-08-23 23:25:46 +00006614 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006615 }
6616 } else {
John McCallb268a282010-08-23 23:25:46 +00006617 if (!First->getType()->isOverloadableType() &&
6618 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006619 // Neither of the arguments is an overloadable type, so try to
6620 // create a built-in binary operation.
6621 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006622 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006623 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006624 if (Result.isInvalid())
6625 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006626
Douglas Gregora16548e2009-08-11 05:31:07 +00006627 return move(Result);
6628 }
6629 }
Mike Stump11289f42009-09-09 15:08:12 +00006630
6631 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006632 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006633 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006634
John McCallb268a282010-08-23 23:25:46 +00006635 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006636 assert(ULE->requiresADL());
6637
6638 // FIXME: Do we have to check
6639 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006640 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006641 } else {
John McCallb268a282010-08-23 23:25:46 +00006642 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006643 }
Mike Stump11289f42009-09-09 15:08:12 +00006644
Douglas Gregora16548e2009-08-11 05:31:07 +00006645 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006646 Expr *Args[2] = { First, Second };
6647 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregora16548e2009-08-11 05:31:07 +00006649 // Create the overloaded operator invocation for unary operators.
6650 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006651 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006652 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006653 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006654 }
Mike Stump11289f42009-09-09 15:08:12 +00006655
Sebastian Redladba46e2009-10-29 20:17:01 +00006656 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006657 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006658 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006659 First,
6660 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006661
Douglas Gregora16548e2009-08-11 05:31:07 +00006662 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006663 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006664 BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006665 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006666 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6667 if (Result.isInvalid())
6668 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006669
Mike Stump11289f42009-09-09 15:08:12 +00006670 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006671}
Mike Stump11289f42009-09-09 15:08:12 +00006672
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006674ExprResult
John McCallb268a282010-08-23 23:25:46 +00006675TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006676 SourceLocation OperatorLoc,
6677 bool isArrow,
6678 NestedNameSpecifier *Qualifier,
6679 SourceRange QualifierRange,
6680 TypeSourceInfo *ScopeType,
6681 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006682 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006683 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006684 CXXScopeSpec SS;
6685 if (Qualifier) {
6686 SS.setRange(QualifierRange);
6687 SS.setScopeRep(Qualifier);
6688 }
6689
John McCallb268a282010-08-23 23:25:46 +00006690 QualType BaseType = Base->getType();
6691 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006692 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006693 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006694 !BaseType->getAs<PointerType>()->getPointeeType()
6695 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006696 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006697 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006698 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006699 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006700 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006701 /*FIXME?*/true);
6702 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006703
Douglas Gregor678f90d2010-02-25 01:56:36 +00006704 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006705 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6706 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6707 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6708 NameInfo.setNamedTypeInfo(DestroyedType);
6709
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006710 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006711
John McCallb268a282010-08-23 23:25:46 +00006712 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006713 OperatorLoc, isArrow,
6714 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006715 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006716 /*TemplateArgs*/ 0);
6717}
6718
Douglas Gregord6ff3322009-08-04 16:50:30 +00006719} // end namespace clang
6720
6721#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H