blob: e0111f1e96d9dc27b9ec5c3a42f5d6aa2afe5cbb [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregor577f75a2009-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 McCall2d887082010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000028#include "clang/Sema/Ownership.h"
29#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000030#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000031#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000032#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCall781472f2010-08-25 08:40:02 +000036using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor577f75a2009-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 Stump1eb44332009-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 Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-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 Gregor43959a92009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-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 Gregor577f75a2009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump1eb44332009-09-09 15:08:12 +000093
94public:
Douglas Gregor577f75a2009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +000097
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000104 }
105
John McCall60d7b3a2010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000108
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000112
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000119
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000127
Douglas Gregor577f75a2009-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 Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +0000141
Douglas Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +0000148
Douglas Gregorb98b1992009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump1eb44332009-09-09 15:08:12 +0000156
Douglas Gregorb98b1992009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump1eb44332009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-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 Gregor6eef5192009-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 }
Sean Huntc3021132010-05-05 15:23:54 +0000182
Douglas Gregor577f75a2009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCalla2becad2009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-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 McCalla93c9342009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000192 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000193
John McCalla2becad2009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 ///
John McCalla2becad2009-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 McCall43fed0d2010-11-12 08:19:04 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-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 McCall43fed0d2010-11-12 08:19:04 +0000208 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000209
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000210 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000211 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000212 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000219 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000220
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000221 /// \brief Transform the given expression.
222 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +0000229 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000230
Douglas Gregor577f75a2009-08-04 16:50:30 +0000231 /// \brief Transform the given declaration, which is referenced from a type
232 /// or expression.
233 ///
Douglas Gregordcee1a12009-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 Gregor7c1e98f2010-03-01 15:56:25 +0000236 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000237
238 /// \brief Transform the definition of the given declaration.
239 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000240 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000241 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000242 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
243 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000244 }
Mike Stump1eb44332009-09-09 15:08:12 +0000245
Douglas Gregor6cd21982009-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 ///
Sean Huntc3021132010-05-05 15:23:54 +0000249 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-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.
Sean Huntc3021132010-05-05 15:23:54 +0000255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000257 }
Sean Huntc3021132010-05-05 15:23:54 +0000258
Douglas Gregor577f75a2009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000268
Douglas Gregor81499bb2009-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 Bagnara25777432010-08-11 22:01:17 +0000275 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000276 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000279 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000280 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000281 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000282 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000283 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000284 QualType ObjectType = QualType(),
285 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Douglas Gregor577f75a2009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump1eb44332009-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 Gregor670444e2009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall833ca992009-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 McCalla93c9342009-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 McCall833ca992009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump1eb44332009-09-09 15:08:12 +0000307
John McCalla2becad2009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000311#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000312
John McCall43fed0d2010-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 McCall21ef0fa2010-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 McCall43fed0d2010-11-12 08:19:04 +0000338 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000339
John McCall60d7b3a2010-08-24 06:29:42 +0000340 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
341 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000342
Douglas Gregor43959a92009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000344 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000346 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000349
Douglas Gregor577f75a2009-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 McCall85737a72009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000361
John McCall85737a72009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000363 ///
John McCall85737a72009-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 Gregor577f75a2009-08-04 16:50:30 +0000367 ///
John McCall85737a72009-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 Stump1eb44332009-09-09 15:08:12 +0000373
Douglas Gregor577f75a2009-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 McCall85737a72009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000381
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000395
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000406
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416
Mike Stump1eb44332009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000424 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump1eb44332009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000435 Expr *SizeExpr,
Douglas Gregor577f75a2009-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 Thompson82287d12010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000445 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000461 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000463
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000473
John McCalla2becad2009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCalled976492009-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 Gregor577f75a2009-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 McCall7da24312009-09-05 00:15:47 +0000495
Mike Stump1eb44332009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-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 McCall2a984ca2010-10-12 00:20:44 +0000500 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501
Mike Stump1eb44332009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-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 McCall2a984ca2010-10-12 00:20:44 +0000511 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000512
Douglas Gregor577f75a2009-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 McCall833ca992009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000521
Douglas Gregor577f75a2009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara465d41b2010-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 McCall21e413f2010-11-04 19:04:38 +0000527 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
528 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000529 NestedNameSpecifier *NNS, QualType Named) {
530 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000531 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000532
533 /// \brief Build a new typename type that refers to a template-id.
534 ///
Abramo Bagnarae4da7a02010-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 McCall33500952010-06-11 00:33:02 +0000538 QualType RebuildDependentTemplateSpecializationType(
539 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000540 NestedNameSpecifier *Qualifier,
541 SourceRange QualifierRange,
John McCall33500952010-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 Gregor1efb6c72010-09-08 23:56:00 +0000548 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000549 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000550
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000551 if (InstName.isNull())
552 return QualType();
553
John McCall33500952010-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 Gregor1efb6c72010-09-08 23:56:00 +0000557 Keyword, Qualifier, Name, Args);
John McCall33500952010-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 Bagnara465d41b2010-05-11 21:36:43 +0000564
Abramo Bagnara22f638a2010-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 Stump1eb44332009-09-09 15:08:12 +0000567 }
Douglas Gregor577f75a2009-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 Bagnarae4da7a02010-05-19 21:37:53 +0000572 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000573 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000574 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000575 NestedNameSpecifier *NNS,
576 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000577 SourceLocation KeywordLoc,
578 SourceRange NNSRange,
579 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000580 CXXScopeSpec SS;
581 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000582 SS.setRange(NNSRange);
583
Douglas Gregor40336422010-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 Bagnara465d41b2010-05-11 21:36:43 +0000590 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000591 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
592 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000593
594 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
595
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000596 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000597 // into a non-dependent elaborated-type-specifier. Find the tag we're
598 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000599 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000600 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
601 if (!DC)
602 return QualType();
603
John McCall56138762010-05-27 06:40:31 +0000604 if (SemaRef.RequireCompleteDeclContext(SS, DC))
605 return QualType();
606
Douglas Gregor40336422010-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;
Sean Huntc3021132010-05-05 15:23:54 +0000613
Douglas Gregor40336422010-03-31 22:19:08 +0000614 case LookupResult::Found:
615 Tag = Result.getAsSingle<TagDecl>();
616 break;
Sean Huntc3021132010-05-05 15:23:54 +0000617
Douglas Gregor40336422010-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();
Sean Huntc3021132010-05-05 15:23:54 +0000622
Douglas Gregor40336422010-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 Gregor1eabb7d2010-03-31 23:17:41 +0000629 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000630 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000631 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000632 return QualType();
633 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000634
Abramo Bagnarae4da7a02010-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 Gregor40336422010-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 Bagnara465d41b2010-05-11 21:36:43 +0000643 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000644 }
Mike Stump1eb44332009-09-09 15:08:12 +0000645
Douglas Gregordcee1a12009-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 Gregora38c6872009-09-03 16:14:30 +0000654 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000655 QualType ObjectType,
656 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-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 Gregoredc90502010-02-25 04:46:04 +0000677 QualType T);
Douglas Gregord1067e52009-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 Gregord1067e52009-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 Gregor1efb6c72010-09-08 23:56:00 +0000697 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000698 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000699 QualType ObjectType,
700 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
Douglas Gregorca1bdd72009-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);
Sean Huntc3021132010-05-05 15:23:54 +0000712
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000717 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000718 MultiStmtArg Statements,
719 SourceLocation RBraceLoc,
720 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000721 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000729 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000730 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000732 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000733 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000734 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000735 ColonLoc);
736 }
Mike Stump1eb44332009-09-09 15:08:12 +0000737
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000742 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000743 getSema().ActOnCaseStmtBody(S, Body);
744 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000745 }
Mike Stump1eb44332009-09-09 15:08:12 +0000746
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000751 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000752 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000753 Stmt *SubStmt) {
754 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000755 /*CurScope=*/0);
756 }
Mike Stump1eb44332009-09-09 15:08:12 +0000757
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000762 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000763 IdentifierInfo *Id,
764 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000765 Stmt *SubStmt, bool HasUnusedAttr) {
766 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
767 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000768 }
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000774 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000775 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000776 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000777 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000778 }
Mike Stump1eb44332009-09-09 15:08:12 +0000779
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000784 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000785 Expr *Cond, VarDecl *CondVar) {
786 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000787 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000788 }
Mike Stump1eb44332009-09-09 15:08:12 +0000789
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000794 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000795 Stmt *Switch, Stmt *Body) {
796 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000803 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000804 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000805 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000806 Stmt *Body) {
807 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000808 }
Mike Stump1eb44332009-09-09 15:08:12 +0000809
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000814 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000815 SourceLocation WhileLoc,
816 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000817 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000818 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000819 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
820 Cond, RParenLoc);
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000827 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000828 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000829 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000830 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000831 SourceLocation RParenLoc, Stmt *Body) {
832 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000833 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000834 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000835 }
Mike Stump1eb44332009-09-09 15:08:12 +0000836
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000841 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000851 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000852 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000853 Expr *Target) {
854 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000855 }
Mike Stump1eb44332009-09-09 15:08:12 +0000856
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000861 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000862 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000863
John McCall9ae2f072010-08-23 23:25:46 +0000864 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000865 }
Mike Stump1eb44332009-09-09 15:08:12 +0000866
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000871 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000872 SourceLocation StartLoc,
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000880
Anders Carlsson703e3942010-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 McCall60d7b3a2010-08-24 06:29:42 +0000885 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000886 bool IsSimple,
887 bool IsVolatile,
888 unsigned NumOutputs,
889 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000890 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000891 MultiExprArg Constraints,
892 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000893 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000894 MultiExprArg Clobbers,
895 SourceLocation RParenLoc,
896 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000897 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000898 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000899 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000900 RParenLoc, MSAsm);
901 }
Douglas Gregor4dfdd1b2010-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 McCall60d7b3a2010-08-24 06:29:42 +0000907 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000908 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000909 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000910 Stmt *Finally) {
911 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
912 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000913 }
914
Douglas Gregorbe270a02010-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) {
Sean Huntc3021132010-05-05 15:23:54 +0000921 return getSema().BuildObjCExceptionDecl(TInfo, T,
922 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000923 ExceptionDecl->getLocation());
924 }
Sean Huntc3021132010-05-05 15:23:54 +0000925
Douglas Gregorbe270a02010-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 McCall60d7b3a2010-08-24 06:29:42 +0000930 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000931 SourceLocation RParenLoc,
932 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000933 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000934 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000935 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000936 }
Sean Huntc3021132010-05-05 15:23:54 +0000937
Douglas Gregor4dfdd1b2010-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 McCall60d7b3a2010-08-24 06:29:42 +0000942 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000943 Stmt *Body) {
944 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000945 }
Sean Huntc3021132010-05-05 15:23:54 +0000946
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000947 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-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 McCall60d7b3a2010-08-24 06:29:42 +0000951 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000952 Expr *Operand) {
953 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000954 }
Sean Huntc3021132010-05-05 15:23:54 +0000955
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000956 /// \brief Build a new Objective-C @synchronized statement.
957 ///
Douglas Gregor8fdc13a2010-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 McCall60d7b3a2010-08-24 06:29:42 +0000960 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000961 Expr *Object,
962 Stmt *Body) {
963 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
964 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000965 }
Douglas Gregorc3203e72010-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 McCall60d7b3a2010-08-24 06:29:42 +0000971 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000972 SourceLocation LParenLoc,
973 Stmt *Element,
974 Expr *Collection,
975 SourceLocation RParenLoc,
976 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000977 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000978 Element,
979 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000980 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000981 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000982 }
Sean Huntc3021132010-05-05 15:23:54 +0000983
Douglas Gregor43959a92009-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 Gregor83cb9422010-09-09 17:09:21 +0000988 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +0000989 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000990 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +0000991 SourceLocation Loc) {
992 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001000 VarDecl *ExceptionDecl,
1001 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001002 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1003 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 }
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001010 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001011 Stmt *TryBlock,
1012 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001013 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001014 }
Mike Stump1eb44332009-09-09 15:08:12 +00001015
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001020 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001021 LookupResult &R,
1022 bool RequiresADL) {
John McCallf7a1a742009-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 McCall60d7b3a2010-08-24 06:29:42 +00001031 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001032 SourceRange QualifierRange,
1033 ValueDecl *VD,
1034 const DeclarationNameInfo &NameInfo,
1035 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001036 CXXScopeSpec SS;
1037 SS.setScopeRep(Qualifier);
1038 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001039
1040 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001041
1042 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001043 }
Mike Stump1eb44332009-09-09 15:08:12 +00001044
Douglas Gregorb98b1992009-08-11 05:31:07 +00001045 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001046 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001049 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001050 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001051 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001052 }
1053
Douglas Gregora71d8192009-09-04 17:36:40 +00001054 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001055 ///
Douglas Gregora71d8192009-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 McCall60d7b3a2010-08-24 06:29:42 +00001058 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001059 SourceLocation OperatorLoc,
1060 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001061 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001062 SourceRange QualifierRange,
1063 TypeSourceInfo *ScopeType,
1064 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001065 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001066 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001067
Douglas Gregorb98b1992009-08-11 05:31:07 +00001068 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001069 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001072 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001073 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001074 Expr *SubExpr) {
1075 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 }
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Douglas Gregor8ecdb652010-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 McCall60d7b3a2010-08-24 06:29:42 +00001082 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001083 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001084 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001085 unsigned NumComponents,
1086 SourceLocation RParenLoc) {
1087 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1088 NumComponents, RParenLoc);
1089 }
Sean Huntc3021132010-05-05 15:23:54 +00001090
Douglas Gregorb98b1992009-08-11 05:31:07 +00001091 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001092 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001095 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001096 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001097 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001098 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 }
1100
Mike Stump1eb44332009-09-09 15:08:12 +00001101 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001102 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001103 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001106 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001108 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001109 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 return move(Result);
1114 }
Mike Stump1eb44332009-09-09 15:08:12 +00001115
Douglas Gregorb98b1992009-08-11 05:31:07 +00001116 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001117 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001120 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001121 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001122 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001123 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001124 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1125 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001126 RBracketLoc);
1127 }
1128
1129 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001130 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001133 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001134 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001135 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001136 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001137 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 }
1139
1140 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001141 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001144 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-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 McCalld5532b62009-11-23 01:53:49 +00001151 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001152 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001153 if (!Member->getDeclName()) {
John McCallf89e55a2010-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 Carlssond8b285f2009-09-01 04:26:58 +00001157 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001158 assert(Member->getType()->isRecordType() &&
1159 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001160
John McCall9ae2f072010-08-23 23:25:46 +00001161 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001162 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001163 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001164
John McCallf89e55a2010-11-18 06:31:45 +00001165 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001166 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001167 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001168 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001169 cast<FieldDecl>(Member)->getType(),
1170 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001171 return getSema().Owned(ME);
1172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001174 CXXScopeSpec SS;
1175 if (Qualifier) {
1176 SS.setRange(QualifierRange);
1177 SS.setScopeRep(Qualifier);
1178 }
1179
John McCall9ae2f072010-08-23 23:25:46 +00001180 getSema().DefaultFunctionArrayConversion(Base);
1181 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001182
John McCall6bb80172010-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 Bagnara25777432010-08-11 22:01:17 +00001185 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001186 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001187 R.resolveKind();
1188
John McCall9ae2f072010-08-23 23:25:46 +00001189 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001190 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001191 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001192 }
Mike Stump1eb44332009-09-09 15:08:12 +00001193
Douglas Gregorb98b1992009-08-11 05:31:07 +00001194 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001195 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001198 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001199 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001200 Expr *LHS, Expr *RHS) {
1201 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001202 }
1203
1204 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001205 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001208 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001210 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001212 Expr *RHS) {
1213 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1214 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001215 }
1216
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001218 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001221 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001222 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001223 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001224 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001225 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 }
Mike Stump1eb44332009-09-09 15:08:12 +00001228
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001230 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001233 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001234 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001236 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001237 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001239 }
Mike Stump1eb44332009-09-09 15:08:12 +00001240
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001242 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001245 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001246 SourceLocation OpLoc,
1247 SourceLocation AccessorLoc,
1248 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001249
John McCall129e2df2009-11-30 22:42:35 +00001250 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001251 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001252 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001253 OpLoc, /*IsArrow*/ false,
1254 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001255 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001256 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001257 }
Mike Stump1eb44332009-09-09 15:08:12 +00001258
Douglas Gregorb98b1992009-08-11 05:31:07 +00001259 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001260 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001263 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001264 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001265 SourceLocation RBraceLoc,
1266 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001267 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001268 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1269 if (Result.isInvalid() || ResultTy->isDependentType())
1270 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001271
Douglas Gregore48319a2009-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 Gregorb98b1992009-08-11 05:31:07 +00001277 }
Mike Stump1eb44332009-09-09 15:08:12 +00001278
Douglas Gregorb98b1992009-08-11 05:31:07 +00001279 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001280 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001283 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 MultiExprArg ArrayExprs,
1285 SourceLocation EqualOrColonLoc,
1286 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001287 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001288 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001290 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001291 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001292 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001293
Douglas Gregorb98b1992009-08-11 05:31:07 +00001294 ArrayExprs.release();
1295 return move(Result);
1296 }
Mike Stump1eb44332009-09-09 15:08:12 +00001297
Douglas Gregorb98b1992009-08-11 05:31:07 +00001298 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001299 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001303 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001304 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1305 }
Mike Stump1eb44332009-09-09 15:08:12 +00001306
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001308 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001311 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001312 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001313 SourceLocation RParenLoc) {
1314 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001315 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001316 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 }
1318
1319 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001320 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001323 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 MultiExprArg SubExprs,
1325 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001326 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001327 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001328 }
Mike Stump1eb44332009-09-09 15:08:12 +00001329
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001331 ///
1332 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001335 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 SourceLocation LabelLoc,
1337 LabelStmt *Label) {
1338 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1339 }
Mike Stump1eb44332009-09-09 15:08:12 +00001340
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001342 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001345 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001346 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001348 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 }
Mike Stump1eb44332009-09-09 15:08:12 +00001350
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001355 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001356 TypeSourceInfo *TInfo1,
1357 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001358 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001359 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1360 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 RParenLoc);
1362 }
Mike Stump1eb44332009-09-09 15:08:12 +00001363
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001368 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001369 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 SourceLocation RParenLoc) {
1371 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001372 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001373 RParenLoc);
1374 }
Mike Stump1eb44332009-09-09 15:08:12 +00001375
Douglas Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +00001381 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 /// argument-dependent lookup, etc. Subclasses may override this routine to
1383 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001384 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001386 Expr *Callee,
1387 Expr *First,
1388 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001389
1390 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 /// reinterpret_cast.
1392 ///
1393 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001394 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001396 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 Stmt::StmtClass Class,
1398 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001399 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 SourceLocation RAngleLoc,
1401 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001402 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 SourceLocation RParenLoc) {
1404 switch (Class) {
1405 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001408 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409
1410 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001413 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001416 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001417 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001418 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001419 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001420
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001422 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001423 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001424 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001425
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 default:
1427 assert(false && "Invalid C++ named cast");
1428 break;
1429 }
Mike Stump1eb44332009-09-09 15:08:12 +00001430
John McCallf312b1e2010-08-26 23:41:50 +00001431 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001440 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 SourceLocation RAngleLoc,
1442 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001443 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001445 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001446 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001447 SourceRange(LAngleLoc, RAngleLoc),
1448 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001455 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001457 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 SourceLocation RAngleLoc,
1459 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001460 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001462 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001463 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001464 SourceRange(LAngleLoc, RAngleLoc),
1465 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001472 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001474 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 SourceLocation RAngleLoc,
1476 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001477 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001479 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001480 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001481 SourceRange(LAngleLoc, RAngleLoc),
1482 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001489 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001491 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 SourceLocation RAngleLoc,
1493 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001494 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001496 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001497 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001498 SourceRange(LAngleLoc, RAngleLoc),
1499 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 }
Mike Stump1eb44332009-09-09 15:08:12 +00001501
Douglas Gregorb98b1992009-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 Gregorab6677e2010-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 McCallf312b1e2010-08-26 23:41:50 +00001511 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 RParenLoc);
1513 }
Mike Stump1eb44332009-09-09 15:08:12 +00001514
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001519 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001520 SourceLocation TypeidLoc,
1521 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001523 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001524 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 }
Mike Stump1eb44332009-09-09 15:08:12 +00001526
Francois Pichet01b7c302010-09-08 12:20:18 +00001527
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001532 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001533 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001534 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001536 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001537 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001538 }
1539
Francois Pichet01b7c302010-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 Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +00001567 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001570 QualType ThisType,
1571 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001573 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1574 isImplicit));
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001581 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001582 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001590 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001591 ParmVarDecl *Param) {
1592 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1593 Param));
Douglas Gregorb98b1992009-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 Gregorab6677e2010-09-08 00:15:04 +00001600 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1601 SourceLocation LParenLoc,
1602 SourceLocation RParenLoc) {
1603 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001604 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001605 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 }
Mike Stump1eb44332009-09-09 15:08:12 +00001607
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001612 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-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 Stump1eb44332009-09-09 15:08:12 +00001624 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 PlacementLParen,
1626 move(PlacementArgs),
1627 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001628 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001629 AllocatedType,
1630 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001631 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 ConstructorLParen,
1633 move(ConstructorArgs),
1634 ConstructorRParen);
1635 }
Mike Stump1eb44332009-09-09 15:08:12 +00001636
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001641 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 bool IsGlobalDelete,
1643 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001644 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001646 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 }
Mike Stump1eb44332009-09-09 15:08:12 +00001648
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001653 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001654 SourceLocation StartLoc,
1655 TypeSourceInfo *T,
1656 SourceLocation RParenLoc) {
1657 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 }
1659
Mike Stump1eb44332009-09-09 15:08:12 +00001660 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 /// expression.
1662 ///
1663 /// By default, performs semantic analysis to build the new expression.
1664 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001665 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001667 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001668 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 CXXScopeSpec SS;
1670 SS.setRange(QualifierRange);
1671 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001672
1673 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001674 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001675 *TemplateArgs);
1676
Abramo Bagnara25777432010-08-11 22:01:17 +00001677 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 }
1679
1680 /// \brief Build a new template-id expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001685 LookupResult &R,
1686 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001687 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001688 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 }
1690
1691 /// \brief Build a new object-construction expression.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001695 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001696 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 CXXConstructorDecl *Constructor,
1698 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001699 MultiExprArg Args,
1700 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001701 CXXConstructExpr::ConstructionKind ConstructKind,
1702 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001703 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001704 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001705 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001706 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001707
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001708 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001709 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001710 RequiresZeroInit, ConstructKind,
1711 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 }
1713
1714 /// \brief Build a new object-construction expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001718 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1719 SourceLocation LParenLoc,
1720 MultiExprArg Args,
1721 SourceLocation RParenLoc) {
1722 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 LParenLoc,
1724 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 RParenLoc);
1726 }
1727
1728 /// \brief Build a new object-construction expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001732 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1733 SourceLocation LParenLoc,
1734 MultiExprArg Args,
1735 SourceLocation RParenLoc) {
1736 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 LParenLoc,
1738 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 RParenLoc);
1740 }
Mike Stump1eb44332009-09-09 15:08:12 +00001741
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 /// \brief Build a new member reference expression.
1743 ///
1744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001746 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001747 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 bool IsArrow,
1749 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001750 NestedNameSpecifier *Qualifier,
1751 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001752 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001753 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001754 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001756 SS.setRange(QualifierRange);
1757 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001758
John McCall9ae2f072010-08-23 23:25:46 +00001759 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001760 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001761 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001762 MemberNameInfo,
1763 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 }
1765
John McCall129e2df2009-11-30 22:42:35 +00001766 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001767 ///
1768 /// By default, performs semantic analysis to build the new expression.
1769 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001770 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001771 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001772 SourceLocation OperatorLoc,
1773 bool IsArrow,
1774 NestedNameSpecifier *Qualifier,
1775 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001776 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001777 LookupResult &R,
1778 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001779 CXXScopeSpec SS;
1780 SS.setRange(QualifierRange);
1781 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001782
John McCall9ae2f072010-08-23 23:25:46 +00001783 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001784 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001785 SS, FirstQualifierInScope,
1786 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001787 }
Mike Stump1eb44332009-09-09 15:08:12 +00001788
Sebastian Redl2e156222010-09-10 20:55:43 +00001789 /// \brief Build a new noexcept expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
1793 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1794 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1795 }
1796
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 /// \brief Build a new Objective-C @encode expression.
1798 ///
1799 /// By default, performs semantic analysis to build the new expression.
1800 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001801 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001802 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001804 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001806 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001807
Douglas Gregor92e986e2010-04-22 16:44:27 +00001808 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001809 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001810 Selector Sel,
1811 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001812 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001813 MultiExprArg Args,
1814 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1816 ReceiverTypeInfo->getType(),
1817 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001818 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001819 move(Args));
1820 }
1821
1822 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001823 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001824 Selector Sel,
1825 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001826 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001827 MultiExprArg Args,
1828 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001829 return SemaRef.BuildInstanceMessage(Receiver,
1830 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001831 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001832 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001833 move(Args));
1834 }
1835
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001836 /// \brief Build a new Objective-C ivar reference expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001840 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001841 SourceLocation IvarLoc,
1842 bool IsArrow, bool IsFreeIvar) {
1843 // FIXME: We lose track of the IsFreeIvar bit.
1844 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001845 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001846 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1847 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001848 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001849 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001850 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001851 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001852 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001853 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001854
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001855 if (Result.get())
1856 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001857
John McCall9ae2f072010-08-23 23:25:46 +00001858 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001859 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001860 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001861 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001862 /*TemplateArgs=*/0);
1863 }
Douglas Gregore3303542010-04-26 20:47:02 +00001864
1865 /// \brief Build a new Objective-C property reference expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001869 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001870 ObjCPropertyDecl *Property,
1871 SourceLocation PropertyLoc) {
1872 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001873 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001874 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1875 Sema::LookupMemberName);
1876 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001877 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001878 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001879 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001880 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001881 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001882
Douglas Gregore3303542010-04-26 20:47:02 +00001883 if (Result.get())
1884 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001885
John McCall9ae2f072010-08-23 23:25:46 +00001886 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001887 /*FIXME:*/PropertyLoc, IsArrow,
1888 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001889 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001890 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001891 /*TemplateArgs=*/0);
1892 }
Sean Huntc3021132010-05-05 15:23:54 +00001893
John McCall12f78a62010-12-02 01:19:52 +00001894 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001895 ///
1896 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00001897 /// Subclasses may override this routine to provide different behavior.
1898 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1899 ObjCMethodDecl *Getter,
1900 ObjCMethodDecl *Setter,
1901 SourceLocation PropertyLoc) {
1902 // Since these expressions can only be value-dependent, we do not
1903 // need to perform semantic analysis again.
1904 return Owned(
1905 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
1906 VK_LValue, OK_ObjCProperty,
1907 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001908 }
1909
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001910 /// \brief Build a new Objective-C "isa" expression.
1911 ///
1912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001914 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001915 bool IsArrow) {
1916 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001917 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001918 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1919 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001920 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001921 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001922 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001923 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001924 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001925
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001926 if (Result.get())
1927 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001928
John McCall9ae2f072010-08-23 23:25:46 +00001929 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001930 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001931 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001932 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001933 /*TemplateArgs=*/0);
1934 }
Sean Huntc3021132010-05-05 15:23:54 +00001935
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936 /// \brief Build a new shuffle vector expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001940 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001941 MultiExprArg SubExprs,
1942 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001944 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1946 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1947 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1948 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001949
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 // Build a reference to the __builtin_shufflevector builtin
1951 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001952 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00001954 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001956
1957 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 unsigned NumSubExprs = SubExprs.size();
1959 Expr **Subs = (Expr **)SubExprs.release();
1960 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1961 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001962 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00001963 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001965 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001966
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001968 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001970 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001971
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001973 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001974 }
John McCall43fed0d2010-11-12 08:19:04 +00001975
1976private:
1977 QualType TransformTypeInObjectScope(QualType T,
1978 QualType ObjectType,
1979 NamedDecl *FirstQualifierInScope,
1980 NestedNameSpecifier *Prefix);
1981
1982 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
1983 QualType ObjectType,
1984 NamedDecl *FirstQualifierInScope,
1985 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00001986};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001987
Douglas Gregor43959a92009-08-20 07:17:43 +00001988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001989StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001990 if (!S)
1991 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001992
Douglas Gregor43959a92009-08-20 07:17:43 +00001993 switch (S->getStmtClass()) {
1994 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001995
Douglas Gregor43959a92009-08-20 07:17:43 +00001996 // Transform individual statement nodes
1997#define STMT(Node, Parent) \
1998 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1999#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002000#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002001
Douglas Gregor43959a92009-08-20 07:17:43 +00002002 // Transform expressions by calling TransformExpr.
2003#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002004#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002005#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002006#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002007 {
John McCall60d7b3a2010-08-24 06:29:42 +00002008 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002009 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002010 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002011
John McCall9ae2f072010-08-23 23:25:46 +00002012 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002013 }
Mike Stump1eb44332009-09-09 15:08:12 +00002014 }
2015
John McCall3fa5cae2010-10-26 07:05:15 +00002016 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002017}
Mike Stump1eb44332009-09-09 15:08:12 +00002018
2019
Douglas Gregor670444e2009-08-04 22:27:00 +00002020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002021ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 if (!E)
2023 return SemaRef.Owned(E);
2024
2025 switch (E->getStmtClass()) {
2026 case Stmt::NoStmtClass: break;
2027#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002028#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002029#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002030 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002031#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002032 }
2033
John McCall3fa5cae2010-10-26 07:05:15 +00002034 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002035}
2036
2037template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002038NestedNameSpecifier *
2039TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002040 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002041 QualType ObjectType,
2042 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002043 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002044
Douglas Gregor43959a92009-08-20 07:17:43 +00002045 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002046 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002047 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002048 ObjectType,
2049 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002050 if (!Prefix)
2051 return 0;
2052 }
Mike Stump1eb44332009-09-09 15:08:12 +00002053
Douglas Gregordcee1a12009-08-06 05:28:30 +00002054 switch (NNS->getKind()) {
2055 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002056 if (Prefix) {
2057 // The object type and qualifier-in-scope really apply to the
2058 // leftmost entity.
2059 ObjectType = QualType();
2060 FirstQualifierInScope = 0;
2061 }
2062
Mike Stump1eb44332009-09-09 15:08:12 +00002063 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002064 "Identifier nested-name-specifier with no prefix or object type");
2065 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2066 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002067 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002068
2069 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002070 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002071 ObjectType,
2072 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002073
Douglas Gregordcee1a12009-08-06 05:28:30 +00002074 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002075 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002077 getDerived().TransformDecl(Range.getBegin(),
2078 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002079 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002080 Prefix == NNS->getPrefix() &&
2081 NS == NNS->getAsNamespace())
2082 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002083
Douglas Gregordcee1a12009-08-06 05:28:30 +00002084 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2085 }
Mike Stump1eb44332009-09-09 15:08:12 +00002086
Douglas Gregordcee1a12009-08-06 05:28:30 +00002087 case NestedNameSpecifier::Global:
2088 // There is no meaningful transformation that one could perform on the
2089 // global scope.
2090 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002091
Douglas Gregordcee1a12009-08-06 05:28:30 +00002092 case NestedNameSpecifier::TypeSpecWithTemplate:
2093 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002094 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002095 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2096 ObjectType,
2097 FirstQualifierInScope,
2098 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002099 if (T.isNull())
2100 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002101
Douglas Gregordcee1a12009-08-06 05:28:30 +00002102 if (!getDerived().AlwaysRebuild() &&
2103 Prefix == NNS->getPrefix() &&
2104 T == QualType(NNS->getAsType(), 0))
2105 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002106
2107 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2108 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002109 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002110 }
2111 }
Mike Stump1eb44332009-09-09 15:08:12 +00002112
Douglas Gregordcee1a12009-08-06 05:28:30 +00002113 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002114 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002115}
2116
2117template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002118DeclarationNameInfo
2119TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002120::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002121 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002122 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002123 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002124
2125 switch (Name.getNameKind()) {
2126 case DeclarationName::Identifier:
2127 case DeclarationName::ObjCZeroArgSelector:
2128 case DeclarationName::ObjCOneArgSelector:
2129 case DeclarationName::ObjCMultiArgSelector:
2130 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002131 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002132 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002133 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002134
Douglas Gregor81499bb2009-09-03 22:13:48 +00002135 case DeclarationName::CXXConstructorName:
2136 case DeclarationName::CXXDestructorName:
2137 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002138 TypeSourceInfo *NewTInfo;
2139 CanQualType NewCanTy;
2140 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002141 NewTInfo = getDerived().TransformType(OldTInfo);
2142 if (!NewTInfo)
2143 return DeclarationNameInfo();
2144 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002145 }
2146 else {
2147 NewTInfo = 0;
2148 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002149 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002150 if (NewT.isNull())
2151 return DeclarationNameInfo();
2152 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2153 }
Mike Stump1eb44332009-09-09 15:08:12 +00002154
Abramo Bagnara25777432010-08-11 22:01:17 +00002155 DeclarationName NewName
2156 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2157 NewCanTy);
2158 DeclarationNameInfo NewNameInfo(NameInfo);
2159 NewNameInfo.setName(NewName);
2160 NewNameInfo.setNamedTypeInfo(NewTInfo);
2161 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002162 }
Mike Stump1eb44332009-09-09 15:08:12 +00002163 }
2164
Abramo Bagnara25777432010-08-11 22:01:17 +00002165 assert(0 && "Unknown name kind.");
2166 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002167}
2168
2169template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002170TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002171TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002172 QualType ObjectType,
2173 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002174 SourceLocation Loc = getDerived().getBaseLocation();
2175
Douglas Gregord1067e52009-08-06 06:41:21 +00002176 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002177 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002178 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002179 /*FIXME*/ SourceRange(Loc),
2180 ObjectType,
2181 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002182 if (!NNS)
2183 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002184
Douglas Gregord1067e52009-08-06 06:41:21 +00002185 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002186 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002187 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002188 if (!TransTemplate)
2189 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Douglas Gregord1067e52009-08-06 06:41:21 +00002191 if (!getDerived().AlwaysRebuild() &&
2192 NNS == QTN->getQualifier() &&
2193 TransTemplate == Template)
2194 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002195
Douglas Gregord1067e52009-08-06 06:41:21 +00002196 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2197 TransTemplate);
2198 }
Mike Stump1eb44332009-09-09 15:08:12 +00002199
John McCallf7a1a742009-11-24 19:00:30 +00002200 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002201 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002202 }
Mike Stump1eb44332009-09-09 15:08:12 +00002203
Douglas Gregord1067e52009-08-06 06:41:21 +00002204 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002205 NestedNameSpecifier *NNS = DTN->getQualifier();
2206 if (NNS) {
2207 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2208 /*FIXME:*/SourceRange(Loc),
2209 ObjectType,
2210 FirstQualifierInScope);
2211 if (!NNS) return TemplateName();
2212
2213 // These apply to the scope specifier, not the template.
2214 ObjectType = QualType();
2215 FirstQualifierInScope = 0;
2216 }
Mike Stump1eb44332009-09-09 15:08:12 +00002217
Douglas Gregord1067e52009-08-06 06:41:21 +00002218 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002219 NNS == DTN->getQualifier() &&
2220 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002221 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002222
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002223 if (DTN->isIdentifier()) {
2224 // FIXME: Bad range
2225 SourceRange QualifierRange(getDerived().getBaseLocation());
2226 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2227 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002228 ObjectType,
2229 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002230 }
Sean Huntc3021132010-05-05 15:23:54 +00002231
2232 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002233 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002234 }
Mike Stump1eb44332009-09-09 15:08:12 +00002235
Douglas Gregord1067e52009-08-06 06:41:21 +00002236 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002237 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002238 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002239 if (!TransTemplate)
2240 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002241
Douglas Gregord1067e52009-08-06 06:41:21 +00002242 if (!getDerived().AlwaysRebuild() &&
2243 TransTemplate == Template)
2244 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002245
Douglas Gregord1067e52009-08-06 06:41:21 +00002246 return TemplateName(TransTemplate);
2247 }
Mike Stump1eb44332009-09-09 15:08:12 +00002248
John McCallf7a1a742009-11-24 19:00:30 +00002249 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002250 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002251 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002252}
2253
2254template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002255void TreeTransform<Derived>::InventTemplateArgumentLoc(
2256 const TemplateArgument &Arg,
2257 TemplateArgumentLoc &Output) {
2258 SourceLocation Loc = getDerived().getBaseLocation();
2259 switch (Arg.getKind()) {
2260 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002261 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002262 break;
2263
2264 case TemplateArgument::Type:
2265 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002266 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002267
John McCall833ca992009-10-29 08:12:44 +00002268 break;
2269
Douglas Gregor788cd062009-11-11 01:00:40 +00002270 case TemplateArgument::Template:
2271 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2272 break;
Sean Huntc3021132010-05-05 15:23:54 +00002273
John McCall833ca992009-10-29 08:12:44 +00002274 case TemplateArgument::Expression:
2275 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2276 break;
2277
2278 case TemplateArgument::Declaration:
2279 case TemplateArgument::Integral:
2280 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002281 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002282 break;
2283 }
2284}
2285
2286template<typename Derived>
2287bool TreeTransform<Derived>::TransformTemplateArgument(
2288 const TemplateArgumentLoc &Input,
2289 TemplateArgumentLoc &Output) {
2290 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002291 switch (Arg.getKind()) {
2292 case TemplateArgument::Null:
2293 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002294 Output = Input;
2295 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002296
Douglas Gregor670444e2009-08-04 22:27:00 +00002297 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002298 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002299 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002300 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002301
2302 DI = getDerived().TransformType(DI);
2303 if (!DI) return true;
2304
2305 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2306 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002307 }
Mike Stump1eb44332009-09-09 15:08:12 +00002308
Douglas Gregor670444e2009-08-04 22:27:00 +00002309 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002310 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002311 DeclarationName Name;
2312 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2313 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002314 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002315 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002316 if (!D) return true;
2317
John McCall828bff22009-10-29 18:45:58 +00002318 Expr *SourceExpr = Input.getSourceDeclExpression();
2319 if (SourceExpr) {
2320 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002321 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002322 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002323 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002324 }
2325
2326 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002327 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002328 }
Mike Stump1eb44332009-09-09 15:08:12 +00002329
Douglas Gregor788cd062009-11-11 01:00:40 +00002330 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002331 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002332 TemplateName Template
2333 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2334 if (Template.isNull())
2335 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002336
Douglas Gregor788cd062009-11-11 01:00:40 +00002337 Output = TemplateArgumentLoc(TemplateArgument(Template),
2338 Input.getTemplateQualifierRange(),
2339 Input.getTemplateNameLoc());
2340 return false;
2341 }
Sean Huntc3021132010-05-05 15:23:54 +00002342
Douglas Gregor670444e2009-08-04 22:27:00 +00002343 case TemplateArgument::Expression: {
2344 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002345 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002346 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002347
John McCall833ca992009-10-29 08:12:44 +00002348 Expr *InputExpr = Input.getSourceExpression();
2349 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2350
John McCall60d7b3a2010-08-24 06:29:42 +00002351 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002352 = getDerived().TransformExpr(InputExpr);
2353 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002354 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002355 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002356 }
Mike Stump1eb44332009-09-09 15:08:12 +00002357
Douglas Gregor670444e2009-08-04 22:27:00 +00002358 case TemplateArgument::Pack: {
2359 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2360 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002361 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002362 AEnd = Arg.pack_end();
2363 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002364
John McCall833ca992009-10-29 08:12:44 +00002365 // FIXME: preserve source information here when we start
2366 // caring about parameter packs.
2367
John McCall828bff22009-10-29 18:45:58 +00002368 TemplateArgumentLoc InputArg;
2369 TemplateArgumentLoc OutputArg;
2370 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2371 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002372 return true;
2373
John McCall828bff22009-10-29 18:45:58 +00002374 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002375 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002376
2377 TemplateArgument *TransformedArgsPtr
2378 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2379 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2380 TransformedArgsPtr);
2381 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2382 TransformedArgs.size()),
2383 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002384 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002385 }
2386 }
Mike Stump1eb44332009-09-09 15:08:12 +00002387
Douglas Gregor670444e2009-08-04 22:27:00 +00002388 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002389 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002390}
2391
Douglas Gregor577f75a2009-08-04 16:50:30 +00002392//===----------------------------------------------------------------------===//
2393// Type transformation
2394//===----------------------------------------------------------------------===//
2395
2396template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002397QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002398 if (getDerived().AlreadyTransformed(T))
2399 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002400
John McCalla2becad2009-10-21 00:40:46 +00002401 // Temporary workaround. All of these transformations should
2402 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002403 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002404 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002405
John McCall43fed0d2010-11-12 08:19:04 +00002406 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002407
John McCalla2becad2009-10-21 00:40:46 +00002408 if (!NewDI)
2409 return QualType();
2410
2411 return NewDI->getType();
2412}
2413
2414template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002415TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002416 if (getDerived().AlreadyTransformed(DI->getType()))
2417 return DI;
2418
2419 TypeLocBuilder TLB;
2420
2421 TypeLoc TL = DI->getTypeLoc();
2422 TLB.reserve(TL.getFullDataSize());
2423
John McCall43fed0d2010-11-12 08:19:04 +00002424 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002425 if (Result.isNull())
2426 return 0;
2427
John McCalla93c9342009-12-07 02:54:59 +00002428 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002429}
2430
2431template<typename Derived>
2432QualType
John McCall43fed0d2010-11-12 08:19:04 +00002433TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002434 switch (T.getTypeLocClass()) {
2435#define ABSTRACT_TYPELOC(CLASS, PARENT)
2436#define TYPELOC(CLASS, PARENT) \
2437 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002438 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002439#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002440 }
Mike Stump1eb44332009-09-09 15:08:12 +00002441
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002442 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002443 return QualType();
2444}
2445
2446/// FIXME: By default, this routine adds type qualifiers only to types
2447/// that can have qualifiers, and silently suppresses those qualifiers
2448/// that are not permitted (e.g., qualifiers on reference or function
2449/// types). This is the right thing for template instantiation, but
2450/// probably not for other clients.
2451template<typename Derived>
2452QualType
2453TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002454 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002455 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002456
John McCall43fed0d2010-11-12 08:19:04 +00002457 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002458 if (Result.isNull())
2459 return QualType();
2460
2461 // Silently suppress qualifiers if the result type can't be qualified.
2462 // FIXME: this is the right thing for template instantiation, but
2463 // probably not for other clients.
2464 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002465 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002466
John McCall28654742010-06-05 06:41:15 +00002467 if (!Quals.empty()) {
2468 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2469 TLB.push<QualifiedTypeLoc>(Result);
2470 // No location information to preserve.
2471 }
John McCalla2becad2009-10-21 00:40:46 +00002472
2473 return Result;
2474}
2475
John McCall43fed0d2010-11-12 08:19:04 +00002476/// \brief Transforms a type that was written in a scope specifier,
2477/// given an object type, the results of unqualified lookup, and
2478/// an already-instantiated prefix.
2479///
2480/// The object type is provided iff the scope specifier qualifies the
2481/// member of a dependent member-access expression. The prefix is
2482/// provided iff the the scope specifier in which this appears has a
2483/// prefix.
2484///
2485/// This is private to TreeTransform.
2486template<typename Derived>
2487QualType
2488TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2489 QualType ObjectType,
2490 NamedDecl *UnqualLookup,
2491 NestedNameSpecifier *Prefix) {
2492 if (getDerived().AlreadyTransformed(T))
2493 return T;
2494
2495 TypeSourceInfo *TSI =
2496 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2497
2498 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2499 UnqualLookup, Prefix);
2500 if (!TSI) return QualType();
2501 return TSI->getType();
2502}
2503
2504template<typename Derived>
2505TypeSourceInfo *
2506TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2507 QualType ObjectType,
2508 NamedDecl *UnqualLookup,
2509 NestedNameSpecifier *Prefix) {
2510 // TODO: in some cases, we might be some verification to do here.
2511 if (ObjectType.isNull())
2512 return getDerived().TransformType(TSI);
2513
2514 QualType T = TSI->getType();
2515 if (getDerived().AlreadyTransformed(T))
2516 return TSI;
2517
2518 TypeLocBuilder TLB;
2519 QualType Result;
2520
2521 if (isa<TemplateSpecializationType>(T)) {
2522 TemplateSpecializationTypeLoc TL
2523 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2524
2525 TemplateName Template =
2526 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2527 ObjectType, UnqualLookup);
2528 if (Template.isNull()) return 0;
2529
2530 Result = getDerived()
2531 .TransformTemplateSpecializationType(TLB, TL, Template);
2532 } else if (isa<DependentTemplateSpecializationType>(T)) {
2533 DependentTemplateSpecializationTypeLoc TL
2534 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2535
2536 Result = getDerived()
2537 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2538 } else {
2539 // Nothing special needs to be done for these.
2540 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2541 }
2542
2543 if (Result.isNull()) return 0;
2544 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2545}
2546
John McCalla2becad2009-10-21 00:40:46 +00002547template <class TyLoc> static inline
2548QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2549 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2550 NewT.setNameLoc(T.getNameLoc());
2551 return T.getType();
2552}
2553
John McCalla2becad2009-10-21 00:40:46 +00002554template<typename Derived>
2555QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002556 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002557 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2558 NewT.setBuiltinLoc(T.getBuiltinLoc());
2559 if (T.needsExtraLocalData())
2560 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2561 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002562}
Mike Stump1eb44332009-09-09 15:08:12 +00002563
Douglas Gregor577f75a2009-08-04 16:50:30 +00002564template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002565QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002566 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002567 // FIXME: recurse?
2568 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002569}
Mike Stump1eb44332009-09-09 15:08:12 +00002570
Douglas Gregor577f75a2009-08-04 16:50:30 +00002571template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002572QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002573 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00002574 QualType PointeeType
2575 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002576 if (PointeeType.isNull())
2577 return QualType();
2578
2579 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002580 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002581 // A dependent pointer type 'T *' has is being transformed such
2582 // that an Objective-C class type is being replaced for 'T'. The
2583 // resulting pointer type is an ObjCObjectPointerType, not a
2584 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002585 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002586
John McCallc12c5bb2010-05-15 11:32:37 +00002587 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2588 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002589 return Result;
2590 }
John McCall43fed0d2010-11-12 08:19:04 +00002591
Douglas Gregor92e986e2010-04-22 16:44:27 +00002592 if (getDerived().AlwaysRebuild() ||
2593 PointeeType != TL.getPointeeLoc().getType()) {
2594 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2595 if (Result.isNull())
2596 return QualType();
2597 }
Sean Huntc3021132010-05-05 15:23:54 +00002598
Douglas Gregor92e986e2010-04-22 16:44:27 +00002599 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2600 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002601 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002602}
Mike Stump1eb44332009-09-09 15:08:12 +00002603
2604template<typename Derived>
2605QualType
John McCalla2becad2009-10-21 00:40:46 +00002606TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002607 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002608 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002609 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2610 if (PointeeType.isNull())
2611 return QualType();
2612
2613 QualType Result = TL.getType();
2614 if (getDerived().AlwaysRebuild() ||
2615 PointeeType != TL.getPointeeLoc().getType()) {
2616 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002617 TL.getSigilLoc());
2618 if (Result.isNull())
2619 return QualType();
2620 }
2621
Douglas Gregor39968ad2010-04-22 16:50:51 +00002622 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002623 NewT.setSigilLoc(TL.getSigilLoc());
2624 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002625}
2626
John McCall85737a72009-10-30 00:06:24 +00002627/// Transforms a reference type. Note that somewhat paradoxically we
2628/// don't care whether the type itself is an l-value type or an r-value
2629/// type; we only care if the type was *written* as an l-value type
2630/// or an r-value type.
2631template<typename Derived>
2632QualType
2633TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002634 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002635 const ReferenceType *T = TL.getTypePtr();
2636
2637 // Note that this works with the pointee-as-written.
2638 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2639 if (PointeeType.isNull())
2640 return QualType();
2641
2642 QualType Result = TL.getType();
2643 if (getDerived().AlwaysRebuild() ||
2644 PointeeType != T->getPointeeTypeAsWritten()) {
2645 Result = getDerived().RebuildReferenceType(PointeeType,
2646 T->isSpelledAsLValue(),
2647 TL.getSigilLoc());
2648 if (Result.isNull())
2649 return QualType();
2650 }
2651
2652 // r-value references can be rebuilt as l-value references.
2653 ReferenceTypeLoc NewTL;
2654 if (isa<LValueReferenceType>(Result))
2655 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2656 else
2657 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2658 NewTL.setSigilLoc(TL.getSigilLoc());
2659
2660 return Result;
2661}
2662
Mike Stump1eb44332009-09-09 15:08:12 +00002663template<typename Derived>
2664QualType
John McCalla2becad2009-10-21 00:40:46 +00002665TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002666 LValueReferenceTypeLoc TL) {
2667 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002668}
2669
Mike Stump1eb44332009-09-09 15:08:12 +00002670template<typename Derived>
2671QualType
John McCalla2becad2009-10-21 00:40:46 +00002672TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002673 RValueReferenceTypeLoc TL) {
2674 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002675}
Mike Stump1eb44332009-09-09 15:08:12 +00002676
Douglas Gregor577f75a2009-08-04 16:50:30 +00002677template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002678QualType
John McCalla2becad2009-10-21 00:40:46 +00002679TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002680 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002681 MemberPointerType *T = TL.getTypePtr();
2682
2683 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684 if (PointeeType.isNull())
2685 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002686
John McCalla2becad2009-10-21 00:40:46 +00002687 // TODO: preserve source information for this.
2688 QualType ClassType
2689 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002690 if (ClassType.isNull())
2691 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002692
John McCalla2becad2009-10-21 00:40:46 +00002693 QualType Result = TL.getType();
2694 if (getDerived().AlwaysRebuild() ||
2695 PointeeType != T->getPointeeType() ||
2696 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002697 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2698 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002699 if (Result.isNull())
2700 return QualType();
2701 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002702
John McCalla2becad2009-10-21 00:40:46 +00002703 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2704 NewTL.setSigilLoc(TL.getSigilLoc());
2705
2706 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002707}
2708
Mike Stump1eb44332009-09-09 15:08:12 +00002709template<typename Derived>
2710QualType
John McCalla2becad2009-10-21 00:40:46 +00002711TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002712 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002713 ConstantArrayType *T = TL.getTypePtr();
2714 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002715 if (ElementType.isNull())
2716 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002717
John McCalla2becad2009-10-21 00:40:46 +00002718 QualType Result = TL.getType();
2719 if (getDerived().AlwaysRebuild() ||
2720 ElementType != T->getElementType()) {
2721 Result = getDerived().RebuildConstantArrayType(ElementType,
2722 T->getSizeModifier(),
2723 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002724 T->getIndexTypeCVRQualifiers(),
2725 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002726 if (Result.isNull())
2727 return QualType();
2728 }
Sean Huntc3021132010-05-05 15:23:54 +00002729
John McCalla2becad2009-10-21 00:40:46 +00002730 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2731 NewTL.setLBracketLoc(TL.getLBracketLoc());
2732 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002733
John McCalla2becad2009-10-21 00:40:46 +00002734 Expr *Size = TL.getSizeExpr();
2735 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002736 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002737 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2738 }
2739 NewTL.setSizeExpr(Size);
2740
2741 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002742}
Mike Stump1eb44332009-09-09 15:08:12 +00002743
Douglas Gregor577f75a2009-08-04 16:50:30 +00002744template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002745QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002746 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002747 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002748 IncompleteArrayType *T = TL.getTypePtr();
2749 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002750 if (ElementType.isNull())
2751 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002752
John McCalla2becad2009-10-21 00:40:46 +00002753 QualType Result = TL.getType();
2754 if (getDerived().AlwaysRebuild() ||
2755 ElementType != T->getElementType()) {
2756 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002757 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002758 T->getIndexTypeCVRQualifiers(),
2759 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002760 if (Result.isNull())
2761 return QualType();
2762 }
Sean Huntc3021132010-05-05 15:23:54 +00002763
John McCalla2becad2009-10-21 00:40:46 +00002764 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2765 NewTL.setLBracketLoc(TL.getLBracketLoc());
2766 NewTL.setRBracketLoc(TL.getRBracketLoc());
2767 NewTL.setSizeExpr(0);
2768
2769 return Result;
2770}
2771
2772template<typename Derived>
2773QualType
2774TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002775 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002776 VariableArrayType *T = TL.getTypePtr();
2777 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2778 if (ElementType.isNull())
2779 return QualType();
2780
2781 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002782 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002783
John McCall60d7b3a2010-08-24 06:29:42 +00002784 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002785 = getDerived().TransformExpr(T->getSizeExpr());
2786 if (SizeResult.isInvalid())
2787 return QualType();
2788
John McCall9ae2f072010-08-23 23:25:46 +00002789 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002790
2791 QualType Result = TL.getType();
2792 if (getDerived().AlwaysRebuild() ||
2793 ElementType != T->getElementType() ||
2794 Size != T->getSizeExpr()) {
2795 Result = getDerived().RebuildVariableArrayType(ElementType,
2796 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002797 Size,
John McCalla2becad2009-10-21 00:40:46 +00002798 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002799 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002800 if (Result.isNull())
2801 return QualType();
2802 }
Sean Huntc3021132010-05-05 15:23:54 +00002803
John McCalla2becad2009-10-21 00:40:46 +00002804 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2805 NewTL.setLBracketLoc(TL.getLBracketLoc());
2806 NewTL.setRBracketLoc(TL.getRBracketLoc());
2807 NewTL.setSizeExpr(Size);
2808
2809 return Result;
2810}
2811
2812template<typename Derived>
2813QualType
2814TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002815 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002816 DependentSizedArrayType *T = TL.getTypePtr();
2817 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2818 if (ElementType.isNull())
2819 return QualType();
2820
2821 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002822 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002823
John McCall60d7b3a2010-08-24 06:29:42 +00002824 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002825 = getDerived().TransformExpr(T->getSizeExpr());
2826 if (SizeResult.isInvalid())
2827 return QualType();
2828
2829 Expr *Size = static_cast<Expr*>(SizeResult.get());
2830
2831 QualType Result = TL.getType();
2832 if (getDerived().AlwaysRebuild() ||
2833 ElementType != T->getElementType() ||
2834 Size != T->getSizeExpr()) {
2835 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2836 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002837 Size,
John McCalla2becad2009-10-21 00:40:46 +00002838 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002839 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002840 if (Result.isNull())
2841 return QualType();
2842 }
2843 else SizeResult.take();
2844
2845 // We might have any sort of array type now, but fortunately they
2846 // all have the same location layout.
2847 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2848 NewTL.setLBracketLoc(TL.getLBracketLoc());
2849 NewTL.setRBracketLoc(TL.getRBracketLoc());
2850 NewTL.setSizeExpr(Size);
2851
2852 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002853}
Mike Stump1eb44332009-09-09 15:08:12 +00002854
2855template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002856QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002857 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002858 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002859 DependentSizedExtVectorType *T = TL.getTypePtr();
2860
2861 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002862 QualType ElementType = getDerived().TransformType(T->getElementType());
2863 if (ElementType.isNull())
2864 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002865
Douglas Gregor670444e2009-08-04 22:27:00 +00002866 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002867 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002868
John McCall60d7b3a2010-08-24 06:29:42 +00002869 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002870 if (Size.isInvalid())
2871 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002872
John McCalla2becad2009-10-21 00:40:46 +00002873 QualType Result = TL.getType();
2874 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002875 ElementType != T->getElementType() ||
2876 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002877 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002878 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002879 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002880 if (Result.isNull())
2881 return QualType();
2882 }
John McCalla2becad2009-10-21 00:40:46 +00002883
2884 // Result might be dependent or not.
2885 if (isa<DependentSizedExtVectorType>(Result)) {
2886 DependentSizedExtVectorTypeLoc NewTL
2887 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2888 NewTL.setNameLoc(TL.getNameLoc());
2889 } else {
2890 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2891 NewTL.setNameLoc(TL.getNameLoc());
2892 }
2893
2894 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002895}
Mike Stump1eb44332009-09-09 15:08:12 +00002896
2897template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002898QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002899 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002900 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002901 QualType ElementType = getDerived().TransformType(T->getElementType());
2902 if (ElementType.isNull())
2903 return QualType();
2904
John McCalla2becad2009-10-21 00:40:46 +00002905 QualType Result = TL.getType();
2906 if (getDerived().AlwaysRebuild() ||
2907 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002908 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00002909 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00002910 if (Result.isNull())
2911 return QualType();
2912 }
Sean Huntc3021132010-05-05 15:23:54 +00002913
John McCalla2becad2009-10-21 00:40:46 +00002914 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2915 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002916
John McCalla2becad2009-10-21 00:40:46 +00002917 return Result;
2918}
2919
2920template<typename Derived>
2921QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002922 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002923 VectorType *T = TL.getTypePtr();
2924 QualType ElementType = getDerived().TransformType(T->getElementType());
2925 if (ElementType.isNull())
2926 return QualType();
2927
2928 QualType Result = TL.getType();
2929 if (getDerived().AlwaysRebuild() ||
2930 ElementType != T->getElementType()) {
2931 Result = getDerived().RebuildExtVectorType(ElementType,
2932 T->getNumElements(),
2933 /*FIXME*/ SourceLocation());
2934 if (Result.isNull())
2935 return QualType();
2936 }
Sean Huntc3021132010-05-05 15:23:54 +00002937
John McCalla2becad2009-10-21 00:40:46 +00002938 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2939 NewTL.setNameLoc(TL.getNameLoc());
2940
2941 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002942}
Mike Stump1eb44332009-09-09 15:08:12 +00002943
2944template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002945ParmVarDecl *
2946TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2947 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2948 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2949 if (!NewDI)
2950 return 0;
2951
2952 if (NewDI == OldDI)
2953 return OldParm;
2954 else
2955 return ParmVarDecl::Create(SemaRef.Context,
2956 OldParm->getDeclContext(),
2957 OldParm->getLocation(),
2958 OldParm->getIdentifier(),
2959 NewDI->getType(),
2960 NewDI,
2961 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002962 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002963 /* DefArg */ NULL);
2964}
2965
2966template<typename Derived>
2967bool TreeTransform<Derived>::
2968 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2969 llvm::SmallVectorImpl<QualType> &PTypes,
2970 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2971 FunctionProtoType *T = TL.getTypePtr();
2972
2973 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2974 ParmVarDecl *OldParm = TL.getArg(i);
2975
2976 QualType NewType;
2977 ParmVarDecl *NewParm;
2978
2979 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002980 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2981 if (!NewParm)
2982 return true;
2983 NewType = NewParm->getType();
2984
2985 // Deal with the possibility that we don't have a parameter
2986 // declaration for this parameter.
2987 } else {
2988 NewParm = 0;
2989
2990 QualType OldType = T->getArgType(i);
2991 NewType = getDerived().TransformType(OldType);
2992 if (NewType.isNull())
2993 return true;
2994 }
2995
2996 PTypes.push_back(NewType);
2997 PVars.push_back(NewParm);
2998 }
2999
3000 return false;
3001}
3002
3003template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003004QualType
John McCalla2becad2009-10-21 00:40:46 +00003005TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003006 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003007 // Transform the parameters and return type.
3008 //
3009 // We instantiate in source order, with the return type first followed by
3010 // the parameters, because users tend to expect this (even if they shouldn't
3011 // rely on it!).
3012 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003013 // When the function has a trailing return type, we instantiate the
3014 // parameters before the return type, since the return type can then refer
3015 // to the parameters themselves (via decltype, sizeof, etc.).
3016 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003017 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003018 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003019 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003020
Douglas Gregordab60ad2010-10-01 18:44:50 +00003021 QualType ResultType;
3022
3023 if (TL.getTrailingReturn()) {
3024 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3025 return QualType();
3026
3027 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3028 if (ResultType.isNull())
3029 return QualType();
3030 }
3031 else {
3032 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3033 if (ResultType.isNull())
3034 return QualType();
3035
3036 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3037 return QualType();
3038 }
3039
John McCalla2becad2009-10-21 00:40:46 +00003040 QualType Result = TL.getType();
3041 if (getDerived().AlwaysRebuild() ||
3042 ResultType != T->getResultType() ||
3043 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3044 Result = getDerived().RebuildFunctionProtoType(ResultType,
3045 ParamTypes.data(),
3046 ParamTypes.size(),
3047 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003048 T->getTypeQuals(),
3049 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003050 if (Result.isNull())
3051 return QualType();
3052 }
Mike Stump1eb44332009-09-09 15:08:12 +00003053
John McCalla2becad2009-10-21 00:40:46 +00003054 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3055 NewTL.setLParenLoc(TL.getLParenLoc());
3056 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003057 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003058 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3059 NewTL.setArg(i, ParamDecls[i]);
3060
3061 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003062}
Mike Stump1eb44332009-09-09 15:08:12 +00003063
Douglas Gregor577f75a2009-08-04 16:50:30 +00003064template<typename Derived>
3065QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003066 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003067 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003068 FunctionNoProtoType *T = TL.getTypePtr();
3069 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3070 if (ResultType.isNull())
3071 return QualType();
3072
3073 QualType Result = TL.getType();
3074 if (getDerived().AlwaysRebuild() ||
3075 ResultType != T->getResultType())
3076 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3077
3078 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3079 NewTL.setLParenLoc(TL.getLParenLoc());
3080 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003081 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003082
3083 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003084}
Mike Stump1eb44332009-09-09 15:08:12 +00003085
John McCalled976492009-12-04 22:46:56 +00003086template<typename Derived> QualType
3087TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003088 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003089 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003090 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003091 if (!D)
3092 return QualType();
3093
3094 QualType Result = TL.getType();
3095 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3096 Result = getDerived().RebuildUnresolvedUsingType(D);
3097 if (Result.isNull())
3098 return QualType();
3099 }
3100
3101 // We might get an arbitrary type spec type back. We should at
3102 // least always get a type spec type, though.
3103 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3104 NewTL.setNameLoc(TL.getNameLoc());
3105
3106 return Result;
3107}
3108
Douglas Gregor577f75a2009-08-04 16:50:30 +00003109template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003110QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003111 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003112 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003113 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003114 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3115 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003116 if (!Typedef)
3117 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003118
John McCalla2becad2009-10-21 00:40:46 +00003119 QualType Result = TL.getType();
3120 if (getDerived().AlwaysRebuild() ||
3121 Typedef != T->getDecl()) {
3122 Result = getDerived().RebuildTypedefType(Typedef);
3123 if (Result.isNull())
3124 return QualType();
3125 }
Mike Stump1eb44332009-09-09 15:08:12 +00003126
John McCalla2becad2009-10-21 00:40:46 +00003127 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3128 NewTL.setNameLoc(TL.getNameLoc());
3129
3130 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003131}
Mike Stump1eb44332009-09-09 15:08:12 +00003132
Douglas Gregor577f75a2009-08-04 16:50:30 +00003133template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003134QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003135 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003136 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003137 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003138
John McCall60d7b3a2010-08-24 06:29:42 +00003139 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003140 if (E.isInvalid())
3141 return QualType();
3142
John McCalla2becad2009-10-21 00:40:46 +00003143 QualType Result = TL.getType();
3144 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003145 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003146 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003147 if (Result.isNull())
3148 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003149 }
John McCalla2becad2009-10-21 00:40:46 +00003150 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003151
John McCalla2becad2009-10-21 00:40:46 +00003152 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003153 NewTL.setTypeofLoc(TL.getTypeofLoc());
3154 NewTL.setLParenLoc(TL.getLParenLoc());
3155 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003156
3157 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003158}
Mike Stump1eb44332009-09-09 15:08:12 +00003159
3160template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003161QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003162 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003163 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3164 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3165 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003166 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003167
John McCalla2becad2009-10-21 00:40:46 +00003168 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003169 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3170 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003171 if (Result.isNull())
3172 return QualType();
3173 }
Mike Stump1eb44332009-09-09 15:08:12 +00003174
John McCalla2becad2009-10-21 00:40:46 +00003175 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003176 NewTL.setTypeofLoc(TL.getTypeofLoc());
3177 NewTL.setLParenLoc(TL.getLParenLoc());
3178 NewTL.setRParenLoc(TL.getRParenLoc());
3179 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003180
3181 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003182}
Mike Stump1eb44332009-09-09 15:08:12 +00003183
3184template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003185QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003186 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003187 DecltypeType *T = TL.getTypePtr();
3188
Douglas Gregor670444e2009-08-04 22:27:00 +00003189 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003190 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003191
John McCall60d7b3a2010-08-24 06:29:42 +00003192 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003193 if (E.isInvalid())
3194 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003195
John McCalla2becad2009-10-21 00:40:46 +00003196 QualType Result = TL.getType();
3197 if (getDerived().AlwaysRebuild() ||
3198 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003199 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003200 if (Result.isNull())
3201 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003202 }
John McCalla2becad2009-10-21 00:40:46 +00003203 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003204
John McCalla2becad2009-10-21 00:40:46 +00003205 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3206 NewTL.setNameLoc(TL.getNameLoc());
3207
3208 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003209}
3210
3211template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003212QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003213 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003214 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003215 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003216 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3217 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003218 if (!Record)
3219 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003220
John McCalla2becad2009-10-21 00:40:46 +00003221 QualType Result = TL.getType();
3222 if (getDerived().AlwaysRebuild() ||
3223 Record != T->getDecl()) {
3224 Result = getDerived().RebuildRecordType(Record);
3225 if (Result.isNull())
3226 return QualType();
3227 }
Mike Stump1eb44332009-09-09 15:08:12 +00003228
John McCalla2becad2009-10-21 00:40:46 +00003229 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3230 NewTL.setNameLoc(TL.getNameLoc());
3231
3232 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003233}
Mike Stump1eb44332009-09-09 15:08:12 +00003234
3235template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003236QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003237 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003238 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003239 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003240 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3241 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003242 if (!Enum)
3243 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003244
John McCalla2becad2009-10-21 00:40:46 +00003245 QualType Result = TL.getType();
3246 if (getDerived().AlwaysRebuild() ||
3247 Enum != T->getDecl()) {
3248 Result = getDerived().RebuildEnumType(Enum);
3249 if (Result.isNull())
3250 return QualType();
3251 }
Mike Stump1eb44332009-09-09 15:08:12 +00003252
John McCalla2becad2009-10-21 00:40:46 +00003253 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3254 NewTL.setNameLoc(TL.getNameLoc());
3255
3256 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003257}
John McCall7da24312009-09-05 00:15:47 +00003258
John McCall3cb0ebd2010-03-10 03:28:59 +00003259template<typename Derived>
3260QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3261 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003262 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003263 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3264 TL.getTypePtr()->getDecl());
3265 if (!D) return QualType();
3266
3267 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3268 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3269 return T;
3270}
3271
Mike Stump1eb44332009-09-09 15:08:12 +00003272
Douglas Gregor577f75a2009-08-04 16:50:30 +00003273template<typename Derived>
3274QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003275 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003276 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003277 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003278}
3279
Mike Stump1eb44332009-09-09 15:08:12 +00003280template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003281QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003282 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003283 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003284 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003285}
3286
3287template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003288QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003289 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003290 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003291 const TemplateSpecializationType *T = TL.getTypePtr();
3292
Mike Stump1eb44332009-09-09 15:08:12 +00003293 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003294 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003295 if (Template.isNull())
3296 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003297
John McCall43fed0d2010-11-12 08:19:04 +00003298 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3299}
3300
3301template <typename Derived>
3302QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3303 TypeLocBuilder &TLB,
3304 TemplateSpecializationTypeLoc TL,
3305 TemplateName Template) {
3306 const TemplateSpecializationType *T = TL.getTypePtr();
3307
John McCalld5532b62009-11-23 01:53:49 +00003308 TemplateArgumentListInfo NewTemplateArgs;
3309 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3310 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3311
3312 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3313 TemplateArgumentLoc Loc;
3314 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003315 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003316 NewTemplateArgs.addArgument(Loc);
3317 }
Mike Stump1eb44332009-09-09 15:08:12 +00003318
John McCall833ca992009-10-29 08:12:44 +00003319 // FIXME: maybe don't rebuild if all the template arguments are the same.
3320
3321 QualType Result =
3322 getDerived().RebuildTemplateSpecializationType(Template,
3323 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003324 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003325
3326 if (!Result.isNull()) {
3327 TemplateSpecializationTypeLoc NewTL
3328 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3329 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3330 NewTL.setLAngleLoc(TL.getLAngleLoc());
3331 NewTL.setRAngleLoc(TL.getRAngleLoc());
3332 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3333 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003334 }
Mike Stump1eb44332009-09-09 15:08:12 +00003335
John McCall833ca992009-10-29 08:12:44 +00003336 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003337}
Mike Stump1eb44332009-09-09 15:08:12 +00003338
3339template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003340QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003341TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003342 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003343 ElaboratedType *T = TL.getTypePtr();
3344
3345 NestedNameSpecifier *NNS = 0;
3346 // NOTE: the qualifier in an ElaboratedType is optional.
3347 if (T->getQualifier() != 0) {
3348 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003349 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003350 if (!NNS)
3351 return QualType();
3352 }
Mike Stump1eb44332009-09-09 15:08:12 +00003353
John McCall43fed0d2010-11-12 08:19:04 +00003354 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3355 if (NamedT.isNull())
3356 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00003357
John McCalla2becad2009-10-21 00:40:46 +00003358 QualType Result = TL.getType();
3359 if (getDerived().AlwaysRebuild() ||
3360 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003361 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00003362 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3363 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003364 if (Result.isNull())
3365 return QualType();
3366 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003367
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003368 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003369 NewTL.setKeywordLoc(TL.getKeywordLoc());
3370 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003371
3372 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003373}
Mike Stump1eb44332009-09-09 15:08:12 +00003374
3375template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003376QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003377 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003378 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003379
Douglas Gregor577f75a2009-08-04 16:50:30 +00003380 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003381 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003382 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003383 if (!NNS)
3384 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003385
John McCall33500952010-06-11 00:33:02 +00003386 QualType Result
3387 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3388 T->getIdentifier(),
3389 TL.getKeywordLoc(),
3390 TL.getQualifierRange(),
3391 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003392 if (Result.isNull())
3393 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003394
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003395 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3396 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003397 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3398
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003399 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3400 NewTL.setKeywordLoc(TL.getKeywordLoc());
3401 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003402 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003403 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3404 NewTL.setKeywordLoc(TL.getKeywordLoc());
3405 NewTL.setQualifierRange(TL.getQualifierRange());
3406 NewTL.setNameLoc(TL.getNameLoc());
3407 }
John McCalla2becad2009-10-21 00:40:46 +00003408 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003409}
Mike Stump1eb44332009-09-09 15:08:12 +00003410
Douglas Gregor577f75a2009-08-04 16:50:30 +00003411template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003412QualType TreeTransform<Derived>::
3413 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003414 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00003415 DependentTemplateSpecializationType *T = TL.getTypePtr();
3416
3417 NestedNameSpecifier *NNS
3418 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003419 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003420 if (!NNS)
3421 return QualType();
3422
John McCall43fed0d2010-11-12 08:19:04 +00003423 return getDerived()
3424 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3425}
3426
3427template<typename Derived>
3428QualType TreeTransform<Derived>::
3429 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3430 DependentTemplateSpecializationTypeLoc TL,
3431 NestedNameSpecifier *NNS) {
3432 DependentTemplateSpecializationType *T = TL.getTypePtr();
3433
John McCall33500952010-06-11 00:33:02 +00003434 TemplateArgumentListInfo NewTemplateArgs;
3435 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3436 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3437
3438 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3439 TemplateArgumentLoc Loc;
3440 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3441 return QualType();
3442 NewTemplateArgs.addArgument(Loc);
3443 }
3444
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003445 QualType Result
3446 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3447 NNS,
3448 TL.getQualifierRange(),
3449 T->getIdentifier(),
3450 TL.getNameLoc(),
3451 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003452 if (Result.isNull())
3453 return QualType();
3454
3455 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3456 QualType NamedT = ElabT->getNamedType();
3457
3458 // Copy information relevant to the template specialization.
3459 TemplateSpecializationTypeLoc NamedTL
3460 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3461 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3462 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3463 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3464 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3465
3466 // Copy information relevant to the elaborated type.
3467 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3468 NewTL.setKeywordLoc(TL.getKeywordLoc());
3469 NewTL.setQualifierRange(TL.getQualifierRange());
3470 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003471 TypeLoc NewTL(Result, TL.getOpaqueData());
3472 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003473 }
3474 return Result;
3475}
3476
3477template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003478QualType
3479TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003480 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003481 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003482 TLB.pushFullCopy(TL);
3483 return TL.getType();
3484}
3485
3486template<typename Derived>
3487QualType
3488TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003489 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00003490 // ObjCObjectType is never dependent.
3491 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003492 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003493}
Mike Stump1eb44332009-09-09 15:08:12 +00003494
3495template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003496QualType
3497TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003498 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003499 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003500 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003501 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003502}
3503
Douglas Gregor577f75a2009-08-04 16:50:30 +00003504//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003505// Statement transformation
3506//===----------------------------------------------------------------------===//
3507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003508StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003509TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003510 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003511}
3512
3513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003514StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003515TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3516 return getDerived().TransformCompoundStmt(S, false);
3517}
3518
3519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003520StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003521TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003522 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003523 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003524 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003525 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003526 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3527 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003528 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003529 if (Result.isInvalid()) {
3530 // Immediately fail if this was a DeclStmt, since it's very
3531 // likely that this will cause problems for future statements.
3532 if (isa<DeclStmt>(*B))
3533 return StmtError();
3534
3535 // Otherwise, just keep processing substatements and fail later.
3536 SubStmtInvalid = true;
3537 continue;
3538 }
Mike Stump1eb44332009-09-09 15:08:12 +00003539
Douglas Gregor43959a92009-08-20 07:17:43 +00003540 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3541 Statements.push_back(Result.takeAs<Stmt>());
3542 }
Mike Stump1eb44332009-09-09 15:08:12 +00003543
John McCall7114cba2010-08-27 19:56:05 +00003544 if (SubStmtInvalid)
3545 return StmtError();
3546
Douglas Gregor43959a92009-08-20 07:17:43 +00003547 if (!getDerived().AlwaysRebuild() &&
3548 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003549 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003550
3551 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3552 move_arg(Statements),
3553 S->getRBracLoc(),
3554 IsStmtExpr);
3555}
Mike Stump1eb44332009-09-09 15:08:12 +00003556
Douglas Gregor43959a92009-08-20 07:17:43 +00003557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003558StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003559TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003560 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003561 {
3562 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003563 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003564
Eli Friedman264c1f82009-11-19 03:14:00 +00003565 // Transform the left-hand case value.
3566 LHS = getDerived().TransformExpr(S->getLHS());
3567 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003568 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003569
Eli Friedman264c1f82009-11-19 03:14:00 +00003570 // Transform the right-hand case value (for the GNU case-range extension).
3571 RHS = getDerived().TransformExpr(S->getRHS());
3572 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003573 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003574 }
Mike Stump1eb44332009-09-09 15:08:12 +00003575
Douglas Gregor43959a92009-08-20 07:17:43 +00003576 // Build the case statement.
3577 // Case statements are always rebuilt so that they will attached to their
3578 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003579 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003580 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003581 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003582 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003583 S->getColonLoc());
3584 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003585 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003586
Douglas Gregor43959a92009-08-20 07:17:43 +00003587 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003588 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003589 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003590 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003591
Douglas Gregor43959a92009-08-20 07:17:43 +00003592 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003593 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003594}
3595
3596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003597StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003598TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003599 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003600 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003601 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003602 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003603
Douglas Gregor43959a92009-08-20 07:17:43 +00003604 // Default statements are always rebuilt
3605 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003606 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003607}
Mike Stump1eb44332009-09-09 15:08:12 +00003608
Douglas Gregor43959a92009-08-20 07:17:43 +00003609template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003610StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003611TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003612 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003613 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003614 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003615
Douglas Gregor43959a92009-08-20 07:17:43 +00003616 // FIXME: Pass the real colon location in.
3617 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3618 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003619 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003620}
Mike Stump1eb44332009-09-09 15:08:12 +00003621
Douglas Gregor43959a92009-08-20 07:17:43 +00003622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003623StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003624TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003625 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003626 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003627 VarDecl *ConditionVar = 0;
3628 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003629 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003630 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003631 getDerived().TransformDefinition(
3632 S->getConditionVariable()->getLocation(),
3633 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003634 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003635 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003636 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003637 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003638
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003639 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003640 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003641
3642 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003643 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003644 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003645 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003646 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003647 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003648 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003649
John McCall9ae2f072010-08-23 23:25:46 +00003650 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003651 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003652 }
Sean Huntc3021132010-05-05 15:23:54 +00003653
John McCall9ae2f072010-08-23 23:25:46 +00003654 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3655 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003656 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003657
Douglas Gregor43959a92009-08-20 07:17:43 +00003658 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003659 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003660 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003661 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003662
Douglas Gregor43959a92009-08-20 07:17:43 +00003663 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003664 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003665 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003666 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003667
Douglas Gregor43959a92009-08-20 07:17:43 +00003668 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003669 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003670 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003671 Then.get() == S->getThen() &&
3672 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00003673 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003674
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003675 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00003676 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00003677 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003678}
3679
3680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003681StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003682TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003683 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003684 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003685 VarDecl *ConditionVar = 0;
3686 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003687 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003688 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003689 getDerived().TransformDefinition(
3690 S->getConditionVariable()->getLocation(),
3691 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003692 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003693 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003694 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003695 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003696
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003697 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003698 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003699 }
Mike Stump1eb44332009-09-09 15:08:12 +00003700
Douglas Gregor43959a92009-08-20 07:17:43 +00003701 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003702 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003703 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003704 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003705 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003706 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003707
Douglas Gregor43959a92009-08-20 07:17:43 +00003708 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003709 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003710 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003711 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003712
Douglas Gregor43959a92009-08-20 07:17:43 +00003713 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003714 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3715 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003716}
Mike Stump1eb44332009-09-09 15:08:12 +00003717
Douglas Gregor43959a92009-08-20 07:17:43 +00003718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003719StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003720TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003721 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003722 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003723 VarDecl *ConditionVar = 0;
3724 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003725 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003726 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003727 getDerived().TransformDefinition(
3728 S->getConditionVariable()->getLocation(),
3729 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003730 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003731 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003732 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003733 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003734
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003735 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003736 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003737
3738 if (S->getCond()) {
3739 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003740 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003741 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003742 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003743 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003744 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003745 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003746 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003747 }
Mike Stump1eb44332009-09-09 15:08:12 +00003748
John McCall9ae2f072010-08-23 23:25:46 +00003749 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3750 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003751 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003752
Douglas Gregor43959a92009-08-20 07:17:43 +00003753 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003754 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003755 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003756 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003757
Douglas Gregor43959a92009-08-20 07:17:43 +00003758 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003759 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003760 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003761 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003762 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003763
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003764 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003765 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003766}
Mike Stump1eb44332009-09-09 15:08:12 +00003767
Douglas Gregor43959a92009-08-20 07:17:43 +00003768template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003769StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003770TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003771 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003772 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003773 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003774 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003775
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003776 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003777 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003778 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003779 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003780
Douglas Gregor43959a92009-08-20 07:17:43 +00003781 if (!getDerived().AlwaysRebuild() &&
3782 Cond.get() == S->getCond() &&
3783 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003784 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003785
John McCall9ae2f072010-08-23 23:25:46 +00003786 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3787 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003788 S->getRParenLoc());
3789}
Mike Stump1eb44332009-09-09 15:08:12 +00003790
Douglas Gregor43959a92009-08-20 07:17:43 +00003791template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003792StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003793TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003794 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003795 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003796 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003797 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003798
Douglas Gregor43959a92009-08-20 07:17:43 +00003799 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003800 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003801 VarDecl *ConditionVar = 0;
3802 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003803 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003804 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003805 getDerived().TransformDefinition(
3806 S->getConditionVariable()->getLocation(),
3807 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003808 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003809 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003810 } else {
3811 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003812
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003813 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003814 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003815
3816 if (S->getCond()) {
3817 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003818 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003819 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003820 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003821 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003822 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003823
John McCall9ae2f072010-08-23 23:25:46 +00003824 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003825 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003826 }
Mike Stump1eb44332009-09-09 15:08:12 +00003827
John McCall9ae2f072010-08-23 23:25:46 +00003828 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3829 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003830 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003831
Douglas Gregor43959a92009-08-20 07:17:43 +00003832 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003833 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003834 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003835 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003836
John McCall9ae2f072010-08-23 23:25:46 +00003837 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3838 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003839 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003840
Douglas Gregor43959a92009-08-20 07:17:43 +00003841 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003842 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003843 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003844 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003845
Douglas Gregor43959a92009-08-20 07:17:43 +00003846 if (!getDerived().AlwaysRebuild() &&
3847 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003848 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003849 Inc.get() == S->getInc() &&
3850 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003851 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003852
Douglas Gregor43959a92009-08-20 07:17:43 +00003853 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003854 Init.get(), FullCond, ConditionVar,
3855 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003856}
3857
3858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003859StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003860TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003861 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003862 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003863 S->getLabel());
3864}
3865
3866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003867StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003868TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003869 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003870 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003871 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003872
Douglas Gregor43959a92009-08-20 07:17:43 +00003873 if (!getDerived().AlwaysRebuild() &&
3874 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00003875 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003876
3877 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003878 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003879}
3880
3881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003882StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003883TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003884 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003885}
Mike Stump1eb44332009-09-09 15:08:12 +00003886
Douglas Gregor43959a92009-08-20 07:17:43 +00003887template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003888StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003889TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003890 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003891}
Mike Stump1eb44332009-09-09 15:08:12 +00003892
Douglas Gregor43959a92009-08-20 07:17:43 +00003893template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003894StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003895TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003896 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003897 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003898 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003899
Mike Stump1eb44332009-09-09 15:08:12 +00003900 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003901 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003902 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003903}
Mike Stump1eb44332009-09-09 15:08:12 +00003904
Douglas Gregor43959a92009-08-20 07:17:43 +00003905template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003906StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003907TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003908 bool DeclChanged = false;
3909 llvm::SmallVector<Decl *, 4> Decls;
3910 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3911 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003912 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3913 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003914 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003915 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003916
Douglas Gregor43959a92009-08-20 07:17:43 +00003917 if (Transformed != *D)
3918 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003919
Douglas Gregor43959a92009-08-20 07:17:43 +00003920 Decls.push_back(Transformed);
3921 }
Mike Stump1eb44332009-09-09 15:08:12 +00003922
Douglas Gregor43959a92009-08-20 07:17:43 +00003923 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003924 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003925
3926 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003927 S->getStartLoc(), S->getEndLoc());
3928}
Mike Stump1eb44332009-09-09 15:08:12 +00003929
Douglas Gregor43959a92009-08-20 07:17:43 +00003930template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003931StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003932TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003933 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00003934 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003935}
3936
3937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003938StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003939TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003940
John McCallca0408f2010-08-23 06:44:23 +00003941 ASTOwningVector<Expr*> Constraints(getSema());
3942 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003943 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003944
John McCall60d7b3a2010-08-24 06:29:42 +00003945 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003946 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003947
3948 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003949
Anders Carlsson703e3942010-01-24 05:50:09 +00003950 // Go through the outputs.
3951 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003952 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003953
Anders Carlsson703e3942010-01-24 05:50:09 +00003954 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00003955 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00003956
Anders Carlsson703e3942010-01-24 05:50:09 +00003957 // Transform the output expr.
3958 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003959 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003960 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003961 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003962
Anders Carlsson703e3942010-01-24 05:50:09 +00003963 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003964
John McCall9ae2f072010-08-23 23:25:46 +00003965 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003966 }
Sean Huntc3021132010-05-05 15:23:54 +00003967
Anders Carlsson703e3942010-01-24 05:50:09 +00003968 // Go through the inputs.
3969 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003970 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003971
Anders Carlsson703e3942010-01-24 05:50:09 +00003972 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00003973 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00003974
Anders Carlsson703e3942010-01-24 05:50:09 +00003975 // Transform the input expr.
3976 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003977 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003978 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003979 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003980
Anders Carlsson703e3942010-01-24 05:50:09 +00003981 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003982
John McCall9ae2f072010-08-23 23:25:46 +00003983 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003984 }
Sean Huntc3021132010-05-05 15:23:54 +00003985
Anders Carlsson703e3942010-01-24 05:50:09 +00003986 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003987 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00003988
3989 // Go through the clobbers.
3990 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00003991 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00003992
3993 // No need to transform the asm string literal.
3994 AsmString = SemaRef.Owned(S->getAsmString());
3995
3996 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3997 S->isSimple(),
3998 S->isVolatile(),
3999 S->getNumOutputs(),
4000 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004001 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004002 move_arg(Constraints),
4003 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004004 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004005 move_arg(Clobbers),
4006 S->getRParenLoc(),
4007 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004008}
4009
4010
4011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004012StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004013TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004014 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004015 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004016 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004017 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004018
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004019 // Transform the @catch statements (if present).
4020 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004021 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004022 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004023 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004024 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004025 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004026 if (Catch.get() != S->getCatchStmt(I))
4027 AnyCatchChanged = true;
4028 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004029 }
Sean Huntc3021132010-05-05 15:23:54 +00004030
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004031 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004032 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004033 if (S->getFinallyStmt()) {
4034 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4035 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004036 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004037 }
4038
4039 // If nothing changed, just retain this statement.
4040 if (!getDerived().AlwaysRebuild() &&
4041 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004042 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004043 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004044 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004045
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004046 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004047 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4048 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004049}
Mike Stump1eb44332009-09-09 15:08:12 +00004050
Douglas Gregor43959a92009-08-20 07:17:43 +00004051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004052StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004053TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004054 // Transform the @catch parameter, if there is one.
4055 VarDecl *Var = 0;
4056 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4057 TypeSourceInfo *TSInfo = 0;
4058 if (FromVar->getTypeSourceInfo()) {
4059 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4060 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004061 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004062 }
Sean Huntc3021132010-05-05 15:23:54 +00004063
Douglas Gregorbe270a02010-04-26 17:57:08 +00004064 QualType T;
4065 if (TSInfo)
4066 T = TSInfo->getType();
4067 else {
4068 T = getDerived().TransformType(FromVar->getType());
4069 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004070 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004071 }
Sean Huntc3021132010-05-05 15:23:54 +00004072
Douglas Gregorbe270a02010-04-26 17:57:08 +00004073 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4074 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004075 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004076 }
Sean Huntc3021132010-05-05 15:23:54 +00004077
John McCall60d7b3a2010-08-24 06:29:42 +00004078 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004079 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004080 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004081
4082 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004083 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004084 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004085}
Mike Stump1eb44332009-09-09 15:08:12 +00004086
Douglas Gregor43959a92009-08-20 07:17:43 +00004087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004088StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004089TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004090 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004091 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004092 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004093 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004094
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004095 // If nothing changed, just retain this statement.
4096 if (!getDerived().AlwaysRebuild() &&
4097 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004098 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004099
4100 // Build a new statement.
4101 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004102 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004103}
Mike Stump1eb44332009-09-09 15:08:12 +00004104
Douglas Gregor43959a92009-08-20 07:17:43 +00004105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004106StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004107TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004108 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004109 if (S->getThrowExpr()) {
4110 Operand = getDerived().TransformExpr(S->getThrowExpr());
4111 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004112 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004113 }
Sean Huntc3021132010-05-05 15:23:54 +00004114
Douglas Gregord1377b22010-04-22 21:44:01 +00004115 if (!getDerived().AlwaysRebuild() &&
4116 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004117 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004118
John McCall9ae2f072010-08-23 23:25:46 +00004119 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004120}
Mike Stump1eb44332009-09-09 15:08:12 +00004121
Douglas Gregor43959a92009-08-20 07:17:43 +00004122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004123StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004124TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004125 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004126 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004127 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004128 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004129 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004130
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004131 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004132 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004133 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004134 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004135
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004136 // If nothing change, just retain the current statement.
4137 if (!getDerived().AlwaysRebuild() &&
4138 Object.get() == S->getSynchExpr() &&
4139 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004140 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004141
4142 // Build a new statement.
4143 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004144 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004145}
4146
4147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004148StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004149TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004150 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004151 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004152 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004153 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004154 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004155
Douglas Gregorc3203e72010-04-22 23:10:45 +00004156 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004157 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004158 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004159 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004160
Douglas Gregorc3203e72010-04-22 23:10:45 +00004161 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004162 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004163 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004164 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004165
Douglas Gregorc3203e72010-04-22 23:10:45 +00004166 // If nothing changed, just retain this statement.
4167 if (!getDerived().AlwaysRebuild() &&
4168 Element.get() == S->getElement() &&
4169 Collection.get() == S->getCollection() &&
4170 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004171 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004172
Douglas Gregorc3203e72010-04-22 23:10:45 +00004173 // Build a new statement.
4174 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4175 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004176 Element.get(),
4177 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004178 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004179 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004180}
4181
4182
4183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004184StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004185TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4186 // Transform the exception declaration, if any.
4187 VarDecl *Var = 0;
4188 if (S->getExceptionDecl()) {
4189 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004190 TypeSourceInfo *T = getDerived().TransformType(
4191 ExceptionDecl->getTypeSourceInfo());
4192 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004193 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004194
Douglas Gregor83cb9422010-09-09 17:09:21 +00004195 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004196 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004197 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004198 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004199 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004200 }
Mike Stump1eb44332009-09-09 15:08:12 +00004201
Douglas Gregor43959a92009-08-20 07:17:43 +00004202 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004203 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004204 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004205 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004206
Douglas Gregor43959a92009-08-20 07:17:43 +00004207 if (!getDerived().AlwaysRebuild() &&
4208 !Var &&
4209 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004210 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004211
4212 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4213 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004214 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004215}
Mike Stump1eb44332009-09-09 15:08:12 +00004216
Douglas Gregor43959a92009-08-20 07:17:43 +00004217template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004218StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004219TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4220 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004221 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004222 = getDerived().TransformCompoundStmt(S->getTryBlock());
4223 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004224 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregor43959a92009-08-20 07:17:43 +00004226 // Transform the handlers.
4227 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004228 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004229 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004230 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004231 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4232 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004233 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004234
Douglas Gregor43959a92009-08-20 07:17:43 +00004235 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4236 Handlers.push_back(Handler.takeAs<Stmt>());
4237 }
Mike Stump1eb44332009-09-09 15:08:12 +00004238
Douglas Gregor43959a92009-08-20 07:17:43 +00004239 if (!getDerived().AlwaysRebuild() &&
4240 TryBlock.get() == S->getTryBlock() &&
4241 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004242 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004243
John McCall9ae2f072010-08-23 23:25:46 +00004244 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004245 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004246}
Mike Stump1eb44332009-09-09 15:08:12 +00004247
Douglas Gregor43959a92009-08-20 07:17:43 +00004248//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004249// Expression transformation
4250//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004252ExprResult
John McCall454feb92009-12-08 09:21:05 +00004253TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004254 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004255}
Mike Stump1eb44332009-09-09 15:08:12 +00004256
4257template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004258ExprResult
John McCall454feb92009-12-08 09:21:05 +00004259TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004260 NestedNameSpecifier *Qualifier = 0;
4261 if (E->getQualifier()) {
4262 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004263 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004264 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004265 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004266 }
John McCalldbd872f2009-12-08 09:08:17 +00004267
4268 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004269 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4270 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004271 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004272 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004273
John McCallec8045d2010-08-17 21:27:17 +00004274 DeclarationNameInfo NameInfo = E->getNameInfo();
4275 if (NameInfo.getName()) {
4276 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4277 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004278 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004279 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004280
4281 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004282 Qualifier == E->getQualifier() &&
4283 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004284 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004285 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004286
4287 // Mark it referenced in the new context regardless.
4288 // FIXME: this is a bit instantiation-specific.
4289 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4290
John McCall3fa5cae2010-10-26 07:05:15 +00004291 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00004292 }
John McCalldbd872f2009-12-08 09:08:17 +00004293
4294 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004295 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004296 TemplateArgs = &TransArgs;
4297 TransArgs.setLAngleLoc(E->getLAngleLoc());
4298 TransArgs.setRAngleLoc(E->getRAngleLoc());
4299 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4300 TemplateArgumentLoc Loc;
4301 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004302 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004303 TransArgs.addArgument(Loc);
4304 }
4305 }
4306
Douglas Gregora2813ce2009-10-23 18:54:35 +00004307 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004308 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004309}
Mike Stump1eb44332009-09-09 15:08:12 +00004310
Douglas Gregorb98b1992009-08-11 05:31:07 +00004311template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004312ExprResult
John McCall454feb92009-12-08 09:21:05 +00004313TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004314 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004315}
Mike Stump1eb44332009-09-09 15:08:12 +00004316
Douglas Gregorb98b1992009-08-11 05:31:07 +00004317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004318ExprResult
John McCall454feb92009-12-08 09:21:05 +00004319TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004320 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004321}
Mike Stump1eb44332009-09-09 15:08:12 +00004322
Douglas Gregorb98b1992009-08-11 05:31:07 +00004323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004324ExprResult
John McCall454feb92009-12-08 09:21:05 +00004325TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004326 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004327}
Mike Stump1eb44332009-09-09 15:08:12 +00004328
Douglas Gregorb98b1992009-08-11 05:31:07 +00004329template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004330ExprResult
John McCall454feb92009-12-08 09:21:05 +00004331TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004332 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004333}
Mike Stump1eb44332009-09-09 15:08:12 +00004334
Douglas Gregorb98b1992009-08-11 05:31:07 +00004335template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004336ExprResult
John McCall454feb92009-12-08 09:21:05 +00004337TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004338 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004339}
4340
4341template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004342ExprResult
John McCall454feb92009-12-08 09:21:05 +00004343TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004344 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004345 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004346 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004347
Douglas Gregorb98b1992009-08-11 05:31:07 +00004348 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004349 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004350
John McCall9ae2f072010-08-23 23:25:46 +00004351 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004352 E->getRParen());
4353}
4354
Mike Stump1eb44332009-09-09 15:08:12 +00004355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004356ExprResult
John McCall454feb92009-12-08 09:21:05 +00004357TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004358 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004359 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004360 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004361
Douglas Gregorb98b1992009-08-11 05:31:07 +00004362 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004363 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004364
Douglas Gregorb98b1992009-08-11 05:31:07 +00004365 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4366 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004367 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004368}
Mike Stump1eb44332009-09-09 15:08:12 +00004369
Douglas Gregorb98b1992009-08-11 05:31:07 +00004370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004371ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004372TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4373 // Transform the type.
4374 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4375 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004376 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004377
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004378 // Transform all of the components into components similar to what the
4379 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004380 // FIXME: It would be slightly more efficient in the non-dependent case to
4381 // just map FieldDecls, rather than requiring the rebuilder to look for
4382 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004383 // template code that we don't care.
4384 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004385 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004386 typedef OffsetOfExpr::OffsetOfNode Node;
4387 llvm::SmallVector<Component, 4> Components;
4388 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4389 const Node &ON = E->getComponent(I);
4390 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004391 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004392 Comp.LocStart = ON.getRange().getBegin();
4393 Comp.LocEnd = ON.getRange().getEnd();
4394 switch (ON.getKind()) {
4395 case Node::Array: {
4396 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004397 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004398 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004399 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004400
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004401 ExprChanged = ExprChanged || Index.get() != FromIndex;
4402 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004403 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004404 break;
4405 }
Sean Huntc3021132010-05-05 15:23:54 +00004406
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004407 case Node::Field:
4408 case Node::Identifier:
4409 Comp.isBrackets = false;
4410 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004411 if (!Comp.U.IdentInfo)
4412 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004413
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004414 break;
Sean Huntc3021132010-05-05 15:23:54 +00004415
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004416 case Node::Base:
4417 // Will be recomputed during the rebuild.
4418 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004419 }
Sean Huntc3021132010-05-05 15:23:54 +00004420
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004421 Components.push_back(Comp);
4422 }
Sean Huntc3021132010-05-05 15:23:54 +00004423
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004424 // If nothing changed, retain the existing expression.
4425 if (!getDerived().AlwaysRebuild() &&
4426 Type == E->getTypeSourceInfo() &&
4427 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004428 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00004429
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004430 // Build a new offsetof expression.
4431 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4432 Components.data(), Components.size(),
4433 E->getRParenLoc());
4434}
4435
4436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004437ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00004438TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4439 assert(getDerived().AlreadyTransformed(E->getType()) &&
4440 "opaque value expression requires transformation");
4441 return SemaRef.Owned(E);
4442}
4443
4444template<typename Derived>
4445ExprResult
John McCall454feb92009-12-08 09:21:05 +00004446TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004447 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004448 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004449
John McCalla93c9342009-12-07 02:54:59 +00004450 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004451 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004452 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004453
John McCall5ab75172009-11-04 07:28:41 +00004454 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00004455 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004456
John McCall5ab75172009-11-04 07:28:41 +00004457 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004458 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004459 E->getSourceRange());
4460 }
Mike Stump1eb44332009-09-09 15:08:12 +00004461
John McCall60d7b3a2010-08-24 06:29:42 +00004462 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004463 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004464 // C++0x [expr.sizeof]p1:
4465 // The operand is either an expression, which is an unevaluated operand
4466 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004467 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004468
Douglas Gregorb98b1992009-08-11 05:31:07 +00004469 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4470 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004471 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004472
Douglas Gregorb98b1992009-08-11 05:31:07 +00004473 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004474 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004475 }
Mike Stump1eb44332009-09-09 15:08:12 +00004476
John McCall9ae2f072010-08-23 23:25:46 +00004477 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004478 E->isSizeOf(),
4479 E->getSourceRange());
4480}
Mike Stump1eb44332009-09-09 15:08:12 +00004481
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004483ExprResult
John McCall454feb92009-12-08 09:21:05 +00004484TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004485 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004486 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004487 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004488
John McCall60d7b3a2010-08-24 06:29:42 +00004489 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004490 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004491 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004492
4493
Douglas Gregorb98b1992009-08-11 05:31:07 +00004494 if (!getDerived().AlwaysRebuild() &&
4495 LHS.get() == E->getLHS() &&
4496 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004497 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004498
John McCall9ae2f072010-08-23 23:25:46 +00004499 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004500 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004501 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004502 E->getRBracketLoc());
4503}
Mike Stump1eb44332009-09-09 15:08:12 +00004504
4505template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004506ExprResult
John McCall454feb92009-12-08 09:21:05 +00004507TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004508 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004509 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004510 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004511 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004512
4513 // Transform arguments.
4514 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004515 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004516 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004517 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004519 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004520
Mike Stump1eb44332009-09-09 15:08:12 +00004521 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004522 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004523 }
Mike Stump1eb44332009-09-09 15:08:12 +00004524
Douglas Gregorb98b1992009-08-11 05:31:07 +00004525 if (!getDerived().AlwaysRebuild() &&
4526 Callee.get() == E->getCallee() &&
4527 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004528 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004529
Douglas Gregorb98b1992009-08-11 05:31:07 +00004530 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004531 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004532 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004533 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004535 E->getRParenLoc());
4536}
Mike Stump1eb44332009-09-09 15:08:12 +00004537
4538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004539ExprResult
John McCall454feb92009-12-08 09:21:05 +00004540TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004541 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004542 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004543 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004544
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004545 NestedNameSpecifier *Qualifier = 0;
4546 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004547 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004548 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004549 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004550 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004551 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004552 }
Mike Stump1eb44332009-09-09 15:08:12 +00004553
Eli Friedmanf595cc42009-12-04 06:40:45 +00004554 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004555 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4556 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004557 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004558 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004559
John McCall6bb80172010-03-30 21:47:33 +00004560 NamedDecl *FoundDecl = E->getFoundDecl();
4561 if (FoundDecl == E->getMemberDecl()) {
4562 FoundDecl = Member;
4563 } else {
4564 FoundDecl = cast_or_null<NamedDecl>(
4565 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4566 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004567 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004568 }
4569
Douglas Gregorb98b1992009-08-11 05:31:07 +00004570 if (!getDerived().AlwaysRebuild() &&
4571 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004572 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004573 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004574 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004575 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004576
Anders Carlsson1f240322009-12-22 05:24:09 +00004577 // Mark it referenced in the new context regardless.
4578 // FIXME: this is a bit instantiation-specific.
4579 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00004580 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00004581 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004582
John McCalld5532b62009-11-23 01:53:49 +00004583 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004584 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004585 TransArgs.setLAngleLoc(E->getLAngleLoc());
4586 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004587 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004588 TemplateArgumentLoc Loc;
4589 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004590 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004591 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004592 }
4593 }
Sean Huntc3021132010-05-05 15:23:54 +00004594
Douglas Gregorb98b1992009-08-11 05:31:07 +00004595 // FIXME: Bogus source location for the operator
4596 SourceLocation FakeOperatorLoc
4597 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4598
John McCallc2233c52010-01-15 08:34:02 +00004599 // FIXME: to do this check properly, we will need to preserve the
4600 // first-qualifier-in-scope here, just in case we had a dependent
4601 // base (and therefore couldn't do the check) and a
4602 // nested-name-qualifier (and therefore could do the lookup).
4603 NamedDecl *FirstQualifierInScope = 0;
4604
John McCall9ae2f072010-08-23 23:25:46 +00004605 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004606 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004607 Qualifier,
4608 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004609 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004610 Member,
John McCall6bb80172010-03-30 21:47:33 +00004611 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004612 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004613 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004614 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004615}
Mike Stump1eb44332009-09-09 15:08:12 +00004616
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004618ExprResult
John McCall454feb92009-12-08 09:21:05 +00004619TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004620 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004621 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004622 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004623
John McCall60d7b3a2010-08-24 06:29:42 +00004624 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004625 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004626 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004627
Douglas Gregorb98b1992009-08-11 05:31:07 +00004628 if (!getDerived().AlwaysRebuild() &&
4629 LHS.get() == E->getLHS() &&
4630 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004631 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004632
Douglas Gregorb98b1992009-08-11 05:31:07 +00004633 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004634 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004635}
4636
Mike Stump1eb44332009-09-09 15:08:12 +00004637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004638ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004639TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004640 CompoundAssignOperator *E) {
4641 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642}
Mike Stump1eb44332009-09-09 15:08:12 +00004643
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004645ExprResult
John McCall454feb92009-12-08 09:21:05 +00004646TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004647 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004649 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004650
John McCall60d7b3a2010-08-24 06:29:42 +00004651 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004652 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004653 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004654
John McCall60d7b3a2010-08-24 06:29:42 +00004655 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004656 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004657 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004658
Douglas Gregorb98b1992009-08-11 05:31:07 +00004659 if (!getDerived().AlwaysRebuild() &&
4660 Cond.get() == E->getCond() &&
4661 LHS.get() == E->getLHS() &&
4662 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004663 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004664
John McCall9ae2f072010-08-23 23:25:46 +00004665 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004666 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004667 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004668 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004669 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004670}
Mike Stump1eb44332009-09-09 15:08:12 +00004671
4672template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004673ExprResult
John McCall454feb92009-12-08 09:21:05 +00004674TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004675 // Implicit casts are eliminated during transformation, since they
4676 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004677 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004678}
Mike Stump1eb44332009-09-09 15:08:12 +00004679
Douglas Gregorb98b1992009-08-11 05:31:07 +00004680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004681ExprResult
John McCall454feb92009-12-08 09:21:05 +00004682TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004683 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4684 if (!Type)
4685 return ExprError();
4686
John McCall60d7b3a2010-08-24 06:29:42 +00004687 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004688 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004689 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004690 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004691
Douglas Gregorb98b1992009-08-11 05:31:07 +00004692 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004693 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004694 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004695 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004696
John McCall9d125032010-01-15 18:39:57 +00004697 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004698 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004699 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004700 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004701}
Mike Stump1eb44332009-09-09 15:08:12 +00004702
Douglas Gregorb98b1992009-08-11 05:31:07 +00004703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004704ExprResult
John McCall454feb92009-12-08 09:21:05 +00004705TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004706 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4707 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4708 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004709 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004710
John McCall60d7b3a2010-08-24 06:29:42 +00004711 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004712 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004714
Douglas Gregorb98b1992009-08-11 05:31:07 +00004715 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004716 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004717 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00004718 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004719
John McCall1d7d8d62010-01-19 22:33:45 +00004720 // Note: the expression type doesn't necessarily match the
4721 // type-as-written, but that's okay, because it should always be
4722 // derivable from the initializer.
4723
John McCall42f56b52010-01-18 19:35:47 +00004724 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004725 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004726 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004727}
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregorb98b1992009-08-11 05:31:07 +00004729template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004730ExprResult
John McCall454feb92009-12-08 09:21:05 +00004731TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004732 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004733 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004734 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004735
Douglas Gregorb98b1992009-08-11 05:31:07 +00004736 if (!getDerived().AlwaysRebuild() &&
4737 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00004738 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004739
Douglas Gregorb98b1992009-08-11 05:31:07 +00004740 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004741 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004742 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004743 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004744 E->getAccessorLoc(),
4745 E->getAccessor());
4746}
Mike Stump1eb44332009-09-09 15:08:12 +00004747
Douglas Gregorb98b1992009-08-11 05:31:07 +00004748template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004749ExprResult
John McCall454feb92009-12-08 09:21:05 +00004750TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004751 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004752
John McCallca0408f2010-08-23 06:44:23 +00004753 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004754 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004755 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004756 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004758
Douglas Gregorb98b1992009-08-11 05:31:07 +00004759 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004760 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004761 }
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004764 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004765
Douglas Gregorb98b1992009-08-11 05:31:07 +00004766 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004767 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004768}
Mike Stump1eb44332009-09-09 15:08:12 +00004769
Douglas Gregorb98b1992009-08-11 05:31:07 +00004770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004771ExprResult
John McCall454feb92009-12-08 09:21:05 +00004772TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004774
Douglas Gregor43959a92009-08-20 07:17:43 +00004775 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004776 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004777 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004778 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004779
Douglas Gregor43959a92009-08-20 07:17:43 +00004780 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004781 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004782 bool ExprChanged = false;
4783 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4784 DEnd = E->designators_end();
4785 D != DEnd; ++D) {
4786 if (D->isFieldDesignator()) {
4787 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4788 D->getDotLoc(),
4789 D->getFieldLoc()));
4790 continue;
4791 }
Mike Stump1eb44332009-09-09 15:08:12 +00004792
Douglas Gregorb98b1992009-08-11 05:31:07 +00004793 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004794 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004795 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004796 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004797
4798 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004799 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004800
Douglas Gregorb98b1992009-08-11 05:31:07 +00004801 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4802 ArrayExprs.push_back(Index.release());
4803 continue;
4804 }
Mike Stump1eb44332009-09-09 15:08:12 +00004805
Douglas Gregorb98b1992009-08-11 05:31:07 +00004806 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004807 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004808 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4809 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004810 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004811
John McCall60d7b3a2010-08-24 06:29:42 +00004812 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004813 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004814 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004815
4816 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004817 End.get(),
4818 D->getLBracketLoc(),
4819 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004820
Douglas Gregorb98b1992009-08-11 05:31:07 +00004821 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4822 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004823
Douglas Gregorb98b1992009-08-11 05:31:07 +00004824 ArrayExprs.push_back(Start.release());
4825 ArrayExprs.push_back(End.release());
4826 }
Mike Stump1eb44332009-09-09 15:08:12 +00004827
Douglas Gregorb98b1992009-08-11 05:31:07 +00004828 if (!getDerived().AlwaysRebuild() &&
4829 Init.get() == E->getInit() &&
4830 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004831 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004832
Douglas Gregorb98b1992009-08-11 05:31:07 +00004833 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4834 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004835 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004836}
Mike Stump1eb44332009-09-09 15:08:12 +00004837
Douglas Gregorb98b1992009-08-11 05:31:07 +00004838template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004839ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004840TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004841 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004842 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004843
Douglas Gregor5557b252009-10-28 00:29:27 +00004844 // FIXME: Will we ever have proper type location here? Will we actually
4845 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004846 QualType T = getDerived().TransformType(E->getType());
4847 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004848 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004849
Douglas Gregorb98b1992009-08-11 05:31:07 +00004850 if (!getDerived().AlwaysRebuild() &&
4851 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00004852 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004853
Douglas Gregorb98b1992009-08-11 05:31:07 +00004854 return getDerived().RebuildImplicitValueInitExpr(T);
4855}
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Douglas Gregorb98b1992009-08-11 05:31:07 +00004857template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004858ExprResult
John McCall454feb92009-12-08 09:21:05 +00004859TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004860 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4861 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004863
John McCall60d7b3a2010-08-24 06:29:42 +00004864 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004865 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004866 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004867
Douglas Gregorb98b1992009-08-11 05:31:07 +00004868 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004869 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004871 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004872
John McCall9ae2f072010-08-23 23:25:46 +00004873 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004874 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004875}
4876
4877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004878ExprResult
John McCall454feb92009-12-08 09:21:05 +00004879TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004880 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004881 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004882 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004883 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004884 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004885 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004886
Douglas Gregorb98b1992009-08-11 05:31:07 +00004887 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004888 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004889 }
Mike Stump1eb44332009-09-09 15:08:12 +00004890
Douglas Gregorb98b1992009-08-11 05:31:07 +00004891 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4892 move_arg(Inits),
4893 E->getRParenLoc());
4894}
Mike Stump1eb44332009-09-09 15:08:12 +00004895
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896/// \brief Transform an address-of-label expression.
4897///
4898/// By default, the transformation of an address-of-label expression always
4899/// rebuilds the expression, so that the label identifier can be resolved to
4900/// the corresponding label statement by semantic analysis.
4901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004902ExprResult
John McCall454feb92009-12-08 09:21:05 +00004903TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004904 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4905 E->getLabel());
4906}
Mike Stump1eb44332009-09-09 15:08:12 +00004907
4908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004909ExprResult
John McCall454feb92009-12-08 09:21:05 +00004910TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004911 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004912 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4913 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004914 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004915
Douglas Gregorb98b1992009-08-11 05:31:07 +00004916 if (!getDerived().AlwaysRebuild() &&
4917 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004918 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004919
4920 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004921 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004922 E->getRParenLoc());
4923}
Mike Stump1eb44332009-09-09 15:08:12 +00004924
Douglas Gregorb98b1992009-08-11 05:31:07 +00004925template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004926ExprResult
John McCall454feb92009-12-08 09:21:05 +00004927TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004928 TypeSourceInfo *TInfo1;
4929 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004930
4931 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4932 if (!TInfo1)
John McCallf312b1e2010-08-26 23:41:50 +00004933 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004934
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004935 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4936 if (!TInfo2)
John McCallf312b1e2010-08-26 23:41:50 +00004937 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004938
4939 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004940 TInfo1 == E->getArgTInfo1() &&
4941 TInfo2 == E->getArgTInfo2())
John McCall3fa5cae2010-10-26 07:05:15 +00004942 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004943
Douglas Gregorb98b1992009-08-11 05:31:07 +00004944 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004945 TInfo1, TInfo2,
4946 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004947}
Mike Stump1eb44332009-09-09 15:08:12 +00004948
Douglas Gregorb98b1992009-08-11 05:31:07 +00004949template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004950ExprResult
John McCall454feb92009-12-08 09:21:05 +00004951TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004952 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004953 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004954 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004955
John McCall60d7b3a2010-08-24 06:29:42 +00004956 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004957 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004958 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004959
John McCall60d7b3a2010-08-24 06:29:42 +00004960 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004961 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004962 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004963
Douglas Gregorb98b1992009-08-11 05:31:07 +00004964 if (!getDerived().AlwaysRebuild() &&
4965 Cond.get() == E->getCond() &&
4966 LHS.get() == E->getLHS() &&
4967 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004968 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004969
Douglas Gregorb98b1992009-08-11 05:31:07 +00004970 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004971 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004972 E->getRParenLoc());
4973}
Mike Stump1eb44332009-09-09 15:08:12 +00004974
Douglas Gregorb98b1992009-08-11 05:31:07 +00004975template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004976ExprResult
John McCall454feb92009-12-08 09:21:05 +00004977TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004978 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004979}
4980
4981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004982ExprResult
John McCall454feb92009-12-08 09:21:05 +00004983TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004984 switch (E->getOperator()) {
4985 case OO_New:
4986 case OO_Delete:
4987 case OO_Array_New:
4988 case OO_Array_Delete:
4989 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004990 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004991
Douglas Gregor668d6d92009-12-13 20:44:55 +00004992 case OO_Call: {
4993 // This is a call to an object's operator().
4994 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4995
4996 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004997 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004998 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004999 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005000
5001 // FIXME: Poor location information
5002 SourceLocation FakeLParenLoc
5003 = SemaRef.PP.getLocForEndOfToken(
5004 static_cast<Expr *>(Object.get())->getLocEnd());
5005
5006 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005007 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00005008 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005009 if (getDerived().DropCallArgument(E->getArg(I)))
5010 break;
Sean Huntc3021132010-05-05 15:23:54 +00005011
John McCall60d7b3a2010-08-24 06:29:42 +00005012 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005013 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005014 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005015
Douglas Gregor668d6d92009-12-13 20:44:55 +00005016 Args.push_back(Arg.release());
5017 }
5018
John McCall9ae2f072010-08-23 23:25:46 +00005019 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005020 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005021 E->getLocEnd());
5022 }
5023
5024#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5025 case OO_##Name:
5026#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5027#include "clang/Basic/OperatorKinds.def"
5028 case OO_Subscript:
5029 // Handled below.
5030 break;
5031
5032 case OO_Conditional:
5033 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005034 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005035
5036 case OO_None:
5037 case NUM_OVERLOADED_OPERATORS:
5038 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005039 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005040 }
5041
John McCall60d7b3a2010-08-24 06:29:42 +00005042 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005043 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005044 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005045
John McCall60d7b3a2010-08-24 06:29:42 +00005046 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005047 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005048 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005049
John McCall60d7b3a2010-08-24 06:29:42 +00005050 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005051 if (E->getNumArgs() == 2) {
5052 Second = getDerived().TransformExpr(E->getArg(1));
5053 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005054 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005055 }
Mike Stump1eb44332009-09-09 15:08:12 +00005056
Douglas Gregorb98b1992009-08-11 05:31:07 +00005057 if (!getDerived().AlwaysRebuild() &&
5058 Callee.get() == E->getCallee() &&
5059 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005060 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005061 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005062
Douglas Gregorb98b1992009-08-11 05:31:07 +00005063 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5064 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005065 Callee.get(),
5066 First.get(),
5067 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005068}
Mike Stump1eb44332009-09-09 15:08:12 +00005069
Douglas Gregorb98b1992009-08-11 05:31:07 +00005070template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005071ExprResult
John McCall454feb92009-12-08 09:21:05 +00005072TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5073 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005074}
Mike Stump1eb44332009-09-09 15:08:12 +00005075
Douglas Gregorb98b1992009-08-11 05:31:07 +00005076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005077ExprResult
John McCall454feb92009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005079 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5080 if (!Type)
5081 return ExprError();
5082
John McCall60d7b3a2010-08-24 06:29:42 +00005083 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005084 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005085 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005086 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005087
Douglas Gregorb98b1992009-08-11 05:31:07 +00005088 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005089 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005091 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005092
Douglas Gregorb98b1992009-08-11 05:31:07 +00005093 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005094 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5096 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5097 SourceLocation FakeRParenLoc
5098 = SemaRef.PP.getLocForEndOfToken(
5099 E->getSubExpr()->getSourceRange().getEnd());
5100 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005101 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005102 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005103 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005104 FakeRAngleLoc,
5105 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005106 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107 FakeRParenLoc);
5108}
Mike Stump1eb44332009-09-09 15:08:12 +00005109
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005111ExprResult
John McCall454feb92009-12-08 09:21:05 +00005112TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5113 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005114}
Mike Stump1eb44332009-09-09 15:08:12 +00005115
5116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005117ExprResult
John McCall454feb92009-12-08 09:21:05 +00005118TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5119 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005120}
5121
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005123ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005125 CXXReinterpretCastExpr *E) {
5126 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127}
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005130ExprResult
John McCall454feb92009-12-08 09:21:05 +00005131TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5132 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005133}
Mike Stump1eb44332009-09-09 15:08:12 +00005134
Douglas Gregorb98b1992009-08-11 05:31:07 +00005135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005136ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005137TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005138 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005139 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5140 if (!Type)
5141 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005142
John McCall60d7b3a2010-08-24 06:29:42 +00005143 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005144 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005147
Douglas Gregorb98b1992009-08-11 05:31:07 +00005148 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005149 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005150 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005151 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005153 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005154 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005155 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005156 E->getRParenLoc());
5157}
Mike Stump1eb44332009-09-09 15:08:12 +00005158
Douglas Gregorb98b1992009-08-11 05:31:07 +00005159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005160ExprResult
John McCall454feb92009-12-08 09:21:05 +00005161TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005162 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005163 TypeSourceInfo *TInfo
5164 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5165 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005166 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregorb98b1992009-08-11 05:31:07 +00005168 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005169 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005170 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005172 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5173 E->getLocStart(),
5174 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005175 E->getLocEnd());
5176 }
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Douglas Gregorb98b1992009-08-11 05:31:07 +00005178 // We don't know whether the expression is potentially evaluated until
5179 // after we perform semantic analysis, so the expression is potentially
5180 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005181 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005182 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005183
John McCall60d7b3a2010-08-24 06:29:42 +00005184 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005185 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188 if (!getDerived().AlwaysRebuild() &&
5189 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005190 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005191
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005192 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5193 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005194 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005195 E->getLocEnd());
5196}
5197
5198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005199ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005200TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5201 if (E->isTypeOperand()) {
5202 TypeSourceInfo *TInfo
5203 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5204 if (!TInfo)
5205 return ExprError();
5206
5207 if (!getDerived().AlwaysRebuild() &&
5208 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005209 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005210
5211 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5212 E->getLocStart(),
5213 TInfo,
5214 E->getLocEnd());
5215 }
5216
5217 // We don't know whether the expression is potentially evaluated until
5218 // after we perform semantic analysis, so the expression is potentially
5219 // potentially evaluated.
5220 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5221
5222 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5223 if (SubExpr.isInvalid())
5224 return ExprError();
5225
5226 if (!getDerived().AlwaysRebuild() &&
5227 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005228 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005229
5230 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5231 E->getLocStart(),
5232 SubExpr.get(),
5233 E->getLocEnd());
5234}
5235
5236template<typename Derived>
5237ExprResult
John McCall454feb92009-12-08 09:21:05 +00005238TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005239 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005240}
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregorb98b1992009-08-11 05:31:07 +00005242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005243ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005244TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005245 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005246 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247}
Mike Stump1eb44332009-09-09 15:08:12 +00005248
Douglas Gregorb98b1992009-08-11 05:31:07 +00005249template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005250ExprResult
John McCall454feb92009-12-08 09:21:05 +00005251TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005252 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5253 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5254 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005255
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005256 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005257 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor828a1972010-01-07 23:12:05 +00005259 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005260}
Mike Stump1eb44332009-09-09 15:08:12 +00005261
Douglas Gregorb98b1992009-08-11 05:31:07 +00005262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005263ExprResult
John McCall454feb92009-12-08 09:21:05 +00005264TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005265 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005267 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005268
Douglas Gregorb98b1992009-08-11 05:31:07 +00005269 if (!getDerived().AlwaysRebuild() &&
5270 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005271 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005272
John McCall9ae2f072010-08-23 23:25:46 +00005273 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274}
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregorb98b1992009-08-11 05:31:07 +00005276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005277ExprResult
John McCall454feb92009-12-08 09:21:05 +00005278TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005279 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005280 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5281 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005283 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005285 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005286 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005287 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005288
Douglas Gregor036aed12009-12-23 23:03:06 +00005289 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005290}
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Douglas Gregorb98b1992009-08-11 05:31:07 +00005292template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005293ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005294TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5295 CXXScalarValueInitExpr *E) {
5296 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5297 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005298 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005299
Douglas Gregorb98b1992009-08-11 05:31:07 +00005300 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005301 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005302 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregorab6677e2010-09-08 00:15:04 +00005304 return getDerived().RebuildCXXScalarValueInitExpr(T,
5305 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005306 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005307}
Mike Stump1eb44332009-09-09 15:08:12 +00005308
Douglas Gregorb98b1992009-08-11 05:31:07 +00005309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005310ExprResult
John McCall454feb92009-12-08 09:21:05 +00005311TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005312 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005313 TypeSourceInfo *AllocTypeInfo
5314 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5315 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005316 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregorb98b1992009-08-11 05:31:07 +00005318 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005319 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005320 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005321 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregorb98b1992009-08-11 05:31:07 +00005323 // Transform the placement arguments (if any).
5324 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005325 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005326 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005327 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5328 ArgumentChanged = true;
5329 break;
5330 }
5331
John McCall60d7b3a2010-08-24 06:29:42 +00005332 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005333 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005334 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005335
Douglas Gregorb98b1992009-08-11 05:31:07 +00005336 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5337 PlacementArgs.push_back(Arg.take());
5338 }
Mike Stump1eb44332009-09-09 15:08:12 +00005339
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005341 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005342 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005343 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5344 ArgumentChanged = true;
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005345 break;
John McCall63d5fb32010-10-05 22:36:42 +00005346 }
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005347
John McCall60d7b3a2010-08-24 06:29:42 +00005348 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005349 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005350 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005351
Douglas Gregorb98b1992009-08-11 05:31:07 +00005352 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5353 ConstructorArgs.push_back(Arg.take());
5354 }
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor1af74512010-02-26 00:38:10 +00005356 // Transform constructor, new operator, and delete operator.
5357 CXXConstructorDecl *Constructor = 0;
5358 if (E->getConstructor()) {
5359 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005360 getDerived().TransformDecl(E->getLocStart(),
5361 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005362 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005363 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005364 }
5365
5366 FunctionDecl *OperatorNew = 0;
5367 if (E->getOperatorNew()) {
5368 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005369 getDerived().TransformDecl(E->getLocStart(),
5370 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005371 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005372 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005373 }
5374
5375 FunctionDecl *OperatorDelete = 0;
5376 if (E->getOperatorDelete()) {
5377 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005378 getDerived().TransformDecl(E->getLocStart(),
5379 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005380 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005381 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005382 }
Sean Huntc3021132010-05-05 15:23:54 +00005383
Douglas Gregorb98b1992009-08-11 05:31:07 +00005384 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005385 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005386 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005387 Constructor == E->getConstructor() &&
5388 OperatorNew == E->getOperatorNew() &&
5389 OperatorDelete == E->getOperatorDelete() &&
5390 !ArgumentChanged) {
5391 // Mark any declarations we need as referenced.
5392 // FIXME: instantiation-specific.
5393 if (Constructor)
5394 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5395 if (OperatorNew)
5396 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5397 if (OperatorDelete)
5398 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00005399 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005400 }
Mike Stump1eb44332009-09-09 15:08:12 +00005401
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005402 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005403 if (!ArraySize.get()) {
5404 // If no array size was specified, but the new expression was
5405 // instantiated with an array type (e.g., "new T" where T is
5406 // instantiated with "int[4]"), extract the outer bound from the
5407 // array type as our array size. We do this with constant and
5408 // dependently-sized array types.
5409 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5410 if (!ArrayT) {
5411 // Do nothing
5412 } else if (const ConstantArrayType *ConsArrayT
5413 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005414 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005415 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5416 ConsArrayT->getSize(),
5417 SemaRef.Context.getSizeType(),
5418 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005419 AllocType = ConsArrayT->getElementType();
5420 } else if (const DependentSizedArrayType *DepArrayT
5421 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5422 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00005423 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005424 AllocType = DepArrayT->getElementType();
5425 }
5426 }
5427 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005428
Douglas Gregorb98b1992009-08-11 05:31:07 +00005429 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5430 E->isGlobalNew(),
5431 /*FIXME:*/E->getLocStart(),
5432 move_arg(PlacementArgs),
5433 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005434 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005435 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005436 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005437 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005438 /*FIXME:*/E->getLocStart(),
5439 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005440 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005441}
Mike Stump1eb44332009-09-09 15:08:12 +00005442
Douglas Gregorb98b1992009-08-11 05:31:07 +00005443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005444ExprResult
John McCall454feb92009-12-08 09:21:05 +00005445TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005446 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005447 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005448 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor1af74512010-02-26 00:38:10 +00005450 // Transform the delete operator, if known.
5451 FunctionDecl *OperatorDelete = 0;
5452 if (E->getOperatorDelete()) {
5453 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005454 getDerived().TransformDecl(E->getLocStart(),
5455 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005456 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005457 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005458 }
Sean Huntc3021132010-05-05 15:23:54 +00005459
Douglas Gregorb98b1992009-08-11 05:31:07 +00005460 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005461 Operand.get() == E->getArgument() &&
5462 OperatorDelete == E->getOperatorDelete()) {
5463 // Mark any declarations we need as referenced.
5464 // FIXME: instantiation-specific.
5465 if (OperatorDelete)
5466 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005467
5468 if (!E->getArgument()->isTypeDependent()) {
5469 QualType Destroyed = SemaRef.Context.getBaseElementType(
5470 E->getDestroyedType());
5471 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5472 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5473 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5474 SemaRef.LookupDestructor(Record));
5475 }
5476 }
5477
John McCall3fa5cae2010-10-26 07:05:15 +00005478 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005479 }
Mike Stump1eb44332009-09-09 15:08:12 +00005480
Douglas Gregorb98b1992009-08-11 05:31:07 +00005481 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5482 E->isGlobalDelete(),
5483 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005484 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005485}
Mike Stump1eb44332009-09-09 15:08:12 +00005486
Douglas Gregorb98b1992009-08-11 05:31:07 +00005487template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005488ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005489TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005490 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005491 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005492 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005494
John McCallb3d87482010-08-24 05:47:05 +00005495 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005496 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005497 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005498 E->getOperatorLoc(),
5499 E->isArrow()? tok::arrow : tok::period,
5500 ObjectTypePtr,
5501 MayBePseudoDestructor);
5502 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005503 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005504
John McCallb3d87482010-08-24 05:47:05 +00005505 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00005506 NestedNameSpecifier *Qualifier = E->getQualifier();
5507 if (Qualifier) {
5508 Qualifier
5509 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5510 E->getQualifierRange(),
5511 ObjectType);
5512 if (!Qualifier)
5513 return ExprError();
5514 }
Mike Stump1eb44332009-09-09 15:08:12 +00005515
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005516 PseudoDestructorTypeStorage Destroyed;
5517 if (E->getDestroyedTypeInfo()) {
5518 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00005519 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5520 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005521 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005522 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005523 Destroyed = DestroyedTypeInfo;
5524 } else if (ObjectType->isDependentType()) {
5525 // We aren't likely to be able to resolve the identifier down to a type
5526 // now anyway, so just retain the identifier.
5527 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5528 E->getDestroyedTypeLoc());
5529 } else {
5530 // Look for a destructor known with the given name.
5531 CXXScopeSpec SS;
5532 if (Qualifier) {
5533 SS.setScopeRep(Qualifier);
5534 SS.setRange(E->getQualifierRange());
5535 }
Sean Huntc3021132010-05-05 15:23:54 +00005536
John McCallb3d87482010-08-24 05:47:05 +00005537 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005538 *E->getDestroyedTypeIdentifier(),
5539 E->getDestroyedTypeLoc(),
5540 /*Scope=*/0,
5541 SS, ObjectTypePtr,
5542 false);
5543 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005544 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005545
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005546 Destroyed
5547 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5548 E->getDestroyedTypeLoc());
5549 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005550
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005551 TypeSourceInfo *ScopeTypeInfo = 0;
5552 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00005553 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005554 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005555 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005556 }
Sean Huntc3021132010-05-05 15:23:54 +00005557
John McCall9ae2f072010-08-23 23:25:46 +00005558 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005559 E->getOperatorLoc(),
5560 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005561 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005562 E->getQualifierRange(),
5563 ScopeTypeInfo,
5564 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005565 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005566 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005567}
Mike Stump1eb44332009-09-09 15:08:12 +00005568
Douglas Gregora71d8192009-09-04 17:36:40 +00005569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005570ExprResult
John McCallba135432009-11-21 08:51:07 +00005571TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005572 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005573 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5574
5575 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5576 Sema::LookupOrdinaryName);
5577
5578 // Transform all the decls.
5579 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5580 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005581 NamedDecl *InstD = static_cast<NamedDecl*>(
5582 getDerived().TransformDecl(Old->getNameLoc(),
5583 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005584 if (!InstD) {
5585 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5586 // This can happen because of dependent hiding.
5587 if (isa<UsingShadowDecl>(*I))
5588 continue;
5589 else
John McCallf312b1e2010-08-26 23:41:50 +00005590 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005591 }
John McCallf7a1a742009-11-24 19:00:30 +00005592
5593 // Expand using declarations.
5594 if (isa<UsingDecl>(InstD)) {
5595 UsingDecl *UD = cast<UsingDecl>(InstD);
5596 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5597 E = UD->shadow_end(); I != E; ++I)
5598 R.addDecl(*I);
5599 continue;
5600 }
5601
5602 R.addDecl(InstD);
5603 }
5604
5605 // Resolve a kind, but don't do any further analysis. If it's
5606 // ambiguous, the callee needs to deal with it.
5607 R.resolveKind();
5608
5609 // Rebuild the nested-name qualifier, if present.
5610 CXXScopeSpec SS;
5611 NestedNameSpecifier *Qualifier = 0;
5612 if (Old->getQualifier()) {
5613 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005614 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005615 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005616 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005617
John McCallf7a1a742009-11-24 19:00:30 +00005618 SS.setScopeRep(Qualifier);
5619 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005620 }
5621
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005622 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005623 CXXRecordDecl *NamingClass
5624 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5625 Old->getNameLoc(),
5626 Old->getNamingClass()));
5627 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005628 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005629
Douglas Gregor66c45152010-04-27 16:10:10 +00005630 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005631 }
5632
5633 // If we have no template arguments, it's a normal declaration name.
5634 if (!Old->hasExplicitTemplateArgs())
5635 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5636
5637 // If we have template arguments, rebuild them, then rebuild the
5638 // templateid expression.
5639 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5640 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5641 TemplateArgumentLoc Loc;
5642 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005643 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005644 TransArgs.addArgument(Loc);
5645 }
5646
5647 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5648 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005649}
Mike Stump1eb44332009-09-09 15:08:12 +00005650
Douglas Gregorb98b1992009-08-11 05:31:07 +00005651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005652ExprResult
John McCall454feb92009-12-08 09:21:05 +00005653TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005654 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5655 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005656 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005657
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005659 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005660 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005661
Mike Stump1eb44332009-09-09 15:08:12 +00005662 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005663 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005664 T,
5665 E->getLocEnd());
5666}
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregorb98b1992009-08-11 05:31:07 +00005668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005669ExprResult
John McCall865d4472009-11-19 22:55:06 +00005670TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005671 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005673 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005674 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005675 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005676 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005677
John McCall43fed0d2010-11-12 08:19:04 +00005678 // TODO: If this is a conversion-function-id, verify that the
5679 // destination type name (if present) resolves the same way after
5680 // instantiation as it did in the local scope.
5681
Abramo Bagnara25777432010-08-11 22:01:17 +00005682 DeclarationNameInfo NameInfo
5683 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5684 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005686
John McCallf7a1a742009-11-24 19:00:30 +00005687 if (!E->hasExplicitTemplateArgs()) {
5688 if (!getDerived().AlwaysRebuild() &&
5689 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005690 // Note: it is sufficient to compare the Name component of NameInfo:
5691 // if name has not changed, DNLoc has not changed either.
5692 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00005693 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005694
John McCallf7a1a742009-11-24 19:00:30 +00005695 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5696 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005697 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005698 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005699 }
John McCalld5532b62009-11-23 01:53:49 +00005700
5701 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005703 TemplateArgumentLoc Loc;
5704 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005705 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005706 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005707 }
5708
John McCallf7a1a742009-11-24 19:00:30 +00005709 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5710 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005711 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005712 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005713}
5714
5715template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005716ExprResult
John McCall454feb92009-12-08 09:21:05 +00005717TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005718 // CXXConstructExprs are always implicit, so when we have a
5719 // 1-argument construction we just transform that argument.
5720 if (E->getNumArgs() == 1 ||
5721 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5722 return getDerived().TransformExpr(E->getArg(0));
5723
Douglas Gregorb98b1992009-08-11 05:31:07 +00005724 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5725
5726 QualType T = getDerived().TransformType(E->getType());
5727 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005728 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005729
5730 CXXConstructorDecl *Constructor
5731 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005732 getDerived().TransformDecl(E->getLocStart(),
5733 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005734 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005736
Douglas Gregorb98b1992009-08-11 05:31:07 +00005737 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005738 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005739 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005740 ArgEnd = E->arg_end();
5741 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005742 if (getDerived().DropCallArgument(*Arg)) {
5743 ArgumentChanged = true;
5744 break;
5745 }
5746
John McCall60d7b3a2010-08-24 06:29:42 +00005747 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005748 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005750
Douglas Gregorb98b1992009-08-11 05:31:07 +00005751 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005752 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753 }
5754
5755 if (!getDerived().AlwaysRebuild() &&
5756 T == E->getType() &&
5757 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005758 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005759 // Mark the constructor as referenced.
5760 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005761 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005762 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00005763 }
Mike Stump1eb44332009-09-09 15:08:12 +00005764
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005765 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5766 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005767 move_arg(Args),
5768 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00005769 E->getConstructionKind(),
5770 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005771}
Mike Stump1eb44332009-09-09 15:08:12 +00005772
Douglas Gregorb98b1992009-08-11 05:31:07 +00005773/// \brief Transform a C++ temporary-binding expression.
5774///
Douglas Gregor51326552009-12-24 18:51:59 +00005775/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5776/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005778ExprResult
John McCall454feb92009-12-08 09:21:05 +00005779TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005780 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005781}
Mike Stump1eb44332009-09-09 15:08:12 +00005782
5783/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005784/// be destroyed after the expression is evaluated.
5785///
Douglas Gregor51326552009-12-24 18:51:59 +00005786/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5787/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005788template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005789ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005790TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005791 CXXExprWithTemporaries *E) {
5792 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793}
Mike Stump1eb44332009-09-09 15:08:12 +00005794
Douglas Gregorb98b1992009-08-11 05:31:07 +00005795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005796ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005797TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005798 CXXTemporaryObjectExpr *E) {
5799 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5800 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005801 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005802
Douglas Gregorb98b1992009-08-11 05:31:07 +00005803 CXXConstructorDecl *Constructor
5804 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005805 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005806 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005807 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005808 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005809
Douglas Gregorb98b1992009-08-11 05:31:07 +00005810 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005811 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005812 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005813 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005814 ArgEnd = E->arg_end();
5815 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005816 if (getDerived().DropCallArgument(*Arg)) {
5817 ArgumentChanged = true;
5818 break;
5819 }
5820
John McCall60d7b3a2010-08-24 06:29:42 +00005821 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005822 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005824
Douglas Gregorb98b1992009-08-11 05:31:07 +00005825 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5826 Args.push_back((Expr *)TransArg.release());
5827 }
Mike Stump1eb44332009-09-09 15:08:12 +00005828
Douglas Gregorb98b1992009-08-11 05:31:07 +00005829 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005830 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005831 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005832 !ArgumentChanged) {
5833 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005834 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005835 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00005836 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005837
5838 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5839 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005840 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005841 E->getLocEnd());
5842}
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregorb98b1992009-08-11 05:31:07 +00005844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005845ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005846TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005847 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005848 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5849 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005850 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Douglas Gregorb98b1992009-08-11 05:31:07 +00005852 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005853 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005854 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5855 ArgEnd = E->arg_end();
5856 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005857 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005858 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005859 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005860
Douglas Gregorb98b1992009-08-11 05:31:07 +00005861 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005862 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005863 }
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Douglas Gregorb98b1992009-08-11 05:31:07 +00005865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005866 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005867 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005868 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005869
Douglas Gregorb98b1992009-08-11 05:31:07 +00005870 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005871 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005872 E->getLParenLoc(),
5873 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005874 E->getRParenLoc());
5875}
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Douglas Gregorb98b1992009-08-11 05:31:07 +00005877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005878ExprResult
John McCall865d4472009-11-19 22:55:06 +00005879TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005880 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005881 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005882 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005883 Expr *OldBase;
5884 QualType BaseType;
5885 QualType ObjectType;
5886 if (!E->isImplicitAccess()) {
5887 OldBase = E->getBase();
5888 Base = getDerived().TransformExpr(OldBase);
5889 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005890 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005891
John McCallaa81e162009-12-01 22:10:20 +00005892 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005893 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005894 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005895 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005896 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005897 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005898 ObjectTy,
5899 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005900 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005901 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005902
John McCallb3d87482010-08-24 05:47:05 +00005903 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005904 BaseType = ((Expr*) Base.get())->getType();
5905 } else {
5906 OldBase = 0;
5907 BaseType = getDerived().TransformType(E->getBaseType());
5908 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5909 }
Mike Stump1eb44332009-09-09 15:08:12 +00005910
Douglas Gregor6cd21982009-10-20 05:58:46 +00005911 // Transform the first part of the nested-name-specifier that qualifies
5912 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005913 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005914 = getDerived().TransformFirstQualifierInScope(
5915 E->getFirstQualifierFoundInScope(),
5916 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005917
Douglas Gregora38c6872009-09-03 16:14:30 +00005918 NestedNameSpecifier *Qualifier = 0;
5919 if (E->getQualifier()) {
5920 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5921 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005922 ObjectType,
5923 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005924 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005925 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005926 }
Mike Stump1eb44332009-09-09 15:08:12 +00005927
John McCall43fed0d2010-11-12 08:19:04 +00005928 // TODO: If this is a conversion-function-id, verify that the
5929 // destination type name (if present) resolves the same way after
5930 // instantiation as it did in the local scope.
5931
Abramo Bagnara25777432010-08-11 22:01:17 +00005932 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00005933 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00005934 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005935 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005936
John McCallaa81e162009-12-01 22:10:20 +00005937 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005938 // This is a reference to a member without an explicitly-specified
5939 // template argument list. Optimize for this common case.
5940 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005941 Base.get() == OldBase &&
5942 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005943 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005944 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005945 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00005946 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005947
John McCall9ae2f072010-08-23 23:25:46 +00005948 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005949 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005950 E->isArrow(),
5951 E->getOperatorLoc(),
5952 Qualifier,
5953 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005954 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005955 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005956 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005957 }
5958
John McCalld5532b62009-11-23 01:53:49 +00005959 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005960 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005961 TemplateArgumentLoc Loc;
5962 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005963 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005964 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005965 }
Mike Stump1eb44332009-09-09 15:08:12 +00005966
John McCall9ae2f072010-08-23 23:25:46 +00005967 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005968 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005969 E->isArrow(),
5970 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005971 Qualifier,
5972 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005973 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005974 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005975 &TransArgs);
5976}
5977
5978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005979ExprResult
John McCall454feb92009-12-08 09:21:05 +00005980TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005981 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005982 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005983 QualType BaseType;
5984 if (!Old->isImplicitAccess()) {
5985 Base = getDerived().TransformExpr(Old->getBase());
5986 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005987 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005988 BaseType = ((Expr*) Base.get())->getType();
5989 } else {
5990 BaseType = getDerived().TransformType(Old->getBaseType());
5991 }
John McCall129e2df2009-11-30 22:42:35 +00005992
5993 NestedNameSpecifier *Qualifier = 0;
5994 if (Old->getQualifier()) {
5995 Qualifier
5996 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005997 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005998 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005999 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006000 }
6001
Abramo Bagnara25777432010-08-11 22:01:17 +00006002 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006003 Sema::LookupOrdinaryName);
6004
6005 // Transform all the decls.
6006 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6007 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006008 NamedDecl *InstD = static_cast<NamedDecl*>(
6009 getDerived().TransformDecl(Old->getMemberLoc(),
6010 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006011 if (!InstD) {
6012 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6013 // This can happen because of dependent hiding.
6014 if (isa<UsingShadowDecl>(*I))
6015 continue;
6016 else
John McCallf312b1e2010-08-26 23:41:50 +00006017 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006018 }
John McCall129e2df2009-11-30 22:42:35 +00006019
6020 // Expand using declarations.
6021 if (isa<UsingDecl>(InstD)) {
6022 UsingDecl *UD = cast<UsingDecl>(InstD);
6023 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6024 E = UD->shadow_end(); I != E; ++I)
6025 R.addDecl(*I);
6026 continue;
6027 }
6028
6029 R.addDecl(InstD);
6030 }
6031
6032 R.resolveKind();
6033
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006034 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006035 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006036 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006037 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006038 Old->getMemberLoc(),
6039 Old->getNamingClass()));
6040 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006041 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006042
Douglas Gregor66c45152010-04-27 16:10:10 +00006043 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006044 }
Sean Huntc3021132010-05-05 15:23:54 +00006045
John McCall129e2df2009-11-30 22:42:35 +00006046 TemplateArgumentListInfo TransArgs;
6047 if (Old->hasExplicitTemplateArgs()) {
6048 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6049 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6050 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6051 TemplateArgumentLoc Loc;
6052 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6053 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00006054 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006055 TransArgs.addArgument(Loc);
6056 }
6057 }
John McCallc2233c52010-01-15 08:34:02 +00006058
6059 // FIXME: to do this check properly, we will need to preserve the
6060 // first-qualifier-in-scope here, just in case we had a dependent
6061 // base (and therefore couldn't do the check) and a
6062 // nested-name-qualifier (and therefore could do the lookup).
6063 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006064
John McCall9ae2f072010-08-23 23:25:46 +00006065 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006066 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006067 Old->getOperatorLoc(),
6068 Old->isArrow(),
6069 Qualifier,
6070 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006071 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006072 R,
6073 (Old->hasExplicitTemplateArgs()
6074 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006075}
6076
6077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006078ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006079TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6080 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6081 if (SubExpr.isInvalid())
6082 return ExprError();
6083
6084 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006085 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006086
6087 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6088}
6089
6090template<typename Derived>
6091ExprResult
John McCall454feb92009-12-08 09:21:05 +00006092TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006093 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006094}
6095
Mike Stump1eb44332009-09-09 15:08:12 +00006096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006097ExprResult
John McCall454feb92009-12-08 09:21:05 +00006098TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006099 TypeSourceInfo *EncodedTypeInfo
6100 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6101 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006102 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006103
Douglas Gregorb98b1992009-08-11 05:31:07 +00006104 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006105 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006106 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107
6108 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006109 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006110 E->getRParenLoc());
6111}
Mike Stump1eb44332009-09-09 15:08:12 +00006112
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006114ExprResult
John McCall454feb92009-12-08 09:21:05 +00006115TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006116 // Transform arguments.
6117 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006118 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006119 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006120 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006121 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006122 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006123
Douglas Gregor92e986e2010-04-22 16:44:27 +00006124 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006125 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006126 }
6127
6128 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6129 // Class message: transform the receiver type.
6130 TypeSourceInfo *ReceiverTypeInfo
6131 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6132 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006133 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006134
Douglas Gregor92e986e2010-04-22 16:44:27 +00006135 // If nothing changed, just retain the existing message send.
6136 if (!getDerived().AlwaysRebuild() &&
6137 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006139
6140 // Build a new class message send.
6141 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6142 E->getSelector(),
6143 E->getMethodDecl(),
6144 E->getLeftLoc(),
6145 move_arg(Args),
6146 E->getRightLoc());
6147 }
6148
6149 // Instance message: transform the receiver
6150 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6151 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006152 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006153 = getDerived().TransformExpr(E->getInstanceReceiver());
6154 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006155 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006156
6157 // If nothing changed, just retain the existing message send.
6158 if (!getDerived().AlwaysRebuild() &&
6159 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006160 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006161
Douglas Gregor92e986e2010-04-22 16:44:27 +00006162 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006163 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006164 E->getSelector(),
6165 E->getMethodDecl(),
6166 E->getLeftLoc(),
6167 move_arg(Args),
6168 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006169}
6170
Mike Stump1eb44332009-09-09 15:08:12 +00006171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006172ExprResult
John McCall454feb92009-12-08 09:21:05 +00006173TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006174 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175}
6176
Mike Stump1eb44332009-09-09 15:08:12 +00006177template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006178ExprResult
John McCall454feb92009-12-08 09:21:05 +00006179TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006180 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181}
6182
Mike Stump1eb44332009-09-09 15:08:12 +00006183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006184ExprResult
John McCall454feb92009-12-08 09:21:05 +00006185TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006186 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006187 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006188 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006189 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006190
6191 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006192
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006193 // If nothing changed, just retain the existing expression.
6194 if (!getDerived().AlwaysRebuild() &&
6195 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006196 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006197
John McCall9ae2f072010-08-23 23:25:46 +00006198 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006199 E->getLocation(),
6200 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201}
6202
Mike Stump1eb44332009-09-09 15:08:12 +00006203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006204ExprResult
John McCall454feb92009-12-08 09:21:05 +00006205TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00006206 // 'super' and types never change. Property never changes. Just
6207 // retain the existing expression.
6208 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006209 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006210
Douglas Gregore3303542010-04-26 20:47:02 +00006211 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006212 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006213 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006214 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006215
Douglas Gregore3303542010-04-26 20:47:02 +00006216 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006217
Douglas Gregore3303542010-04-26 20:47:02 +00006218 // If nothing changed, just retain the existing expression.
6219 if (!getDerived().AlwaysRebuild() &&
6220 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006221 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222
John McCall12f78a62010-12-02 01:19:52 +00006223 if (E->isExplicitProperty())
6224 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6225 E->getExplicitProperty(),
6226 E->getLocation());
6227
6228 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6229 E->getType(),
6230 E->getImplicitPropertyGetter(),
6231 E->getImplicitPropertySetter(),
6232 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006233}
6234
Mike Stump1eb44332009-09-09 15:08:12 +00006235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006236ExprResult
John McCall454feb92009-12-08 09:21:05 +00006237TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006238 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006239 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006240 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006241 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006242
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006243 // If nothing changed, just retain the existing expression.
6244 if (!getDerived().AlwaysRebuild() &&
6245 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006246 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006247
John McCall9ae2f072010-08-23 23:25:46 +00006248 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006249 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006250}
6251
Mike Stump1eb44332009-09-09 15:08:12 +00006252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006253ExprResult
John McCall454feb92009-12-08 09:21:05 +00006254TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006255 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006256 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006257 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006258 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006259 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006260 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006261
Douglas Gregorb98b1992009-08-11 05:31:07 +00006262 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006263 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006264 }
Mike Stump1eb44332009-09-09 15:08:12 +00006265
Douglas Gregorb98b1992009-08-11 05:31:07 +00006266 if (!getDerived().AlwaysRebuild() &&
6267 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006268 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006269
Douglas Gregorb98b1992009-08-11 05:31:07 +00006270 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6271 move_arg(SubExprs),
6272 E->getRParenLoc());
6273}
6274
Mike Stump1eb44332009-09-09 15:08:12 +00006275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006276ExprResult
John McCall454feb92009-12-08 09:21:05 +00006277TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006278 SourceLocation CaretLoc(E->getExprLoc());
6279
6280 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6281 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6282 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6283 llvm::SmallVector<ParmVarDecl*, 4> Params;
6284 llvm::SmallVector<QualType, 4> ParamTypes;
6285
6286 // Parameter substitution.
6287 const BlockDecl *BD = E->getBlockDecl();
6288 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6289 EN = BD->param_end(); P != EN; ++P) {
6290 ParmVarDecl *OldParm = (*P);
6291 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6292 QualType NewType = NewParm->getType();
6293 Params.push_back(NewParm);
6294 ParamTypes.push_back(NewParm->getType());
6295 }
6296
6297 const FunctionType *BExprFunctionType = E->getFunctionType();
6298 QualType BExprResultType = BExprFunctionType->getResultType();
6299 if (!BExprResultType.isNull()) {
6300 if (!BExprResultType->isDependentType())
6301 CurBlock->ReturnType = BExprResultType;
6302 else if (BExprResultType != SemaRef.Context.DependentTy)
6303 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6304 }
6305
6306 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006307 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006308 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006309 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006310 // Set the parameters on the block decl.
6311 if (!Params.empty())
6312 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6313
6314 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6315 CurBlock->ReturnType,
6316 ParamTypes.data(),
6317 ParamTypes.size(),
6318 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006319 0,
6320 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006321
6322 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006323 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324}
6325
Mike Stump1eb44332009-09-09 15:08:12 +00006326template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006327ExprResult
John McCall454feb92009-12-08 09:21:05 +00006328TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006329 NestedNameSpecifier *Qualifier = 0;
6330
6331 ValueDecl *ND
6332 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6333 E->getDecl()));
6334 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006335 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006336
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006337 if (!getDerived().AlwaysRebuild() &&
6338 ND == E->getDecl()) {
6339 // Mark it referenced in the new context regardless.
6340 // FIXME: this is a bit instantiation-specific.
6341 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6342
John McCall3fa5cae2010-10-26 07:05:15 +00006343 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006344 }
6345
Abramo Bagnara25777432010-08-11 22:01:17 +00006346 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006347 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006348 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349}
Mike Stump1eb44332009-09-09 15:08:12 +00006350
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006352// Type reconstruction
6353//===----------------------------------------------------------------------===//
6354
Mike Stump1eb44332009-09-09 15:08:12 +00006355template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006356QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6357 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006358 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006359 getDerived().getBaseEntity());
6360}
6361
Mike Stump1eb44332009-09-09 15:08:12 +00006362template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006363QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6364 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006365 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006366 getDerived().getBaseEntity());
6367}
6368
Mike Stump1eb44332009-09-09 15:08:12 +00006369template<typename Derived>
6370QualType
John McCall85737a72009-10-30 00:06:24 +00006371TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6372 bool WrittenAsLValue,
6373 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006374 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006375 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006376}
6377
6378template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006379QualType
John McCall85737a72009-10-30 00:06:24 +00006380TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6381 QualType ClassType,
6382 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006383 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006384 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006385}
6386
6387template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006388QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006389TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6390 ArrayType::ArraySizeModifier SizeMod,
6391 const llvm::APInt *Size,
6392 Expr *SizeExpr,
6393 unsigned IndexTypeQuals,
6394 SourceRange BracketsRange) {
6395 if (SizeExpr || !Size)
6396 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6397 IndexTypeQuals, BracketsRange,
6398 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006399
6400 QualType Types[] = {
6401 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6402 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6403 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006404 };
6405 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6406 QualType SizeType;
6407 for (unsigned I = 0; I != NumTypes; ++I)
6408 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6409 SizeType = Types[I];
6410 break;
6411 }
Mike Stump1eb44332009-09-09 15:08:12 +00006412
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006413 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6414 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006415 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006416 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006417 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006418}
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Douglas Gregor577f75a2009-08-04 16:50:30 +00006420template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006421QualType
6422TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006423 ArrayType::ArraySizeModifier SizeMod,
6424 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006425 unsigned IndexTypeQuals,
6426 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006427 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006428 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006429}
6430
6431template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006432QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006433TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006434 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006435 unsigned IndexTypeQuals,
6436 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006437 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006438 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006439}
Mike Stump1eb44332009-09-09 15:08:12 +00006440
Douglas Gregor577f75a2009-08-04 16:50:30 +00006441template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006442QualType
6443TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006444 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006445 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006446 unsigned IndexTypeQuals,
6447 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006448 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006449 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006450 IndexTypeQuals, BracketsRange);
6451}
6452
6453template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006454QualType
6455TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006456 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006457 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006458 unsigned IndexTypeQuals,
6459 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006460 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006461 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006462 IndexTypeQuals, BracketsRange);
6463}
6464
6465template<typename Derived>
6466QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00006467 unsigned NumElements,
6468 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006469 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00006470 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006471}
Mike Stump1eb44332009-09-09 15:08:12 +00006472
Douglas Gregor577f75a2009-08-04 16:50:30 +00006473template<typename Derived>
6474QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6475 unsigned NumElements,
6476 SourceLocation AttributeLoc) {
6477 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6478 NumElements, true);
6479 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006480 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6481 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006482 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006483}
Mike Stump1eb44332009-09-09 15:08:12 +00006484
Douglas Gregor577f75a2009-08-04 16:50:30 +00006485template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006486QualType
6487TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006488 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006489 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006490 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006491}
Mike Stump1eb44332009-09-09 15:08:12 +00006492
Douglas Gregor577f75a2009-08-04 16:50:30 +00006493template<typename Derived>
6494QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006495 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006496 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006497 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006498 unsigned Quals,
6499 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006500 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006501 Quals,
6502 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006503 getDerived().getBaseEntity(),
6504 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006505}
Mike Stump1eb44332009-09-09 15:08:12 +00006506
Douglas Gregor577f75a2009-08-04 16:50:30 +00006507template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006508QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6509 return SemaRef.Context.getFunctionNoProtoType(T);
6510}
6511
6512template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006513QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6514 assert(D && "no decl found");
6515 if (D->isInvalidDecl()) return QualType();
6516
Douglas Gregor92e986e2010-04-22 16:44:27 +00006517 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006518 TypeDecl *Ty;
6519 if (isa<UsingDecl>(D)) {
6520 UsingDecl *Using = cast<UsingDecl>(D);
6521 assert(Using->isTypeName() &&
6522 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6523
6524 // A valid resolved using typename decl points to exactly one type decl.
6525 assert(++Using->shadow_begin() == Using->shadow_end());
6526 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006527
John McCalled976492009-12-04 22:46:56 +00006528 } else {
6529 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6530 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6531 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6532 }
6533
6534 return SemaRef.Context.getTypeDeclType(Ty);
6535}
6536
6537template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006538QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6539 SourceLocation Loc) {
6540 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006541}
6542
6543template<typename Derived>
6544QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6545 return SemaRef.Context.getTypeOfType(Underlying);
6546}
6547
6548template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006549QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6550 SourceLocation Loc) {
6551 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006552}
6553
6554template<typename Derived>
6555QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006556 TemplateName Template,
6557 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006558 const TemplateArgumentListInfo &TemplateArgs) {
6559 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006560}
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Douglas Gregordcee1a12009-08-06 05:28:30 +00006562template<typename Derived>
6563NestedNameSpecifier *
6564TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6565 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006566 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006567 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006568 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006569 CXXScopeSpec SS;
6570 // FIXME: The source location information is all wrong.
6571 SS.setRange(Range);
6572 SS.setScopeRep(Prefix);
6573 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006574 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006575 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006576 ObjectType,
6577 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006578 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006579}
6580
6581template<typename Derived>
6582NestedNameSpecifier *
6583TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6584 SourceRange Range,
6585 NamespaceDecl *NS) {
6586 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6587}
6588
6589template<typename Derived>
6590NestedNameSpecifier *
6591TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6592 SourceRange Range,
6593 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006594 QualType T) {
6595 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006596 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006597 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006598 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6599 T.getTypePtr());
6600 }
Mike Stump1eb44332009-09-09 15:08:12 +00006601
Douglas Gregordcee1a12009-08-06 05:28:30 +00006602 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6603 return 0;
6604}
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregord1067e52009-08-06 06:41:21 +00006606template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006607TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006608TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6609 bool TemplateKW,
6610 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006611 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006612 Template);
6613}
6614
6615template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006616TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006617TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006618 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006619 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00006620 QualType ObjectType,
6621 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006622 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006623 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006624 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006625 UnqualifiedId Name;
6626 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006627 Sema::TemplateTy Template;
6628 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6629 /*FIXME:*/getDerived().getBaseLocation(),
6630 SS,
6631 Name,
John McCallb3d87482010-08-24 05:47:05 +00006632 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006633 /*EnteringContext=*/false,
6634 Template);
John McCall43fed0d2010-11-12 08:19:04 +00006635 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00006636}
Mike Stump1eb44332009-09-09 15:08:12 +00006637
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006639TemplateName
6640TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6641 OverloadedOperatorKind Operator,
6642 QualType ObjectType) {
6643 CXXScopeSpec SS;
6644 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6645 SS.setScopeRep(Qualifier);
6646 UnqualifiedId Name;
6647 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6648 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6649 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006650 Sema::TemplateTy Template;
6651 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006652 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006653 SS,
6654 Name,
John McCallb3d87482010-08-24 05:47:05 +00006655 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006656 /*EnteringContext=*/false,
6657 Template);
6658 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006659}
Sean Huntc3021132010-05-05 15:23:54 +00006660
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006662ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6664 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006665 Expr *OrigCallee,
6666 Expr *First,
6667 Expr *Second) {
6668 Expr *Callee = OrigCallee->IgnoreParenCasts();
6669 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006672 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006673 if (!First->getType()->isOverloadableType() &&
6674 !Second->getType()->isOverloadableType())
6675 return getSema().CreateBuiltinArraySubscriptExpr(First,
6676 Callee->getLocStart(),
6677 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006678 } else if (Op == OO_Arrow) {
6679 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006680 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6681 } else if (Second == 0 || isPostIncDec) {
6682 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 // The argument is not of overloadable type, so try to create a
6684 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006685 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006687
John McCall9ae2f072010-08-23 23:25:46 +00006688 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 }
6690 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006691 if (!First->getType()->isOverloadableType() &&
6692 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 // Neither of the arguments is an overloadable type, so try to
6694 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006695 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006696 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006697 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006699 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006700
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 return move(Result);
6702 }
6703 }
Mike Stump1eb44332009-09-09 15:08:12 +00006704
6705 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006707 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006708
John McCall9ae2f072010-08-23 23:25:46 +00006709 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006710 assert(ULE->requiresADL());
6711
6712 // FIXME: Do we have to check
6713 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006714 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006715 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006716 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006717 }
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006720 Expr *Args[2] = { First, Second };
6721 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 // Create the overloaded operator invocation for unary operators.
6724 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006725 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006727 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 }
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Sebastian Redlf322ed62009-10-29 20:17:01 +00006730 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006731 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006732 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006733 First,
6734 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006735
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006737 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006738 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6740 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006741 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Mike Stump1eb44332009-09-09 15:08:12 +00006743 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744}
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006747ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006748TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006749 SourceLocation OperatorLoc,
6750 bool isArrow,
6751 NestedNameSpecifier *Qualifier,
6752 SourceRange QualifierRange,
6753 TypeSourceInfo *ScopeType,
6754 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006755 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006756 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006757 CXXScopeSpec SS;
6758 if (Qualifier) {
6759 SS.setRange(QualifierRange);
6760 SS.setScopeRep(Qualifier);
6761 }
6762
John McCall9ae2f072010-08-23 23:25:46 +00006763 QualType BaseType = Base->getType();
6764 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006765 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006766 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006767 !BaseType->getAs<PointerType>()->getPointeeType()
6768 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006769 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006770 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006771 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006772 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006773 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006774 /*FIXME?*/true);
6775 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006776
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006777 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006778 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6779 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6780 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6781 NameInfo.setNamedTypeInfo(DestroyedType);
6782
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006783 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006784
John McCall9ae2f072010-08-23 23:25:46 +00006785 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006786 OperatorLoc, isArrow,
6787 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006788 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006789 /*TemplateArgs*/ 0);
6790}
6791
Douglas Gregor577f75a2009-08-04 16:50:30 +00006792} // end namespace clang
6793
6794#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H