blob: 816a1701d8639113c652e90e3612045e399862bc [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John 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 Gregor451d1b12010-12-02 00:05:49 +000032#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000036using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000037
Douglas Gregord6ff3322009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump11289f42009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump11289f42009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000093
94public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000097
Douglas Gregord6ff3322009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000104 }
105
John McCalldadc5752010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000119
Douglas Gregord6ff3322009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump11289f42009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregora16548e2009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000141
Douglas Gregora16548e2009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregora16548e2009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Douglas Gregora16548e2009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump11289f42009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregord196a582009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000182
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCall550e0c22009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000192 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000193
John McCall550e0c22009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 ///
John McCall550e0c22009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000203
204 /// \brief Transform the given type-with-location into a new
205 /// type, collecting location information in the given builder
206 /// as necessary.
207 ///
John McCall31f82722010-11-12 08:19:04 +0000208 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000209
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000210 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000211 ///
Mike Stump11289f42009-09-09 15:08:12 +0000212 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000213 /// appropriate TransformXXXStmt function to transform a specific kind of
214 /// statement or the TransformExpr() function to transform an expression.
215 /// Subclasses may override this function to transform statements using some
216 /// other mechanism.
217 ///
218 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000219 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000220
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000221 /// \brief Transform the given expression.
222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 /// By default, this routine transforms an expression by delegating to the
224 /// appropriate TransformXXXExpr function to build a new expression.
225 /// Subclasses may override this function to transform expressions using some
226 /// other mechanism.
227 ///
228 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000229 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000230
Douglas Gregord6ff3322009-08-04 16:50:30 +0000231 /// \brief Transform the given declaration, which is referenced from a type
232 /// or expression.
233 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000234 /// By default, acts as the identity function on declarations. Subclasses
235 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000236 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000237
238 /// \brief Transform the definition of the given declaration.
239 ///
Mike Stump11289f42009-09-09 15:08:12 +0000240 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000241 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000242 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
243 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000244 }
Mike Stump11289f42009-09-09 15:08:12 +0000245
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000249 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000257 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000258
Douglas Gregord6ff3322009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregorf816bd72009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000275 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000276 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000277
Douglas Gregord6ff3322009-08-04 16:50:30 +0000278 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000279 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000280 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000281 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000282 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000283 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000284 QualType ObjectType = QualType(),
285 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000286
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump11289f42009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCallbcd03502009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump11289f42009-09-09 15:08:12 +0000307
John McCall550e0c22009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000311#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000312
John McCall31f82722010-11-12 08:19:04 +0000313 QualType
314 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
315 TemplateSpecializationTypeLoc TL,
316 TemplateName Template);
317
318 QualType
319 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
320 DependentTemplateSpecializationTypeLoc TL,
321 NestedNameSpecifier *Prefix);
322
John McCall58f10c32010-03-11 09:03:00 +0000323 /// \brief Transforms the parameters of a function type into the
324 /// given vectors.
325 ///
326 /// The result vectors should be kept in sync; null entries in the
327 /// variables vector are acceptable.
328 ///
329 /// Return true on error.
330 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
331 llvm::SmallVectorImpl<QualType> &PTypes,
332 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
333
334 /// \brief Transforms a single function-type parameter. Return null
335 /// on error.
336 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
337
John McCall31f82722010-11-12 08:19:04 +0000338 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000339
John McCalldadc5752010-08-24 06:29:42 +0000340 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
341 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000344 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000346 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000424 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000435 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000445 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000461 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000473
John McCall550e0c22009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCallb96ec562009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCallfcc33b02009-09-05 00:15:47 +0000495
Mike Stump11289f42009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000500 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501
Mike Stump11289f42009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump11289f42009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000511 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000521
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000527 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
528 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000529 NestedNameSpecifier *NNS, QualType Named) {
530 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000531 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000532
533 /// \brief Build a new typename type that refers to a template-id.
534 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000535 /// By default, builds a new DependentNameType type from the
536 /// nested-name-specifier and the given type. Subclasses may override
537 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000538 QualType RebuildDependentTemplateSpecializationType(
539 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000540 NestedNameSpecifier *Qualifier,
541 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000542 const IdentifierInfo *Name,
543 SourceLocation NameLoc,
544 const TemplateArgumentListInfo &Args) {
545 // Rebuild the template name.
546 // TODO: avoid TemplateName abstraction
547 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000548 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000549 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000550
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000551 if (InstName.isNull())
552 return QualType();
553
John McCallc392f372010-06-11 00:33:02 +0000554 // If it's still dependent, make a dependent specialization.
555 if (InstName.getAsDependentTemplateName())
556 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000557 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000558
559 // Otherwise, make an elaborated type wrapping a non-dependent
560 // specialization.
561 QualType T =
562 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
563 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000564
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000565 // NOTE: NNS is already recorded in template specialization type T.
566 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000567 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568
569 /// \brief Build a new typename type that refers to an identifier.
570 ///
571 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000573 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000575 NestedNameSpecifier *NNS,
576 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000577 SourceLocation KeywordLoc,
578 SourceRange NNSRange,
579 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000580 CXXScopeSpec SS;
581 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000582 SS.setRange(NNSRange);
583
Douglas Gregore677daf2010-03-31 22:19:08 +0000584 if (NNS->isDependent()) {
585 // If the name is still dependent, just build a new dependent name type.
586 if (!SemaRef.computeDeclContext(SS))
587 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
588 }
589
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000591 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
592 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000593
594 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
595
Abramo Bagnarad7548482010-05-19 21:37:53 +0000596 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000597 // into a non-dependent elaborated-type-specifier. Find the tag we're
598 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000599 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000600 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
601 if (!DC)
602 return QualType();
603
John McCallbf8c5192010-05-27 06:40:31 +0000604 if (SemaRef.RequireCompleteDeclContext(SS, DC))
605 return QualType();
606
Douglas Gregore677daf2010-03-31 22:19:08 +0000607 TagDecl *Tag = 0;
608 SemaRef.LookupQualifiedName(Result, DC);
609 switch (Result.getResultKind()) {
610 case LookupResult::NotFound:
611 case LookupResult::NotFoundInCurrentInstantiation:
612 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000613
Douglas Gregore677daf2010-03-31 22:19:08 +0000614 case LookupResult::Found:
615 Tag = Result.getAsSingle<TagDecl>();
616 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000617
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 case LookupResult::FoundOverloaded:
619 case LookupResult::FoundUnresolvedValue:
620 llvm_unreachable("Tag lookup cannot find non-tags");
621 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000622
Douglas Gregore677daf2010-03-31 22:19:08 +0000623 case LookupResult::Ambiguous:
624 // Let the LookupResult structure handle ambiguities.
625 return QualType();
626 }
627
628 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000629 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000630 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000631 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000632 return QualType();
633 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000634
Abramo Bagnarad7548482010-05-19 21:37:53 +0000635 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
636 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000637 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
638 return QualType();
639 }
640
641 // Build the elaborated-type-specifier type.
642 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000643 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000644 }
Mike Stump11289f42009-09-09 15:08:12 +0000645
Douglas Gregor1135c352009-08-06 05:28:30 +0000646 /// \brief Build a new nested-name-specifier given the prefix and an
647 /// identifier that names the next step in the nested-name-specifier.
648 ///
649 /// By default, performs semantic analysis when building the new
650 /// nested-name-specifier. Subclasses may override this routine to provide
651 /// different behavior.
652 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
653 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000654 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000655 QualType ObjectType,
656 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// namespace named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 NamespaceDecl *NS);
667
668 /// \brief Build a new nested-name-specifier given the prefix and the
669 /// type named in the next step in the nested-name-specifier.
670 ///
671 /// By default, performs semantic analysis when building the new
672 /// nested-name-specifier. Subclasses may override this routine to provide
673 /// different behavior.
674 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
675 SourceRange Range,
676 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000677 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000678
679 /// \brief Build a new template name given a nested name specifier, a flag
680 /// indicating whether the "template" keyword was provided, and the template
681 /// that the template name refers to.
682 ///
683 /// By default, builds the new template name directly. Subclasses may override
684 /// this routine to provide different behavior.
685 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
686 bool TemplateKW,
687 TemplateDecl *Template);
688
Douglas Gregor71dc5092009-08-06 06:41:21 +0000689 /// \brief Build a new template name given a nested name specifier and the
690 /// name that is referred to as a template.
691 ///
692 /// By default, performs semantic analysis to determine whether the name can
693 /// be resolved to a specific template, then builds the appropriate kind of
694 /// template name. Subclasses may override this routine to provide different
695 /// behavior.
696 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000697 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000698 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000699 QualType ObjectType,
700 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregor71395fa2009-11-04 00:56:37 +0000702 /// \brief Build a new template name given a nested name specifier and the
703 /// overloaded operator name that is referred to as a template.
704 ///
705 /// By default, performs semantic analysis to determine whether the name can
706 /// be resolved to a specific template, then builds the appropriate kind of
707 /// template name. Subclasses may override this routine to provide different
708 /// behavior.
709 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
710 OverloadedOperatorKind Operator,
711 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000712
Douglas Gregorebe10102009-08-20 07:17:43 +0000713 /// \brief Build a new compound statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000717 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000718 MultiStmtArg Statements,
719 SourceLocation RBraceLoc,
720 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000721 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000722 IsStmtExpr);
723 }
724
725 /// \brief Build a new case statement.
726 ///
727 /// By default, performs semantic analysis to build the new statement.
728 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000729 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000730 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000732 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000734 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 ColonLoc);
736 }
Mike Stump11289f42009-09-09 15:08:12 +0000737
Douglas Gregorebe10102009-08-20 07:17:43 +0000738 /// \brief Attach the body to a new case statement.
739 ///
740 /// By default, performs semantic analysis to build the new statement.
741 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000742 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000743 getSema().ActOnCaseStmtBody(S, Body);
744 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 }
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 /// \brief Build a new default statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000751 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000753 Stmt *SubStmt) {
754 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /*CurScope=*/0);
756 }
Mike Stump11289f42009-09-09 15:08:12 +0000757
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 /// \brief Build a new label statement.
759 ///
760 /// By default, performs semantic analysis to build the new statement.
761 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000762 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 IdentifierInfo *Id,
764 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000765 Stmt *SubStmt, bool HasUnusedAttr) {
766 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
767 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 }
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 /// \brief Build a new "if" statement.
771 ///
772 /// By default, performs semantic analysis to build the new statement.
773 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000774 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000775 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000776 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000777 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 }
Mike Stump11289f42009-09-09 15:08:12 +0000779
Douglas Gregorebe10102009-08-20 07:17:43 +0000780 /// \brief Start building a new switch statement.
781 ///
782 /// By default, performs semantic analysis to build the new statement.
783 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000784 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000785 Expr *Cond, VarDecl *CondVar) {
786 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000787 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000788 }
Mike Stump11289f42009-09-09 15:08:12 +0000789
Douglas Gregorebe10102009-08-20 07:17:43 +0000790 /// \brief Attach the body to the switch statement.
791 ///
792 /// By default, performs semantic analysis to build the new statement.
793 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000794 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000795 Stmt *Switch, Stmt *Body) {
796 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 }
798
799 /// \brief Build a new while statement.
800 ///
801 /// By default, performs semantic analysis to build the new statement.
802 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000803 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000804 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000805 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000806 Stmt *Body) {
807 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 }
Mike Stump11289f42009-09-09 15:08:12 +0000809
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 /// \brief Build a new do-while statement.
811 ///
812 /// By default, performs semantic analysis to build the new statement.
813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000814 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000815 SourceLocation WhileLoc,
816 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000817 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000819 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
820 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000821 }
822
823 /// \brief Build a new for statement.
824 ///
825 /// By default, performs semantic analysis to build the new statement.
826 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000827 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000828 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000829 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000830 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000831 SourceLocation RParenLoc, Stmt *Body) {
832 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000833 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000834 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000835 }
Mike Stump11289f42009-09-09 15:08:12 +0000836
Douglas Gregorebe10102009-08-20 07:17:43 +0000837 /// \brief Build a new goto statement.
838 ///
839 /// By default, performs semantic analysis to build the new statement.
840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000841 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000842 SourceLocation LabelLoc,
843 LabelStmt *Label) {
844 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
845 }
846
847 /// \brief Build a new indirect goto statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000851 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000853 Expr *Target) {
854 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000855 }
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 /// \brief Build a new return statement.
858 ///
859 /// By default, performs semantic analysis to build the new statement.
860 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000861 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000862 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000863
John McCallb268a282010-08-23 23:25:46 +0000864 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 }
Mike Stump11289f42009-09-09 15:08:12 +0000866
Douglas Gregorebe10102009-08-20 07:17:43 +0000867 /// \brief Build a new declaration statement.
868 ///
869 /// By default, performs semantic analysis to build the new statement.
870 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000871 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000872 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000873 SourceLocation EndLoc) {
874 return getSema().Owned(
875 new (getSema().Context) DeclStmt(
876 DeclGroupRef::Create(getSema().Context,
877 Decls, NumDecls),
878 StartLoc, EndLoc));
879 }
Mike Stump11289f42009-09-09 15:08:12 +0000880
Anders Carlssonaaeef072010-01-24 05:50:09 +0000881 /// \brief Build a new inline asm statement.
882 ///
883 /// By default, performs semantic analysis to build the new statement.
884 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000885 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000886 bool IsSimple,
887 bool IsVolatile,
888 unsigned NumOutputs,
889 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000890 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000891 MultiExprArg Constraints,
892 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000893 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000894 MultiExprArg Clobbers,
895 SourceLocation RParenLoc,
896 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000897 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000898 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000899 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000900 RParenLoc, MSAsm);
901 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000902
903 /// \brief Build a new Objective-C @try statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000907 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000908 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000909 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000910 Stmt *Finally) {
911 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
912 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000913 }
914
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000915 /// \brief Rebuild an Objective-C exception declaration.
916 ///
917 /// By default, performs semantic analysis to build the new declaration.
918 /// Subclasses may override this routine to provide different behavior.
919 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
920 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000921 return getSema().BuildObjCExceptionDecl(TInfo, T,
922 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 ExceptionDecl->getLocation());
924 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000925
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000926 /// \brief Build a new Objective-C @catch statement.
927 ///
928 /// By default, performs semantic analysis to build the new statement.
929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000930 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000931 SourceLocation RParenLoc,
932 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000933 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000934 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000935 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000936 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000937
Douglas Gregor306de2f2010-04-22 23:59:56 +0000938 /// \brief Build a new Objective-C @finally statement.
939 ///
940 /// By default, performs semantic analysis to build the new statement.
941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000942 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000943 Stmt *Body) {
944 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000945 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000946
Douglas Gregor6148de72010-04-22 22:01:21 +0000947 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000948 ///
949 /// By default, performs semantic analysis to build the new statement.
950 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000951 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000952 Expr *Operand) {
953 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000954 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000955
Douglas Gregor6148de72010-04-22 22:01:21 +0000956 /// \brief Build a new Objective-C @synchronized statement.
957 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000958 /// By default, performs semantic analysis to build the new statement.
959 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000960 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000961 Expr *Object,
962 Stmt *Body) {
963 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
964 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000965 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000966
967 /// \brief Build a new Objective-C fast enumeration statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000971 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000972 SourceLocation LParenLoc,
973 Stmt *Element,
974 Expr *Collection,
975 SourceLocation RParenLoc,
976 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000977 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Element,
979 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000980 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000981 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000982 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000983
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 /// \brief Build a new C++ exception declaration.
985 ///
986 /// By default, performs semantic analysis to build the new decaration.
987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000988 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +0000989 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000990 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +0000991 SourceLocation Loc) {
992 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
994
995 /// \brief Build a new C++ catch statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001000 VarDecl *ExceptionDecl,
1001 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001002 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1003 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new C++ try statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001010 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001011 Stmt *TryBlock,
1012 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001013 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001014 }
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 /// \brief Build a new expression that references a declaration.
1017 ///
1018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001020 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001021 LookupResult &R,
1022 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001023 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1024 }
1025
1026
1027 /// \brief Build a new expression that references a declaration.
1028 ///
1029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001031 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001032 SourceRange QualifierRange,
1033 ValueDecl *VD,
1034 const DeclarationNameInfo &NameInfo,
1035 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001036 CXXScopeSpec SS;
1037 SS.setScopeRep(Qualifier);
1038 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001039
1040 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001041
1042 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 }
Mike Stump11289f42009-09-09 15:08:12 +00001044
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001046 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 /// By default, performs semantic analysis to build the new expression.
1048 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001049 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001051 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 }
1053
Douglas Gregorad8a3362009-09-04 17:36:40 +00001054 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001055 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001056 /// By default, performs semantic analysis to build the new expression.
1057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001058 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001059 SourceLocation OperatorLoc,
1060 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001061 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001062 SourceRange QualifierRange,
1063 TypeSourceInfo *ScopeType,
1064 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001065 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001066 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001072 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001073 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001074 Expr *SubExpr) {
1075 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 }
Mike Stump11289f42009-09-09 15:08:12 +00001077
Douglas Gregor882211c2010-04-28 22:16:22 +00001078 /// \brief Build a new builtin offsetof expression.
1079 ///
1080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001082 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001083 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001084 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001085 unsigned NumComponents,
1086 SourceLocation RParenLoc) {
1087 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1088 NumComponents, RParenLoc);
1089 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001092 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 /// By default, performs semantic analysis to build the new expression.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001095 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001096 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001098 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 }
1100
Mike Stump11289f42009-09-09 15:08:12 +00001101 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// By default, performs semantic analysis to build the new expression.
1105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001106 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001108 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001109 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 return move(Result);
1114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001117 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 /// By default, performs semantic analysis to build the new expression.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001122 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001124 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1125 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 RBracketLoc);
1127 }
1128
1129 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001130 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001131 /// By default, performs semantic analysis to build the new expression.
1132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001133 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001136 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001137 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 }
1139
1140 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001141 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// By default, performs semantic analysis to build the new expression.
1143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001144 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001145 bool isArrow,
1146 NestedNameSpecifier *Qualifier,
1147 SourceRange QualifierRange,
1148 const DeclarationNameInfo &MemberNameInfo,
1149 ValueDecl *Member,
1150 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001151 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001152 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001153 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001154 // We have a reference to an unnamed field. This is always the
1155 // base of an anonymous struct/union member access, i.e. the
1156 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001157 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001158 assert(Member->getType()->isRecordType() &&
1159 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001160
John McCallb268a282010-08-23 23:25:46 +00001161 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001162 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001163 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001164
John McCall7decc9e2010-11-18 06:31:45 +00001165 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001166 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001167 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001168 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001169 cast<FieldDecl>(Member)->getType(),
1170 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001171 return getSema().Owned(ME);
1172 }
Mike Stump11289f42009-09-09 15:08:12 +00001173
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001174 CXXScopeSpec SS;
1175 if (Qualifier) {
1176 SS.setRange(QualifierRange);
1177 SS.setScopeRep(Qualifier);
1178 }
1179
John McCallb268a282010-08-23 23:25:46 +00001180 getSema().DefaultFunctionArrayConversion(Base);
1181 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001182
John McCall16df1e52010-03-30 21:47:33 +00001183 // FIXME: this involves duplicating earlier analysis in a lot of
1184 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001185 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001186 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001187 R.resolveKind();
1188
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001190 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001191 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 /// \brief Build a new binary 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 RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001199 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001200 Expr *LHS, Expr *RHS) {
1201 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 }
1203
1204 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001205 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// By default, performs semantic analysis to build the new expression.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001210 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001212 Expr *RHS) {
1213 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1214 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 }
1216
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001218 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 /// By default, performs semantic analysis to build the new expression.
1220 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001221 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001222 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001224 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001225 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001226 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 }
Mike Stump11289f42009-09-09 15:08:12 +00001228
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001230 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001233 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001234 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001236 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001237 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 }
Mike Stump11289f42009-09-09 15:08:12 +00001240
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001242 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 /// By default, performs semantic analysis to build the new expression.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 SourceLocation OpLoc,
1247 SourceLocation AccessorLoc,
1248 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001249
John McCall10eae182009-11-30 22:42:35 +00001250 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001251 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001252 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001253 OpLoc, /*IsArrow*/ false,
1254 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001255 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001256 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001265 SourceLocation RBraceLoc,
1266 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001267 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001268 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1269 if (Result.isInvalid() || ResultTy->isDependentType())
1270 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001271
Douglas Gregord3d93062009-11-09 17:16:50 +00001272 // Patch in the result type we were given, which may have been computed
1273 // when the initial InitListExpr was built.
1274 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1275 ILE->setType(ResultTy);
1276 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 }
Mike Stump11289f42009-09-09 15:08:12 +00001278
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001280 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// By default, performs semantic analysis to build the new expression.
1282 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001283 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 MultiExprArg ArrayExprs,
1285 SourceLocation EqualOrColonLoc,
1286 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001287 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001288 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001290 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001293
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 ArrayExprs.release();
1295 return move(Result);
1296 }
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001299 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// By default, builds the implicit value initialization without performing
1301 /// any semantic analysis. Subclasses may override this routine to provide
1302 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001303 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1305 }
Mike Stump11289f42009-09-09 15:08:12 +00001306
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001308 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001311 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001312 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001313 SourceLocation RParenLoc) {
1314 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001315 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001316 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
1318
1319 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 MultiExprArg SubExprs,
1325 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001326 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001327 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
1332 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// rather than attempting to map the label statement itself.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation LabelLoc,
1337 LabelStmt *Label) {
1338 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001342 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// 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 RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001346 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001348 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 }
Mike Stump11289f42009-09-09 15:08:12 +00001350
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// \brief Build a new __builtin_types_compatible_p expression.
1352 ///
1353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001355 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001356 TypeSourceInfo *TInfo1,
1357 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001359 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1360 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 RParenLoc);
1362 }
Mike Stump11289f42009-09-09 15:08:12 +00001363
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 /// \brief Build a new __builtin_choose_expr expression.
1365 ///
1366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001368 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001369 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 SourceLocation RParenLoc) {
1371 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001372 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 RParenLoc);
1374 }
Mike Stump11289f42009-09-09 15:08:12 +00001375
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 /// \brief Build a new overloaded operator call expression.
1377 ///
1378 /// By default, performs semantic analysis to build the new expression.
1379 /// The semantic analysis provides the behavior of template instantiation,
1380 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001381 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// argument-dependent lookup, etc. Subclasses may override this routine to
1383 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001384 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001386 Expr *Callee,
1387 Expr *First,
1388 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001389
1390 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 /// reinterpret_cast.
1392 ///
1393 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001394 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001396 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 Stmt::StmtClass Class,
1398 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001399 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 SourceLocation RAngleLoc,
1401 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001402 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 SourceLocation RParenLoc) {
1404 switch (Class) {
1405 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001408 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001409
1410 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001413 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001416 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001417 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001418 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001422 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001423 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001424 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 default:
1427 assert(false && "Invalid C++ named cast");
1428 break;
1429 }
Mike Stump11289f42009-09-09 15:08:12 +00001430
John McCallfaf5fb42010-08-26 23:41:50 +00001431 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 }
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new C++ static_cast expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001440 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RAngleLoc,
1442 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001443 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001445 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001446 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001447 SourceRange(LAngleLoc, RAngleLoc),
1448 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 }
1450
1451 /// \brief Build a new C++ dynamic_cast expression.
1452 ///
1453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001455 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001457 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 SourceLocation RAngleLoc,
1459 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001460 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001462 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001463 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001464 SourceRange(LAngleLoc, RAngleLoc),
1465 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 }
1467
1468 /// \brief Build a new C++ reinterpret_cast expression.
1469 ///
1470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001472 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001474 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 SourceLocation RAngleLoc,
1476 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001477 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001479 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001480 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001481 SourceRange(LAngleLoc, RAngleLoc),
1482 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 }
1484
1485 /// \brief Build a new C++ const_cast expression.
1486 ///
1487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001489 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001491 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 SourceLocation RAngleLoc,
1493 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001494 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001496 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001497 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001498 SourceRange(LAngleLoc, RAngleLoc),
1499 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 }
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// \brief Build a new C++ functional-style cast expression.
1503 ///
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001506 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1507 SourceLocation LParenLoc,
1508 Expr *Sub,
1509 SourceLocation RParenLoc) {
1510 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001511 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 RParenLoc);
1513 }
Mike Stump11289f42009-09-09 15:08:12 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new C++ typeid(type) expression.
1516 ///
1517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001519 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001520 SourceLocation TypeidLoc,
1521 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001523 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001524 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 }
Mike Stump11289f42009-09-09 15:08:12 +00001526
Francois Pichet9f4f2072010-09-08 12:20:18 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new C++ typeid(expr) expression.
1529 ///
1530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001532 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001533 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001534 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001536 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001537 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001538 }
1539
Francois Pichet9f4f2072010-09-08 12:20:18 +00001540 /// \brief Build a new C++ __uuidof(type) expression.
1541 ///
1542 /// By default, performs semantic analysis to build the new expression.
1543 /// Subclasses may override this routine to provide different behavior.
1544 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1545 SourceLocation TypeidLoc,
1546 TypeSourceInfo *Operand,
1547 SourceLocation RParenLoc) {
1548 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1549 RParenLoc);
1550 }
1551
1552 /// \brief Build a new C++ __uuidof(expr) expression.
1553 ///
1554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
1556 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1557 SourceLocation TypeidLoc,
1558 Expr *Operand,
1559 SourceLocation RParenLoc) {
1560 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1561 RParenLoc);
1562 }
1563
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 /// \brief Build a new C++ "this" expression.
1565 ///
1566 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001567 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001569 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001570 QualType ThisType,
1571 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001573 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1574 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 }
1576
1577 /// \brief Build a new C++ throw expression.
1578 ///
1579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001581 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001582 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 }
1584
1585 /// \brief Build a new C++ default-argument expression.
1586 ///
1587 /// By default, builds a new default-argument expression, which does not
1588 /// require any semantic analysis. Subclasses may override this routine to
1589 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001590 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001591 ParmVarDecl *Param) {
1592 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1593 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 }
1595
1596 /// \brief Build a new C++ zero-initialization expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001600 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1601 SourceLocation LParenLoc,
1602 SourceLocation RParenLoc) {
1603 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001604 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001605 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 }
Mike Stump11289f42009-09-09 15:08:12 +00001607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// \brief Build a new C++ "new" expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001612 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001613 bool UseGlobal,
1614 SourceLocation PlacementLParen,
1615 MultiExprArg PlacementArgs,
1616 SourceLocation PlacementRParen,
1617 SourceRange TypeIdParens,
1618 QualType AllocatedType,
1619 TypeSourceInfo *AllocatedTypeInfo,
1620 Expr *ArraySize,
1621 SourceLocation ConstructorLParen,
1622 MultiExprArg ConstructorArgs,
1623 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001624 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 PlacementLParen,
1626 move(PlacementArgs),
1627 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001628 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001629 AllocatedType,
1630 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001631 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 ConstructorLParen,
1633 move(ConstructorArgs),
1634 ConstructorRParen);
1635 }
Mike Stump11289f42009-09-09 15:08:12 +00001636
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// \brief Build a new C++ "delete" expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001641 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 bool IsGlobalDelete,
1643 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001644 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001646 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 }
Mike Stump11289f42009-09-09 15:08:12 +00001648
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 /// \brief Build a new unary type trait expression.
1650 ///
1651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001653 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001654 SourceLocation StartLoc,
1655 TypeSourceInfo *T,
1656 SourceLocation RParenLoc) {
1657 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 }
1659
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001660 /// \brief Build a new binary type trait expression.
1661 ///
1662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
1664 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1665 SourceLocation StartLoc,
1666 TypeSourceInfo *LhsT,
1667 TypeSourceInfo *RhsT,
1668 SourceLocation RParenLoc) {
1669 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1670 }
1671
Mike Stump11289f42009-09-09 15:08:12 +00001672 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 /// expression.
1674 ///
1675 /// By default, performs semantic analysis to build the new expression.
1676 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001677 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001679 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001680 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 CXXScopeSpec SS;
1682 SS.setRange(QualifierRange);
1683 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001684
1685 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001686 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001687 *TemplateArgs);
1688
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001689 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 }
1691
1692 /// \brief Build a new template-id expression.
1693 ///
1694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001696 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001697 LookupResult &R,
1698 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001699 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001700 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 }
1702
1703 /// \brief Build a new object-construction expression.
1704 ///
1705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001707 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001708 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 CXXConstructorDecl *Constructor,
1710 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001711 MultiExprArg Args,
1712 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001713 CXXConstructExpr::ConstructionKind ConstructKind,
1714 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001715 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001716 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001717 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001718 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001719
Douglas Gregordb121ba2009-12-14 16:27:04 +00001720 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001721 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001722 RequiresZeroInit, ConstructKind,
1723 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 }
1725
1726 /// \brief Build a new object-construction expression.
1727 ///
1728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001730 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1731 SourceLocation LParenLoc,
1732 MultiExprArg Args,
1733 SourceLocation RParenLoc) {
1734 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 LParenLoc,
1736 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 RParenLoc);
1738 }
1739
1740 /// \brief Build a new object-construction expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001744 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1745 SourceLocation LParenLoc,
1746 MultiExprArg Args,
1747 SourceLocation RParenLoc) {
1748 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 LParenLoc,
1750 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 RParenLoc);
1752 }
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 /// \brief Build a new member reference expression.
1755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001758 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001759 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 bool IsArrow,
1761 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001762 NestedNameSpecifier *Qualifier,
1763 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001764 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001765 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001766 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001768 SS.setRange(QualifierRange);
1769 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001770
John McCallb268a282010-08-23 23:25:46 +00001771 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001772 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001773 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001774 MemberNameInfo,
1775 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 }
1777
John McCall10eae182009-11-30 22:42:35 +00001778 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001779 ///
1780 /// By default, performs semantic analysis to build the new expression.
1781 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001783 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001784 SourceLocation OperatorLoc,
1785 bool IsArrow,
1786 NestedNameSpecifier *Qualifier,
1787 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001788 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001789 LookupResult &R,
1790 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001791 CXXScopeSpec SS;
1792 SS.setRange(QualifierRange);
1793 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001794
John McCallb268a282010-08-23 23:25:46 +00001795 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001796 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001797 SS, FirstQualifierInScope,
1798 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001799 }
Mike Stump11289f42009-09-09 15:08:12 +00001800
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001801 /// \brief Build a new noexcept expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
1805 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1806 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1807 }
1808
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 /// \brief Build a new Objective-C @encode expression.
1810 ///
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001813 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001814 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001816 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001818 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001819
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001820 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001822 Selector Sel,
1823 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001824 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001825 MultiExprArg Args,
1826 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001827 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1828 ReceiverTypeInfo->getType(),
1829 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001830 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001831 move(Args));
1832 }
1833
1834 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001836 Selector Sel,
1837 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001838 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001839 MultiExprArg Args,
1840 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001841 return SemaRef.BuildInstanceMessage(Receiver,
1842 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001843 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001844 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001845 move(Args));
1846 }
1847
Douglas Gregord51d90d2010-04-26 20:11:03 +00001848 /// \brief Build a new Objective-C ivar reference expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001853 SourceLocation IvarLoc,
1854 bool IsArrow, bool IsFreeIvar) {
1855 // FIXME: We lose track of the IsFreeIvar bit.
1856 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001857 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001858 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1859 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001861 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001862 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001863 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001864 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001865 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001866
Douglas Gregord51d90d2010-04-26 20:11:03 +00001867 if (Result.get())
1868 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001869
John McCallb268a282010-08-23 23:25:46 +00001870 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001872 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001873 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001874 /*TemplateArgs=*/0);
1875 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001876
1877 /// \brief Build a new Objective-C property reference expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001881 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001882 ObjCPropertyDecl *Property,
1883 SourceLocation PropertyLoc) {
1884 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001885 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001886 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1887 Sema::LookupMemberName);
1888 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001889 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001890 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001891 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001892 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001893 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001894
Douglas Gregor9faee212010-04-26 20:47:02 +00001895 if (Result.get())
1896 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001897
John McCallb268a282010-08-23 23:25:46 +00001898 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001899 /*FIXME:*/PropertyLoc, IsArrow,
1900 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001901 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001902 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001903 /*TemplateArgs=*/0);
1904 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001905
John McCallb7bd14f2010-12-02 01:19:52 +00001906 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001907 ///
1908 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00001909 /// Subclasses may override this routine to provide different behavior.
1910 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1911 ObjCMethodDecl *Getter,
1912 ObjCMethodDecl *Setter,
1913 SourceLocation PropertyLoc) {
1914 // Since these expressions can only be value-dependent, we do not
1915 // need to perform semantic analysis again.
1916 return Owned(
1917 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
1918 VK_LValue, OK_ObjCProperty,
1919 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001920 }
1921
Douglas Gregord51d90d2010-04-26 20:11:03 +00001922 /// \brief Build a new Objective-C "isa" expression.
1923 ///
1924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001926 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001927 bool IsArrow) {
1928 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001929 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001930 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1931 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001932 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001933 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001934 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001935 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001936 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001937
Douglas Gregord51d90d2010-04-26 20:11:03 +00001938 if (Result.get())
1939 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001940
John McCallb268a282010-08-23 23:25:46 +00001941 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001942 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001943 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001944 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001945 /*TemplateArgs=*/0);
1946 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001947
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 /// \brief Build a new shuffle vector expression.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001952 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001953 MultiExprArg SubExprs,
1954 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001956 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1958 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1959 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1960 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 // Build a reference to the __builtin_shufflevector builtin
1963 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001964 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00001966 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001968
1969 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 unsigned NumSubExprs = SubExprs.size();
1971 Expr **Subs = (Expr **)SubExprs.release();
1972 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1973 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001974 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00001975 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001977 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001978
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001983
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001985 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 }
John McCall31f82722010-11-12 08:19:04 +00001987
1988private:
1989 QualType TransformTypeInObjectScope(QualType T,
1990 QualType ObjectType,
1991 NamedDecl *FirstQualifierInScope,
1992 NestedNameSpecifier *Prefix);
1993
1994 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
1995 QualType ObjectType,
1996 NamedDecl *FirstQualifierInScope,
1997 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001998};
Douglas Gregora16548e2009-08-11 05:31:07 +00001999
Douglas Gregorebe10102009-08-20 07:17:43 +00002000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002001StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002002 if (!S)
2003 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002004
Douglas Gregorebe10102009-08-20 07:17:43 +00002005 switch (S->getStmtClass()) {
2006 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002007
Douglas Gregorebe10102009-08-20 07:17:43 +00002008 // Transform individual statement nodes
2009#define STMT(Node, Parent) \
2010 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2011#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002012#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002013
Douglas Gregorebe10102009-08-20 07:17:43 +00002014 // Transform expressions by calling TransformExpr.
2015#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002016#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002017#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002018#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002019 {
John McCalldadc5752010-08-24 06:29:42 +00002020 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002021 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002022 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002023
John McCallb268a282010-08-23 23:25:46 +00002024 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002025 }
Mike Stump11289f42009-09-09 15:08:12 +00002026 }
2027
John McCallc3007a22010-10-26 07:05:15 +00002028 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002029}
Mike Stump11289f42009-09-09 15:08:12 +00002030
2031
Douglas Gregore922c772009-08-04 22:27:00 +00002032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002033ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 if (!E)
2035 return SemaRef.Owned(E);
2036
2037 switch (E->getStmtClass()) {
2038 case Stmt::NoStmtClass: break;
2039#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002040#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002041#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002042 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002043#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002044 }
2045
John McCallc3007a22010-10-26 07:05:15 +00002046 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002047}
2048
2049template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002050NestedNameSpecifier *
2051TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002052 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002053 QualType ObjectType,
2054 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002055 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregorebe10102009-08-20 07:17:43 +00002057 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002058 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002059 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002060 ObjectType,
2061 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002062 if (!Prefix)
2063 return 0;
2064 }
Mike Stump11289f42009-09-09 15:08:12 +00002065
Douglas Gregor1135c352009-08-06 05:28:30 +00002066 switch (NNS->getKind()) {
2067 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002068 if (Prefix) {
2069 // The object type and qualifier-in-scope really apply to the
2070 // leftmost entity.
2071 ObjectType = QualType();
2072 FirstQualifierInScope = 0;
2073 }
2074
Mike Stump11289f42009-09-09 15:08:12 +00002075 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002076 "Identifier nested-name-specifier with no prefix or object type");
2077 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2078 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002079 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002080
2081 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002082 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002083 ObjectType,
2084 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregor1135c352009-08-06 05:28:30 +00002086 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002087 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002088 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002089 getDerived().TransformDecl(Range.getBegin(),
2090 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002091 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002092 Prefix == NNS->getPrefix() &&
2093 NS == NNS->getAsNamespace())
2094 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002095
Douglas Gregor1135c352009-08-06 05:28:30 +00002096 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2097 }
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregor1135c352009-08-06 05:28:30 +00002099 case NestedNameSpecifier::Global:
2100 // There is no meaningful transformation that one could perform on the
2101 // global scope.
2102 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002103
Douglas Gregor1135c352009-08-06 05:28:30 +00002104 case NestedNameSpecifier::TypeSpecWithTemplate:
2105 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002106 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002107 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2108 ObjectType,
2109 FirstQualifierInScope,
2110 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002111 if (T.isNull())
2112 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002113
Douglas Gregor1135c352009-08-06 05:28:30 +00002114 if (!getDerived().AlwaysRebuild() &&
2115 Prefix == NNS->getPrefix() &&
2116 T == QualType(NNS->getAsType(), 0))
2117 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002118
2119 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2120 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002121 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002122 }
2123 }
Mike Stump11289f42009-09-09 15:08:12 +00002124
Douglas Gregor1135c352009-08-06 05:28:30 +00002125 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002126 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002127}
2128
2129template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002130DeclarationNameInfo
2131TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002132::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002133 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002134 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002135 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002136
2137 switch (Name.getNameKind()) {
2138 case DeclarationName::Identifier:
2139 case DeclarationName::ObjCZeroArgSelector:
2140 case DeclarationName::ObjCOneArgSelector:
2141 case DeclarationName::ObjCMultiArgSelector:
2142 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002143 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002144 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002145 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002146
Douglas Gregorf816bd72009-09-03 22:13:48 +00002147 case DeclarationName::CXXConstructorName:
2148 case DeclarationName::CXXDestructorName:
2149 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002150 TypeSourceInfo *NewTInfo;
2151 CanQualType NewCanTy;
2152 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002153 NewTInfo = getDerived().TransformType(OldTInfo);
2154 if (!NewTInfo)
2155 return DeclarationNameInfo();
2156 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002157 }
2158 else {
2159 NewTInfo = 0;
2160 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002161 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002162 if (NewT.isNull())
2163 return DeclarationNameInfo();
2164 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2165 }
Mike Stump11289f42009-09-09 15:08:12 +00002166
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002167 DeclarationName NewName
2168 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2169 NewCanTy);
2170 DeclarationNameInfo NewNameInfo(NameInfo);
2171 NewNameInfo.setName(NewName);
2172 NewNameInfo.setNamedTypeInfo(NewTInfo);
2173 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002174 }
Mike Stump11289f42009-09-09 15:08:12 +00002175 }
2176
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002177 assert(0 && "Unknown name kind.");
2178 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002179}
2180
2181template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002182TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002183TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002184 QualType ObjectType,
2185 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002186 SourceLocation Loc = getDerived().getBaseLocation();
2187
Douglas Gregor71dc5092009-08-06 06:41:21 +00002188 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002189 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002190 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002191 /*FIXME*/ SourceRange(Loc),
2192 ObjectType,
2193 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002194 if (!NNS)
2195 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002196
Douglas Gregor71dc5092009-08-06 06:41:21 +00002197 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002198 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002199 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002200 if (!TransTemplate)
2201 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregor71dc5092009-08-06 06:41:21 +00002203 if (!getDerived().AlwaysRebuild() &&
2204 NNS == QTN->getQualifier() &&
2205 TransTemplate == Template)
2206 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002207
Douglas Gregor71dc5092009-08-06 06:41:21 +00002208 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2209 TransTemplate);
2210 }
Mike Stump11289f42009-09-09 15:08:12 +00002211
John McCalle66edc12009-11-24 19:00:30 +00002212 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002213 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002214 }
Mike Stump11289f42009-09-09 15:08:12 +00002215
Douglas Gregor71dc5092009-08-06 06:41:21 +00002216 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002217 NestedNameSpecifier *NNS = DTN->getQualifier();
2218 if (NNS) {
2219 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2220 /*FIXME:*/SourceRange(Loc),
2221 ObjectType,
2222 FirstQualifierInScope);
2223 if (!NNS) return TemplateName();
2224
2225 // These apply to the scope specifier, not the template.
2226 ObjectType = QualType();
2227 FirstQualifierInScope = 0;
2228 }
Mike Stump11289f42009-09-09 15:08:12 +00002229
Douglas Gregor71dc5092009-08-06 06:41:21 +00002230 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002231 NNS == DTN->getQualifier() &&
2232 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002233 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregora5614c52010-09-08 23:56:00 +00002235 if (DTN->isIdentifier()) {
2236 // FIXME: Bad range
2237 SourceRange QualifierRange(getDerived().getBaseLocation());
2238 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2239 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002240 ObjectType,
2241 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002242 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002243
2244 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002245 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002246 }
Mike Stump11289f42009-09-09 15:08:12 +00002247
Douglas Gregor71dc5092009-08-06 06:41:21 +00002248 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002249 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002250 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002251 if (!TransTemplate)
2252 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002253
Douglas Gregor71dc5092009-08-06 06:41:21 +00002254 if (!getDerived().AlwaysRebuild() &&
2255 TransTemplate == Template)
2256 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002257
Douglas Gregor71dc5092009-08-06 06:41:21 +00002258 return TemplateName(TransTemplate);
2259 }
Mike Stump11289f42009-09-09 15:08:12 +00002260
John McCalle66edc12009-11-24 19:00:30 +00002261 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002262 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002263 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002264}
2265
2266template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002267void TreeTransform<Derived>::InventTemplateArgumentLoc(
2268 const TemplateArgument &Arg,
2269 TemplateArgumentLoc &Output) {
2270 SourceLocation Loc = getDerived().getBaseLocation();
2271 switch (Arg.getKind()) {
2272 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002273 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002274 break;
2275
2276 case TemplateArgument::Type:
2277 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002278 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002279
John McCall0ad16662009-10-29 08:12:44 +00002280 break;
2281
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002282 case TemplateArgument::Template:
2283 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2284 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002285
John McCall0ad16662009-10-29 08:12:44 +00002286 case TemplateArgument::Expression:
2287 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2288 break;
2289
2290 case TemplateArgument::Declaration:
2291 case TemplateArgument::Integral:
2292 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002293 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002294 break;
2295 }
2296}
2297
2298template<typename Derived>
2299bool TreeTransform<Derived>::TransformTemplateArgument(
2300 const TemplateArgumentLoc &Input,
2301 TemplateArgumentLoc &Output) {
2302 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002303 switch (Arg.getKind()) {
2304 case TemplateArgument::Null:
2305 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002306 Output = Input;
2307 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002308
Douglas Gregore922c772009-08-04 22:27:00 +00002309 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002310 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002311 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002312 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002313
2314 DI = getDerived().TransformType(DI);
2315 if (!DI) return true;
2316
2317 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2318 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002319 }
Mike Stump11289f42009-09-09 15:08:12 +00002320
Douglas Gregore922c772009-08-04 22:27:00 +00002321 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002322 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002323 DeclarationName Name;
2324 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2325 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002326 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002327 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002328 if (!D) return true;
2329
John McCall0d07eb32009-10-29 18:45:58 +00002330 Expr *SourceExpr = Input.getSourceDeclExpression();
2331 if (SourceExpr) {
2332 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002333 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002334 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002335 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002336 }
2337
2338 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002339 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002340 }
Mike Stump11289f42009-09-09 15:08:12 +00002341
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002342 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002343 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002344 TemplateName Template
2345 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2346 if (Template.isNull())
2347 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002348
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002349 Output = TemplateArgumentLoc(TemplateArgument(Template),
2350 Input.getTemplateQualifierRange(),
2351 Input.getTemplateNameLoc());
2352 return false;
2353 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002354
Douglas Gregore922c772009-08-04 22:27:00 +00002355 case TemplateArgument::Expression: {
2356 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002357 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002358 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002359
John McCall0ad16662009-10-29 08:12:44 +00002360 Expr *InputExpr = Input.getSourceExpression();
2361 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2362
John McCalldadc5752010-08-24 06:29:42 +00002363 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002364 = getDerived().TransformExpr(InputExpr);
2365 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002366 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002367 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002368 }
Mike Stump11289f42009-09-09 15:08:12 +00002369
Douglas Gregore922c772009-08-04 22:27:00 +00002370 case TemplateArgument::Pack: {
2371 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2372 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002373 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002374 AEnd = Arg.pack_end();
2375 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002376
John McCall0ad16662009-10-29 08:12:44 +00002377 // FIXME: preserve source information here when we start
2378 // caring about parameter packs.
2379
John McCall0d07eb32009-10-29 18:45:58 +00002380 TemplateArgumentLoc InputArg;
2381 TemplateArgumentLoc OutputArg;
2382 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2383 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002384 return true;
2385
John McCall0d07eb32009-10-29 18:45:58 +00002386 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002387 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002388
2389 TemplateArgument *TransformedArgsPtr
2390 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2391 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2392 TransformedArgsPtr);
2393 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2394 TransformedArgs.size()),
2395 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002396 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002397 }
2398 }
Mike Stump11289f42009-09-09 15:08:12 +00002399
Douglas Gregore922c772009-08-04 22:27:00 +00002400 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002401 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002402}
2403
Douglas Gregord6ff3322009-08-04 16:50:30 +00002404//===----------------------------------------------------------------------===//
2405// Type transformation
2406//===----------------------------------------------------------------------===//
2407
2408template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002409QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002410 if (getDerived().AlreadyTransformed(T))
2411 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002412
John McCall550e0c22009-10-21 00:40:46 +00002413 // Temporary workaround. All of these transformations should
2414 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002415 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002416 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002417
John McCall31f82722010-11-12 08:19:04 +00002418 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002419
John McCall550e0c22009-10-21 00:40:46 +00002420 if (!NewDI)
2421 return QualType();
2422
2423 return NewDI->getType();
2424}
2425
2426template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002427TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002428 if (getDerived().AlreadyTransformed(DI->getType()))
2429 return DI;
2430
2431 TypeLocBuilder TLB;
2432
2433 TypeLoc TL = DI->getTypeLoc();
2434 TLB.reserve(TL.getFullDataSize());
2435
John McCall31f82722010-11-12 08:19:04 +00002436 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002437 if (Result.isNull())
2438 return 0;
2439
John McCallbcd03502009-12-07 02:54:59 +00002440 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002441}
2442
2443template<typename Derived>
2444QualType
John McCall31f82722010-11-12 08:19:04 +00002445TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002446 switch (T.getTypeLocClass()) {
2447#define ABSTRACT_TYPELOC(CLASS, PARENT)
2448#define TYPELOC(CLASS, PARENT) \
2449 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002450 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002451#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002452 }
Mike Stump11289f42009-09-09 15:08:12 +00002453
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002454 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002455 return QualType();
2456}
2457
2458/// FIXME: By default, this routine adds type qualifiers only to types
2459/// that can have qualifiers, and silently suppresses those qualifiers
2460/// that are not permitted (e.g., qualifiers on reference or function
2461/// types). This is the right thing for template instantiation, but
2462/// probably not for other clients.
2463template<typename Derived>
2464QualType
2465TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002466 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002467 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002468
John McCall31f82722010-11-12 08:19:04 +00002469 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002470 if (Result.isNull())
2471 return QualType();
2472
2473 // Silently suppress qualifiers if the result type can't be qualified.
2474 // FIXME: this is the right thing for template instantiation, but
2475 // probably not for other clients.
2476 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002477 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002478
John McCallcb0f89a2010-06-05 06:41:15 +00002479 if (!Quals.empty()) {
2480 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2481 TLB.push<QualifiedTypeLoc>(Result);
2482 // No location information to preserve.
2483 }
John McCall550e0c22009-10-21 00:40:46 +00002484
2485 return Result;
2486}
2487
John McCall31f82722010-11-12 08:19:04 +00002488/// \brief Transforms a type that was written in a scope specifier,
2489/// given an object type, the results of unqualified lookup, and
2490/// an already-instantiated prefix.
2491///
2492/// The object type is provided iff the scope specifier qualifies the
2493/// member of a dependent member-access expression. The prefix is
2494/// provided iff the the scope specifier in which this appears has a
2495/// prefix.
2496///
2497/// This is private to TreeTransform.
2498template<typename Derived>
2499QualType
2500TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2501 QualType ObjectType,
2502 NamedDecl *UnqualLookup,
2503 NestedNameSpecifier *Prefix) {
2504 if (getDerived().AlreadyTransformed(T))
2505 return T;
2506
2507 TypeSourceInfo *TSI =
2508 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2509
2510 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2511 UnqualLookup, Prefix);
2512 if (!TSI) return QualType();
2513 return TSI->getType();
2514}
2515
2516template<typename Derived>
2517TypeSourceInfo *
2518TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2519 QualType ObjectType,
2520 NamedDecl *UnqualLookup,
2521 NestedNameSpecifier *Prefix) {
2522 // TODO: in some cases, we might be some verification to do here.
2523 if (ObjectType.isNull())
2524 return getDerived().TransformType(TSI);
2525
2526 QualType T = TSI->getType();
2527 if (getDerived().AlreadyTransformed(T))
2528 return TSI;
2529
2530 TypeLocBuilder TLB;
2531 QualType Result;
2532
2533 if (isa<TemplateSpecializationType>(T)) {
2534 TemplateSpecializationTypeLoc TL
2535 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2536
2537 TemplateName Template =
2538 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2539 ObjectType, UnqualLookup);
2540 if (Template.isNull()) return 0;
2541
2542 Result = getDerived()
2543 .TransformTemplateSpecializationType(TLB, TL, Template);
2544 } else if (isa<DependentTemplateSpecializationType>(T)) {
2545 DependentTemplateSpecializationTypeLoc TL
2546 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2547
2548 Result = getDerived()
2549 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2550 } else {
2551 // Nothing special needs to be done for these.
2552 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2553 }
2554
2555 if (Result.isNull()) return 0;
2556 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2557}
2558
John McCall550e0c22009-10-21 00:40:46 +00002559template <class TyLoc> static inline
2560QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2561 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2562 NewT.setNameLoc(T.getNameLoc());
2563 return T.getType();
2564}
2565
John McCall550e0c22009-10-21 00:40:46 +00002566template<typename Derived>
2567QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002568 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002569 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2570 NewT.setBuiltinLoc(T.getBuiltinLoc());
2571 if (T.needsExtraLocalData())
2572 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2573 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002574}
Mike Stump11289f42009-09-09 15:08:12 +00002575
Douglas Gregord6ff3322009-08-04 16:50:30 +00002576template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002577QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002578 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002579 // FIXME: recurse?
2580 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002581}
Mike Stump11289f42009-09-09 15:08:12 +00002582
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002584QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002585 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002586 QualType PointeeType
2587 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002588 if (PointeeType.isNull())
2589 return QualType();
2590
2591 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002592 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002593 // A dependent pointer type 'T *' has is being transformed such
2594 // that an Objective-C class type is being replaced for 'T'. The
2595 // resulting pointer type is an ObjCObjectPointerType, not a
2596 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002597 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002598
John McCall8b07ec22010-05-15 11:32:37 +00002599 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2600 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002601 return Result;
2602 }
John McCall31f82722010-11-12 08:19:04 +00002603
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002604 if (getDerived().AlwaysRebuild() ||
2605 PointeeType != TL.getPointeeLoc().getType()) {
2606 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2607 if (Result.isNull())
2608 return QualType();
2609 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002610
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002611 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2612 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002613 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002614}
Mike Stump11289f42009-09-09 15:08:12 +00002615
2616template<typename Derived>
2617QualType
John McCall550e0c22009-10-21 00:40:46 +00002618TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002619 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002620 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002621 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2622 if (PointeeType.isNull())
2623 return QualType();
2624
2625 QualType Result = TL.getType();
2626 if (getDerived().AlwaysRebuild() ||
2627 PointeeType != TL.getPointeeLoc().getType()) {
2628 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002629 TL.getSigilLoc());
2630 if (Result.isNull())
2631 return QualType();
2632 }
2633
Douglas Gregor049211a2010-04-22 16:50:51 +00002634 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002635 NewT.setSigilLoc(TL.getSigilLoc());
2636 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002637}
2638
John McCall70dd5f62009-10-30 00:06:24 +00002639/// Transforms a reference type. Note that somewhat paradoxically we
2640/// don't care whether the type itself is an l-value type or an r-value
2641/// type; we only care if the type was *written* as an l-value type
2642/// or an r-value type.
2643template<typename Derived>
2644QualType
2645TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002646 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002647 const ReferenceType *T = TL.getTypePtr();
2648
2649 // Note that this works with the pointee-as-written.
2650 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2651 if (PointeeType.isNull())
2652 return QualType();
2653
2654 QualType Result = TL.getType();
2655 if (getDerived().AlwaysRebuild() ||
2656 PointeeType != T->getPointeeTypeAsWritten()) {
2657 Result = getDerived().RebuildReferenceType(PointeeType,
2658 T->isSpelledAsLValue(),
2659 TL.getSigilLoc());
2660 if (Result.isNull())
2661 return QualType();
2662 }
2663
2664 // r-value references can be rebuilt as l-value references.
2665 ReferenceTypeLoc NewTL;
2666 if (isa<LValueReferenceType>(Result))
2667 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2668 else
2669 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2670 NewTL.setSigilLoc(TL.getSigilLoc());
2671
2672 return Result;
2673}
2674
Mike Stump11289f42009-09-09 15:08:12 +00002675template<typename Derived>
2676QualType
John McCall550e0c22009-10-21 00:40:46 +00002677TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002678 LValueReferenceTypeLoc TL) {
2679 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002680}
2681
Mike Stump11289f42009-09-09 15:08:12 +00002682template<typename Derived>
2683QualType
John McCall550e0c22009-10-21 00:40:46 +00002684TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002685 RValueReferenceTypeLoc TL) {
2686 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002687}
Mike Stump11289f42009-09-09 15:08:12 +00002688
Douglas Gregord6ff3322009-08-04 16:50:30 +00002689template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002690QualType
John McCall550e0c22009-10-21 00:40:46 +00002691TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002692 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002693 MemberPointerType *T = TL.getTypePtr();
2694
2695 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002696 if (PointeeType.isNull())
2697 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002698
John McCall550e0c22009-10-21 00:40:46 +00002699 // TODO: preserve source information for this.
2700 QualType ClassType
2701 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002702 if (ClassType.isNull())
2703 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002704
John McCall550e0c22009-10-21 00:40:46 +00002705 QualType Result = TL.getType();
2706 if (getDerived().AlwaysRebuild() ||
2707 PointeeType != T->getPointeeType() ||
2708 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002709 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2710 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002711 if (Result.isNull())
2712 return QualType();
2713 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002714
John McCall550e0c22009-10-21 00:40:46 +00002715 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2716 NewTL.setSigilLoc(TL.getSigilLoc());
2717
2718 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002719}
2720
Mike Stump11289f42009-09-09 15:08:12 +00002721template<typename Derived>
2722QualType
John McCall550e0c22009-10-21 00:40:46 +00002723TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002724 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002725 ConstantArrayType *T = TL.getTypePtr();
2726 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002727 if (ElementType.isNull())
2728 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002729
John McCall550e0c22009-10-21 00:40:46 +00002730 QualType Result = TL.getType();
2731 if (getDerived().AlwaysRebuild() ||
2732 ElementType != T->getElementType()) {
2733 Result = getDerived().RebuildConstantArrayType(ElementType,
2734 T->getSizeModifier(),
2735 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002736 T->getIndexTypeCVRQualifiers(),
2737 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002738 if (Result.isNull())
2739 return QualType();
2740 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002741
John McCall550e0c22009-10-21 00:40:46 +00002742 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2743 NewTL.setLBracketLoc(TL.getLBracketLoc());
2744 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002745
John McCall550e0c22009-10-21 00:40:46 +00002746 Expr *Size = TL.getSizeExpr();
2747 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002748 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002749 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2750 }
2751 NewTL.setSizeExpr(Size);
2752
2753 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002754}
Mike Stump11289f42009-09-09 15:08:12 +00002755
Douglas Gregord6ff3322009-08-04 16:50:30 +00002756template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002757QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002758 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002759 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002760 IncompleteArrayType *T = TL.getTypePtr();
2761 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002762 if (ElementType.isNull())
2763 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002764
John McCall550e0c22009-10-21 00:40:46 +00002765 QualType Result = TL.getType();
2766 if (getDerived().AlwaysRebuild() ||
2767 ElementType != T->getElementType()) {
2768 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002769 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002770 T->getIndexTypeCVRQualifiers(),
2771 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002772 if (Result.isNull())
2773 return QualType();
2774 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002775
John McCall550e0c22009-10-21 00:40:46 +00002776 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2777 NewTL.setLBracketLoc(TL.getLBracketLoc());
2778 NewTL.setRBracketLoc(TL.getRBracketLoc());
2779 NewTL.setSizeExpr(0);
2780
2781 return Result;
2782}
2783
2784template<typename Derived>
2785QualType
2786TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002787 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002788 VariableArrayType *T = TL.getTypePtr();
2789 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2790 if (ElementType.isNull())
2791 return QualType();
2792
2793 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002794 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002795
John McCalldadc5752010-08-24 06:29:42 +00002796 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002797 = getDerived().TransformExpr(T->getSizeExpr());
2798 if (SizeResult.isInvalid())
2799 return QualType();
2800
John McCallb268a282010-08-23 23:25:46 +00002801 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002802
2803 QualType Result = TL.getType();
2804 if (getDerived().AlwaysRebuild() ||
2805 ElementType != T->getElementType() ||
2806 Size != T->getSizeExpr()) {
2807 Result = getDerived().RebuildVariableArrayType(ElementType,
2808 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002809 Size,
John McCall550e0c22009-10-21 00:40:46 +00002810 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002811 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002812 if (Result.isNull())
2813 return QualType();
2814 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002815
John McCall550e0c22009-10-21 00:40:46 +00002816 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2817 NewTL.setLBracketLoc(TL.getLBracketLoc());
2818 NewTL.setRBracketLoc(TL.getRBracketLoc());
2819 NewTL.setSizeExpr(Size);
2820
2821 return Result;
2822}
2823
2824template<typename Derived>
2825QualType
2826TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002827 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002828 DependentSizedArrayType *T = TL.getTypePtr();
2829 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2830 if (ElementType.isNull())
2831 return QualType();
2832
2833 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002834 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002835
John McCalldadc5752010-08-24 06:29:42 +00002836 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002837 = getDerived().TransformExpr(T->getSizeExpr());
2838 if (SizeResult.isInvalid())
2839 return QualType();
2840
2841 Expr *Size = static_cast<Expr*>(SizeResult.get());
2842
2843 QualType Result = TL.getType();
2844 if (getDerived().AlwaysRebuild() ||
2845 ElementType != T->getElementType() ||
2846 Size != T->getSizeExpr()) {
2847 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2848 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002849 Size,
John McCall550e0c22009-10-21 00:40:46 +00002850 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002851 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002852 if (Result.isNull())
2853 return QualType();
2854 }
2855 else SizeResult.take();
2856
2857 // We might have any sort of array type now, but fortunately they
2858 // all have the same location layout.
2859 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2860 NewTL.setLBracketLoc(TL.getLBracketLoc());
2861 NewTL.setRBracketLoc(TL.getRBracketLoc());
2862 NewTL.setSizeExpr(Size);
2863
2864 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002865}
Mike Stump11289f42009-09-09 15:08:12 +00002866
2867template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002868QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002869 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002870 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002871 DependentSizedExtVectorType *T = TL.getTypePtr();
2872
2873 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002874 QualType ElementType = getDerived().TransformType(T->getElementType());
2875 if (ElementType.isNull())
2876 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002877
Douglas Gregore922c772009-08-04 22:27:00 +00002878 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002879 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002880
John McCalldadc5752010-08-24 06:29:42 +00002881 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002882 if (Size.isInvalid())
2883 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002884
John McCall550e0c22009-10-21 00:40:46 +00002885 QualType Result = TL.getType();
2886 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002887 ElementType != T->getElementType() ||
2888 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002889 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002890 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002891 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002892 if (Result.isNull())
2893 return QualType();
2894 }
John McCall550e0c22009-10-21 00:40:46 +00002895
2896 // Result might be dependent or not.
2897 if (isa<DependentSizedExtVectorType>(Result)) {
2898 DependentSizedExtVectorTypeLoc NewTL
2899 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2900 NewTL.setNameLoc(TL.getNameLoc());
2901 } else {
2902 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2903 NewTL.setNameLoc(TL.getNameLoc());
2904 }
2905
2906 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002907}
Mike Stump11289f42009-09-09 15:08:12 +00002908
2909template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002910QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002911 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002912 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002913 QualType ElementType = getDerived().TransformType(T->getElementType());
2914 if (ElementType.isNull())
2915 return QualType();
2916
John McCall550e0c22009-10-21 00:40:46 +00002917 QualType Result = TL.getType();
2918 if (getDerived().AlwaysRebuild() ||
2919 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002920 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00002921 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00002922 if (Result.isNull())
2923 return QualType();
2924 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002925
John McCall550e0c22009-10-21 00:40:46 +00002926 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2927 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002928
John McCall550e0c22009-10-21 00:40:46 +00002929 return Result;
2930}
2931
2932template<typename Derived>
2933QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002934 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002935 VectorType *T = TL.getTypePtr();
2936 QualType ElementType = getDerived().TransformType(T->getElementType());
2937 if (ElementType.isNull())
2938 return QualType();
2939
2940 QualType Result = TL.getType();
2941 if (getDerived().AlwaysRebuild() ||
2942 ElementType != T->getElementType()) {
2943 Result = getDerived().RebuildExtVectorType(ElementType,
2944 T->getNumElements(),
2945 /*FIXME*/ SourceLocation());
2946 if (Result.isNull())
2947 return QualType();
2948 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002949
John McCall550e0c22009-10-21 00:40:46 +00002950 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2951 NewTL.setNameLoc(TL.getNameLoc());
2952
2953 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002954}
Mike Stump11289f42009-09-09 15:08:12 +00002955
2956template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002957ParmVarDecl *
2958TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2959 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2960 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2961 if (!NewDI)
2962 return 0;
2963
2964 if (NewDI == OldDI)
2965 return OldParm;
2966 else
2967 return ParmVarDecl::Create(SemaRef.Context,
2968 OldParm->getDeclContext(),
2969 OldParm->getLocation(),
2970 OldParm->getIdentifier(),
2971 NewDI->getType(),
2972 NewDI,
2973 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002974 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002975 /* DefArg */ NULL);
2976}
2977
2978template<typename Derived>
2979bool TreeTransform<Derived>::
2980 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2981 llvm::SmallVectorImpl<QualType> &PTypes,
2982 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2983 FunctionProtoType *T = TL.getTypePtr();
2984
2985 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2986 ParmVarDecl *OldParm = TL.getArg(i);
2987
2988 QualType NewType;
2989 ParmVarDecl *NewParm;
2990
2991 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002992 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2993 if (!NewParm)
2994 return true;
2995 NewType = NewParm->getType();
2996
2997 // Deal with the possibility that we don't have a parameter
2998 // declaration for this parameter.
2999 } else {
3000 NewParm = 0;
3001
3002 QualType OldType = T->getArgType(i);
3003 NewType = getDerived().TransformType(OldType);
3004 if (NewType.isNull())
3005 return true;
3006 }
3007
3008 PTypes.push_back(NewType);
3009 PVars.push_back(NewParm);
3010 }
3011
3012 return false;
3013}
3014
3015template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003016QualType
John McCall550e0c22009-10-21 00:40:46 +00003017TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003018 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003019 // Transform the parameters and return type.
3020 //
3021 // We instantiate in source order, with the return type first followed by
3022 // the parameters, because users tend to expect this (even if they shouldn't
3023 // rely on it!).
3024 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003025 // When the function has a trailing return type, we instantiate the
3026 // parameters before the return type, since the return type can then refer
3027 // to the parameters themselves (via decltype, sizeof, etc.).
3028 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003029 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003030 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003031 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003032
Douglas Gregor7fb25412010-10-01 18:44:50 +00003033 QualType ResultType;
3034
3035 if (TL.getTrailingReturn()) {
3036 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3037 return QualType();
3038
3039 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3040 if (ResultType.isNull())
3041 return QualType();
3042 }
3043 else {
3044 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3045 if (ResultType.isNull())
3046 return QualType();
3047
3048 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3049 return QualType();
3050 }
3051
John McCall550e0c22009-10-21 00:40:46 +00003052 QualType Result = TL.getType();
3053 if (getDerived().AlwaysRebuild() ||
3054 ResultType != T->getResultType() ||
3055 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3056 Result = getDerived().RebuildFunctionProtoType(ResultType,
3057 ParamTypes.data(),
3058 ParamTypes.size(),
3059 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003060 T->getTypeQuals(),
3061 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003062 if (Result.isNull())
3063 return QualType();
3064 }
Mike Stump11289f42009-09-09 15:08:12 +00003065
John McCall550e0c22009-10-21 00:40:46 +00003066 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3067 NewTL.setLParenLoc(TL.getLParenLoc());
3068 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003069 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003070 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3071 NewTL.setArg(i, ParamDecls[i]);
3072
3073 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003074}
Mike Stump11289f42009-09-09 15:08:12 +00003075
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076template<typename Derived>
3077QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003078 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003079 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003080 FunctionNoProtoType *T = TL.getTypePtr();
3081 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3082 if (ResultType.isNull())
3083 return QualType();
3084
3085 QualType Result = TL.getType();
3086 if (getDerived().AlwaysRebuild() ||
3087 ResultType != T->getResultType())
3088 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3089
3090 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3091 NewTL.setLParenLoc(TL.getLParenLoc());
3092 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003093 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003094
3095 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003096}
Mike Stump11289f42009-09-09 15:08:12 +00003097
John McCallb96ec562009-12-04 22:46:56 +00003098template<typename Derived> QualType
3099TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003100 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003101 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003102 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003103 if (!D)
3104 return QualType();
3105
3106 QualType Result = TL.getType();
3107 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3108 Result = getDerived().RebuildUnresolvedUsingType(D);
3109 if (Result.isNull())
3110 return QualType();
3111 }
3112
3113 // We might get an arbitrary type spec type back. We should at
3114 // least always get a type spec type, though.
3115 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3116 NewTL.setNameLoc(TL.getNameLoc());
3117
3118 return Result;
3119}
3120
Douglas Gregord6ff3322009-08-04 16:50:30 +00003121template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003122QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003123 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003124 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003125 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003126 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3127 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 if (!Typedef)
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 Typedef != T->getDecl()) {
3134 Result = getDerived().RebuildTypedefType(Typedef);
3135 if (Result.isNull())
3136 return QualType();
3137 }
Mike Stump11289f42009-09-09 15:08:12 +00003138
John McCall550e0c22009-10-21 00:40:46 +00003139 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3140 NewTL.setNameLoc(TL.getNameLoc());
3141
3142 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003143}
Mike Stump11289f42009-09-09 15:08:12 +00003144
Douglas Gregord6ff3322009-08-04 16:50:30 +00003145template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003146QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003147 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003148 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003149 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003150
John McCalldadc5752010-08-24 06:29:42 +00003151 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152 if (E.isInvalid())
3153 return QualType();
3154
John McCall550e0c22009-10-21 00:40:46 +00003155 QualType Result = TL.getType();
3156 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003157 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003158 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003159 if (Result.isNull())
3160 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003161 }
John McCall550e0c22009-10-21 00:40:46 +00003162 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003163
John McCall550e0c22009-10-21 00:40:46 +00003164 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003165 NewTL.setTypeofLoc(TL.getTypeofLoc());
3166 NewTL.setLParenLoc(TL.getLParenLoc());
3167 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003168
3169 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003170}
Mike Stump11289f42009-09-09 15:08:12 +00003171
3172template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003173QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003174 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003175 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3176 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3177 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003178 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003179
John McCall550e0c22009-10-21 00:40:46 +00003180 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003181 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3182 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003183 if (Result.isNull())
3184 return QualType();
3185 }
Mike Stump11289f42009-09-09 15:08:12 +00003186
John McCall550e0c22009-10-21 00:40:46 +00003187 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003188 NewTL.setTypeofLoc(TL.getTypeofLoc());
3189 NewTL.setLParenLoc(TL.getLParenLoc());
3190 NewTL.setRParenLoc(TL.getRParenLoc());
3191 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003192
3193 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003194}
Mike Stump11289f42009-09-09 15:08:12 +00003195
3196template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003197QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003198 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003199 DecltypeType *T = TL.getTypePtr();
3200
Douglas Gregore922c772009-08-04 22:27:00 +00003201 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003202 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003203
John McCalldadc5752010-08-24 06:29:42 +00003204 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003205 if (E.isInvalid())
3206 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003207
John McCall550e0c22009-10-21 00:40:46 +00003208 QualType Result = TL.getType();
3209 if (getDerived().AlwaysRebuild() ||
3210 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003211 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003212 if (Result.isNull())
3213 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003214 }
John McCall550e0c22009-10-21 00:40:46 +00003215 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003216
John McCall550e0c22009-10-21 00:40:46 +00003217 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3218 NewTL.setNameLoc(TL.getNameLoc());
3219
3220 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003221}
3222
3223template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003224QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003225 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003226 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003227 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003228 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3229 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003230 if (!Record)
3231 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003232
John McCall550e0c22009-10-21 00:40:46 +00003233 QualType Result = TL.getType();
3234 if (getDerived().AlwaysRebuild() ||
3235 Record != T->getDecl()) {
3236 Result = getDerived().RebuildRecordType(Record);
3237 if (Result.isNull())
3238 return QualType();
3239 }
Mike Stump11289f42009-09-09 15:08:12 +00003240
John McCall550e0c22009-10-21 00:40:46 +00003241 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3242 NewTL.setNameLoc(TL.getNameLoc());
3243
3244 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 TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003249 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003250 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003252 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3253 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003254 if (!Enum)
3255 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003256
John McCall550e0c22009-10-21 00:40:46 +00003257 QualType Result = TL.getType();
3258 if (getDerived().AlwaysRebuild() ||
3259 Enum != T->getDecl()) {
3260 Result = getDerived().RebuildEnumType(Enum);
3261 if (Result.isNull())
3262 return QualType();
3263 }
Mike Stump11289f42009-09-09 15:08:12 +00003264
John McCall550e0c22009-10-21 00:40:46 +00003265 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3266 NewTL.setNameLoc(TL.getNameLoc());
3267
3268 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003269}
John McCallfcc33b02009-09-05 00:15:47 +00003270
John McCalle78aac42010-03-10 03:28:59 +00003271template<typename Derived>
3272QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3273 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003274 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003275 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3276 TL.getTypePtr()->getDecl());
3277 if (!D) return QualType();
3278
3279 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3280 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3281 return T;
3282}
3283
Mike Stump11289f42009-09-09 15:08:12 +00003284
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285template<typename Derived>
3286QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003287 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003288 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003289 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290}
3291
Mike Stump11289f42009-09-09 15:08:12 +00003292template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003293QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003294 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003295 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003296 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003297}
3298
3299template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003300QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003301 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003302 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003303 const TemplateSpecializationType *T = TL.getTypePtr();
3304
Mike Stump11289f42009-09-09 15:08:12 +00003305 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003306 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003307 if (Template.isNull())
3308 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003309
John McCall31f82722010-11-12 08:19:04 +00003310 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3311}
3312
3313template <typename Derived>
3314QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3315 TypeLocBuilder &TLB,
3316 TemplateSpecializationTypeLoc TL,
3317 TemplateName Template) {
3318 const TemplateSpecializationType *T = TL.getTypePtr();
3319
John McCall6b51f282009-11-23 01:53:49 +00003320 TemplateArgumentListInfo NewTemplateArgs;
3321 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3322 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3323
3324 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3325 TemplateArgumentLoc Loc;
3326 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003328 NewTemplateArgs.addArgument(Loc);
3329 }
Mike Stump11289f42009-09-09 15:08:12 +00003330
John McCall0ad16662009-10-29 08:12:44 +00003331 // FIXME: maybe don't rebuild if all the template arguments are the same.
3332
3333 QualType Result =
3334 getDerived().RebuildTemplateSpecializationType(Template,
3335 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003336 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003337
3338 if (!Result.isNull()) {
3339 TemplateSpecializationTypeLoc NewTL
3340 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3341 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3342 NewTL.setLAngleLoc(TL.getLAngleLoc());
3343 NewTL.setRAngleLoc(TL.getRAngleLoc());
3344 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3345 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003346 }
Mike Stump11289f42009-09-09 15:08:12 +00003347
John McCall0ad16662009-10-29 08:12:44 +00003348 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003349}
Mike Stump11289f42009-09-09 15:08:12 +00003350
3351template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003352QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003353TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003354 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003355 ElaboratedType *T = TL.getTypePtr();
3356
3357 NestedNameSpecifier *NNS = 0;
3358 // NOTE: the qualifier in an ElaboratedType is optional.
3359 if (T->getQualifier() != 0) {
3360 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003361 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003362 if (!NNS)
3363 return QualType();
3364 }
Mike Stump11289f42009-09-09 15:08:12 +00003365
John McCall31f82722010-11-12 08:19:04 +00003366 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3367 if (NamedT.isNull())
3368 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003369
John McCall550e0c22009-10-21 00:40:46 +00003370 QualType Result = TL.getType();
3371 if (getDerived().AlwaysRebuild() ||
3372 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003373 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003374 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3375 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003376 if (Result.isNull())
3377 return QualType();
3378 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003379
Abramo Bagnara6150c882010-05-11 21:36:43 +00003380 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003381 NewTL.setKeywordLoc(TL.getKeywordLoc());
3382 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003383
3384 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003385}
Mike Stump11289f42009-09-09 15:08:12 +00003386
3387template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003388QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003389 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003390 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003391
Douglas Gregord6ff3322009-08-04 16:50:30 +00003392 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003393 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003394 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003395 if (!NNS)
3396 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003397
John McCallc392f372010-06-11 00:33:02 +00003398 QualType Result
3399 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3400 T->getIdentifier(),
3401 TL.getKeywordLoc(),
3402 TL.getQualifierRange(),
3403 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003404 if (Result.isNull())
3405 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003406
Abramo Bagnarad7548482010-05-19 21:37:53 +00003407 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3408 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003409 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3410
Abramo Bagnarad7548482010-05-19 21:37:53 +00003411 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3412 NewTL.setKeywordLoc(TL.getKeywordLoc());
3413 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003414 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003415 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3416 NewTL.setKeywordLoc(TL.getKeywordLoc());
3417 NewTL.setQualifierRange(TL.getQualifierRange());
3418 NewTL.setNameLoc(TL.getNameLoc());
3419 }
John McCall550e0c22009-10-21 00:40:46 +00003420 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003421}
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregord6ff3322009-08-04 16:50:30 +00003423template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003424QualType TreeTransform<Derived>::
3425 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003426 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003427 DependentTemplateSpecializationType *T = TL.getTypePtr();
3428
3429 NestedNameSpecifier *NNS
3430 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003431 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003432 if (!NNS)
3433 return QualType();
3434
John McCall31f82722010-11-12 08:19:04 +00003435 return getDerived()
3436 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3437}
3438
3439template<typename Derived>
3440QualType TreeTransform<Derived>::
3441 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3442 DependentTemplateSpecializationTypeLoc TL,
3443 NestedNameSpecifier *NNS) {
3444 DependentTemplateSpecializationType *T = TL.getTypePtr();
3445
John McCallc392f372010-06-11 00:33:02 +00003446 TemplateArgumentListInfo NewTemplateArgs;
3447 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3448 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3449
3450 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3451 TemplateArgumentLoc Loc;
3452 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3453 return QualType();
3454 NewTemplateArgs.addArgument(Loc);
3455 }
3456
Douglas Gregora5614c52010-09-08 23:56:00 +00003457 QualType Result
3458 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3459 NNS,
3460 TL.getQualifierRange(),
3461 T->getIdentifier(),
3462 TL.getNameLoc(),
3463 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003464 if (Result.isNull())
3465 return QualType();
3466
3467 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3468 QualType NamedT = ElabT->getNamedType();
3469
3470 // Copy information relevant to the template specialization.
3471 TemplateSpecializationTypeLoc NamedTL
3472 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3473 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3474 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3475 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3476 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3477
3478 // Copy information relevant to the elaborated type.
3479 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3480 NewTL.setKeywordLoc(TL.getKeywordLoc());
3481 NewTL.setQualifierRange(TL.getQualifierRange());
3482 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003483 TypeLoc NewTL(Result, TL.getOpaqueData());
3484 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003485 }
3486 return Result;
3487}
3488
3489template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003490QualType
3491TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003492 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003493 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003494 TLB.pushFullCopy(TL);
3495 return TL.getType();
3496}
3497
3498template<typename Derived>
3499QualType
3500TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003501 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003502 // ObjCObjectType is never dependent.
3503 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003504 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003505}
Mike Stump11289f42009-09-09 15:08:12 +00003506
3507template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003508QualType
3509TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003510 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003511 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003512 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003513 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003514}
3515
Douglas Gregord6ff3322009-08-04 16:50:30 +00003516//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003517// Statement transformation
3518//===----------------------------------------------------------------------===//
3519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003520StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003521TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003522 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003523}
3524
3525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003526StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003527TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3528 return getDerived().TransformCompoundStmt(S, false);
3529}
3530
3531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003532StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003533TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003534 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003535 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003537 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003538 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3539 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003540 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003541 if (Result.isInvalid()) {
3542 // Immediately fail if this was a DeclStmt, since it's very
3543 // likely that this will cause problems for future statements.
3544 if (isa<DeclStmt>(*B))
3545 return StmtError();
3546
3547 // Otherwise, just keep processing substatements and fail later.
3548 SubStmtInvalid = true;
3549 continue;
3550 }
Mike Stump11289f42009-09-09 15:08:12 +00003551
Douglas Gregorebe10102009-08-20 07:17:43 +00003552 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3553 Statements.push_back(Result.takeAs<Stmt>());
3554 }
Mike Stump11289f42009-09-09 15:08:12 +00003555
John McCall1ababa62010-08-27 19:56:05 +00003556 if (SubStmtInvalid)
3557 return StmtError();
3558
Douglas Gregorebe10102009-08-20 07:17:43 +00003559 if (!getDerived().AlwaysRebuild() &&
3560 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003561 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003562
3563 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3564 move_arg(Statements),
3565 S->getRBracLoc(),
3566 IsStmtExpr);
3567}
Mike Stump11289f42009-09-09 15:08:12 +00003568
Douglas Gregorebe10102009-08-20 07:17:43 +00003569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003570StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003571TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003572 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003573 {
3574 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003575 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003576
Eli Friedman06577382009-11-19 03:14:00 +00003577 // Transform the left-hand case value.
3578 LHS = getDerived().TransformExpr(S->getLHS());
3579 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003580 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003581
Eli Friedman06577382009-11-19 03:14:00 +00003582 // Transform the right-hand case value (for the GNU case-range extension).
3583 RHS = getDerived().TransformExpr(S->getRHS());
3584 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003585 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003586 }
Mike Stump11289f42009-09-09 15:08:12 +00003587
Douglas Gregorebe10102009-08-20 07:17:43 +00003588 // Build the case statement.
3589 // Case statements are always rebuilt so that they will attached to their
3590 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003591 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003592 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003593 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003594 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003595 S->getColonLoc());
3596 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003597 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003598
Douglas Gregorebe10102009-08-20 07:17:43 +00003599 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003600 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003601 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003602 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregorebe10102009-08-20 07:17:43 +00003604 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003605 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003606}
3607
3608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003609StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003610TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003612 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003613 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003614 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003615
Douglas Gregorebe10102009-08-20 07:17:43 +00003616 // Default statements are always rebuilt
3617 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003618 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003619}
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregorebe10102009-08-20 07:17:43 +00003621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003622StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003623TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003624 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003625 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003626 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregorebe10102009-08-20 07:17:43 +00003628 // FIXME: Pass the real colon location in.
3629 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3630 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003631 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003632}
Mike Stump11289f42009-09-09 15:08:12 +00003633
Douglas Gregorebe10102009-08-20 07:17:43 +00003634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003635StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003636TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003637 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003638 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003639 VarDecl *ConditionVar = 0;
3640 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003641 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003642 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003643 getDerived().TransformDefinition(
3644 S->getConditionVariable()->getLocation(),
3645 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003646 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003647 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003648 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003649 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003650
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003651 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003652 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003653
3654 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003655 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003656 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003657 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003658 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003659 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003660 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003661
John McCallb268a282010-08-23 23:25:46 +00003662 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003663 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003664 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003665
John McCallb268a282010-08-23 23:25:46 +00003666 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3667 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003668 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003669
Douglas Gregorebe10102009-08-20 07:17:43 +00003670 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003671 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003672 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003673 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregorebe10102009-08-20 07:17:43 +00003675 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003676 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003677 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003678 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003679
Douglas Gregorebe10102009-08-20 07:17:43 +00003680 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003681 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003682 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003683 Then.get() == S->getThen() &&
3684 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00003685 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003686
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003687 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00003688 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00003689 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003690}
3691
3692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003693StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003694TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003695 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003696 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003697 VarDecl *ConditionVar = 0;
3698 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003699 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003700 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003701 getDerived().TransformDefinition(
3702 S->getConditionVariable()->getLocation(),
3703 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003704 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003705 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003706 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003707 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003708
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003709 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003710 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003711 }
Mike Stump11289f42009-09-09 15:08:12 +00003712
Douglas Gregorebe10102009-08-20 07:17:43 +00003713 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003714 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003715 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003716 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003717 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003718 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003719
Douglas Gregorebe10102009-08-20 07:17:43 +00003720 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003721 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003723 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003724
Douglas Gregorebe10102009-08-20 07:17:43 +00003725 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003726 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3727 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003728}
Mike Stump11289f42009-09-09 15:08:12 +00003729
Douglas Gregorebe10102009-08-20 07:17:43 +00003730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003731StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003732TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003733 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003734 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003735 VarDecl *ConditionVar = 0;
3736 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003737 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003738 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003739 getDerived().TransformDefinition(
3740 S->getConditionVariable()->getLocation(),
3741 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003742 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003743 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003744 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003745 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003746
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003747 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003748 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003749
3750 if (S->getCond()) {
3751 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003752 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003753 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003754 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003755 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003756 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003757 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003758 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003759 }
Mike Stump11289f42009-09-09 15:08:12 +00003760
John McCallb268a282010-08-23 23:25:46 +00003761 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3762 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003763 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003764
Douglas Gregorebe10102009-08-20 07:17:43 +00003765 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003766 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003767 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003768 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003769
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003771 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003772 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003773 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003774 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003775
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003776 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003777 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003778}
Mike Stump11289f42009-09-09 15:08:12 +00003779
Douglas Gregorebe10102009-08-20 07:17:43 +00003780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003781StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003782TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003783 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003784 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003785 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003786 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003787
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003788 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003789 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003790 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003791 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003792
Douglas Gregorebe10102009-08-20 07:17:43 +00003793 if (!getDerived().AlwaysRebuild() &&
3794 Cond.get() == S->getCond() &&
3795 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003796 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003797
John McCallb268a282010-08-23 23:25:46 +00003798 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3799 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003800 S->getRParenLoc());
3801}
Mike Stump11289f42009-09-09 15:08:12 +00003802
Douglas Gregorebe10102009-08-20 07:17:43 +00003803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003804StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003805TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003806 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003807 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003808 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003809 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003810
Douglas Gregorebe10102009-08-20 07:17:43 +00003811 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003812 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003813 VarDecl *ConditionVar = 0;
3814 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003815 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003816 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003817 getDerived().TransformDefinition(
3818 S->getConditionVariable()->getLocation(),
3819 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003820 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003821 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003822 } else {
3823 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003824
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003825 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003826 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003827
3828 if (S->getCond()) {
3829 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003830 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003831 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003832 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003833 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003834 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003835
John McCallb268a282010-08-23 23:25:46 +00003836 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003837 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003838 }
Mike Stump11289f42009-09-09 15:08:12 +00003839
John McCallb268a282010-08-23 23:25:46 +00003840 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3841 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003842 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003843
Douglas Gregorebe10102009-08-20 07:17:43 +00003844 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003845 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003846 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003847 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003848
John McCallb268a282010-08-23 23:25:46 +00003849 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3850 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003851 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003852
Douglas Gregorebe10102009-08-20 07:17:43 +00003853 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003854 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003855 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003856 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003857
Douglas Gregorebe10102009-08-20 07:17:43 +00003858 if (!getDerived().AlwaysRebuild() &&
3859 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003860 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003861 Inc.get() == S->getInc() &&
3862 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00003863 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003864
Douglas Gregorebe10102009-08-20 07:17:43 +00003865 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003866 Init.get(), FullCond, ConditionVar,
3867 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003868}
3869
3870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003871StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003872TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003873 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003874 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003875 S->getLabel());
3876}
3877
3878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003879StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003880TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003881 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003882 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003883 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003884
Douglas Gregorebe10102009-08-20 07:17:43 +00003885 if (!getDerived().AlwaysRebuild() &&
3886 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00003887 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003888
3889 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003890 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003891}
3892
3893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003894StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003895TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003896 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003897}
Mike Stump11289f42009-09-09 15:08:12 +00003898
Douglas Gregorebe10102009-08-20 07:17:43 +00003899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003900StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003901TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003902 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003903}
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregorebe10102009-08-20 07:17:43 +00003905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003906StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003907TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003908 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003909 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003910 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003911
Mike Stump11289f42009-09-09 15:08:12 +00003912 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003913 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003914 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003915}
Mike Stump11289f42009-09-09 15:08:12 +00003916
Douglas Gregorebe10102009-08-20 07:17:43 +00003917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003918StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003919TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003920 bool DeclChanged = false;
3921 llvm::SmallVector<Decl *, 4> Decls;
3922 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3923 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003924 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3925 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003926 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003927 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregorebe10102009-08-20 07:17:43 +00003929 if (Transformed != *D)
3930 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003931
Douglas Gregorebe10102009-08-20 07:17:43 +00003932 Decls.push_back(Transformed);
3933 }
Mike Stump11289f42009-09-09 15:08:12 +00003934
Douglas Gregorebe10102009-08-20 07:17:43 +00003935 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00003936 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003937
3938 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003939 S->getStartLoc(), S->getEndLoc());
3940}
Mike Stump11289f42009-09-09 15:08:12 +00003941
Douglas Gregorebe10102009-08-20 07:17:43 +00003942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003943StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003944TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003945 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00003946 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003947}
3948
3949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003950StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003951TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003952
John McCall37ad5512010-08-23 06:44:23 +00003953 ASTOwningVector<Expr*> Constraints(getSema());
3954 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003955 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003956
John McCalldadc5752010-08-24 06:29:42 +00003957 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003958 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003959
3960 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003961
Anders Carlssonaaeef072010-01-24 05:50:09 +00003962 // Go through the outputs.
3963 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003964 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003965
Anders Carlssonaaeef072010-01-24 05:50:09 +00003966 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003967 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003968
Anders Carlssonaaeef072010-01-24 05:50:09 +00003969 // Transform the output expr.
3970 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003971 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003972 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003973 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003974
Anders Carlssonaaeef072010-01-24 05:50:09 +00003975 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003976
John McCallb268a282010-08-23 23:25:46 +00003977 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003978 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003979
Anders Carlssonaaeef072010-01-24 05:50:09 +00003980 // Go through the inputs.
3981 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003982 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003983
Anders Carlssonaaeef072010-01-24 05:50:09 +00003984 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00003985 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003986
Anders Carlssonaaeef072010-01-24 05:50:09 +00003987 // Transform the input expr.
3988 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003989 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003990 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003991 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003992
Anders Carlssonaaeef072010-01-24 05:50:09 +00003993 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003994
John McCallb268a282010-08-23 23:25:46 +00003995 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003996 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003997
Anders Carlssonaaeef072010-01-24 05:50:09 +00003998 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00003999 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004000
4001 // Go through the clobbers.
4002 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004003 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004004
4005 // No need to transform the asm string literal.
4006 AsmString = SemaRef.Owned(S->getAsmString());
4007
4008 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4009 S->isSimple(),
4010 S->isVolatile(),
4011 S->getNumOutputs(),
4012 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004013 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004014 move_arg(Constraints),
4015 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004016 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004017 move_arg(Clobbers),
4018 S->getRParenLoc(),
4019 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004020}
4021
4022
4023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004024StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004025TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004026 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004027 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004028 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004029 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004030
Douglas Gregor96c79492010-04-23 22:50:49 +00004031 // Transform the @catch statements (if present).
4032 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004033 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004034 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004035 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004036 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004037 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004038 if (Catch.get() != S->getCatchStmt(I))
4039 AnyCatchChanged = true;
4040 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004041 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004042
Douglas Gregor306de2f2010-04-22 23:59:56 +00004043 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004044 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004045 if (S->getFinallyStmt()) {
4046 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4047 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004048 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004049 }
4050
4051 // If nothing changed, just retain this statement.
4052 if (!getDerived().AlwaysRebuild() &&
4053 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004054 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004055 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004056 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004057
Douglas Gregor306de2f2010-04-22 23:59:56 +00004058 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004059 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4060 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
Douglas Gregorebe10102009-08-20 07:17:43 +00004063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004064StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004065TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004066 // Transform the @catch parameter, if there is one.
4067 VarDecl *Var = 0;
4068 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4069 TypeSourceInfo *TSInfo = 0;
4070 if (FromVar->getTypeSourceInfo()) {
4071 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4072 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004073 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004074 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004075
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004076 QualType T;
4077 if (TSInfo)
4078 T = TSInfo->getType();
4079 else {
4080 T = getDerived().TransformType(FromVar->getType());
4081 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004082 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004083 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004084
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004085 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4086 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004087 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004088 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004089
John McCalldadc5752010-08-24 06:29:42 +00004090 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004091 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004092 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004093
4094 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004095 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004096 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004097}
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregorebe10102009-08-20 07:17:43 +00004099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004100StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004101TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004102 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004103 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004104 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004105 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004106
Douglas Gregor306de2f2010-04-22 23:59:56 +00004107 // If nothing changed, just retain this statement.
4108 if (!getDerived().AlwaysRebuild() &&
4109 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004110 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004111
4112 // Build a new statement.
4113 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004114 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004115}
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregorebe10102009-08-20 07:17:43 +00004117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004118StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004119TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004120 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004121 if (S->getThrowExpr()) {
4122 Operand = getDerived().TransformExpr(S->getThrowExpr());
4123 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004124 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004125 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004126
Douglas Gregor2900c162010-04-22 21:44:01 +00004127 if (!getDerived().AlwaysRebuild() &&
4128 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004129 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004130
John McCallb268a282010-08-23 23:25:46 +00004131 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregorebe10102009-08-20 07:17:43 +00004134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004135StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004136TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004137 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004138 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004139 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004140 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004141 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004142
Douglas Gregor6148de72010-04-22 22:01:21 +00004143 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004144 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004145 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004146 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004147
Douglas Gregor6148de72010-04-22 22:01:21 +00004148 // If nothing change, just retain the current statement.
4149 if (!getDerived().AlwaysRebuild() &&
4150 Object.get() == S->getSynchExpr() &&
4151 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004152 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004153
4154 // Build a new statement.
4155 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004156 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004157}
4158
4159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004160StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004161TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004162 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004163 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004164 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004165 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004166 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004167
Douglas Gregorf68a5082010-04-22 23:10:45 +00004168 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004169 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004170 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004171 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004172
Douglas Gregorf68a5082010-04-22 23:10:45 +00004173 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004174 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004175 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004176 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004177
Douglas Gregorf68a5082010-04-22 23:10:45 +00004178 // If nothing changed, just retain this statement.
4179 if (!getDerived().AlwaysRebuild() &&
4180 Element.get() == S->getElement() &&
4181 Collection.get() == S->getCollection() &&
4182 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004183 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004184
Douglas Gregorf68a5082010-04-22 23:10:45 +00004185 // Build a new statement.
4186 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4187 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004188 Element.get(),
4189 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004190 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004191 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004192}
4193
4194
4195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004196StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004197TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4198 // Transform the exception declaration, if any.
4199 VarDecl *Var = 0;
4200 if (S->getExceptionDecl()) {
4201 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004202 TypeSourceInfo *T = getDerived().TransformType(
4203 ExceptionDecl->getTypeSourceInfo());
4204 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004205 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004206
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004207 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004208 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004209 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004210 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004211 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004212 }
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregorebe10102009-08-20 07:17:43 +00004214 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004215 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004216 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004217 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregorebe10102009-08-20 07:17:43 +00004219 if (!getDerived().AlwaysRebuild() &&
4220 !Var &&
4221 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004222 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004223
4224 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4225 Var,
John McCallb268a282010-08-23 23:25:46 +00004226 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004227}
Mike Stump11289f42009-09-09 15:08:12 +00004228
Douglas Gregorebe10102009-08-20 07:17:43 +00004229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004230StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004231TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4232 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004233 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004234 = getDerived().TransformCompoundStmt(S->getTryBlock());
4235 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004236 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregorebe10102009-08-20 07:17:43 +00004238 // Transform the handlers.
4239 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004240 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004241 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004242 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004243 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4244 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004245 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004246
Douglas Gregorebe10102009-08-20 07:17:43 +00004247 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4248 Handlers.push_back(Handler.takeAs<Stmt>());
4249 }
Mike Stump11289f42009-09-09 15:08:12 +00004250
Douglas Gregorebe10102009-08-20 07:17:43 +00004251 if (!getDerived().AlwaysRebuild() &&
4252 TryBlock.get() == S->getTryBlock() &&
4253 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004254 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004255
John McCallb268a282010-08-23 23:25:46 +00004256 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004257 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004258}
Mike Stump11289f42009-09-09 15:08:12 +00004259
Douglas Gregorebe10102009-08-20 07:17:43 +00004260//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004261// Expression transformation
4262//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004265TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004266 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004267}
Mike Stump11289f42009-09-09 15:08:12 +00004268
4269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004270ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004271TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004272 NestedNameSpecifier *Qualifier = 0;
4273 if (E->getQualifier()) {
4274 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004275 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004276 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004277 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004278 }
John McCallce546572009-12-08 09:08:17 +00004279
4280 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004281 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4282 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004283 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004285
John McCall815039a2010-08-17 21:27:17 +00004286 DeclarationNameInfo NameInfo = E->getNameInfo();
4287 if (NameInfo.getName()) {
4288 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4289 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004290 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004291 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004292
4293 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004294 Qualifier == E->getQualifier() &&
4295 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004296 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004297 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004298
4299 // Mark it referenced in the new context regardless.
4300 // FIXME: this is a bit instantiation-specific.
4301 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4302
John McCallc3007a22010-10-26 07:05:15 +00004303 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004304 }
John McCallce546572009-12-08 09:08:17 +00004305
4306 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004307 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004308 TemplateArgs = &TransArgs;
4309 TransArgs.setLAngleLoc(E->getLAngleLoc());
4310 TransArgs.setRAngleLoc(E->getRAngleLoc());
4311 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4312 TemplateArgumentLoc Loc;
4313 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004314 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004315 TransArgs.addArgument(Loc);
4316 }
4317 }
4318
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004319 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004320 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004321}
Mike Stump11289f42009-09-09 15:08:12 +00004322
Douglas Gregora16548e2009-08-11 05:31:07 +00004323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004324ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004325TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004326 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004327}
Mike Stump11289f42009-09-09 15:08:12 +00004328
Douglas Gregora16548e2009-08-11 05:31:07 +00004329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004330ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004331TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004332 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004333}
Mike Stump11289f42009-09-09 15:08:12 +00004334
Douglas Gregora16548e2009-08-11 05:31:07 +00004335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004336ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004337TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004338 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004339}
Mike Stump11289f42009-09-09 15:08:12 +00004340
Douglas Gregora16548e2009-08-11 05:31:07 +00004341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004342ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004343TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004344 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004345}
Mike Stump11289f42009-09-09 15:08:12 +00004346
Douglas Gregora16548e2009-08-11 05:31:07 +00004347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004349TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004350 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004351}
4352
4353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004354ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004355TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004356 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004358 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004359
Douglas Gregora16548e2009-08-11 05:31:07 +00004360 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004361 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004362
John McCallb268a282010-08-23 23:25:46 +00004363 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 E->getRParen());
4365}
4366
Mike Stump11289f42009-09-09 15:08:12 +00004367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004369TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004370 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004375 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4378 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004379 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004380}
Mike Stump11289f42009-09-09 15:08:12 +00004381
Douglas Gregora16548e2009-08-11 05:31:07 +00004382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004383ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004384TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4385 // Transform the type.
4386 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4387 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004388 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004389
Douglas Gregor882211c2010-04-28 22:16:22 +00004390 // Transform all of the components into components similar to what the
4391 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004392 // FIXME: It would be slightly more efficient in the non-dependent case to
4393 // just map FieldDecls, rather than requiring the rebuilder to look for
4394 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004395 // template code that we don't care.
4396 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004397 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004398 typedef OffsetOfExpr::OffsetOfNode Node;
4399 llvm::SmallVector<Component, 4> Components;
4400 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4401 const Node &ON = E->getComponent(I);
4402 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004403 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004404 Comp.LocStart = ON.getRange().getBegin();
4405 Comp.LocEnd = ON.getRange().getEnd();
4406 switch (ON.getKind()) {
4407 case Node::Array: {
4408 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004409 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004410 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004411 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004412
Douglas Gregor882211c2010-04-28 22:16:22 +00004413 ExprChanged = ExprChanged || Index.get() != FromIndex;
4414 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004415 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004416 break;
4417 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004418
Douglas Gregor882211c2010-04-28 22:16:22 +00004419 case Node::Field:
4420 case Node::Identifier:
4421 Comp.isBrackets = false;
4422 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004423 if (!Comp.U.IdentInfo)
4424 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004425
Douglas Gregor882211c2010-04-28 22:16:22 +00004426 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004427
Douglas Gregord1702062010-04-29 00:18:15 +00004428 case Node::Base:
4429 // Will be recomputed during the rebuild.
4430 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004431 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004432
Douglas Gregor882211c2010-04-28 22:16:22 +00004433 Components.push_back(Comp);
4434 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004435
Douglas Gregor882211c2010-04-28 22:16:22 +00004436 // If nothing changed, retain the existing expression.
4437 if (!getDerived().AlwaysRebuild() &&
4438 Type == E->getTypeSourceInfo() &&
4439 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004440 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004441
Douglas Gregor882211c2010-04-28 22:16:22 +00004442 // Build a new offsetof expression.
4443 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4444 Components.data(), Components.size(),
4445 E->getRParenLoc());
4446}
4447
4448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004449ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004450TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4451 assert(getDerived().AlreadyTransformed(E->getType()) &&
4452 "opaque value expression requires transformation");
4453 return SemaRef.Owned(E);
4454}
4455
4456template<typename Derived>
4457ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004458TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004459 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004460 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004461
John McCallbcd03502009-12-07 02:54:59 +00004462 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004463 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004465
John McCall4c98fd82009-11-04 07:28:41 +00004466 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004467 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004468
John McCall4c98fd82009-11-04 07:28:41 +00004469 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004470 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 E->getSourceRange());
4472 }
Mike Stump11289f42009-09-09 15:08:12 +00004473
John McCalldadc5752010-08-24 06:29:42 +00004474 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004475 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 // C++0x [expr.sizeof]p1:
4477 // The operand is either an expression, which is an unevaluated operand
4478 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004479 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004480
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4482 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004483 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004484
Douglas Gregora16548e2009-08-11 05:31:07 +00004485 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004486 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 }
Mike Stump11289f42009-09-09 15:08:12 +00004488
John McCallb268a282010-08-23 23:25:46 +00004489 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004490 E->isSizeOf(),
4491 E->getSourceRange());
4492}
Mike Stump11289f42009-09-09 15:08:12 +00004493
Douglas Gregora16548e2009-08-11 05:31:07 +00004494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004496TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004497 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004498 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004499 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004500
John McCalldadc5752010-08-24 06:29:42 +00004501 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004502 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004504
4505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 if (!getDerived().AlwaysRebuild() &&
4507 LHS.get() == E->getLHS() &&
4508 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004509 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004510
John McCallb268a282010-08-23 23:25:46 +00004511 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004512 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004513 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 E->getRBracketLoc());
4515}
Mike Stump11289f42009-09-09 15:08:12 +00004516
4517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004518ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004519TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004521 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004522 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004523 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004524
4525 // Transform arguments.
4526 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004527 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004528 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004529 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004532
Mike Stump11289f42009-09-09 15:08:12 +00004533 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004534 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 }
Mike Stump11289f42009-09-09 15:08:12 +00004536
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 if (!getDerived().AlwaysRebuild() &&
4538 Callee.get() == E->getCallee() &&
4539 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004540 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregora16548e2009-08-11 05:31:07 +00004542 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004543 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004545 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004546 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 E->getRParenLoc());
4548}
Mike Stump11289f42009-09-09 15:08:12 +00004549
4550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004551ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004552TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004553 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004555 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004556
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004557 NestedNameSpecifier *Qualifier = 0;
4558 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004559 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004560 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004561 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004562 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004563 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004564 }
Mike Stump11289f42009-09-09 15:08:12 +00004565
Eli Friedman2cfcef62009-12-04 06:40:45 +00004566 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004567 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4568 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004569 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004571
John McCall16df1e52010-03-30 21:47:33 +00004572 NamedDecl *FoundDecl = E->getFoundDecl();
4573 if (FoundDecl == E->getMemberDecl()) {
4574 FoundDecl = Member;
4575 } else {
4576 FoundDecl = cast_or_null<NamedDecl>(
4577 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4578 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004579 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004580 }
4581
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 if (!getDerived().AlwaysRebuild() &&
4583 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004584 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004585 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004586 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004587 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004588
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004589 // Mark it referenced in the new context regardless.
4590 // FIXME: this is a bit instantiation-specific.
4591 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004592 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004593 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004594
John McCall6b51f282009-11-23 01:53:49 +00004595 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004596 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004597 TransArgs.setLAngleLoc(E->getLAngleLoc());
4598 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004599 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004600 TemplateArgumentLoc Loc;
4601 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004602 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004603 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004604 }
4605 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004606
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 // FIXME: Bogus source location for the operator
4608 SourceLocation FakeOperatorLoc
4609 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4610
John McCall38836f02010-01-15 08:34:02 +00004611 // FIXME: to do this check properly, we will need to preserve the
4612 // first-qualifier-in-scope here, just in case we had a dependent
4613 // base (and therefore couldn't do the check) and a
4614 // nested-name-qualifier (and therefore could do the lookup).
4615 NamedDecl *FirstQualifierInScope = 0;
4616
John McCallb268a282010-08-23 23:25:46 +00004617 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004618 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004619 Qualifier,
4620 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004621 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004622 Member,
John McCall16df1e52010-03-30 21:47:33 +00004623 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004624 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004625 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004626 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004627}
Mike Stump11289f42009-09-09 15:08:12 +00004628
Douglas Gregora16548e2009-08-11 05:31:07 +00004629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004630ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004631TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004632 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004634 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004635
John McCalldadc5752010-08-24 06:29:42 +00004636 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004637 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004639
Douglas Gregora16548e2009-08-11 05:31:07 +00004640 if (!getDerived().AlwaysRebuild() &&
4641 LHS.get() == E->getLHS() &&
4642 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004643 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004644
Douglas Gregora16548e2009-08-11 05:31:07 +00004645 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004646 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004647}
4648
Mike Stump11289f42009-09-09 15:08:12 +00004649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004650ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004651TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004652 CompoundAssignOperator *E) {
4653 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004654}
Mike Stump11289f42009-09-09 15:08:12 +00004655
Douglas Gregora16548e2009-08-11 05:31:07 +00004656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004657ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004658TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004659 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004662
John McCalldadc5752010-08-24 06:29:42 +00004663 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004665 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004666
John McCalldadc5752010-08-24 06:29:42 +00004667 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 if (!getDerived().AlwaysRebuild() &&
4672 Cond.get() == E->getCond() &&
4673 LHS.get() == E->getLHS() &&
4674 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004675 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004676
John McCallb268a282010-08-23 23:25:46 +00004677 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004678 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004679 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004680 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004681 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004682}
Mike Stump11289f42009-09-09 15:08:12 +00004683
4684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004685ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004686TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004687 // Implicit casts are eliminated during transformation, since they
4688 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004689 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004690}
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregora16548e2009-08-11 05:31:07 +00004692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004694TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004695 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4696 if (!Type)
4697 return ExprError();
4698
John McCalldadc5752010-08-24 06:29:42 +00004699 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004700 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004705 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004707 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004708
John McCall97513962010-01-15 18:39:57 +00004709 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00004710 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004712 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004713}
Mike Stump11289f42009-09-09 15:08:12 +00004714
Douglas Gregora16548e2009-08-11 05:31:07 +00004715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004716ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004717TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004718 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4719 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4720 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004722
John McCalldadc5752010-08-24 06:29:42 +00004723 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004728 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00004730 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004731
John McCall5d7aa7f2010-01-19 22:33:45 +00004732 // Note: the expression type doesn't necessarily match the
4733 // type-as-written, but that's okay, because it should always be
4734 // derivable from the initializer.
4735
John McCalle15bbff2010-01-18 19:35:47 +00004736 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004738 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004739}
Mike Stump11289f42009-09-09 15:08:12 +00004740
Douglas Gregora16548e2009-08-11 05:31:07 +00004741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004743TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004744 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004745 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 if (!getDerived().AlwaysRebuild() &&
4749 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00004750 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004753 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004755 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004756 E->getAccessorLoc(),
4757 E->getAccessor());
4758}
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregora16548e2009-08-11 05:31:07 +00004760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004761ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004762TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004763 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004764
John McCall37ad5512010-08-23 06:44:23 +00004765 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004767 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004768 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004772 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 }
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00004776 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004779 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004780}
Mike Stump11289f42009-09-09 15:08:12 +00004781
Douglas Gregora16548e2009-08-11 05:31:07 +00004782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004783ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004784TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregorebe10102009-08-20 07:17:43 +00004787 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004788 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004789 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregorebe10102009-08-20 07:17:43 +00004792 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004793 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 bool ExprChanged = false;
4795 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4796 DEnd = E->designators_end();
4797 D != DEnd; ++D) {
4798 if (D->isFieldDesignator()) {
4799 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4800 D->getDotLoc(),
4801 D->getFieldLoc()));
4802 continue;
4803 }
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004806 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004809
4810 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004812
Douglas Gregora16548e2009-08-11 05:31:07 +00004813 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4814 ArrayExprs.push_back(Index.release());
4815 continue;
4816 }
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004819 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4821 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004822 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004823
John McCalldadc5752010-08-24 06:29:42 +00004824 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004827
4828 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004829 End.get(),
4830 D->getLBracketLoc(),
4831 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4834 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregora16548e2009-08-11 05:31:07 +00004836 ArrayExprs.push_back(Start.release());
4837 ArrayExprs.push_back(End.release());
4838 }
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840 if (!getDerived().AlwaysRebuild() &&
4841 Init.get() == E->getInit() &&
4842 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004843 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregora16548e2009-08-11 05:31:07 +00004845 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4846 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004847 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004848}
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregora16548e2009-08-11 05:31:07 +00004850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004851ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004852TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004853 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004854 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004855
Douglas Gregor3da3c062009-10-28 00:29:27 +00004856 // FIXME: Will we ever have proper type location here? Will we actually
4857 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004858 QualType T = getDerived().TransformType(E->getType());
4859 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregora16548e2009-08-11 05:31:07 +00004862 if (!getDerived().AlwaysRebuild() &&
4863 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00004864 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004865
Douglas Gregora16548e2009-08-11 05:31:07 +00004866 return getDerived().RebuildImplicitValueInitExpr(T);
4867}
Mike Stump11289f42009-09-09 15:08:12 +00004868
Douglas Gregora16548e2009-08-11 05:31:07 +00004869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004871TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004872 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4873 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004874 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004875
John McCalldadc5752010-08-24 06:29:42 +00004876 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004879
Douglas Gregora16548e2009-08-11 05:31:07 +00004880 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004881 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004883 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004884
John McCallb268a282010-08-23 23:25:46 +00004885 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004886 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004887}
4888
4889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004891TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004892 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004893 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004895 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004897 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004900 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004901 }
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4904 move_arg(Inits),
4905 E->getRParenLoc());
4906}
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregora16548e2009-08-11 05:31:07 +00004908/// \brief Transform an address-of-label expression.
4909///
4910/// By default, the transformation of an address-of-label expression always
4911/// rebuilds the expression, so that the label identifier can be resolved to
4912/// the corresponding label statement by semantic analysis.
4913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004915TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004916 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4917 E->getLabel());
4918}
Mike Stump11289f42009-09-09 15:08:12 +00004919
4920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004922TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004923 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004924 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4925 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004926 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 if (!getDerived().AlwaysRebuild() &&
4929 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00004930 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004931
4932 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004933 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004934 E->getRParenLoc());
4935}
Mike Stump11289f42009-09-09 15:08:12 +00004936
Douglas Gregora16548e2009-08-11 05:31:07 +00004937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004938ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004939TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004940 TypeSourceInfo *TInfo1;
4941 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004942
4943 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4944 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004945 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004946
Douglas Gregor7058c262010-08-10 14:27:00 +00004947 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4948 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004949 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004950
4951 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004952 TInfo1 == E->getArgTInfo1() &&
4953 TInfo2 == E->getArgTInfo2())
John McCallc3007a22010-10-26 07:05:15 +00004954 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004955
Douglas Gregora16548e2009-08-11 05:31:07 +00004956 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004957 TInfo1, TInfo2,
4958 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004959}
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregora16548e2009-08-11 05:31:07 +00004961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004962ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004963TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004964 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004965 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004967
John McCalldadc5752010-08-24 06:29:42 +00004968 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004969 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004971
John McCalldadc5752010-08-24 06:29:42 +00004972 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004973 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregora16548e2009-08-11 05:31:07 +00004976 if (!getDerived().AlwaysRebuild() &&
4977 Cond.get() == E->getCond() &&
4978 LHS.get() == E->getLHS() &&
4979 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004980 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004983 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 E->getRParenLoc());
4985}
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregora16548e2009-08-11 05:31:07 +00004987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004988ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004989TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004990 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004991}
4992
4993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004994ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004995TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004996 switch (E->getOperator()) {
4997 case OO_New:
4998 case OO_Delete:
4999 case OO_Array_New:
5000 case OO_Array_Delete:
5001 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005002 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005003
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005004 case OO_Call: {
5005 // This is a call to an object's operator().
5006 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5007
5008 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005009 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005010 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005011 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005012
5013 // FIXME: Poor location information
5014 SourceLocation FakeLParenLoc
5015 = SemaRef.PP.getLocForEndOfToken(
5016 static_cast<Expr *>(Object.get())->getLocEnd());
5017
5018 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005019 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005020 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00005021 if (getDerived().DropCallArgument(E->getArg(I)))
5022 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005023
John McCalldadc5752010-08-24 06:29:42 +00005024 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005025 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005026 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005027
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005028 Args.push_back(Arg.release());
5029 }
5030
John McCallb268a282010-08-23 23:25:46 +00005031 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005032 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005033 E->getLocEnd());
5034 }
5035
5036#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5037 case OO_##Name:
5038#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5039#include "clang/Basic/OperatorKinds.def"
5040 case OO_Subscript:
5041 // Handled below.
5042 break;
5043
5044 case OO_Conditional:
5045 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005046 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005047
5048 case OO_None:
5049 case NUM_OVERLOADED_OPERATORS:
5050 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005051 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005052 }
5053
John McCalldadc5752010-08-24 06:29:42 +00005054 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005055 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005057
John McCalldadc5752010-08-24 06:29:42 +00005058 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005060 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005061
John McCalldadc5752010-08-24 06:29:42 +00005062 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 if (E->getNumArgs() == 2) {
5064 Second = getDerived().TransformExpr(E->getArg(1));
5065 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005066 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 }
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregora16548e2009-08-11 05:31:07 +00005069 if (!getDerived().AlwaysRebuild() &&
5070 Callee.get() == E->getCallee() &&
5071 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005072 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005073 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregora16548e2009-08-11 05:31:07 +00005075 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5076 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005077 Callee.get(),
5078 First.get(),
5079 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005083ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5085 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005086}
Mike Stump11289f42009-09-09 15:08:12 +00005087
Douglas Gregora16548e2009-08-11 05:31:07 +00005088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005089ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005090TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005091 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5092 if (!Type)
5093 return ExprError();
5094
John McCalldadc5752010-08-24 06:29:42 +00005095 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005096 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005097 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005098 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005099
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005101 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005102 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005103 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005106 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5108 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5109 SourceLocation FakeRParenLoc
5110 = SemaRef.PP.getLocForEndOfToken(
5111 E->getSubExpr()->getSourceRange().getEnd());
5112 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005113 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005114 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005115 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 FakeRAngleLoc,
5117 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005118 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005119 FakeRParenLoc);
5120}
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregora16548e2009-08-11 05:31:07 +00005122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005124TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5125 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005126}
Mike Stump11289f42009-09-09 15:08:12 +00005127
5128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005129ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005130TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5131 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005132}
5133
Douglas Gregora16548e2009-08-11 05:31:07 +00005134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005135ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005136TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005137 CXXReinterpretCastExpr *E) {
5138 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005139}
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregora16548e2009-08-11 05:31:07 +00005141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005143TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5144 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005145}
Mike Stump11289f42009-09-09 15:08:12 +00005146
Douglas Gregora16548e2009-08-11 05:31:07 +00005147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005148ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005149TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005150 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005151 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5152 if (!Type)
5153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005154
John McCalldadc5752010-08-24 06:29:42 +00005155 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005156 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005157 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005158 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregora16548e2009-08-11 05:31:07 +00005160 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005161 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005163 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005165 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005166 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005167 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 E->getRParenLoc());
5169}
Mike Stump11289f42009-09-09 15:08:12 +00005170
Douglas Gregora16548e2009-08-11 05:31:07 +00005171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005172ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005173TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005174 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005175 TypeSourceInfo *TInfo
5176 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5177 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregora16548e2009-08-11 05:31:07 +00005180 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005181 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005182 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005183
Douglas Gregor9da64192010-04-26 22:37:10 +00005184 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5185 E->getLocStart(),
5186 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005187 E->getLocEnd());
5188 }
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregora16548e2009-08-11 05:31:07 +00005190 // We don't know whether the expression is potentially evaluated until
5191 // after we perform semantic analysis, so the expression is potentially
5192 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005193 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005194 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005195
John McCalldadc5752010-08-24 06:29:42 +00005196 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005197 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 if (!getDerived().AlwaysRebuild() &&
5201 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005202 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005203
Douglas Gregor9da64192010-04-26 22:37:10 +00005204 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5205 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005206 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005207 E->getLocEnd());
5208}
5209
5210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005211ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005212TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5213 if (E->isTypeOperand()) {
5214 TypeSourceInfo *TInfo
5215 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5216 if (!TInfo)
5217 return ExprError();
5218
5219 if (!getDerived().AlwaysRebuild() &&
5220 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005221 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005222
5223 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5224 E->getLocStart(),
5225 TInfo,
5226 E->getLocEnd());
5227 }
5228
5229 // We don't know whether the expression is potentially evaluated until
5230 // after we perform semantic analysis, so the expression is potentially
5231 // potentially evaluated.
5232 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5233
5234 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5235 if (SubExpr.isInvalid())
5236 return ExprError();
5237
5238 if (!getDerived().AlwaysRebuild() &&
5239 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005240 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005241
5242 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5243 E->getLocStart(),
5244 SubExpr.get(),
5245 E->getLocEnd());
5246}
5247
5248template<typename Derived>
5249ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005250TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005251 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005252}
Mike Stump11289f42009-09-09 15:08:12 +00005253
Douglas Gregora16548e2009-08-11 05:31:07 +00005254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005255ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005256TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005257 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005258 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005259}
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregora16548e2009-08-11 05:31:07 +00005261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005262ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005263TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005264 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5265 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5266 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005267
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005268 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005269 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005270
Douglas Gregorb15af892010-01-07 23:12:05 +00005271 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005272}
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005275ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005276TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005277 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005278 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregora16548e2009-08-11 05:31:07 +00005281 if (!getDerived().AlwaysRebuild() &&
5282 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005283 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005284
John McCallb268a282010-08-23 23:25:46 +00005285 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005286}
Mike Stump11289f42009-09-09 15:08:12 +00005287
Douglas Gregora16548e2009-08-11 05:31:07 +00005288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005290TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005291 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005292 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5293 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005296
Chandler Carruth794da4c2010-02-08 06:42:49 +00005297 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005298 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005299 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005300
Douglas Gregor033f6752009-12-23 23:03:06 +00005301 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005302}
Mike Stump11289f42009-09-09 15:08:12 +00005303
Douglas Gregora16548e2009-08-11 05:31:07 +00005304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005305ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005306TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5307 CXXScalarValueInitExpr *E) {
5308 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5309 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005310 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005311
Douglas Gregora16548e2009-08-11 05:31:07 +00005312 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005313 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005314 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005315
Douglas Gregor2b88c112010-09-08 00:15:04 +00005316 return getDerived().RebuildCXXScalarValueInitExpr(T,
5317 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005318 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005319}
Mike Stump11289f42009-09-09 15:08:12 +00005320
Douglas Gregora16548e2009-08-11 05:31:07 +00005321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005323TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005324 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005325 TypeSourceInfo *AllocTypeInfo
5326 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5327 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005329
Douglas Gregora16548e2009-08-11 05:31:07 +00005330 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005331 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005332 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005334
Douglas Gregora16548e2009-08-11 05:31:07 +00005335 // Transform the placement arguments (if any).
5336 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005337 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005338 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005339 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5340 ArgumentChanged = true;
5341 break;
5342 }
5343
John McCalldadc5752010-08-24 06:29:42 +00005344 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005345 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005347
Douglas Gregora16548e2009-08-11 05:31:07 +00005348 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5349 PlacementArgs.push_back(Arg.take());
5350 }
Mike Stump11289f42009-09-09 15:08:12 +00005351
Douglas Gregorebe10102009-08-20 07:17:43 +00005352 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005353 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005354 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005355 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5356 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005357 break;
John McCall09d13692010-10-05 22:36:42 +00005358 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005359
John McCalldadc5752010-08-24 06:29:42 +00005360 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005361 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005363
Douglas Gregora16548e2009-08-11 05:31:07 +00005364 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5365 ConstructorArgs.push_back(Arg.take());
5366 }
Mike Stump11289f42009-09-09 15:08:12 +00005367
Douglas Gregord2d9da02010-02-26 00:38:10 +00005368 // Transform constructor, new operator, and delete operator.
5369 CXXConstructorDecl *Constructor = 0;
5370 if (E->getConstructor()) {
5371 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005372 getDerived().TransformDecl(E->getLocStart(),
5373 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005374 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005375 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005376 }
5377
5378 FunctionDecl *OperatorNew = 0;
5379 if (E->getOperatorNew()) {
5380 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005381 getDerived().TransformDecl(E->getLocStart(),
5382 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005383 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005384 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005385 }
5386
5387 FunctionDecl *OperatorDelete = 0;
5388 if (E->getOperatorDelete()) {
5389 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005390 getDerived().TransformDecl(E->getLocStart(),
5391 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005392 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005393 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005394 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005395
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005397 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005399 Constructor == E->getConstructor() &&
5400 OperatorNew == E->getOperatorNew() &&
5401 OperatorDelete == E->getOperatorDelete() &&
5402 !ArgumentChanged) {
5403 // Mark any declarations we need as referenced.
5404 // FIXME: instantiation-specific.
5405 if (Constructor)
5406 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5407 if (OperatorNew)
5408 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5409 if (OperatorDelete)
5410 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005411 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005412 }
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregor0744ef62010-09-07 21:49:58 +00005414 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005415 if (!ArraySize.get()) {
5416 // If no array size was specified, but the new expression was
5417 // instantiated with an array type (e.g., "new T" where T is
5418 // instantiated with "int[4]"), extract the outer bound from the
5419 // array type as our array size. We do this with constant and
5420 // dependently-sized array types.
5421 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5422 if (!ArrayT) {
5423 // Do nothing
5424 } else if (const ConstantArrayType *ConsArrayT
5425 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005426 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005427 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5428 ConsArrayT->getSize(),
5429 SemaRef.Context.getSizeType(),
5430 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005431 AllocType = ConsArrayT->getElementType();
5432 } else if (const DependentSizedArrayType *DepArrayT
5433 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5434 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005435 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005436 AllocType = DepArrayT->getElementType();
5437 }
5438 }
5439 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005440
Douglas Gregora16548e2009-08-11 05:31:07 +00005441 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5442 E->isGlobalNew(),
5443 /*FIXME:*/E->getLocStart(),
5444 move_arg(PlacementArgs),
5445 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005446 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005448 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005449 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 /*FIXME:*/E->getLocStart(),
5451 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005452 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005453}
Mike Stump11289f42009-09-09 15:08:12 +00005454
Douglas Gregora16548e2009-08-11 05:31:07 +00005455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005457TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005458 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005459 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005460 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005461
Douglas Gregord2d9da02010-02-26 00:38:10 +00005462 // Transform the delete operator, if known.
5463 FunctionDecl *OperatorDelete = 0;
5464 if (E->getOperatorDelete()) {
5465 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005466 getDerived().TransformDecl(E->getLocStart(),
5467 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005468 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005470 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005471
Douglas Gregora16548e2009-08-11 05:31:07 +00005472 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005473 Operand.get() == E->getArgument() &&
5474 OperatorDelete == E->getOperatorDelete()) {
5475 // Mark any declarations we need as referenced.
5476 // FIXME: instantiation-specific.
5477 if (OperatorDelete)
5478 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005479
5480 if (!E->getArgument()->isTypeDependent()) {
5481 QualType Destroyed = SemaRef.Context.getBaseElementType(
5482 E->getDestroyedType());
5483 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5484 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5485 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5486 SemaRef.LookupDestructor(Record));
5487 }
5488 }
5489
John McCallc3007a22010-10-26 07:05:15 +00005490 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005491 }
Mike Stump11289f42009-09-09 15:08:12 +00005492
Douglas Gregora16548e2009-08-11 05:31:07 +00005493 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5494 E->isGlobalDelete(),
5495 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005496 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005497}
Mike Stump11289f42009-09-09 15:08:12 +00005498
Douglas Gregora16548e2009-08-11 05:31:07 +00005499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005500ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005501TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005502 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005503 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005504 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005506
John McCallba7bf592010-08-24 05:47:05 +00005507 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005508 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005509 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005510 E->getOperatorLoc(),
5511 E->isArrow()? tok::arrow : tok::period,
5512 ObjectTypePtr,
5513 MayBePseudoDestructor);
5514 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005516
John McCallba7bf592010-08-24 05:47:05 +00005517 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005518 NestedNameSpecifier *Qualifier = E->getQualifier();
5519 if (Qualifier) {
5520 Qualifier
5521 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5522 E->getQualifierRange(),
5523 ObjectType);
5524 if (!Qualifier)
5525 return ExprError();
5526 }
Mike Stump11289f42009-09-09 15:08:12 +00005527
Douglas Gregor678f90d2010-02-25 01:56:36 +00005528 PseudoDestructorTypeStorage Destroyed;
5529 if (E->getDestroyedTypeInfo()) {
5530 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005531 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5532 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005533 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005534 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005535 Destroyed = DestroyedTypeInfo;
5536 } else if (ObjectType->isDependentType()) {
5537 // We aren't likely to be able to resolve the identifier down to a type
5538 // now anyway, so just retain the identifier.
5539 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5540 E->getDestroyedTypeLoc());
5541 } else {
5542 // Look for a destructor known with the given name.
5543 CXXScopeSpec SS;
5544 if (Qualifier) {
5545 SS.setScopeRep(Qualifier);
5546 SS.setRange(E->getQualifierRange());
5547 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005548
John McCallba7bf592010-08-24 05:47:05 +00005549 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005550 *E->getDestroyedTypeIdentifier(),
5551 E->getDestroyedTypeLoc(),
5552 /*Scope=*/0,
5553 SS, ObjectTypePtr,
5554 false);
5555 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005556 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005557
Douglas Gregor678f90d2010-02-25 01:56:36 +00005558 Destroyed
5559 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5560 E->getDestroyedTypeLoc());
5561 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005562
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005563 TypeSourceInfo *ScopeTypeInfo = 0;
5564 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005565 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005566 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005568 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005569
John McCallb268a282010-08-23 23:25:46 +00005570 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005571 E->getOperatorLoc(),
5572 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005573 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005574 E->getQualifierRange(),
5575 ScopeTypeInfo,
5576 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005577 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005578 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005579}
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregorad8a3362009-09-04 17:36:40 +00005581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005582ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005583TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005584 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005585 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5586
5587 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5588 Sema::LookupOrdinaryName);
5589
5590 // Transform all the decls.
5591 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5592 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005593 NamedDecl *InstD = static_cast<NamedDecl*>(
5594 getDerived().TransformDecl(Old->getNameLoc(),
5595 *I));
John McCall84d87672009-12-10 09:41:52 +00005596 if (!InstD) {
5597 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5598 // This can happen because of dependent hiding.
5599 if (isa<UsingShadowDecl>(*I))
5600 continue;
5601 else
John McCallfaf5fb42010-08-26 23:41:50 +00005602 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005603 }
John McCalle66edc12009-11-24 19:00:30 +00005604
5605 // Expand using declarations.
5606 if (isa<UsingDecl>(InstD)) {
5607 UsingDecl *UD = cast<UsingDecl>(InstD);
5608 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5609 E = UD->shadow_end(); I != E; ++I)
5610 R.addDecl(*I);
5611 continue;
5612 }
5613
5614 R.addDecl(InstD);
5615 }
5616
5617 // Resolve a kind, but don't do any further analysis. If it's
5618 // ambiguous, the callee needs to deal with it.
5619 R.resolveKind();
5620
5621 // Rebuild the nested-name qualifier, if present.
5622 CXXScopeSpec SS;
5623 NestedNameSpecifier *Qualifier = 0;
5624 if (Old->getQualifier()) {
5625 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005626 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005627 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005628 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005629
John McCalle66edc12009-11-24 19:00:30 +00005630 SS.setScopeRep(Qualifier);
5631 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005632 }
5633
Douglas Gregor9262f472010-04-27 18:19:34 +00005634 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005635 CXXRecordDecl *NamingClass
5636 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5637 Old->getNameLoc(),
5638 Old->getNamingClass()));
5639 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005640 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005641
Douglas Gregorda7be082010-04-27 16:10:10 +00005642 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005643 }
5644
5645 // If we have no template arguments, it's a normal declaration name.
5646 if (!Old->hasExplicitTemplateArgs())
5647 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5648
5649 // If we have template arguments, rebuild them, then rebuild the
5650 // templateid expression.
5651 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5652 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5653 TemplateArgumentLoc Loc;
5654 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005655 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005656 TransArgs.addArgument(Loc);
5657 }
5658
5659 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5660 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005661}
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregora16548e2009-08-11 05:31:07 +00005663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005665TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005666 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5667 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregora16548e2009-08-11 05:31:07 +00005670 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005671 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005672 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005673
Mike Stump11289f42009-09-09 15:08:12 +00005674 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005676 T,
5677 E->getLocEnd());
5678}
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregora16548e2009-08-11 05:31:07 +00005680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005681ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00005682TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
5683 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
5684 if (!LhsT)
5685 return ExprError();
5686
5687 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
5688 if (!RhsT)
5689 return ExprError();
5690
5691 if (!getDerived().AlwaysRebuild() &&
5692 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
5693 return SemaRef.Owned(E);
5694
5695 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
5696 E->getLocStart(),
5697 LhsT, RhsT,
5698 E->getLocEnd());
5699}
5700
5701template<typename Derived>
5702ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005703TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005704 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005705 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005706 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005707 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005710
John McCall31f82722010-11-12 08:19:04 +00005711 // TODO: If this is a conversion-function-id, verify that the
5712 // destination type name (if present) resolves the same way after
5713 // instantiation as it did in the local scope.
5714
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005715 DeclarationNameInfo NameInfo
5716 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5717 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005718 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005719
John McCalle66edc12009-11-24 19:00:30 +00005720 if (!E->hasExplicitTemplateArgs()) {
5721 if (!getDerived().AlwaysRebuild() &&
5722 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005723 // Note: it is sufficient to compare the Name component of NameInfo:
5724 // if name has not changed, DNLoc has not changed either.
5725 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00005726 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005727
John McCalle66edc12009-11-24 19:00:30 +00005728 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5729 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005730 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005731 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005732 }
John McCall6b51f282009-11-23 01:53:49 +00005733
5734 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005736 TemplateArgumentLoc Loc;
5737 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005738 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005739 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 }
5741
John McCalle66edc12009-11-24 19:00:30 +00005742 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5743 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005744 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005745 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005746}
5747
5748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005749ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005750TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005751 // CXXConstructExprs are always implicit, so when we have a
5752 // 1-argument construction we just transform that argument.
5753 if (E->getNumArgs() == 1 ||
5754 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5755 return getDerived().TransformExpr(E->getArg(0));
5756
Douglas Gregora16548e2009-08-11 05:31:07 +00005757 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5758
5759 QualType T = getDerived().TransformType(E->getType());
5760 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005762
5763 CXXConstructorDecl *Constructor
5764 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005765 getDerived().TransformDecl(E->getLocStart(),
5766 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005767 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005769
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005771 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005772 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 ArgEnd = E->arg_end();
5774 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005775 if (getDerived().DropCallArgument(*Arg)) {
5776 ArgumentChanged = true;
5777 break;
5778 }
5779
John McCalldadc5752010-08-24 06:29:42 +00005780 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005783
Douglas Gregora16548e2009-08-11 05:31:07 +00005784 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005785 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005786 }
5787
5788 if (!getDerived().AlwaysRebuild() &&
5789 T == E->getType() &&
5790 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005791 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005792 // Mark the constructor as referenced.
5793 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005794 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005795 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00005796 }
Mike Stump11289f42009-09-09 15:08:12 +00005797
Douglas Gregordb121ba2009-12-14 16:27:04 +00005798 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5799 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005800 move_arg(Args),
5801 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00005802 E->getConstructionKind(),
5803 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005804}
Mike Stump11289f42009-09-09 15:08:12 +00005805
Douglas Gregora16548e2009-08-11 05:31:07 +00005806/// \brief Transform a C++ temporary-binding expression.
5807///
Douglas Gregor363b1512009-12-24 18:51:59 +00005808/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5809/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005811ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005812TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005813 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005814}
Mike Stump11289f42009-09-09 15:08:12 +00005815
John McCall5d413782010-12-06 08:20:24 +00005816/// \brief Transform a C++ expression that contains cleanups that should
5817/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00005818///
John McCall5d413782010-12-06 08:20:24 +00005819/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00005820/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005822ExprResult
John McCall5d413782010-12-06 08:20:24 +00005823TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005824 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005825}
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregora16548e2009-08-11 05:31:07 +00005827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005828ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005829TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005830 CXXTemporaryObjectExpr *E) {
5831 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5832 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005834
Douglas Gregora16548e2009-08-11 05:31:07 +00005835 CXXConstructorDecl *Constructor
5836 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005837 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005838 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005841
Douglas Gregora16548e2009-08-11 05:31:07 +00005842 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005843 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005844 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005845 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005846 ArgEnd = E->arg_end();
5847 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005848 if (getDerived().DropCallArgument(*Arg)) {
5849 ArgumentChanged = true;
5850 break;
5851 }
5852
John McCalldadc5752010-08-24 06:29:42 +00005853 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005855 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005856
Douglas Gregora16548e2009-08-11 05:31:07 +00005857 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5858 Args.push_back((Expr *)TransArg.release());
5859 }
Mike Stump11289f42009-09-09 15:08:12 +00005860
Douglas Gregora16548e2009-08-11 05:31:07 +00005861 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005862 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005863 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005864 !ArgumentChanged) {
5865 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005866 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00005867 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005868 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005869
5870 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5871 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005873 E->getLocEnd());
5874}
Mike Stump11289f42009-09-09 15:08:12 +00005875
Douglas Gregora16548e2009-08-11 05:31:07 +00005876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005877ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005878TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005879 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005880 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5881 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005882 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005883
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005885 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5887 ArgEnd = E->arg_end();
5888 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005889 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005890 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005892
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005894 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005895 }
Mike Stump11289f42009-09-09 15:08:12 +00005896
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005898 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00005900 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005901
Douglas Gregora16548e2009-08-11 05:31:07 +00005902 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005903 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005904 E->getLParenLoc(),
5905 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005906 E->getRParenLoc());
5907}
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregora16548e2009-08-11 05:31:07 +00005909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005910ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005911TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005912 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005913 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005914 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005915 Expr *OldBase;
5916 QualType BaseType;
5917 QualType ObjectType;
5918 if (!E->isImplicitAccess()) {
5919 OldBase = E->getBase();
5920 Base = getDerived().TransformExpr(OldBase);
5921 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005923
John McCall2d74de92009-12-01 22:10:20 +00005924 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005925 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005926 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005927 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005928 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005929 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005930 ObjectTy,
5931 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005932 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005933 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005934
John McCallba7bf592010-08-24 05:47:05 +00005935 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005936 BaseType = ((Expr*) Base.get())->getType();
5937 } else {
5938 OldBase = 0;
5939 BaseType = getDerived().TransformType(E->getBaseType());
5940 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5941 }
Mike Stump11289f42009-09-09 15:08:12 +00005942
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005943 // Transform the first part of the nested-name-specifier that qualifies
5944 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005945 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005946 = getDerived().TransformFirstQualifierInScope(
5947 E->getFirstQualifierFoundInScope(),
5948 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005949
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005950 NestedNameSpecifier *Qualifier = 0;
5951 if (E->getQualifier()) {
5952 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5953 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005954 ObjectType,
5955 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005956 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005957 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005958 }
Mike Stump11289f42009-09-09 15:08:12 +00005959
John McCall31f82722010-11-12 08:19:04 +00005960 // TODO: If this is a conversion-function-id, verify that the
5961 // destination type name (if present) resolves the same way after
5962 // instantiation as it did in the local scope.
5963
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005964 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00005965 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005966 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005968
John McCall2d74de92009-12-01 22:10:20 +00005969 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005970 // This is a reference to a member without an explicitly-specified
5971 // template argument list. Optimize for this common case.
5972 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005973 Base.get() == OldBase &&
5974 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005975 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005976 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005977 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00005978 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005979
John McCallb268a282010-08-23 23:25:46 +00005980 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005981 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005982 E->isArrow(),
5983 E->getOperatorLoc(),
5984 Qualifier,
5985 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005986 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005987 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005988 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005989 }
5990
John McCall6b51f282009-11-23 01:53:49 +00005991 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005992 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005993 TemplateArgumentLoc Loc;
5994 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005995 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005996 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005997 }
Mike Stump11289f42009-09-09 15:08:12 +00005998
John McCallb268a282010-08-23 23:25:46 +00005999 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006000 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006001 E->isArrow(),
6002 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006003 Qualifier,
6004 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006005 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006006 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006007 &TransArgs);
6008}
6009
6010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006012TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006013 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006014 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006015 QualType BaseType;
6016 if (!Old->isImplicitAccess()) {
6017 Base = getDerived().TransformExpr(Old->getBase());
6018 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006019 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006020 BaseType = ((Expr*) Base.get())->getType();
6021 } else {
6022 BaseType = getDerived().TransformType(Old->getBaseType());
6023 }
John McCall10eae182009-11-30 22:42:35 +00006024
6025 NestedNameSpecifier *Qualifier = 0;
6026 if (Old->getQualifier()) {
6027 Qualifier
6028 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006029 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006030 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006031 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006032 }
6033
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006034 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006035 Sema::LookupOrdinaryName);
6036
6037 // Transform all the decls.
6038 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6039 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006040 NamedDecl *InstD = static_cast<NamedDecl*>(
6041 getDerived().TransformDecl(Old->getMemberLoc(),
6042 *I));
John McCall84d87672009-12-10 09:41:52 +00006043 if (!InstD) {
6044 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6045 // This can happen because of dependent hiding.
6046 if (isa<UsingShadowDecl>(*I))
6047 continue;
6048 else
John McCallfaf5fb42010-08-26 23:41:50 +00006049 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006050 }
John McCall10eae182009-11-30 22:42:35 +00006051
6052 // Expand using declarations.
6053 if (isa<UsingDecl>(InstD)) {
6054 UsingDecl *UD = cast<UsingDecl>(InstD);
6055 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6056 E = UD->shadow_end(); I != E; ++I)
6057 R.addDecl(*I);
6058 continue;
6059 }
6060
6061 R.addDecl(InstD);
6062 }
6063
6064 R.resolveKind();
6065
Douglas Gregor9262f472010-04-27 18:19:34 +00006066 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006067 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006068 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006069 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006070 Old->getMemberLoc(),
6071 Old->getNamingClass()));
6072 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006073 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006074
Douglas Gregorda7be082010-04-27 16:10:10 +00006075 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006076 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006077
John McCall10eae182009-11-30 22:42:35 +00006078 TemplateArgumentListInfo TransArgs;
6079 if (Old->hasExplicitTemplateArgs()) {
6080 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6081 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6082 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6083 TemplateArgumentLoc Loc;
6084 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6085 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006087 TransArgs.addArgument(Loc);
6088 }
6089 }
John McCall38836f02010-01-15 08:34:02 +00006090
6091 // FIXME: to do this check properly, we will need to preserve the
6092 // first-qualifier-in-scope here, just in case we had a dependent
6093 // base (and therefore couldn't do the check) and a
6094 // nested-name-qualifier (and therefore could do the lookup).
6095 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006096
John McCallb268a282010-08-23 23:25:46 +00006097 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006098 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006099 Old->getOperatorLoc(),
6100 Old->isArrow(),
6101 Qualifier,
6102 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006103 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006104 R,
6105 (Old->hasExplicitTemplateArgs()
6106 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006107}
6108
6109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006110ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006111TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6112 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6113 if (SubExpr.isInvalid())
6114 return ExprError();
6115
6116 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006117 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006118
6119 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6120}
6121
6122template<typename Derived>
6123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006125 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006126}
6127
Mike Stump11289f42009-09-09 15:08:12 +00006128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006129ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006130TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006131 TypeSourceInfo *EncodedTypeInfo
6132 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6133 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006134 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006135
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006137 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006139
6140 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006141 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006142 E->getRParenLoc());
6143}
Mike Stump11289f42009-09-09 15:08:12 +00006144
Douglas Gregora16548e2009-08-11 05:31:07 +00006145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006146ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006147TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006148 // Transform arguments.
6149 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006150 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006151 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006152 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006153 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006154 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006155
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006156 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006157 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006158 }
6159
6160 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6161 // Class message: transform the receiver type.
6162 TypeSourceInfo *ReceiverTypeInfo
6163 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6164 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006165 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006166
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006167 // If nothing changed, just retain the existing message send.
6168 if (!getDerived().AlwaysRebuild() &&
6169 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006170 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006171
6172 // Build a new class message send.
6173 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6174 E->getSelector(),
6175 E->getMethodDecl(),
6176 E->getLeftLoc(),
6177 move_arg(Args),
6178 E->getRightLoc());
6179 }
6180
6181 // Instance message: transform the receiver
6182 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6183 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006184 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006185 = getDerived().TransformExpr(E->getInstanceReceiver());
6186 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006187 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006188
6189 // If nothing changed, just retain the existing message send.
6190 if (!getDerived().AlwaysRebuild() &&
6191 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006192 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006193
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006194 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006195 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006196 E->getSelector(),
6197 E->getMethodDecl(),
6198 E->getLeftLoc(),
6199 move_arg(Args),
6200 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006201}
6202
Mike Stump11289f42009-09-09 15:08:12 +00006203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006204ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006205TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006206 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006207}
6208
Mike Stump11289f42009-09-09 15:08:12 +00006209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006210ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006211TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006212 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006213}
6214
Mike Stump11289f42009-09-09 15:08:12 +00006215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006218 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006219 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006220 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006221 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006222
6223 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006224
Douglas Gregord51d90d2010-04-26 20:11:03 +00006225 // If nothing changed, just retain the existing expression.
6226 if (!getDerived().AlwaysRebuild() &&
6227 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006228 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006229
John McCallb268a282010-08-23 23:25:46 +00006230 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006231 E->getLocation(),
6232 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006233}
6234
Mike Stump11289f42009-09-09 15:08:12 +00006235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006237TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006238 // 'super' and types never change. Property never changes. Just
6239 // retain the existing expression.
6240 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006241 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006242
Douglas Gregor9faee212010-04-26 20:47:02 +00006243 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006244 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006245 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006246 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006247
Douglas Gregor9faee212010-04-26 20:47:02 +00006248 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006249
Douglas Gregor9faee212010-04-26 20:47:02 +00006250 // If nothing changed, just retain the existing expression.
6251 if (!getDerived().AlwaysRebuild() &&
6252 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006253 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006254
John McCallb7bd14f2010-12-02 01:19:52 +00006255 if (E->isExplicitProperty())
6256 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6257 E->getExplicitProperty(),
6258 E->getLocation());
6259
6260 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6261 E->getType(),
6262 E->getImplicitPropertyGetter(),
6263 E->getImplicitPropertySetter(),
6264 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006265}
6266
Mike Stump11289f42009-09-09 15:08:12 +00006267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006269TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006270 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006271 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006272 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006273 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006274
Douglas Gregord51d90d2010-04-26 20:11:03 +00006275 // If nothing changed, just retain the existing expression.
6276 if (!getDerived().AlwaysRebuild() &&
6277 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006278 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006279
John McCallb268a282010-08-23 23:25:46 +00006280 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006281 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006282}
6283
Mike Stump11289f42009-09-09 15:08:12 +00006284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006286TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006287 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006288 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006289 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006290 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006291 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006293
Douglas Gregora16548e2009-08-11 05:31:07 +00006294 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006295 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 }
Mike Stump11289f42009-09-09 15:08:12 +00006297
Douglas Gregora16548e2009-08-11 05:31:07 +00006298 if (!getDerived().AlwaysRebuild() &&
6299 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006300 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006301
Douglas Gregora16548e2009-08-11 05:31:07 +00006302 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6303 move_arg(SubExprs),
6304 E->getRParenLoc());
6305}
6306
Mike Stump11289f42009-09-09 15:08:12 +00006307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006309TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006310 SourceLocation CaretLoc(E->getExprLoc());
6311
6312 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6313 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6314 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6315 llvm::SmallVector<ParmVarDecl*, 4> Params;
6316 llvm::SmallVector<QualType, 4> ParamTypes;
6317
6318 // Parameter substitution.
6319 const BlockDecl *BD = E->getBlockDecl();
6320 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6321 EN = BD->param_end(); P != EN; ++P) {
6322 ParmVarDecl *OldParm = (*P);
6323 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6324 QualType NewType = NewParm->getType();
6325 Params.push_back(NewParm);
6326 ParamTypes.push_back(NewParm->getType());
6327 }
6328
6329 const FunctionType *BExprFunctionType = E->getFunctionType();
6330 QualType BExprResultType = BExprFunctionType->getResultType();
6331 if (!BExprResultType.isNull()) {
6332 if (!BExprResultType->isDependentType())
6333 CurBlock->ReturnType = BExprResultType;
6334 else if (BExprResultType != SemaRef.Context.DependentTy)
6335 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6336 }
6337
6338 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006339 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006340 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006341 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006342 // Set the parameters on the block decl.
6343 if (!Params.empty())
6344 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6345
6346 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6347 CurBlock->ReturnType,
6348 ParamTypes.data(),
6349 ParamTypes.size(),
6350 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006351 0,
6352 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006353
6354 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006355 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006356}
6357
Mike Stump11289f42009-09-09 15:08:12 +00006358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006360TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006361 NestedNameSpecifier *Qualifier = 0;
6362
6363 ValueDecl *ND
6364 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6365 E->getDecl()));
6366 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006367 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006368
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006369 if (!getDerived().AlwaysRebuild() &&
6370 ND == E->getDecl()) {
6371 // Mark it referenced in the new context regardless.
6372 // FIXME: this is a bit instantiation-specific.
6373 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6374
John McCallc3007a22010-10-26 07:05:15 +00006375 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006376 }
6377
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006378 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006379 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006380 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006381}
Mike Stump11289f42009-09-09 15:08:12 +00006382
Douglas Gregora16548e2009-08-11 05:31:07 +00006383//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006384// Type reconstruction
6385//===----------------------------------------------------------------------===//
6386
Mike Stump11289f42009-09-09 15:08:12 +00006387template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006388QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6389 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006390 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391 getDerived().getBaseEntity());
6392}
6393
Mike Stump11289f42009-09-09 15:08:12 +00006394template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006395QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6396 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006397 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006398 getDerived().getBaseEntity());
6399}
6400
Mike Stump11289f42009-09-09 15:08:12 +00006401template<typename Derived>
6402QualType
John McCall70dd5f62009-10-30 00:06:24 +00006403TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6404 bool WrittenAsLValue,
6405 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006406 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006407 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006408}
6409
6410template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006411QualType
John McCall70dd5f62009-10-30 00:06:24 +00006412TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6413 QualType ClassType,
6414 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006415 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006416 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006417}
6418
6419template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006420QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006421TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6422 ArrayType::ArraySizeModifier SizeMod,
6423 const llvm::APInt *Size,
6424 Expr *SizeExpr,
6425 unsigned IndexTypeQuals,
6426 SourceRange BracketsRange) {
6427 if (SizeExpr || !Size)
6428 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6429 IndexTypeQuals, BracketsRange,
6430 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006431
6432 QualType Types[] = {
6433 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6434 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6435 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006436 };
6437 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6438 QualType SizeType;
6439 for (unsigned I = 0; I != NumTypes; ++I)
6440 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6441 SizeType = Types[I];
6442 break;
6443 }
Mike Stump11289f42009-09-09 15:08:12 +00006444
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006445 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6446 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006447 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006448 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006449 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006450}
Mike Stump11289f42009-09-09 15:08:12 +00006451
Douglas Gregord6ff3322009-08-04 16:50:30 +00006452template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006453QualType
6454TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006455 ArrayType::ArraySizeModifier SizeMod,
6456 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006457 unsigned IndexTypeQuals,
6458 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006459 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006460 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006461}
6462
6463template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006464QualType
Mike Stump11289f42009-09-09 15:08:12 +00006465TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006466 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006467 unsigned IndexTypeQuals,
6468 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006469 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006470 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006471}
Mike Stump11289f42009-09-09 15:08:12 +00006472
Douglas Gregord6ff3322009-08-04 16:50:30 +00006473template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006474QualType
6475TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006476 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006477 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006478 unsigned IndexTypeQuals,
6479 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006480 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006481 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006482 IndexTypeQuals, BracketsRange);
6483}
6484
6485template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006486QualType
6487TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006488 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006489 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006490 unsigned IndexTypeQuals,
6491 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006492 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006493 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006494 IndexTypeQuals, BracketsRange);
6495}
6496
6497template<typename Derived>
6498QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006499 unsigned NumElements,
6500 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006501 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006502 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006503}
Mike Stump11289f42009-09-09 15:08:12 +00006504
Douglas Gregord6ff3322009-08-04 16:50:30 +00006505template<typename Derived>
6506QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6507 unsigned NumElements,
6508 SourceLocation AttributeLoc) {
6509 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6510 NumElements, true);
6511 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006512 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6513 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006514 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006515}
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregord6ff3322009-08-04 16:50:30 +00006517template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006518QualType
6519TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006520 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006521 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006522 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006523}
Mike Stump11289f42009-09-09 15:08:12 +00006524
Douglas Gregord6ff3322009-08-04 16:50:30 +00006525template<typename Derived>
6526QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006527 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006528 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006529 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006530 unsigned Quals,
6531 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006532 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006533 Quals,
6534 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006535 getDerived().getBaseEntity(),
6536 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006537}
Mike Stump11289f42009-09-09 15:08:12 +00006538
Douglas Gregord6ff3322009-08-04 16:50:30 +00006539template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006540QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6541 return SemaRef.Context.getFunctionNoProtoType(T);
6542}
6543
6544template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006545QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6546 assert(D && "no decl found");
6547 if (D->isInvalidDecl()) return QualType();
6548
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006549 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006550 TypeDecl *Ty;
6551 if (isa<UsingDecl>(D)) {
6552 UsingDecl *Using = cast<UsingDecl>(D);
6553 assert(Using->isTypeName() &&
6554 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6555
6556 // A valid resolved using typename decl points to exactly one type decl.
6557 assert(++Using->shadow_begin() == Using->shadow_end());
6558 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006559
John McCallb96ec562009-12-04 22:46:56 +00006560 } else {
6561 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6562 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6563 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6564 }
6565
6566 return SemaRef.Context.getTypeDeclType(Ty);
6567}
6568
6569template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006570QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6571 SourceLocation Loc) {
6572 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006573}
6574
6575template<typename Derived>
6576QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6577 return SemaRef.Context.getTypeOfType(Underlying);
6578}
6579
6580template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006581QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6582 SourceLocation Loc) {
6583 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006584}
6585
6586template<typename Derived>
6587QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006588 TemplateName Template,
6589 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006590 const TemplateArgumentListInfo &TemplateArgs) {
6591 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006592}
Mike Stump11289f42009-09-09 15:08:12 +00006593
Douglas Gregor1135c352009-08-06 05:28:30 +00006594template<typename Derived>
6595NestedNameSpecifier *
6596TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6597 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006598 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006599 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006600 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006601 CXXScopeSpec SS;
6602 // FIXME: The source location information is all wrong.
6603 SS.setRange(Range);
6604 SS.setScopeRep(Prefix);
6605 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006606 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006607 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006608 ObjectType,
6609 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006610 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006611}
6612
6613template<typename Derived>
6614NestedNameSpecifier *
6615TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6616 SourceRange Range,
6617 NamespaceDecl *NS) {
6618 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6619}
6620
6621template<typename Derived>
6622NestedNameSpecifier *
6623TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6624 SourceRange Range,
6625 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006626 QualType T) {
6627 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006628 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006629 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006630 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6631 T.getTypePtr());
6632 }
Mike Stump11289f42009-09-09 15:08:12 +00006633
Douglas Gregor1135c352009-08-06 05:28:30 +00006634 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6635 return 0;
6636}
Mike Stump11289f42009-09-09 15:08:12 +00006637
Douglas Gregor71dc5092009-08-06 06:41:21 +00006638template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006639TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006640TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6641 bool TemplateKW,
6642 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006643 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006644 Template);
6645}
6646
6647template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006648TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006649TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006650 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006651 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00006652 QualType ObjectType,
6653 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006654 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006655 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006656 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006657 UnqualifiedId Name;
6658 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006659 Sema::TemplateTy Template;
6660 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6661 /*FIXME:*/getDerived().getBaseLocation(),
6662 SS,
6663 Name,
John McCallba7bf592010-08-24 05:47:05 +00006664 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006665 /*EnteringContext=*/false,
6666 Template);
John McCall31f82722010-11-12 08:19:04 +00006667 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006668}
Mike Stump11289f42009-09-09 15:08:12 +00006669
Douglas Gregora16548e2009-08-11 05:31:07 +00006670template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006671TemplateName
6672TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6673 OverloadedOperatorKind Operator,
6674 QualType ObjectType) {
6675 CXXScopeSpec SS;
6676 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6677 SS.setScopeRep(Qualifier);
6678 UnqualifiedId Name;
6679 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6680 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6681 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006682 Sema::TemplateTy Template;
6683 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006684 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006685 SS,
6686 Name,
John McCallba7bf592010-08-24 05:47:05 +00006687 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006688 /*EnteringContext=*/false,
6689 Template);
6690 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006691}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006692
Douglas Gregor71395fa2009-11-04 00:56:37 +00006693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006694ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006695TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6696 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006697 Expr *OrigCallee,
6698 Expr *First,
6699 Expr *Second) {
6700 Expr *Callee = OrigCallee->IgnoreParenCasts();
6701 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006702
Douglas Gregora16548e2009-08-11 05:31:07 +00006703 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006704 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006705 if (!First->getType()->isOverloadableType() &&
6706 !Second->getType()->isOverloadableType())
6707 return getSema().CreateBuiltinArraySubscriptExpr(First,
6708 Callee->getLocStart(),
6709 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006710 } else if (Op == OO_Arrow) {
6711 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006712 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6713 } else if (Second == 0 || isPostIncDec) {
6714 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006715 // The argument is not of overloadable type, so try to create a
6716 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006717 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006718 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006719
John McCallb268a282010-08-23 23:25:46 +00006720 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006721 }
6722 } else {
John McCallb268a282010-08-23 23:25:46 +00006723 if (!First->getType()->isOverloadableType() &&
6724 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006725 // Neither of the arguments is an overloadable type, so try to
6726 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006727 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006728 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006729 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006730 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006732
Douglas Gregora16548e2009-08-11 05:31:07 +00006733 return move(Result);
6734 }
6735 }
Mike Stump11289f42009-09-09 15:08:12 +00006736
6737 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006738 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006739 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006740
John McCallb268a282010-08-23 23:25:46 +00006741 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006742 assert(ULE->requiresADL());
6743
6744 // FIXME: Do we have to check
6745 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006746 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006747 } else {
John McCallb268a282010-08-23 23:25:46 +00006748 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006749 }
Mike Stump11289f42009-09-09 15:08:12 +00006750
Douglas Gregora16548e2009-08-11 05:31:07 +00006751 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006752 Expr *Args[2] = { First, Second };
6753 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006754
Douglas Gregora16548e2009-08-11 05:31:07 +00006755 // Create the overloaded operator invocation for unary operators.
6756 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006757 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006758 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006759 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006760 }
Mike Stump11289f42009-09-09 15:08:12 +00006761
Sebastian Redladba46e2009-10-29 20:17:01 +00006762 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006763 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006764 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006765 First,
6766 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006767
Douglas Gregora16548e2009-08-11 05:31:07 +00006768 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006769 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006770 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006771 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6772 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006773 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006774
Mike Stump11289f42009-09-09 15:08:12 +00006775 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006776}
Mike Stump11289f42009-09-09 15:08:12 +00006777
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006779ExprResult
John McCallb268a282010-08-23 23:25:46 +00006780TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006781 SourceLocation OperatorLoc,
6782 bool isArrow,
6783 NestedNameSpecifier *Qualifier,
6784 SourceRange QualifierRange,
6785 TypeSourceInfo *ScopeType,
6786 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006787 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006788 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006789 CXXScopeSpec SS;
6790 if (Qualifier) {
6791 SS.setRange(QualifierRange);
6792 SS.setScopeRep(Qualifier);
6793 }
6794
John McCallb268a282010-08-23 23:25:46 +00006795 QualType BaseType = Base->getType();
6796 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006797 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006798 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006799 !BaseType->getAs<PointerType>()->getPointeeType()
6800 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006801 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006802 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006803 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006804 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006805 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006806 /*FIXME?*/true);
6807 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006808
Douglas Gregor678f90d2010-02-25 01:56:36 +00006809 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006810 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6811 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6812 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6813 NameInfo.setNamedTypeInfo(DestroyedType);
6814
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006815 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006816
John McCallb268a282010-08-23 23:25:46 +00006817 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006818 OperatorLoc, isArrow,
6819 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006820 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006821 /*TemplateArgs*/ 0);
6822}
6823
Douglas Gregord6ff3322009-08-04 16:50:30 +00006824} // end namespace clang
6825
6826#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H