blob: f4a4ae28cf6f7f462cb5482813ad11a7154f4b01 [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
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000522 /// \brief Build a new parenthesized type.
523 ///
524 /// By default, builds a new ParenType type from the inner type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildParenType(QualType InnerType) {
527 return SemaRef.Context.getParenType(InnerType);
528 }
529
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530 /// \brief Build a new qualified name type.
531 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000532 /// By default, builds a new ElaboratedType type from the keyword,
533 /// the nested-name-specifier and the named type.
534 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000535 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
536 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000537 NestedNameSpecifier *NNS, QualType Named) {
538 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000539 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000540
541 /// \brief Build a new typename type that refers to a template-id.
542 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000543 /// By default, builds a new DependentNameType type from the
544 /// nested-name-specifier and the given type. Subclasses may override
545 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000546 QualType RebuildDependentTemplateSpecializationType(
547 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000548 NestedNameSpecifier *Qualifier,
549 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000550 const IdentifierInfo *Name,
551 SourceLocation NameLoc,
552 const TemplateArgumentListInfo &Args) {
553 // Rebuild the template name.
554 // TODO: avoid TemplateName abstraction
555 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000556 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000557 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000558
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000559 if (InstName.isNull())
560 return QualType();
561
John McCall33500952010-06-11 00:33:02 +0000562 // If it's still dependent, make a dependent specialization.
563 if (InstName.getAsDependentTemplateName())
564 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000565 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000566
567 // Otherwise, make an elaborated type wrapping a non-dependent
568 // specialization.
569 QualType T =
570 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
571 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000572
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000573 // NOTE: NNS is already recorded in template specialization type T.
574 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000575 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000576
577 /// \brief Build a new typename type that refers to an identifier.
578 ///
579 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000580 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000581 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000582 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000583 NestedNameSpecifier *NNS,
584 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000585 SourceLocation KeywordLoc,
586 SourceRange NNSRange,
587 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000588 CXXScopeSpec SS;
589 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000590 SS.setRange(NNSRange);
591
Douglas Gregor40336422010-03-31 22:19:08 +0000592 if (NNS->isDependent()) {
593 // If the name is still dependent, just build a new dependent name type.
594 if (!SemaRef.computeDeclContext(SS))
595 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
596 }
597
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000598 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000599 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
600 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000601
602 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
603
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000604 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000605 // into a non-dependent elaborated-type-specifier. Find the tag we're
606 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000607 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000608 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
609 if (!DC)
610 return QualType();
611
John McCall56138762010-05-27 06:40:31 +0000612 if (SemaRef.RequireCompleteDeclContext(SS, DC))
613 return QualType();
614
Douglas Gregor40336422010-03-31 22:19:08 +0000615 TagDecl *Tag = 0;
616 SemaRef.LookupQualifiedName(Result, DC);
617 switch (Result.getResultKind()) {
618 case LookupResult::NotFound:
619 case LookupResult::NotFoundInCurrentInstantiation:
620 break;
Sean Huntc3021132010-05-05 15:23:54 +0000621
Douglas Gregor40336422010-03-31 22:19:08 +0000622 case LookupResult::Found:
623 Tag = Result.getAsSingle<TagDecl>();
624 break;
Sean Huntc3021132010-05-05 15:23:54 +0000625
Douglas Gregor40336422010-03-31 22:19:08 +0000626 case LookupResult::FoundOverloaded:
627 case LookupResult::FoundUnresolvedValue:
628 llvm_unreachable("Tag lookup cannot find non-tags");
629 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000630
Douglas Gregor40336422010-03-31 22:19:08 +0000631 case LookupResult::Ambiguous:
632 // Let the LookupResult structure handle ambiguities.
633 return QualType();
634 }
635
636 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000637 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000638 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000639 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000640 return QualType();
641 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000642
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000643 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
644 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000645 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
646 return QualType();
647 }
648
649 // Build the elaborated-type-specifier type.
650 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000651 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000652 }
Mike Stump1eb44332009-09-09 15:08:12 +0000653
Douglas Gregordcee1a12009-08-06 05:28:30 +0000654 /// \brief Build a new nested-name-specifier given the prefix and an
655 /// identifier that names the next step in the nested-name-specifier.
656 ///
657 /// By default, performs semantic analysis when building the new
658 /// nested-name-specifier. Subclasses may override this routine to provide
659 /// different behavior.
660 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
661 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000662 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000663 QualType ObjectType,
664 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000665
666 /// \brief Build a new nested-name-specifier given the prefix and the
667 /// namespace named in the next step in the nested-name-specifier.
668 ///
669 /// By default, performs semantic analysis when building the new
670 /// nested-name-specifier. Subclasses may override this routine to provide
671 /// different behavior.
672 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
673 SourceRange Range,
674 NamespaceDecl *NS);
675
676 /// \brief Build a new nested-name-specifier given the prefix and the
677 /// type named in the next step in the nested-name-specifier.
678 ///
679 /// By default, performs semantic analysis when building the new
680 /// nested-name-specifier. Subclasses may override this routine to provide
681 /// different behavior.
682 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
683 SourceRange Range,
684 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000685 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000686
687 /// \brief Build a new template name given a nested name specifier, a flag
688 /// indicating whether the "template" keyword was provided, and the template
689 /// that the template name refers to.
690 ///
691 /// By default, builds the new template name directly. Subclasses may override
692 /// this routine to provide different behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
694 bool TemplateKW,
695 TemplateDecl *Template);
696
Douglas Gregord1067e52009-08-06 06:41:21 +0000697 /// \brief Build a new template name given a nested name specifier and the
698 /// name that is referred to as a template.
699 ///
700 /// By default, performs semantic analysis to determine whether the name can
701 /// be resolved to a specific template, then builds the appropriate kind of
702 /// template name. Subclasses may override this routine to provide different
703 /// behavior.
704 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000705 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000706 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000707 QualType ObjectType,
708 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000710 /// \brief Build a new template name given a nested name specifier and the
711 /// overloaded operator name that is referred to as a template.
712 ///
713 /// By default, performs semantic analysis to determine whether the name can
714 /// be resolved to a specific template, then builds the appropriate kind of
715 /// template name. Subclasses may override this routine to provide different
716 /// behavior.
717 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
718 OverloadedOperatorKind Operator,
719 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000720
Douglas Gregor43959a92009-08-20 07:17:43 +0000721 /// \brief Build a new compound statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000725 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000726 MultiStmtArg Statements,
727 SourceLocation RBraceLoc,
728 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000729 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000730 IsStmtExpr);
731 }
732
733 /// \brief Build a new case statement.
734 ///
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000737 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000738 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000739 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000740 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000741 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000742 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000743 ColonLoc);
744 }
Mike Stump1eb44332009-09-09 15:08:12 +0000745
Douglas Gregor43959a92009-08-20 07:17:43 +0000746 /// \brief Attach the body to a new case statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000750 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000751 getSema().ActOnCaseStmtBody(S, Body);
752 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000753 }
Mike Stump1eb44332009-09-09 15:08:12 +0000754
Douglas Gregor43959a92009-08-20 07:17:43 +0000755 /// \brief Build a new default statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000759 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000760 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000761 Stmt *SubStmt) {
762 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000763 /*CurScope=*/0);
764 }
Mike Stump1eb44332009-09-09 15:08:12 +0000765
Douglas Gregor43959a92009-08-20 07:17:43 +0000766 /// \brief Build a new label statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000770 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000771 IdentifierInfo *Id,
772 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000773 Stmt *SubStmt, bool HasUnusedAttr) {
774 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
775 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000776 }
Mike Stump1eb44332009-09-09 15:08:12 +0000777
Douglas Gregor43959a92009-08-20 07:17:43 +0000778 /// \brief Build a new "if" statement.
779 ///
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000782 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000783 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000784 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000785 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000786 }
Mike Stump1eb44332009-09-09 15:08:12 +0000787
Douglas Gregor43959a92009-08-20 07:17:43 +0000788 /// \brief Start building a new switch statement.
789 ///
790 /// By default, performs semantic analysis to build the new statement.
791 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000792 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000793 Expr *Cond, VarDecl *CondVar) {
794 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000795 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000796 }
Mike Stump1eb44332009-09-09 15:08:12 +0000797
Douglas Gregor43959a92009-08-20 07:17:43 +0000798 /// \brief Attach the body to the switch statement.
799 ///
800 /// By default, performs semantic analysis to build the new statement.
801 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000802 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000803 Stmt *Switch, Stmt *Body) {
804 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000805 }
806
807 /// \brief Build a new while statement.
808 ///
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000811 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000812 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000813 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000814 Stmt *Body) {
815 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000816 }
Mike Stump1eb44332009-09-09 15:08:12 +0000817
Douglas Gregor43959a92009-08-20 07:17:43 +0000818 /// \brief Build a new do-while statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000822 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000823 SourceLocation WhileLoc,
824 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000825 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000826 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000827 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
828 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000829 }
830
831 /// \brief Build a new for statement.
832 ///
833 /// By default, performs semantic analysis to build the new statement.
834 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000835 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000836 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000837 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000838 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000839 SourceLocation RParenLoc, Stmt *Body) {
840 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000841 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000842 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000843 }
Mike Stump1eb44332009-09-09 15:08:12 +0000844
Douglas Gregor43959a92009-08-20 07:17:43 +0000845 /// \brief Build a new goto statement.
846 ///
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000849 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000850 SourceLocation LabelLoc,
851 LabelStmt *Label) {
852 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
853 }
854
855 /// \brief Build a new indirect goto statement.
856 ///
857 /// By default, performs semantic analysis to build the new statement.
858 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000859 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000860 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000861 Expr *Target) {
862 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000863 }
Mike Stump1eb44332009-09-09 15:08:12 +0000864
Douglas Gregor43959a92009-08-20 07:17:43 +0000865 /// \brief Build a new return statement.
866 ///
867 /// By default, performs semantic analysis to build the new statement.
868 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000869 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000870 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000871
John McCall9ae2f072010-08-23 23:25:46 +0000872 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000873 }
Mike Stump1eb44332009-09-09 15:08:12 +0000874
Douglas Gregor43959a92009-08-20 07:17:43 +0000875 /// \brief Build a new declaration statement.
876 ///
877 /// By default, performs semantic analysis to build the new statement.
878 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000879 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000880 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000881 SourceLocation EndLoc) {
882 return getSema().Owned(
883 new (getSema().Context) DeclStmt(
884 DeclGroupRef::Create(getSema().Context,
885 Decls, NumDecls),
886 StartLoc, EndLoc));
887 }
Mike Stump1eb44332009-09-09 15:08:12 +0000888
Anders Carlsson703e3942010-01-24 05:50:09 +0000889 /// \brief Build a new inline asm statement.
890 ///
891 /// By default, performs semantic analysis to build the new statement.
892 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000893 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000894 bool IsSimple,
895 bool IsVolatile,
896 unsigned NumOutputs,
897 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000898 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000899 MultiExprArg Constraints,
900 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000901 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000902 MultiExprArg Clobbers,
903 SourceLocation RParenLoc,
904 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000905 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000906 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000907 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000908 RParenLoc, MSAsm);
909 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000910
911 /// \brief Build a new Objective-C @try statement.
912 ///
913 /// By default, performs semantic analysis to build the new statement.
914 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000915 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000916 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000917 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000918 Stmt *Finally) {
919 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
920 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000921 }
922
Douglas Gregorbe270a02010-04-26 17:57:08 +0000923 /// \brief Rebuild an Objective-C exception declaration.
924 ///
925 /// By default, performs semantic analysis to build the new declaration.
926 /// Subclasses may override this routine to provide different behavior.
927 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
928 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000929 return getSema().BuildObjCExceptionDecl(TInfo, T,
930 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000931 ExceptionDecl->getLocation());
932 }
Sean Huntc3021132010-05-05 15:23:54 +0000933
Douglas Gregorbe270a02010-04-26 17:57:08 +0000934 /// \brief Build a new Objective-C @catch statement.
935 ///
936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000938 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000939 SourceLocation RParenLoc,
940 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000941 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000942 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000943 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000944 }
Sean Huntc3021132010-05-05 15:23:54 +0000945
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000946 /// \brief Build a new Objective-C @finally statement.
947 ///
948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000950 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000951 Stmt *Body) {
952 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000953 }
Sean Huntc3021132010-05-05 15:23:54 +0000954
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000955 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000959 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000960 Expr *Operand) {
961 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000962 }
Sean Huntc3021132010-05-05 15:23:54 +0000963
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000964 /// \brief Build a new Objective-C @synchronized statement.
965 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000968 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000969 Expr *Object,
970 Stmt *Body) {
971 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
972 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000973 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000974
975 /// \brief Build a new Objective-C fast enumeration statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000979 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000980 SourceLocation LParenLoc,
981 Stmt *Element,
982 Expr *Collection,
983 SourceLocation RParenLoc,
984 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000985 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000986 Element,
987 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000988 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000989 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000990 }
Sean Huntc3021132010-05-05 15:23:54 +0000991
Douglas Gregor43959a92009-08-20 07:17:43 +0000992 /// \brief Build a new C++ exception declaration.
993 ///
994 /// By default, performs semantic analysis to build the new decaration.
995 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +0000996 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +0000997 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +0000999 SourceLocation Loc) {
1000 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001001 }
1002
1003 /// \brief Build a new C++ catch statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001007 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001008 VarDecl *ExceptionDecl,
1009 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001010 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1011 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001012 }
Mike Stump1eb44332009-09-09 15:08:12 +00001013
Douglas Gregor43959a92009-08-20 07:17:43 +00001014 /// \brief Build a new C++ try statement.
1015 ///
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001018 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001019 Stmt *TryBlock,
1020 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001021 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001022 }
Mike Stump1eb44332009-09-09 15:08:12 +00001023
Douglas Gregorb98b1992009-08-11 05:31:07 +00001024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001028 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001029 LookupResult &R,
1030 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001031 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1032 }
1033
1034
1035 /// \brief Build a new expression that references a declaration.
1036 ///
1037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001040 SourceRange QualifierRange,
1041 ValueDecl *VD,
1042 const DeclarationNameInfo &NameInfo,
1043 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001044 CXXScopeSpec SS;
1045 SS.setScopeRep(Qualifier);
1046 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001047
1048 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001049
1050 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001051 }
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregorb98b1992009-08-11 05:31:07 +00001053 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001054 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001057 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001058 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001059 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001060 }
1061
Douglas Gregora71d8192009-09-04 17:36:40 +00001062 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001063 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001067 SourceLocation OperatorLoc,
1068 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001069 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001070 SourceRange QualifierRange,
1071 TypeSourceInfo *ScopeType,
1072 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001073 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001074 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001077 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001078 /// By default, performs semantic analysis to build the new expression.
1079 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001080 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001081 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001082 Expr *SubExpr) {
1083 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001084 }
Mike Stump1eb44332009-09-09 15:08:12 +00001085
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001086 /// \brief Build a new builtin offsetof expression.
1087 ///
1088 /// By default, performs semantic analysis to build the new expression.
1089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001090 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001091 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001092 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001093 unsigned NumComponents,
1094 SourceLocation RParenLoc) {
1095 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1096 NumComponents, RParenLoc);
1097 }
Sean Huntc3021132010-05-05 15:23:54 +00001098
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001100 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001104 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001105 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001106 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 }
1108
Mike Stump1eb44332009-09-09 15:08:12 +00001109 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001111 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001114 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001115 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001116 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001117 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001119 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001120
Douglas Gregorb98b1992009-08-11 05:31:07 +00001121 return move(Result);
1122 }
Mike Stump1eb44332009-09-09 15:08:12 +00001123
Douglas Gregorb98b1992009-08-11 05:31:07 +00001124 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001125 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001126 /// By default, performs semantic analysis to build the new expression.
1127 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001128 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001129 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001130 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001132 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1133 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001134 RBracketLoc);
1135 }
1136
1137 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001138 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001141 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001142 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001143 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001144 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001145 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001146 }
1147
1148 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001149 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001150 /// By default, performs semantic analysis to build the new expression.
1151 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001152 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001153 bool isArrow,
1154 NestedNameSpecifier *Qualifier,
1155 SourceRange QualifierRange,
1156 const DeclarationNameInfo &MemberNameInfo,
1157 ValueDecl *Member,
1158 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001159 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001160 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001161 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001162 // We have a reference to an unnamed field. This is always the
1163 // base of an anonymous struct/union member access, i.e. the
1164 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001165 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001166 assert(Member->getType()->isRecordType() &&
1167 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001168
John McCall9ae2f072010-08-23 23:25:46 +00001169 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001170 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001171 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001172
John McCallf89e55a2010-11-18 06:31:45 +00001173 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001174 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001175 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001176 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001177 cast<FieldDecl>(Member)->getType(),
1178 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001179 return getSema().Owned(ME);
1180 }
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001182 CXXScopeSpec SS;
1183 if (Qualifier) {
1184 SS.setRange(QualifierRange);
1185 SS.setScopeRep(Qualifier);
1186 }
1187
John McCall9ae2f072010-08-23 23:25:46 +00001188 getSema().DefaultFunctionArrayConversion(Base);
1189 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001190
John McCall6bb80172010-03-30 21:47:33 +00001191 // FIXME: this involves duplicating earlier analysis in a lot of
1192 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001193 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001194 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001195 R.resolveKind();
1196
John McCall9ae2f072010-08-23 23:25:46 +00001197 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001198 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001199 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001200 }
Mike Stump1eb44332009-09-09 15:08:12 +00001201
Douglas Gregorb98b1992009-08-11 05:31:07 +00001202 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001203 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001204 /// By default, performs semantic analysis to build the new expression.
1205 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001206 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001207 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001208 Expr *LHS, Expr *RHS) {
1209 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001210 }
1211
1212 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001213 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001214 /// By default, performs semantic analysis to build the new expression.
1215 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001216 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001220 Expr *RHS) {
1221 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1222 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001223 }
1224
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001226 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 /// By default, performs semantic analysis to build the new expression.
1228 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001229 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001230 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001232 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001233 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001234 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 }
Mike Stump1eb44332009-09-09 15:08:12 +00001236
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001238 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001239 /// By default, performs semantic analysis to build the new expression.
1240 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001241 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001242 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001244 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001245 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001246 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001247 }
Mike Stump1eb44332009-09-09 15:08:12 +00001248
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001250 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001253 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001254 SourceLocation OpLoc,
1255 SourceLocation AccessorLoc,
1256 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001257
John McCall129e2df2009-11-30 22:42:35 +00001258 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001259 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001260 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001261 OpLoc, /*IsArrow*/ false,
1262 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001263 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001264 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001265 }
Mike Stump1eb44332009-09-09 15:08:12 +00001266
Douglas Gregorb98b1992009-08-11 05:31:07 +00001267 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001268 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001271 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001272 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001273 SourceLocation RBraceLoc,
1274 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001275 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001276 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1277 if (Result.isInvalid() || ResultTy->isDependentType())
1278 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001279
Douglas Gregore48319a2009-11-09 17:16:50 +00001280 // Patch in the result type we were given, which may have been computed
1281 // when the initial InitListExpr was built.
1282 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1283 ILE->setType(ResultTy);
1284 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 }
Mike Stump1eb44332009-09-09 15:08:12 +00001286
Douglas Gregorb98b1992009-08-11 05:31:07 +00001287 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001288 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001291 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 MultiExprArg ArrayExprs,
1293 SourceLocation EqualOrColonLoc,
1294 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001295 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001296 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001298 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001300 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001301
Douglas Gregorb98b1992009-08-11 05:31:07 +00001302 ArrayExprs.release();
1303 return move(Result);
1304 }
Mike Stump1eb44332009-09-09 15:08:12 +00001305
Douglas Gregorb98b1992009-08-11 05:31:07 +00001306 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001307 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001308 /// By default, builds the implicit value initialization without performing
1309 /// any semantic analysis. Subclasses may override this routine to provide
1310 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001311 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1313 }
Mike Stump1eb44332009-09-09 15:08:12 +00001314
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001316 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001319 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001320 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001321 SourceLocation RParenLoc) {
1322 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001323 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001324 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 }
1326
1327 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001328 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001331 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 MultiExprArg SubExprs,
1333 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001334 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001335 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 }
Mike Stump1eb44332009-09-09 15:08:12 +00001337
Douglas Gregorb98b1992009-08-11 05:31:07 +00001338 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001339 ///
1340 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 /// rather than attempting to map the label statement itself.
1342 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001343 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001344 SourceLocation LabelLoc,
1345 LabelStmt *Label) {
1346 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1347 }
Mike Stump1eb44332009-09-09 15:08:12 +00001348
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001350 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001353 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001354 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001356 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 }
Mike Stump1eb44332009-09-09 15:08:12 +00001358
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 /// \brief Build a new __builtin_choose_expr expression.
1360 ///
1361 /// By default, performs semantic analysis to build the new expression.
1362 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001363 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001364 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 SourceLocation RParenLoc) {
1366 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001367 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 RParenLoc);
1369 }
Mike Stump1eb44332009-09-09 15:08:12 +00001370
Douglas Gregorb98b1992009-08-11 05:31:07 +00001371 /// \brief Build a new overloaded operator call expression.
1372 ///
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// The semantic analysis provides the behavior of template instantiation,
1375 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001376 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001377 /// argument-dependent lookup, etc. Subclasses may override this routine to
1378 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001379 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001381 Expr *Callee,
1382 Expr *First,
1383 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001384
1385 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 /// reinterpret_cast.
1387 ///
1388 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001389 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001391 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 Stmt::StmtClass Class,
1393 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001394 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 SourceLocation RAngleLoc,
1396 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001397 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 SourceLocation RParenLoc) {
1399 switch (Class) {
1400 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001403 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404
1405 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001408 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001413 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001415
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001417 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001418 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001419 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001420
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 default:
1422 assert(false && "Invalid C++ named cast");
1423 break;
1424 }
Mike Stump1eb44332009-09-09 15:08:12 +00001425
John McCallf312b1e2010-08-26 23:41:50 +00001426 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001427 }
Mike Stump1eb44332009-09-09 15:08:12 +00001428
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 /// \brief Build a new C++ static_cast expression.
1430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001433 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 SourceLocation RAngleLoc,
1437 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001438 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001440 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001441 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001442 SourceRange(LAngleLoc, RAngleLoc),
1443 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new C++ dynamic_cast expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001450 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001452 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 SourceLocation RAngleLoc,
1454 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001455 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001457 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001458 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001459 SourceRange(LAngleLoc, RAngleLoc),
1460 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 }
1462
1463 /// \brief Build a new C++ reinterpret_cast expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001467 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001469 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 SourceLocation RAngleLoc,
1471 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001472 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001474 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001475 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001476 SourceRange(LAngleLoc, RAngleLoc),
1477 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 }
1479
1480 /// \brief Build a new C++ const_cast expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001484 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001486 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation RAngleLoc,
1488 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001489 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001491 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001492 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001493 SourceRange(LAngleLoc, RAngleLoc),
1494 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 }
Mike Stump1eb44332009-09-09 15:08:12 +00001496
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 /// \brief Build a new C++ functional-style cast expression.
1498 ///
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001501 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1502 SourceLocation LParenLoc,
1503 Expr *Sub,
1504 SourceLocation RParenLoc) {
1505 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001506 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 RParenLoc);
1508 }
Mike Stump1eb44332009-09-09 15:08:12 +00001509
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 /// \brief Build a new C++ typeid(type) expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001514 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001515 SourceLocation TypeidLoc,
1516 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001518 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001519 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 }
Mike Stump1eb44332009-09-09 15:08:12 +00001521
Francois Pichet01b7c302010-09-08 12:20:18 +00001522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new C++ typeid(expr) expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001527 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001528 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001529 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001531 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001532 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001533 }
1534
Francois Pichet01b7c302010-09-08 12:20:18 +00001535 /// \brief Build a new C++ __uuidof(type) expression.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
1539 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1540 SourceLocation TypeidLoc,
1541 TypeSourceInfo *Operand,
1542 SourceLocation RParenLoc) {
1543 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1544 RParenLoc);
1545 }
1546
1547 /// \brief Build a new C++ __uuidof(expr) expression.
1548 ///
1549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
1551 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1552 SourceLocation TypeidLoc,
1553 Expr *Operand,
1554 SourceLocation RParenLoc) {
1555 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1556 RParenLoc);
1557 }
1558
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// \brief Build a new C++ "this" expression.
1560 ///
1561 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001562 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001564 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001565 QualType ThisType,
1566 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001568 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1569 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 }
1571
1572 /// \brief Build a new C++ throw expression.
1573 ///
1574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001577 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
1579
1580 /// \brief Build a new C++ default-argument expression.
1581 ///
1582 /// By default, builds a new default-argument expression, which does not
1583 /// require any semantic analysis. Subclasses may override this routine to
1584 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001586 ParmVarDecl *Param) {
1587 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1588 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 }
1590
1591 /// \brief Build a new C++ zero-initialization expression.
1592 ///
1593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001595 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1596 SourceLocation LParenLoc,
1597 SourceLocation RParenLoc) {
1598 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001599 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001600 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 }
Mike Stump1eb44332009-09-09 15:08:12 +00001602
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 /// \brief Build a new C++ "new" expression.
1604 ///
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001607 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001608 bool UseGlobal,
1609 SourceLocation PlacementLParen,
1610 MultiExprArg PlacementArgs,
1611 SourceLocation PlacementRParen,
1612 SourceRange TypeIdParens,
1613 QualType AllocatedType,
1614 TypeSourceInfo *AllocatedTypeInfo,
1615 Expr *ArraySize,
1616 SourceLocation ConstructorLParen,
1617 MultiExprArg ConstructorArgs,
1618 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001619 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 PlacementLParen,
1621 move(PlacementArgs),
1622 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001623 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001624 AllocatedType,
1625 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001626 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 ConstructorLParen,
1628 move(ConstructorArgs),
1629 ConstructorRParen);
1630 }
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// \brief Build a new C++ "delete" expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001636 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 bool IsGlobalDelete,
1638 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001639 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001641 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 }
Mike Stump1eb44332009-09-09 15:08:12 +00001643
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 /// \brief Build a new unary type trait expression.
1645 ///
1646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001648 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001649 SourceLocation StartLoc,
1650 TypeSourceInfo *T,
1651 SourceLocation RParenLoc) {
1652 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 }
1654
Francois Pichet6ad6f282010-12-07 00:08:36 +00001655 /// \brief Build a new binary type trait expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
1659 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1660 SourceLocation StartLoc,
1661 TypeSourceInfo *LhsT,
1662 TypeSourceInfo *RhsT,
1663 SourceLocation RParenLoc) {
1664 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1665 }
1666
Mike Stump1eb44332009-09-09 15:08:12 +00001667 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 /// expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001674 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001675 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 CXXScopeSpec SS;
1677 SS.setRange(QualifierRange);
1678 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001679
1680 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001681 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001682 *TemplateArgs);
1683
Abramo Bagnara25777432010-08-11 22:01:17 +00001684 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new template-id expression.
1688 ///
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001691 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001692 LookupResult &R,
1693 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001694 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001695 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 }
1697
1698 /// \brief Build a new object-construction expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001702 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001703 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 CXXConstructorDecl *Constructor,
1705 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001706 MultiExprArg Args,
1707 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001708 CXXConstructExpr::ConstructionKind ConstructKind,
1709 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001710 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001711 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001712 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001713 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001714
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001715 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001716 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001717 RequiresZeroInit, ConstructKind,
1718 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 }
1720
1721 /// \brief Build a new object-construction expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001725 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1726 SourceLocation LParenLoc,
1727 MultiExprArg Args,
1728 SourceLocation RParenLoc) {
1729 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 LParenLoc,
1731 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 RParenLoc);
1733 }
1734
1735 /// \brief Build a new object-construction expression.
1736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001739 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1740 SourceLocation LParenLoc,
1741 MultiExprArg Args,
1742 SourceLocation RParenLoc) {
1743 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 LParenLoc,
1745 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 RParenLoc);
1747 }
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 /// \brief Build a new member reference expression.
1750 ///
1751 /// By default, performs semantic analysis to build the new expression.
1752 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001753 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001754 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 bool IsArrow,
1756 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001757 NestedNameSpecifier *Qualifier,
1758 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001759 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001760 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001761 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001763 SS.setRange(QualifierRange);
1764 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001765
John McCall9ae2f072010-08-23 23:25:46 +00001766 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001767 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001768 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001769 MemberNameInfo,
1770 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 }
1772
John McCall129e2df2009-11-30 22:42:35 +00001773 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001777 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001778 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001779 SourceLocation OperatorLoc,
1780 bool IsArrow,
1781 NestedNameSpecifier *Qualifier,
1782 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001783 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001784 LookupResult &R,
1785 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001786 CXXScopeSpec SS;
1787 SS.setRange(QualifierRange);
1788 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001789
John McCall9ae2f072010-08-23 23:25:46 +00001790 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001791 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001792 SS, FirstQualifierInScope,
1793 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001794 }
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Sebastian Redl2e156222010-09-10 20:55:43 +00001796 /// \brief Build a new noexcept expression.
1797 ///
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
1800 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1801 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1802 }
1803
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 /// \brief Build a new Objective-C @encode expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001808 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001809 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001811 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001813 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001816 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001817 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001818 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001819 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001820 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001821 MultiExprArg Args,
1822 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001823 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1824 ReceiverTypeInfo->getType(),
1825 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001826 Sel, Method, LBracLoc, SelectorLoc,
1827 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001828 }
1829
1830 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001831 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001832 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001833 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001834 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001835 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001836 MultiExprArg Args,
1837 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001838 return SemaRef.BuildInstanceMessage(Receiver,
1839 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001840 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001841 Sel, Method, LBracLoc, SelectorLoc,
1842 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001843 }
1844
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001845 /// \brief Build a new Objective-C ivar reference expression.
1846 ///
1847 /// By default, performs semantic analysis to build the new expression.
1848 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001849 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001850 SourceLocation IvarLoc,
1851 bool IsArrow, bool IsFreeIvar) {
1852 // FIXME: We lose track of the IsFreeIvar bit.
1853 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001854 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001855 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1856 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001858 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001859 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001860 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001861 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001862 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001863
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001864 if (Result.get())
1865 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001866
John McCall9ae2f072010-08-23 23:25:46 +00001867 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001868 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001869 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001870 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001871 /*TemplateArgs=*/0);
1872 }
Douglas Gregore3303542010-04-26 20:47:02 +00001873
1874 /// \brief Build a new Objective-C property reference expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001878 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001879 ObjCPropertyDecl *Property,
1880 SourceLocation PropertyLoc) {
1881 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001882 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001883 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1884 Sema::LookupMemberName);
1885 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001887 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001888 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001889 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001890 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001891
Douglas Gregore3303542010-04-26 20:47:02 +00001892 if (Result.get())
1893 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001894
John McCall9ae2f072010-08-23 23:25:46 +00001895 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001896 /*FIXME:*/PropertyLoc, IsArrow,
1897 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001898 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001899 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001900 /*TemplateArgs=*/0);
1901 }
Sean Huntc3021132010-05-05 15:23:54 +00001902
John McCall12f78a62010-12-02 01:19:52 +00001903 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001904 ///
1905 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00001906 /// Subclasses may override this routine to provide different behavior.
1907 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1908 ObjCMethodDecl *Getter,
1909 ObjCMethodDecl *Setter,
1910 SourceLocation PropertyLoc) {
1911 // Since these expressions can only be value-dependent, we do not
1912 // need to perform semantic analysis again.
1913 return Owned(
1914 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
1915 VK_LValue, OK_ObjCProperty,
1916 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001917 }
1918
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001919 /// \brief Build a new Objective-C "isa" expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001923 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001924 bool IsArrow) {
1925 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001926 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001927 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1928 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001929 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001930 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001931 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001932 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001933 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001934
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001935 if (Result.get())
1936 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001937
John McCall9ae2f072010-08-23 23:25:46 +00001938 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001939 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001940 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001941 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001942 /*TemplateArgs=*/0);
1943 }
Sean Huntc3021132010-05-05 15:23:54 +00001944
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 /// \brief Build a new shuffle vector expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001949 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001950 MultiExprArg SubExprs,
1951 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001953 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1955 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1956 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1957 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 // Build a reference to the __builtin_shufflevector builtin
1960 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001961 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00001963 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001965
1966 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 unsigned NumSubExprs = SubExprs.size();
1968 Expr **Subs = (Expr **)SubExprs.release();
1969 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1970 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001971 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00001972 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001974 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001975
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001977 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001980
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001982 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001983 }
John McCall43fed0d2010-11-12 08:19:04 +00001984
1985private:
1986 QualType TransformTypeInObjectScope(QualType T,
1987 QualType ObjectType,
1988 NamedDecl *FirstQualifierInScope,
1989 NestedNameSpecifier *Prefix);
1990
1991 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
1992 QualType ObjectType,
1993 NamedDecl *FirstQualifierInScope,
1994 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00001995};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996
Douglas Gregor43959a92009-08-20 07:17:43 +00001997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001998StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001999 if (!S)
2000 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002001
Douglas Gregor43959a92009-08-20 07:17:43 +00002002 switch (S->getStmtClass()) {
2003 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002004
Douglas Gregor43959a92009-08-20 07:17:43 +00002005 // Transform individual statement nodes
2006#define STMT(Node, Parent) \
2007 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2008#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002009#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002010
Douglas Gregor43959a92009-08-20 07:17:43 +00002011 // Transform expressions by calling TransformExpr.
2012#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002013#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002014#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002015#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002016 {
John McCall60d7b3a2010-08-24 06:29:42 +00002017 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002018 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002019 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002020
John McCall9ae2f072010-08-23 23:25:46 +00002021 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002022 }
Mike Stump1eb44332009-09-09 15:08:12 +00002023 }
2024
John McCall3fa5cae2010-10-26 07:05:15 +00002025 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002026}
Mike Stump1eb44332009-09-09 15:08:12 +00002027
2028
Douglas Gregor670444e2009-08-04 22:27:00 +00002029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002030ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002031 if (!E)
2032 return SemaRef.Owned(E);
2033
2034 switch (E->getStmtClass()) {
2035 case Stmt::NoStmtClass: break;
2036#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002037#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002038#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002039 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002040#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002041 }
2042
John McCall3fa5cae2010-10-26 07:05:15 +00002043 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002044}
2045
2046template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002047NestedNameSpecifier *
2048TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002049 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002050 QualType ObjectType,
2051 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002052 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002053
Douglas Gregor43959a92009-08-20 07:17:43 +00002054 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002055 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002056 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002057 ObjectType,
2058 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002059 if (!Prefix)
2060 return 0;
2061 }
Mike Stump1eb44332009-09-09 15:08:12 +00002062
Douglas Gregordcee1a12009-08-06 05:28:30 +00002063 switch (NNS->getKind()) {
2064 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002065 if (Prefix) {
2066 // The object type and qualifier-in-scope really apply to the
2067 // leftmost entity.
2068 ObjectType = QualType();
2069 FirstQualifierInScope = 0;
2070 }
2071
Mike Stump1eb44332009-09-09 15:08:12 +00002072 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002073 "Identifier nested-name-specifier with no prefix or object type");
2074 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2075 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002077
2078 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002079 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002080 ObjectType,
2081 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002082
Douglas Gregordcee1a12009-08-06 05:28:30 +00002083 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002084 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002085 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002086 getDerived().TransformDecl(Range.getBegin(),
2087 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002088 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002089 Prefix == NNS->getPrefix() &&
2090 NS == NNS->getAsNamespace())
2091 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002092
Douglas Gregordcee1a12009-08-06 05:28:30 +00002093 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2094 }
Mike Stump1eb44332009-09-09 15:08:12 +00002095
Douglas Gregordcee1a12009-08-06 05:28:30 +00002096 case NestedNameSpecifier::Global:
2097 // There is no meaningful transformation that one could perform on the
2098 // global scope.
2099 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002100
Douglas Gregordcee1a12009-08-06 05:28:30 +00002101 case NestedNameSpecifier::TypeSpecWithTemplate:
2102 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002103 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002104 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2105 ObjectType,
2106 FirstQualifierInScope,
2107 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002108 if (T.isNull())
2109 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002110
Douglas Gregordcee1a12009-08-06 05:28:30 +00002111 if (!getDerived().AlwaysRebuild() &&
2112 Prefix == NNS->getPrefix() &&
2113 T == QualType(NNS->getAsType(), 0))
2114 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002115
2116 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2117 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002118 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002119 }
2120 }
Mike Stump1eb44332009-09-09 15:08:12 +00002121
Douglas Gregordcee1a12009-08-06 05:28:30 +00002122 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002123 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002124}
2125
2126template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002127DeclarationNameInfo
2128TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002129::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002130 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002131 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002132 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002133
2134 switch (Name.getNameKind()) {
2135 case DeclarationName::Identifier:
2136 case DeclarationName::ObjCZeroArgSelector:
2137 case DeclarationName::ObjCOneArgSelector:
2138 case DeclarationName::ObjCMultiArgSelector:
2139 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002140 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002141 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002142 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002143
Douglas Gregor81499bb2009-09-03 22:13:48 +00002144 case DeclarationName::CXXConstructorName:
2145 case DeclarationName::CXXDestructorName:
2146 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002147 TypeSourceInfo *NewTInfo;
2148 CanQualType NewCanTy;
2149 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002150 NewTInfo = getDerived().TransformType(OldTInfo);
2151 if (!NewTInfo)
2152 return DeclarationNameInfo();
2153 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002154 }
2155 else {
2156 NewTInfo = 0;
2157 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002158 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002159 if (NewT.isNull())
2160 return DeclarationNameInfo();
2161 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2162 }
Mike Stump1eb44332009-09-09 15:08:12 +00002163
Abramo Bagnara25777432010-08-11 22:01:17 +00002164 DeclarationName NewName
2165 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2166 NewCanTy);
2167 DeclarationNameInfo NewNameInfo(NameInfo);
2168 NewNameInfo.setName(NewName);
2169 NewNameInfo.setNamedTypeInfo(NewTInfo);
2170 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002171 }
Mike Stump1eb44332009-09-09 15:08:12 +00002172 }
2173
Abramo Bagnara25777432010-08-11 22:01:17 +00002174 assert(0 && "Unknown name kind.");
2175 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002176}
2177
2178template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002179TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002180TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002181 QualType ObjectType,
2182 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002183 SourceLocation Loc = getDerived().getBaseLocation();
2184
Douglas Gregord1067e52009-08-06 06:41:21 +00002185 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002186 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002187 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002188 /*FIXME*/ SourceRange(Loc),
2189 ObjectType,
2190 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002191 if (!NNS)
2192 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002193
Douglas Gregord1067e52009-08-06 06:41:21 +00002194 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002195 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002196 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002197 if (!TransTemplate)
2198 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002199
Douglas Gregord1067e52009-08-06 06:41:21 +00002200 if (!getDerived().AlwaysRebuild() &&
2201 NNS == QTN->getQualifier() &&
2202 TransTemplate == Template)
2203 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002204
Douglas Gregord1067e52009-08-06 06:41:21 +00002205 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2206 TransTemplate);
2207 }
Mike Stump1eb44332009-09-09 15:08:12 +00002208
John McCallf7a1a742009-11-24 19:00:30 +00002209 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002210 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002211 }
Mike Stump1eb44332009-09-09 15:08:12 +00002212
Douglas Gregord1067e52009-08-06 06:41:21 +00002213 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002214 NestedNameSpecifier *NNS = DTN->getQualifier();
2215 if (NNS) {
2216 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2217 /*FIXME:*/SourceRange(Loc),
2218 ObjectType,
2219 FirstQualifierInScope);
2220 if (!NNS) return TemplateName();
2221
2222 // These apply to the scope specifier, not the template.
2223 ObjectType = QualType();
2224 FirstQualifierInScope = 0;
2225 }
Mike Stump1eb44332009-09-09 15:08:12 +00002226
Douglas Gregord1067e52009-08-06 06:41:21 +00002227 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002228 NNS == DTN->getQualifier() &&
2229 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002230 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002231
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002232 if (DTN->isIdentifier()) {
2233 // FIXME: Bad range
2234 SourceRange QualifierRange(getDerived().getBaseLocation());
2235 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2236 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002237 ObjectType,
2238 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002239 }
Sean Huntc3021132010-05-05 15:23:54 +00002240
2241 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002242 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002243 }
Mike Stump1eb44332009-09-09 15:08:12 +00002244
Douglas Gregord1067e52009-08-06 06:41:21 +00002245 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002246 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002247 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002248 if (!TransTemplate)
2249 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002250
Douglas Gregord1067e52009-08-06 06:41:21 +00002251 if (!getDerived().AlwaysRebuild() &&
2252 TransTemplate == Template)
2253 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002254
Douglas Gregord1067e52009-08-06 06:41:21 +00002255 return TemplateName(TransTemplate);
2256 }
Mike Stump1eb44332009-09-09 15:08:12 +00002257
John McCallf7a1a742009-11-24 19:00:30 +00002258 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002259 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002260 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002261}
2262
2263template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002264void TreeTransform<Derived>::InventTemplateArgumentLoc(
2265 const TemplateArgument &Arg,
2266 TemplateArgumentLoc &Output) {
2267 SourceLocation Loc = getDerived().getBaseLocation();
2268 switch (Arg.getKind()) {
2269 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002270 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002271 break;
2272
2273 case TemplateArgument::Type:
2274 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002275 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002276
John McCall833ca992009-10-29 08:12:44 +00002277 break;
2278
Douglas Gregor788cd062009-11-11 01:00:40 +00002279 case TemplateArgument::Template:
2280 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2281 break;
Sean Huntc3021132010-05-05 15:23:54 +00002282
John McCall833ca992009-10-29 08:12:44 +00002283 case TemplateArgument::Expression:
2284 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2285 break;
2286
2287 case TemplateArgument::Declaration:
2288 case TemplateArgument::Integral:
2289 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002290 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002291 break;
2292 }
2293}
2294
2295template<typename Derived>
2296bool TreeTransform<Derived>::TransformTemplateArgument(
2297 const TemplateArgumentLoc &Input,
2298 TemplateArgumentLoc &Output) {
2299 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002300 switch (Arg.getKind()) {
2301 case TemplateArgument::Null:
2302 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002303 Output = Input;
2304 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002305
Douglas Gregor670444e2009-08-04 22:27:00 +00002306 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002307 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002308 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002309 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002310
2311 DI = getDerived().TransformType(DI);
2312 if (!DI) return true;
2313
2314 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2315 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002316 }
Mike Stump1eb44332009-09-09 15:08:12 +00002317
Douglas Gregor670444e2009-08-04 22:27:00 +00002318 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002319 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002320 DeclarationName Name;
2321 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2322 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002323 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002324 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002325 if (!D) return true;
2326
John McCall828bff22009-10-29 18:45:58 +00002327 Expr *SourceExpr = Input.getSourceDeclExpression();
2328 if (SourceExpr) {
2329 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002330 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002331 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002332 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002333 }
2334
2335 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002336 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002337 }
Mike Stump1eb44332009-09-09 15:08:12 +00002338
Douglas Gregor788cd062009-11-11 01:00:40 +00002339 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002340 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002341 TemplateName Template
2342 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2343 if (Template.isNull())
2344 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002345
Douglas Gregor788cd062009-11-11 01:00:40 +00002346 Output = TemplateArgumentLoc(TemplateArgument(Template),
2347 Input.getTemplateQualifierRange(),
2348 Input.getTemplateNameLoc());
2349 return false;
2350 }
Sean Huntc3021132010-05-05 15:23:54 +00002351
Douglas Gregor670444e2009-08-04 22:27:00 +00002352 case TemplateArgument::Expression: {
2353 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002354 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002355 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002356
John McCall833ca992009-10-29 08:12:44 +00002357 Expr *InputExpr = Input.getSourceExpression();
2358 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2359
John McCall60d7b3a2010-08-24 06:29:42 +00002360 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002361 = getDerived().TransformExpr(InputExpr);
2362 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002363 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002364 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002365 }
Mike Stump1eb44332009-09-09 15:08:12 +00002366
Douglas Gregor670444e2009-08-04 22:27:00 +00002367 case TemplateArgument::Pack: {
2368 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2369 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002370 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002371 AEnd = Arg.pack_end();
2372 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002373
John McCall833ca992009-10-29 08:12:44 +00002374 // FIXME: preserve source information here when we start
2375 // caring about parameter packs.
2376
John McCall828bff22009-10-29 18:45:58 +00002377 TemplateArgumentLoc InputArg;
2378 TemplateArgumentLoc OutputArg;
2379 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2380 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002381 return true;
2382
John McCall828bff22009-10-29 18:45:58 +00002383 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002384 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002385
2386 TemplateArgument *TransformedArgsPtr
2387 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2388 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2389 TransformedArgsPtr);
2390 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2391 TransformedArgs.size()),
2392 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002393 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002394 }
2395 }
Mike Stump1eb44332009-09-09 15:08:12 +00002396
Douglas Gregor670444e2009-08-04 22:27:00 +00002397 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002398 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002399}
2400
Douglas Gregor577f75a2009-08-04 16:50:30 +00002401//===----------------------------------------------------------------------===//
2402// Type transformation
2403//===----------------------------------------------------------------------===//
2404
2405template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002406QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002407 if (getDerived().AlreadyTransformed(T))
2408 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002409
John McCalla2becad2009-10-21 00:40:46 +00002410 // Temporary workaround. All of these transformations should
2411 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002412 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002413 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002414
John McCall43fed0d2010-11-12 08:19:04 +00002415 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002416
John McCalla2becad2009-10-21 00:40:46 +00002417 if (!NewDI)
2418 return QualType();
2419
2420 return NewDI->getType();
2421}
2422
2423template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002424TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002425 if (getDerived().AlreadyTransformed(DI->getType()))
2426 return DI;
2427
2428 TypeLocBuilder TLB;
2429
2430 TypeLoc TL = DI->getTypeLoc();
2431 TLB.reserve(TL.getFullDataSize());
2432
John McCall43fed0d2010-11-12 08:19:04 +00002433 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002434 if (Result.isNull())
2435 return 0;
2436
John McCalla93c9342009-12-07 02:54:59 +00002437 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002438}
2439
2440template<typename Derived>
2441QualType
John McCall43fed0d2010-11-12 08:19:04 +00002442TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002443 switch (T.getTypeLocClass()) {
2444#define ABSTRACT_TYPELOC(CLASS, PARENT)
2445#define TYPELOC(CLASS, PARENT) \
2446 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002447 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002448#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002449 }
Mike Stump1eb44332009-09-09 15:08:12 +00002450
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002451 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002452 return QualType();
2453}
2454
2455/// FIXME: By default, this routine adds type qualifiers only to types
2456/// that can have qualifiers, and silently suppresses those qualifiers
2457/// that are not permitted (e.g., qualifiers on reference or function
2458/// types). This is the right thing for template instantiation, but
2459/// probably not for other clients.
2460template<typename Derived>
2461QualType
2462TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002463 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002464 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002465
John McCall43fed0d2010-11-12 08:19:04 +00002466 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002467 if (Result.isNull())
2468 return QualType();
2469
2470 // Silently suppress qualifiers if the result type can't be qualified.
2471 // FIXME: this is the right thing for template instantiation, but
2472 // probably not for other clients.
2473 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002474 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002475
John McCall28654742010-06-05 06:41:15 +00002476 if (!Quals.empty()) {
2477 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2478 TLB.push<QualifiedTypeLoc>(Result);
2479 // No location information to preserve.
2480 }
John McCalla2becad2009-10-21 00:40:46 +00002481
2482 return Result;
2483}
2484
John McCall43fed0d2010-11-12 08:19:04 +00002485/// \brief Transforms a type that was written in a scope specifier,
2486/// given an object type, the results of unqualified lookup, and
2487/// an already-instantiated prefix.
2488///
2489/// The object type is provided iff the scope specifier qualifies the
2490/// member of a dependent member-access expression. The prefix is
2491/// provided iff the the scope specifier in which this appears has a
2492/// prefix.
2493///
2494/// This is private to TreeTransform.
2495template<typename Derived>
2496QualType
2497TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2498 QualType ObjectType,
2499 NamedDecl *UnqualLookup,
2500 NestedNameSpecifier *Prefix) {
2501 if (getDerived().AlreadyTransformed(T))
2502 return T;
2503
2504 TypeSourceInfo *TSI =
2505 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2506
2507 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2508 UnqualLookup, Prefix);
2509 if (!TSI) return QualType();
2510 return TSI->getType();
2511}
2512
2513template<typename Derived>
2514TypeSourceInfo *
2515TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2516 QualType ObjectType,
2517 NamedDecl *UnqualLookup,
2518 NestedNameSpecifier *Prefix) {
2519 // TODO: in some cases, we might be some verification to do here.
2520 if (ObjectType.isNull())
2521 return getDerived().TransformType(TSI);
2522
2523 QualType T = TSI->getType();
2524 if (getDerived().AlreadyTransformed(T))
2525 return TSI;
2526
2527 TypeLocBuilder TLB;
2528 QualType Result;
2529
2530 if (isa<TemplateSpecializationType>(T)) {
2531 TemplateSpecializationTypeLoc TL
2532 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2533
2534 TemplateName Template =
2535 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2536 ObjectType, UnqualLookup);
2537 if (Template.isNull()) return 0;
2538
2539 Result = getDerived()
2540 .TransformTemplateSpecializationType(TLB, TL, Template);
2541 } else if (isa<DependentTemplateSpecializationType>(T)) {
2542 DependentTemplateSpecializationTypeLoc TL
2543 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2544
2545 Result = getDerived()
2546 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2547 } else {
2548 // Nothing special needs to be done for these.
2549 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2550 }
2551
2552 if (Result.isNull()) return 0;
2553 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2554}
2555
John McCalla2becad2009-10-21 00:40:46 +00002556template <class TyLoc> static inline
2557QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2558 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2559 NewT.setNameLoc(T.getNameLoc());
2560 return T.getType();
2561}
2562
John McCalla2becad2009-10-21 00:40:46 +00002563template<typename Derived>
2564QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002565 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002566 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2567 NewT.setBuiltinLoc(T.getBuiltinLoc());
2568 if (T.needsExtraLocalData())
2569 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2570 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002571}
Mike Stump1eb44332009-09-09 15:08:12 +00002572
Douglas Gregor577f75a2009-08-04 16:50:30 +00002573template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002574QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002575 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002576 // FIXME: recurse?
2577 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002578}
Mike Stump1eb44332009-09-09 15:08:12 +00002579
Douglas Gregor577f75a2009-08-04 16:50:30 +00002580template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002581QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002582 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00002583 QualType PointeeType
2584 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002585 if (PointeeType.isNull())
2586 return QualType();
2587
2588 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002589 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002590 // A dependent pointer type 'T *' has is being transformed such
2591 // that an Objective-C class type is being replaced for 'T'. The
2592 // resulting pointer type is an ObjCObjectPointerType, not a
2593 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002594 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002595
John McCallc12c5bb2010-05-15 11:32:37 +00002596 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2597 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002598 return Result;
2599 }
John McCall43fed0d2010-11-12 08:19:04 +00002600
Douglas Gregor92e986e2010-04-22 16:44:27 +00002601 if (getDerived().AlwaysRebuild() ||
2602 PointeeType != TL.getPointeeLoc().getType()) {
2603 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2604 if (Result.isNull())
2605 return QualType();
2606 }
Sean Huntc3021132010-05-05 15:23:54 +00002607
Douglas Gregor92e986e2010-04-22 16:44:27 +00002608 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2609 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002610 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002611}
Mike Stump1eb44332009-09-09 15:08:12 +00002612
2613template<typename Derived>
2614QualType
John McCalla2becad2009-10-21 00:40:46 +00002615TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002616 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002617 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002618 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2619 if (PointeeType.isNull())
2620 return QualType();
2621
2622 QualType Result = TL.getType();
2623 if (getDerived().AlwaysRebuild() ||
2624 PointeeType != TL.getPointeeLoc().getType()) {
2625 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002626 TL.getSigilLoc());
2627 if (Result.isNull())
2628 return QualType();
2629 }
2630
Douglas Gregor39968ad2010-04-22 16:50:51 +00002631 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002632 NewT.setSigilLoc(TL.getSigilLoc());
2633 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002634}
2635
John McCall85737a72009-10-30 00:06:24 +00002636/// Transforms a reference type. Note that somewhat paradoxically we
2637/// don't care whether the type itself is an l-value type or an r-value
2638/// type; we only care if the type was *written* as an l-value type
2639/// or an r-value type.
2640template<typename Derived>
2641QualType
2642TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002643 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002644 const ReferenceType *T = TL.getTypePtr();
2645
2646 // Note that this works with the pointee-as-written.
2647 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2648 if (PointeeType.isNull())
2649 return QualType();
2650
2651 QualType Result = TL.getType();
2652 if (getDerived().AlwaysRebuild() ||
2653 PointeeType != T->getPointeeTypeAsWritten()) {
2654 Result = getDerived().RebuildReferenceType(PointeeType,
2655 T->isSpelledAsLValue(),
2656 TL.getSigilLoc());
2657 if (Result.isNull())
2658 return QualType();
2659 }
2660
2661 // r-value references can be rebuilt as l-value references.
2662 ReferenceTypeLoc NewTL;
2663 if (isa<LValueReferenceType>(Result))
2664 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2665 else
2666 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2667 NewTL.setSigilLoc(TL.getSigilLoc());
2668
2669 return Result;
2670}
2671
Mike Stump1eb44332009-09-09 15:08:12 +00002672template<typename Derived>
2673QualType
John McCalla2becad2009-10-21 00:40:46 +00002674TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002675 LValueReferenceTypeLoc TL) {
2676 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002677}
2678
Mike Stump1eb44332009-09-09 15:08:12 +00002679template<typename Derived>
2680QualType
John McCalla2becad2009-10-21 00:40:46 +00002681TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002682 RValueReferenceTypeLoc TL) {
2683 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684}
Mike Stump1eb44332009-09-09 15:08:12 +00002685
Douglas Gregor577f75a2009-08-04 16:50:30 +00002686template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002687QualType
John McCalla2becad2009-10-21 00:40:46 +00002688TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002689 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002690 MemberPointerType *T = TL.getTypePtr();
2691
2692 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002693 if (PointeeType.isNull())
2694 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002695
John McCalla2becad2009-10-21 00:40:46 +00002696 // TODO: preserve source information for this.
2697 QualType ClassType
2698 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002699 if (ClassType.isNull())
2700 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002701
John McCalla2becad2009-10-21 00:40:46 +00002702 QualType Result = TL.getType();
2703 if (getDerived().AlwaysRebuild() ||
2704 PointeeType != T->getPointeeType() ||
2705 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002706 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2707 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002708 if (Result.isNull())
2709 return QualType();
2710 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002711
John McCalla2becad2009-10-21 00:40:46 +00002712 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2713 NewTL.setSigilLoc(TL.getSigilLoc());
2714
2715 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002716}
2717
Mike Stump1eb44332009-09-09 15:08:12 +00002718template<typename Derived>
2719QualType
John McCalla2becad2009-10-21 00:40:46 +00002720TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002721 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002722 ConstantArrayType *T = TL.getTypePtr();
2723 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002724 if (ElementType.isNull())
2725 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002726
John McCalla2becad2009-10-21 00:40:46 +00002727 QualType Result = TL.getType();
2728 if (getDerived().AlwaysRebuild() ||
2729 ElementType != T->getElementType()) {
2730 Result = getDerived().RebuildConstantArrayType(ElementType,
2731 T->getSizeModifier(),
2732 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002733 T->getIndexTypeCVRQualifiers(),
2734 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002735 if (Result.isNull())
2736 return QualType();
2737 }
Sean Huntc3021132010-05-05 15:23:54 +00002738
John McCalla2becad2009-10-21 00:40:46 +00002739 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2740 NewTL.setLBracketLoc(TL.getLBracketLoc());
2741 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002742
John McCalla2becad2009-10-21 00:40:46 +00002743 Expr *Size = TL.getSizeExpr();
2744 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002745 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002746 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2747 }
2748 NewTL.setSizeExpr(Size);
2749
2750 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002751}
Mike Stump1eb44332009-09-09 15:08:12 +00002752
Douglas Gregor577f75a2009-08-04 16:50:30 +00002753template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002754QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002755 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002756 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002757 IncompleteArrayType *T = TL.getTypePtr();
2758 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002759 if (ElementType.isNull())
2760 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002761
John McCalla2becad2009-10-21 00:40:46 +00002762 QualType Result = TL.getType();
2763 if (getDerived().AlwaysRebuild() ||
2764 ElementType != T->getElementType()) {
2765 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002766 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002767 T->getIndexTypeCVRQualifiers(),
2768 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002769 if (Result.isNull())
2770 return QualType();
2771 }
Sean Huntc3021132010-05-05 15:23:54 +00002772
John McCalla2becad2009-10-21 00:40:46 +00002773 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2774 NewTL.setLBracketLoc(TL.getLBracketLoc());
2775 NewTL.setRBracketLoc(TL.getRBracketLoc());
2776 NewTL.setSizeExpr(0);
2777
2778 return Result;
2779}
2780
2781template<typename Derived>
2782QualType
2783TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002784 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002785 VariableArrayType *T = TL.getTypePtr();
2786 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2787 if (ElementType.isNull())
2788 return QualType();
2789
2790 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002791 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002792
John McCall60d7b3a2010-08-24 06:29:42 +00002793 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002794 = getDerived().TransformExpr(T->getSizeExpr());
2795 if (SizeResult.isInvalid())
2796 return QualType();
2797
John McCall9ae2f072010-08-23 23:25:46 +00002798 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002799
2800 QualType Result = TL.getType();
2801 if (getDerived().AlwaysRebuild() ||
2802 ElementType != T->getElementType() ||
2803 Size != T->getSizeExpr()) {
2804 Result = getDerived().RebuildVariableArrayType(ElementType,
2805 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002806 Size,
John McCalla2becad2009-10-21 00:40:46 +00002807 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002808 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002809 if (Result.isNull())
2810 return QualType();
2811 }
Sean Huntc3021132010-05-05 15:23:54 +00002812
John McCalla2becad2009-10-21 00:40:46 +00002813 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2814 NewTL.setLBracketLoc(TL.getLBracketLoc());
2815 NewTL.setRBracketLoc(TL.getRBracketLoc());
2816 NewTL.setSizeExpr(Size);
2817
2818 return Result;
2819}
2820
2821template<typename Derived>
2822QualType
2823TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002824 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002825 DependentSizedArrayType *T = TL.getTypePtr();
2826 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2827 if (ElementType.isNull())
2828 return QualType();
2829
2830 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002831 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002832
John McCall60d7b3a2010-08-24 06:29:42 +00002833 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002834 = getDerived().TransformExpr(T->getSizeExpr());
2835 if (SizeResult.isInvalid())
2836 return QualType();
2837
2838 Expr *Size = static_cast<Expr*>(SizeResult.get());
2839
2840 QualType Result = TL.getType();
2841 if (getDerived().AlwaysRebuild() ||
2842 ElementType != T->getElementType() ||
2843 Size != T->getSizeExpr()) {
2844 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2845 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002846 Size,
John McCalla2becad2009-10-21 00:40:46 +00002847 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002848 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002849 if (Result.isNull())
2850 return QualType();
2851 }
2852 else SizeResult.take();
2853
2854 // We might have any sort of array type now, but fortunately they
2855 // all have the same location layout.
2856 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2857 NewTL.setLBracketLoc(TL.getLBracketLoc());
2858 NewTL.setRBracketLoc(TL.getRBracketLoc());
2859 NewTL.setSizeExpr(Size);
2860
2861 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002862}
Mike Stump1eb44332009-09-09 15:08:12 +00002863
2864template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002865QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002866 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002867 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002868 DependentSizedExtVectorType *T = TL.getTypePtr();
2869
2870 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002871 QualType ElementType = getDerived().TransformType(T->getElementType());
2872 if (ElementType.isNull())
2873 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002874
Douglas Gregor670444e2009-08-04 22:27:00 +00002875 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002876 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002877
John McCall60d7b3a2010-08-24 06:29:42 +00002878 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002879 if (Size.isInvalid())
2880 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002881
John McCalla2becad2009-10-21 00:40:46 +00002882 QualType Result = TL.getType();
2883 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002884 ElementType != T->getElementType() ||
2885 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002886 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002887 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002888 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002889 if (Result.isNull())
2890 return QualType();
2891 }
John McCalla2becad2009-10-21 00:40:46 +00002892
2893 // Result might be dependent or not.
2894 if (isa<DependentSizedExtVectorType>(Result)) {
2895 DependentSizedExtVectorTypeLoc NewTL
2896 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2897 NewTL.setNameLoc(TL.getNameLoc());
2898 } else {
2899 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2900 NewTL.setNameLoc(TL.getNameLoc());
2901 }
2902
2903 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002904}
Mike Stump1eb44332009-09-09 15:08:12 +00002905
2906template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002907QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002908 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002909 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002910 QualType ElementType = getDerived().TransformType(T->getElementType());
2911 if (ElementType.isNull())
2912 return QualType();
2913
John McCalla2becad2009-10-21 00:40:46 +00002914 QualType Result = TL.getType();
2915 if (getDerived().AlwaysRebuild() ||
2916 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002917 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00002918 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00002919 if (Result.isNull())
2920 return QualType();
2921 }
Sean Huntc3021132010-05-05 15:23:54 +00002922
John McCalla2becad2009-10-21 00:40:46 +00002923 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2924 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002925
John McCalla2becad2009-10-21 00:40:46 +00002926 return Result;
2927}
2928
2929template<typename Derived>
2930QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002931 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002932 VectorType *T = TL.getTypePtr();
2933 QualType ElementType = getDerived().TransformType(T->getElementType());
2934 if (ElementType.isNull())
2935 return QualType();
2936
2937 QualType Result = TL.getType();
2938 if (getDerived().AlwaysRebuild() ||
2939 ElementType != T->getElementType()) {
2940 Result = getDerived().RebuildExtVectorType(ElementType,
2941 T->getNumElements(),
2942 /*FIXME*/ SourceLocation());
2943 if (Result.isNull())
2944 return QualType();
2945 }
Sean Huntc3021132010-05-05 15:23:54 +00002946
John McCalla2becad2009-10-21 00:40:46 +00002947 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2948 NewTL.setNameLoc(TL.getNameLoc());
2949
2950 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002951}
Mike Stump1eb44332009-09-09 15:08:12 +00002952
2953template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002954ParmVarDecl *
2955TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2956 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2957 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2958 if (!NewDI)
2959 return 0;
2960
2961 if (NewDI == OldDI)
2962 return OldParm;
2963 else
2964 return ParmVarDecl::Create(SemaRef.Context,
2965 OldParm->getDeclContext(),
2966 OldParm->getLocation(),
2967 OldParm->getIdentifier(),
2968 NewDI->getType(),
2969 NewDI,
2970 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002971 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002972 /* DefArg */ NULL);
2973}
2974
2975template<typename Derived>
2976bool TreeTransform<Derived>::
2977 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2978 llvm::SmallVectorImpl<QualType> &PTypes,
2979 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2980 FunctionProtoType *T = TL.getTypePtr();
2981
2982 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2983 ParmVarDecl *OldParm = TL.getArg(i);
2984
2985 QualType NewType;
2986 ParmVarDecl *NewParm;
2987
2988 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002989 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2990 if (!NewParm)
2991 return true;
2992 NewType = NewParm->getType();
2993
2994 // Deal with the possibility that we don't have a parameter
2995 // declaration for this parameter.
2996 } else {
2997 NewParm = 0;
2998
2999 QualType OldType = T->getArgType(i);
3000 NewType = getDerived().TransformType(OldType);
3001 if (NewType.isNull())
3002 return true;
3003 }
3004
3005 PTypes.push_back(NewType);
3006 PVars.push_back(NewParm);
3007 }
3008
3009 return false;
3010}
3011
3012template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003013QualType
John McCalla2becad2009-10-21 00:40:46 +00003014TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003015 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003016 // Transform the parameters and return type.
3017 //
3018 // We instantiate in source order, with the return type first followed by
3019 // the parameters, because users tend to expect this (even if they shouldn't
3020 // rely on it!).
3021 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003022 // When the function has a trailing return type, we instantiate the
3023 // parameters before the return type, since the return type can then refer
3024 // to the parameters themselves (via decltype, sizeof, etc.).
3025 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003026 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003027 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003028 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003029
Douglas Gregordab60ad2010-10-01 18:44:50 +00003030 QualType ResultType;
3031
3032 if (TL.getTrailingReturn()) {
3033 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3034 return QualType();
3035
3036 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3037 if (ResultType.isNull())
3038 return QualType();
3039 }
3040 else {
3041 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3042 if (ResultType.isNull())
3043 return QualType();
3044
3045 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3046 return QualType();
3047 }
3048
John McCalla2becad2009-10-21 00:40:46 +00003049 QualType Result = TL.getType();
3050 if (getDerived().AlwaysRebuild() ||
3051 ResultType != T->getResultType() ||
3052 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3053 Result = getDerived().RebuildFunctionProtoType(ResultType,
3054 ParamTypes.data(),
3055 ParamTypes.size(),
3056 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003057 T->getTypeQuals(),
3058 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003059 if (Result.isNull())
3060 return QualType();
3061 }
Mike Stump1eb44332009-09-09 15:08:12 +00003062
John McCalla2becad2009-10-21 00:40:46 +00003063 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3064 NewTL.setLParenLoc(TL.getLParenLoc());
3065 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003066 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003067 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3068 NewTL.setArg(i, ParamDecls[i]);
3069
3070 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003071}
Mike Stump1eb44332009-09-09 15:08:12 +00003072
Douglas Gregor577f75a2009-08-04 16:50:30 +00003073template<typename Derived>
3074QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003075 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003076 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003077 FunctionNoProtoType *T = TL.getTypePtr();
3078 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3079 if (ResultType.isNull())
3080 return QualType();
3081
3082 QualType Result = TL.getType();
3083 if (getDerived().AlwaysRebuild() ||
3084 ResultType != T->getResultType())
3085 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3086
3087 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3088 NewTL.setLParenLoc(TL.getLParenLoc());
3089 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003090 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003091
3092 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003093}
Mike Stump1eb44332009-09-09 15:08:12 +00003094
John McCalled976492009-12-04 22:46:56 +00003095template<typename Derived> QualType
3096TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003097 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003098 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003099 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003100 if (!D)
3101 return QualType();
3102
3103 QualType Result = TL.getType();
3104 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3105 Result = getDerived().RebuildUnresolvedUsingType(D);
3106 if (Result.isNull())
3107 return QualType();
3108 }
3109
3110 // We might get an arbitrary type spec type back. We should at
3111 // least always get a type spec type, though.
3112 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3113 NewTL.setNameLoc(TL.getNameLoc());
3114
3115 return Result;
3116}
3117
Douglas Gregor577f75a2009-08-04 16:50:30 +00003118template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003119QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003120 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003121 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003122 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003123 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3124 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003125 if (!Typedef)
3126 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003127
John McCalla2becad2009-10-21 00:40:46 +00003128 QualType Result = TL.getType();
3129 if (getDerived().AlwaysRebuild() ||
3130 Typedef != T->getDecl()) {
3131 Result = getDerived().RebuildTypedefType(Typedef);
3132 if (Result.isNull())
3133 return QualType();
3134 }
Mike Stump1eb44332009-09-09 15:08:12 +00003135
John McCalla2becad2009-10-21 00:40:46 +00003136 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3137 NewTL.setNameLoc(TL.getNameLoc());
3138
3139 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003140}
Mike Stump1eb44332009-09-09 15:08:12 +00003141
Douglas Gregor577f75a2009-08-04 16:50:30 +00003142template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003143QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003144 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003145 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003146 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003147
John McCall60d7b3a2010-08-24 06:29:42 +00003148 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003149 if (E.isInvalid())
3150 return QualType();
3151
John McCalla2becad2009-10-21 00:40:46 +00003152 QualType Result = TL.getType();
3153 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003154 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003155 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003156 if (Result.isNull())
3157 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003158 }
John McCalla2becad2009-10-21 00:40:46 +00003159 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003160
John McCalla2becad2009-10-21 00:40:46 +00003161 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003162 NewTL.setTypeofLoc(TL.getTypeofLoc());
3163 NewTL.setLParenLoc(TL.getLParenLoc());
3164 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003165
3166 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003167}
Mike Stump1eb44332009-09-09 15:08:12 +00003168
3169template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003170QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003171 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003172 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3173 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3174 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003175 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003176
John McCalla2becad2009-10-21 00:40:46 +00003177 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003178 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3179 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003180 if (Result.isNull())
3181 return QualType();
3182 }
Mike Stump1eb44332009-09-09 15:08:12 +00003183
John McCalla2becad2009-10-21 00:40:46 +00003184 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003185 NewTL.setTypeofLoc(TL.getTypeofLoc());
3186 NewTL.setLParenLoc(TL.getLParenLoc());
3187 NewTL.setRParenLoc(TL.getRParenLoc());
3188 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003189
3190 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003191}
Mike Stump1eb44332009-09-09 15:08:12 +00003192
3193template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003194QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003195 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003196 DecltypeType *T = TL.getTypePtr();
3197
Douglas Gregor670444e2009-08-04 22:27:00 +00003198 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003199 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003200
John McCall60d7b3a2010-08-24 06:29:42 +00003201 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003202 if (E.isInvalid())
3203 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003204
John McCalla2becad2009-10-21 00:40:46 +00003205 QualType Result = TL.getType();
3206 if (getDerived().AlwaysRebuild() ||
3207 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003208 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003209 if (Result.isNull())
3210 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003211 }
John McCalla2becad2009-10-21 00:40:46 +00003212 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003213
John McCalla2becad2009-10-21 00:40:46 +00003214 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3215 NewTL.setNameLoc(TL.getNameLoc());
3216
3217 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003218}
3219
3220template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003221QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003222 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003223 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003224 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003225 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3226 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003227 if (!Record)
3228 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003229
John McCalla2becad2009-10-21 00:40:46 +00003230 QualType Result = TL.getType();
3231 if (getDerived().AlwaysRebuild() ||
3232 Record != T->getDecl()) {
3233 Result = getDerived().RebuildRecordType(Record);
3234 if (Result.isNull())
3235 return QualType();
3236 }
Mike Stump1eb44332009-09-09 15:08:12 +00003237
John McCalla2becad2009-10-21 00:40:46 +00003238 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3239 NewTL.setNameLoc(TL.getNameLoc());
3240
3241 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003242}
Mike Stump1eb44332009-09-09 15:08:12 +00003243
3244template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003245QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003246 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003247 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003248 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003249 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3250 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251 if (!Enum)
3252 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003253
John McCalla2becad2009-10-21 00:40:46 +00003254 QualType Result = TL.getType();
3255 if (getDerived().AlwaysRebuild() ||
3256 Enum != T->getDecl()) {
3257 Result = getDerived().RebuildEnumType(Enum);
3258 if (Result.isNull())
3259 return QualType();
3260 }
Mike Stump1eb44332009-09-09 15:08:12 +00003261
John McCalla2becad2009-10-21 00:40:46 +00003262 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3263 NewTL.setNameLoc(TL.getNameLoc());
3264
3265 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003266}
John McCall7da24312009-09-05 00:15:47 +00003267
John McCall3cb0ebd2010-03-10 03:28:59 +00003268template<typename Derived>
3269QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3270 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003271 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003272 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3273 TL.getTypePtr()->getDecl());
3274 if (!D) return QualType();
3275
3276 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3277 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3278 return T;
3279}
3280
Mike Stump1eb44332009-09-09 15:08:12 +00003281
Douglas Gregor577f75a2009-08-04 16:50:30 +00003282template<typename Derived>
3283QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003284 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003285 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003286 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003287}
3288
Mike Stump1eb44332009-09-09 15:08:12 +00003289template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003290QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003291 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003292 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003293 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003294}
3295
3296template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003297QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003298 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003299 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003300 const TemplateSpecializationType *T = TL.getTypePtr();
3301
Mike Stump1eb44332009-09-09 15:08:12 +00003302 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003303 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003304 if (Template.isNull())
3305 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003306
John McCall43fed0d2010-11-12 08:19:04 +00003307 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3308}
3309
3310template <typename Derived>
3311QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3312 TypeLocBuilder &TLB,
3313 TemplateSpecializationTypeLoc TL,
3314 TemplateName Template) {
3315 const TemplateSpecializationType *T = TL.getTypePtr();
3316
John McCalld5532b62009-11-23 01:53:49 +00003317 TemplateArgumentListInfo NewTemplateArgs;
3318 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3319 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3320
3321 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3322 TemplateArgumentLoc Loc;
3323 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003324 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003325 NewTemplateArgs.addArgument(Loc);
3326 }
Mike Stump1eb44332009-09-09 15:08:12 +00003327
John McCall833ca992009-10-29 08:12:44 +00003328 // FIXME: maybe don't rebuild if all the template arguments are the same.
3329
3330 QualType Result =
3331 getDerived().RebuildTemplateSpecializationType(Template,
3332 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003333 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003334
3335 if (!Result.isNull()) {
3336 TemplateSpecializationTypeLoc NewTL
3337 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3338 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3339 NewTL.setLAngleLoc(TL.getLAngleLoc());
3340 NewTL.setRAngleLoc(TL.getRAngleLoc());
3341 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3342 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003343 }
Mike Stump1eb44332009-09-09 15:08:12 +00003344
John McCall833ca992009-10-29 08:12:44 +00003345 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003346}
Mike Stump1eb44332009-09-09 15:08:12 +00003347
3348template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003349QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003350TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003351 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003352 ElaboratedType *T = TL.getTypePtr();
3353
3354 NestedNameSpecifier *NNS = 0;
3355 // NOTE: the qualifier in an ElaboratedType is optional.
3356 if (T->getQualifier() != 0) {
3357 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003358 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003359 if (!NNS)
3360 return QualType();
3361 }
Mike Stump1eb44332009-09-09 15:08:12 +00003362
John McCall43fed0d2010-11-12 08:19:04 +00003363 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3364 if (NamedT.isNull())
3365 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00003366
John McCalla2becad2009-10-21 00:40:46 +00003367 QualType Result = TL.getType();
3368 if (getDerived().AlwaysRebuild() ||
3369 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003370 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00003371 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3372 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003373 if (Result.isNull())
3374 return QualType();
3375 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003376
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003377 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003378 NewTL.setKeywordLoc(TL.getKeywordLoc());
3379 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003380
3381 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003382}
Mike Stump1eb44332009-09-09 15:08:12 +00003383
3384template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00003385QualType
3386TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3387 ParenTypeLoc TL) {
3388 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3389 if (Inner.isNull())
3390 return QualType();
3391
3392 QualType Result = TL.getType();
3393 if (getDerived().AlwaysRebuild() ||
3394 Inner != TL.getInnerLoc().getType()) {
3395 Result = getDerived().RebuildParenType(Inner);
3396 if (Result.isNull())
3397 return QualType();
3398 }
3399
3400 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3401 NewTL.setLParenLoc(TL.getLParenLoc());
3402 NewTL.setRParenLoc(TL.getRParenLoc());
3403 return Result;
3404}
3405
3406template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003407QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003408 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003409 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003410
Douglas Gregor577f75a2009-08-04 16:50:30 +00003411 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003412 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003413 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003414 if (!NNS)
3415 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003416
John McCall33500952010-06-11 00:33:02 +00003417 QualType Result
3418 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3419 T->getIdentifier(),
3420 TL.getKeywordLoc(),
3421 TL.getQualifierRange(),
3422 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003423 if (Result.isNull())
3424 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003425
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003426 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3427 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003428 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3429
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003430 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3431 NewTL.setKeywordLoc(TL.getKeywordLoc());
3432 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003433 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003434 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3435 NewTL.setKeywordLoc(TL.getKeywordLoc());
3436 NewTL.setQualifierRange(TL.getQualifierRange());
3437 NewTL.setNameLoc(TL.getNameLoc());
3438 }
John McCalla2becad2009-10-21 00:40:46 +00003439 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003440}
Mike Stump1eb44332009-09-09 15:08:12 +00003441
Douglas Gregor577f75a2009-08-04 16:50:30 +00003442template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003443QualType TreeTransform<Derived>::
3444 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003445 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00003446 DependentTemplateSpecializationType *T = TL.getTypePtr();
3447
3448 NestedNameSpecifier *NNS
3449 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003450 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003451 if (!NNS)
3452 return QualType();
3453
John McCall43fed0d2010-11-12 08:19:04 +00003454 return getDerived()
3455 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3456}
3457
3458template<typename Derived>
3459QualType TreeTransform<Derived>::
3460 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3461 DependentTemplateSpecializationTypeLoc TL,
3462 NestedNameSpecifier *NNS) {
3463 DependentTemplateSpecializationType *T = TL.getTypePtr();
3464
John McCall33500952010-06-11 00:33:02 +00003465 TemplateArgumentListInfo NewTemplateArgs;
3466 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3467 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3468
3469 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3470 TemplateArgumentLoc Loc;
3471 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3472 return QualType();
3473 NewTemplateArgs.addArgument(Loc);
3474 }
3475
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003476 QualType Result
3477 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3478 NNS,
3479 TL.getQualifierRange(),
3480 T->getIdentifier(),
3481 TL.getNameLoc(),
3482 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003483 if (Result.isNull())
3484 return QualType();
3485
3486 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3487 QualType NamedT = ElabT->getNamedType();
3488
3489 // Copy information relevant to the template specialization.
3490 TemplateSpecializationTypeLoc NamedTL
3491 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3492 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3493 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3494 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3495 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3496
3497 // Copy information relevant to the elaborated type.
3498 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3499 NewTL.setKeywordLoc(TL.getKeywordLoc());
3500 NewTL.setQualifierRange(TL.getQualifierRange());
3501 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003502 TypeLoc NewTL(Result, TL.getOpaqueData());
3503 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003504 }
3505 return Result;
3506}
3507
3508template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003509QualType
3510TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003511 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003512 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003513 TLB.pushFullCopy(TL);
3514 return TL.getType();
3515}
3516
3517template<typename Derived>
3518QualType
3519TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003520 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00003521 // ObjCObjectType is never dependent.
3522 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003523 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003524}
Mike Stump1eb44332009-09-09 15:08:12 +00003525
3526template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003527QualType
3528TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003529 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003530 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003531 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003532 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003533}
3534
Douglas Gregor577f75a2009-08-04 16:50:30 +00003535//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003536// Statement transformation
3537//===----------------------------------------------------------------------===//
3538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003539StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003540TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003541 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003542}
3543
3544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003545StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003546TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3547 return getDerived().TransformCompoundStmt(S, false);
3548}
3549
3550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003551StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003552TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003553 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003554 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003555 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003556 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003557 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3558 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003559 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003560 if (Result.isInvalid()) {
3561 // Immediately fail if this was a DeclStmt, since it's very
3562 // likely that this will cause problems for future statements.
3563 if (isa<DeclStmt>(*B))
3564 return StmtError();
3565
3566 // Otherwise, just keep processing substatements and fail later.
3567 SubStmtInvalid = true;
3568 continue;
3569 }
Mike Stump1eb44332009-09-09 15:08:12 +00003570
Douglas Gregor43959a92009-08-20 07:17:43 +00003571 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3572 Statements.push_back(Result.takeAs<Stmt>());
3573 }
Mike Stump1eb44332009-09-09 15:08:12 +00003574
John McCall7114cba2010-08-27 19:56:05 +00003575 if (SubStmtInvalid)
3576 return StmtError();
3577
Douglas Gregor43959a92009-08-20 07:17:43 +00003578 if (!getDerived().AlwaysRebuild() &&
3579 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003580 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003581
3582 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3583 move_arg(Statements),
3584 S->getRBracLoc(),
3585 IsStmtExpr);
3586}
Mike Stump1eb44332009-09-09 15:08:12 +00003587
Douglas Gregor43959a92009-08-20 07:17:43 +00003588template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003589StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003590TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003591 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003592 {
3593 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003594 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003595
Eli Friedman264c1f82009-11-19 03:14:00 +00003596 // Transform the left-hand case value.
3597 LHS = getDerived().TransformExpr(S->getLHS());
3598 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003599 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003600
Eli Friedman264c1f82009-11-19 03:14:00 +00003601 // Transform the right-hand case value (for the GNU case-range extension).
3602 RHS = getDerived().TransformExpr(S->getRHS());
3603 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003604 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003605 }
Mike Stump1eb44332009-09-09 15:08:12 +00003606
Douglas Gregor43959a92009-08-20 07:17:43 +00003607 // Build the case statement.
3608 // Case statements are always rebuilt so that they will attached to their
3609 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003610 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003611 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003612 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003613 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003614 S->getColonLoc());
3615 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003616 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003617
Douglas Gregor43959a92009-08-20 07:17:43 +00003618 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003619 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003620 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003621 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003622
Douglas Gregor43959a92009-08-20 07:17:43 +00003623 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003624 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003625}
3626
3627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003628StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003629TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003630 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003631 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003632 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003633 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003634
Douglas Gregor43959a92009-08-20 07:17:43 +00003635 // Default statements are always rebuilt
3636 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003637 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003638}
Mike Stump1eb44332009-09-09 15:08:12 +00003639
Douglas Gregor43959a92009-08-20 07:17:43 +00003640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003641StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003642TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003643 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003644 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003645 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003646
Douglas Gregor43959a92009-08-20 07:17:43 +00003647 // FIXME: Pass the real colon location in.
3648 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3649 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003650 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003651}
Mike Stump1eb44332009-09-09 15:08:12 +00003652
Douglas Gregor43959a92009-08-20 07:17:43 +00003653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003654StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003655TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003656 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003657 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003658 VarDecl *ConditionVar = 0;
3659 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003660 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003661 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003662 getDerived().TransformDefinition(
3663 S->getConditionVariable()->getLocation(),
3664 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003665 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003666 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003667 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003668 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003669
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003670 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003671 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003672
3673 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003674 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003675 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003676 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003677 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003678 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003679 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003680
John McCall9ae2f072010-08-23 23:25:46 +00003681 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003682 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003683 }
Sean Huntc3021132010-05-05 15:23:54 +00003684
John McCall9ae2f072010-08-23 23:25:46 +00003685 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3686 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003687 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003688
Douglas Gregor43959a92009-08-20 07:17:43 +00003689 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003690 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003691 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003692 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003693
Douglas Gregor43959a92009-08-20 07:17:43 +00003694 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003695 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003696 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003697 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003698
Douglas Gregor43959a92009-08-20 07:17:43 +00003699 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003700 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003701 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003702 Then.get() == S->getThen() &&
3703 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00003704 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003705
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003706 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00003707 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00003708 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003709}
3710
3711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003712StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003713TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003714 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003715 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003716 VarDecl *ConditionVar = 0;
3717 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003718 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003719 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003720 getDerived().TransformDefinition(
3721 S->getConditionVariable()->getLocation(),
3722 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003723 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003724 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003725 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003726 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003727
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003728 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003729 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003730 }
Mike Stump1eb44332009-09-09 15:08:12 +00003731
Douglas Gregor43959a92009-08-20 07:17:43 +00003732 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003733 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003734 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003735 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003736 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003737 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003738
Douglas Gregor43959a92009-08-20 07:17:43 +00003739 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003740 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003741 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003742 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003743
Douglas Gregor43959a92009-08-20 07:17:43 +00003744 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003745 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3746 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003747}
Mike Stump1eb44332009-09-09 15:08:12 +00003748
Douglas Gregor43959a92009-08-20 07:17:43 +00003749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003750StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003751TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003752 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003753 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003754 VarDecl *ConditionVar = 0;
3755 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003756 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003757 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003758 getDerived().TransformDefinition(
3759 S->getConditionVariable()->getLocation(),
3760 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003761 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003762 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003763 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003764 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003765
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003766 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003767 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003768
3769 if (S->getCond()) {
3770 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003771 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003772 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003773 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003774 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003775 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003776 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003777 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003778 }
Mike Stump1eb44332009-09-09 15:08:12 +00003779
John McCall9ae2f072010-08-23 23:25:46 +00003780 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3781 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003782 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003783
Douglas Gregor43959a92009-08-20 07:17:43 +00003784 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003785 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003786 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003787 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003788
Douglas Gregor43959a92009-08-20 07:17:43 +00003789 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003790 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003791 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003792 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003793 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003794
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003795 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003796 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003797}
Mike Stump1eb44332009-09-09 15:08:12 +00003798
Douglas Gregor43959a92009-08-20 07:17:43 +00003799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003800StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003801TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003802 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003803 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003804 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003805 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003806
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003807 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003808 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003809 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003810 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003811
Douglas Gregor43959a92009-08-20 07:17:43 +00003812 if (!getDerived().AlwaysRebuild() &&
3813 Cond.get() == S->getCond() &&
3814 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003815 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003816
John McCall9ae2f072010-08-23 23:25:46 +00003817 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3818 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003819 S->getRParenLoc());
3820}
Mike Stump1eb44332009-09-09 15:08:12 +00003821
Douglas Gregor43959a92009-08-20 07:17:43 +00003822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003823StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003824TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003825 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003826 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003827 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003828 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003829
Douglas Gregor43959a92009-08-20 07:17:43 +00003830 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003831 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003832 VarDecl *ConditionVar = 0;
3833 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003834 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003835 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003836 getDerived().TransformDefinition(
3837 S->getConditionVariable()->getLocation(),
3838 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003839 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003840 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003841 } else {
3842 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003843
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003844 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003845 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003846
3847 if (S->getCond()) {
3848 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003849 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003850 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003851 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003852 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003853 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003854
John McCall9ae2f072010-08-23 23:25:46 +00003855 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003856 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003857 }
Mike Stump1eb44332009-09-09 15:08:12 +00003858
John McCall9ae2f072010-08-23 23:25:46 +00003859 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3860 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003861 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003862
Douglas Gregor43959a92009-08-20 07:17:43 +00003863 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003864 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003865 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003866 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003867
John McCall9ae2f072010-08-23 23:25:46 +00003868 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3869 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003870 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003871
Douglas Gregor43959a92009-08-20 07:17:43 +00003872 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003873 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003874 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003875 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003876
Douglas Gregor43959a92009-08-20 07:17:43 +00003877 if (!getDerived().AlwaysRebuild() &&
3878 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003879 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003880 Inc.get() == S->getInc() &&
3881 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003882 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003883
Douglas Gregor43959a92009-08-20 07:17:43 +00003884 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003885 Init.get(), FullCond, ConditionVar,
3886 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003887}
3888
3889template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003890StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003891TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003892 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003893 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003894 S->getLabel());
3895}
3896
3897template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003898StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003899TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003900 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003901 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003902 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003903
Douglas Gregor43959a92009-08-20 07:17:43 +00003904 if (!getDerived().AlwaysRebuild() &&
3905 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00003906 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003907
3908 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003909 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003910}
3911
3912template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003913StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003914TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003915 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003916}
Mike Stump1eb44332009-09-09 15:08:12 +00003917
Douglas Gregor43959a92009-08-20 07:17:43 +00003918template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003919StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003920TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003921 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003922}
Mike Stump1eb44332009-09-09 15:08:12 +00003923
Douglas Gregor43959a92009-08-20 07:17:43 +00003924template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003925StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003926TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003927 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003928 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003929 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003930
Mike Stump1eb44332009-09-09 15:08:12 +00003931 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003932 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003933 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003934}
Mike Stump1eb44332009-09-09 15:08:12 +00003935
Douglas Gregor43959a92009-08-20 07:17:43 +00003936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003937StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003938TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003939 bool DeclChanged = false;
3940 llvm::SmallVector<Decl *, 4> Decls;
3941 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3942 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003943 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3944 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003945 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003946 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003947
Douglas Gregor43959a92009-08-20 07:17:43 +00003948 if (Transformed != *D)
3949 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003950
Douglas Gregor43959a92009-08-20 07:17:43 +00003951 Decls.push_back(Transformed);
3952 }
Mike Stump1eb44332009-09-09 15:08:12 +00003953
Douglas Gregor43959a92009-08-20 07:17:43 +00003954 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003955 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003956
3957 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003958 S->getStartLoc(), S->getEndLoc());
3959}
Mike Stump1eb44332009-09-09 15:08:12 +00003960
Douglas Gregor43959a92009-08-20 07:17:43 +00003961template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003962StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003963TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003964 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00003965 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003966}
3967
3968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003969StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003970TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003971
John McCallca0408f2010-08-23 06:44:23 +00003972 ASTOwningVector<Expr*> Constraints(getSema());
3973 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003974 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003975
John McCall60d7b3a2010-08-24 06:29:42 +00003976 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003977 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003978
3979 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003980
Anders Carlsson703e3942010-01-24 05:50:09 +00003981 // Go through the outputs.
3982 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003983 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003984
Anders Carlsson703e3942010-01-24 05:50:09 +00003985 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00003986 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00003987
Anders Carlsson703e3942010-01-24 05:50:09 +00003988 // Transform the output expr.
3989 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003990 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003991 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003992 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003993
Anders Carlsson703e3942010-01-24 05:50:09 +00003994 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003995
John McCall9ae2f072010-08-23 23:25:46 +00003996 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003997 }
Sean Huntc3021132010-05-05 15:23:54 +00003998
Anders Carlsson703e3942010-01-24 05:50:09 +00003999 // Go through the inputs.
4000 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004001 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004002
Anders Carlsson703e3942010-01-24 05:50:09 +00004003 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004004 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004005
Anders Carlsson703e3942010-01-24 05:50:09 +00004006 // Transform the input expr.
4007 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004008 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004009 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004010 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004011
Anders Carlsson703e3942010-01-24 05:50:09 +00004012 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004013
John McCall9ae2f072010-08-23 23:25:46 +00004014 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004015 }
Sean Huntc3021132010-05-05 15:23:54 +00004016
Anders Carlsson703e3942010-01-24 05:50:09 +00004017 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004018 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004019
4020 // Go through the clobbers.
4021 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004022 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004023
4024 // No need to transform the asm string literal.
4025 AsmString = SemaRef.Owned(S->getAsmString());
4026
4027 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4028 S->isSimple(),
4029 S->isVolatile(),
4030 S->getNumOutputs(),
4031 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004032 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004033 move_arg(Constraints),
4034 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004035 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004036 move_arg(Clobbers),
4037 S->getRParenLoc(),
4038 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004039}
4040
4041
4042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004043StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004044TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004045 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004046 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004047 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004048 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004049
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004050 // Transform the @catch statements (if present).
4051 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004052 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004053 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004054 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004055 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004056 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004057 if (Catch.get() != S->getCatchStmt(I))
4058 AnyCatchChanged = true;
4059 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004060 }
Sean Huntc3021132010-05-05 15:23:54 +00004061
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004062 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004063 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004064 if (S->getFinallyStmt()) {
4065 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4066 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004067 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004068 }
4069
4070 // If nothing changed, just retain this statement.
4071 if (!getDerived().AlwaysRebuild() &&
4072 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004073 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004074 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004075 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004076
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004077 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004078 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4079 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004080}
Mike Stump1eb44332009-09-09 15:08:12 +00004081
Douglas Gregor43959a92009-08-20 07:17:43 +00004082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004083StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004084TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004085 // Transform the @catch parameter, if there is one.
4086 VarDecl *Var = 0;
4087 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4088 TypeSourceInfo *TSInfo = 0;
4089 if (FromVar->getTypeSourceInfo()) {
4090 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4091 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004092 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004093 }
Sean Huntc3021132010-05-05 15:23:54 +00004094
Douglas Gregorbe270a02010-04-26 17:57:08 +00004095 QualType T;
4096 if (TSInfo)
4097 T = TSInfo->getType();
4098 else {
4099 T = getDerived().TransformType(FromVar->getType());
4100 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004101 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004102 }
Sean Huntc3021132010-05-05 15:23:54 +00004103
Douglas Gregorbe270a02010-04-26 17:57:08 +00004104 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4105 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004106 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004107 }
Sean Huntc3021132010-05-05 15:23:54 +00004108
John McCall60d7b3a2010-08-24 06:29:42 +00004109 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004110 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004111 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004112
4113 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004114 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004115 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004116}
Mike Stump1eb44332009-09-09 15:08:12 +00004117
Douglas Gregor43959a92009-08-20 07:17:43 +00004118template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004119StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004120TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004121 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004122 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004123 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004124 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004125
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004126 // If nothing changed, just retain this statement.
4127 if (!getDerived().AlwaysRebuild() &&
4128 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004129 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004130
4131 // Build a new statement.
4132 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004133 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004134}
Mike Stump1eb44332009-09-09 15:08:12 +00004135
Douglas Gregor43959a92009-08-20 07:17:43 +00004136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004137StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004138TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004139 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004140 if (S->getThrowExpr()) {
4141 Operand = getDerived().TransformExpr(S->getThrowExpr());
4142 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004143 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004144 }
Sean Huntc3021132010-05-05 15:23:54 +00004145
Douglas Gregord1377b22010-04-22 21:44:01 +00004146 if (!getDerived().AlwaysRebuild() &&
4147 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004148 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004149
John McCall9ae2f072010-08-23 23:25:46 +00004150 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004151}
Mike Stump1eb44332009-09-09 15:08:12 +00004152
Douglas Gregor43959a92009-08-20 07:17:43 +00004153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004154StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004155TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004156 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004157 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004158 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004159 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004160 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004161
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004162 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004163 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004164 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004165 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004166
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004167 // If nothing change, just retain the current statement.
4168 if (!getDerived().AlwaysRebuild() &&
4169 Object.get() == S->getSynchExpr() &&
4170 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004171 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004172
4173 // Build a new statement.
4174 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004175 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004176}
4177
4178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004179StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004180TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004181 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004182 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004183 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004184 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004185 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004186
Douglas Gregorc3203e72010-04-22 23:10:45 +00004187 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004188 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004189 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004190 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004191
Douglas Gregorc3203e72010-04-22 23:10:45 +00004192 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004193 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004194 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004195 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004196
Douglas Gregorc3203e72010-04-22 23:10:45 +00004197 // If nothing changed, just retain this statement.
4198 if (!getDerived().AlwaysRebuild() &&
4199 Element.get() == S->getElement() &&
4200 Collection.get() == S->getCollection() &&
4201 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004202 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004203
Douglas Gregorc3203e72010-04-22 23:10:45 +00004204 // Build a new statement.
4205 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4206 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004207 Element.get(),
4208 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004209 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004210 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004211}
4212
4213
4214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004215StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004216TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4217 // Transform the exception declaration, if any.
4218 VarDecl *Var = 0;
4219 if (S->getExceptionDecl()) {
4220 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004221 TypeSourceInfo *T = getDerived().TransformType(
4222 ExceptionDecl->getTypeSourceInfo());
4223 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004224 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregor83cb9422010-09-09 17:09:21 +00004226 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004227 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004228 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004229 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004230 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004231 }
Mike Stump1eb44332009-09-09 15:08:12 +00004232
Douglas Gregor43959a92009-08-20 07:17:43 +00004233 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004234 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004235 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004236 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004237
Douglas Gregor43959a92009-08-20 07:17:43 +00004238 if (!getDerived().AlwaysRebuild() &&
4239 !Var &&
4240 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004241 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004242
4243 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4244 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004245 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004246}
Mike Stump1eb44332009-09-09 15:08:12 +00004247
Douglas Gregor43959a92009-08-20 07:17:43 +00004248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004249StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004250TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4251 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004252 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004253 = getDerived().TransformCompoundStmt(S->getTryBlock());
4254 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004255 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004256
Douglas Gregor43959a92009-08-20 07:17:43 +00004257 // Transform the handlers.
4258 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004259 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004260 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004261 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004262 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4263 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004264 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004265
Douglas Gregor43959a92009-08-20 07:17:43 +00004266 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4267 Handlers.push_back(Handler.takeAs<Stmt>());
4268 }
Mike Stump1eb44332009-09-09 15:08:12 +00004269
Douglas Gregor43959a92009-08-20 07:17:43 +00004270 if (!getDerived().AlwaysRebuild() &&
4271 TryBlock.get() == S->getTryBlock() &&
4272 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004273 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004274
John McCall9ae2f072010-08-23 23:25:46 +00004275 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004276 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004277}
Mike Stump1eb44332009-09-09 15:08:12 +00004278
Douglas Gregor43959a92009-08-20 07:17:43 +00004279//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004280// Expression transformation
4281//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004283ExprResult
John McCall454feb92009-12-08 09:21:05 +00004284TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004285 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004286}
Mike Stump1eb44332009-09-09 15:08:12 +00004287
4288template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004289ExprResult
John McCall454feb92009-12-08 09:21:05 +00004290TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004291 NestedNameSpecifier *Qualifier = 0;
4292 if (E->getQualifier()) {
4293 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004294 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004295 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004296 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004297 }
John McCalldbd872f2009-12-08 09:08:17 +00004298
4299 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004300 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4301 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004302 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004303 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004304
John McCallec8045d2010-08-17 21:27:17 +00004305 DeclarationNameInfo NameInfo = E->getNameInfo();
4306 if (NameInfo.getName()) {
4307 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4308 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004309 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004310 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004311
4312 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004313 Qualifier == E->getQualifier() &&
4314 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004315 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004316 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004317
4318 // Mark it referenced in the new context regardless.
4319 // FIXME: this is a bit instantiation-specific.
4320 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4321
John McCall3fa5cae2010-10-26 07:05:15 +00004322 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00004323 }
John McCalldbd872f2009-12-08 09:08:17 +00004324
4325 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004326 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004327 TemplateArgs = &TransArgs;
4328 TransArgs.setLAngleLoc(E->getLAngleLoc());
4329 TransArgs.setRAngleLoc(E->getRAngleLoc());
4330 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4331 TemplateArgumentLoc Loc;
4332 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004333 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004334 TransArgs.addArgument(Loc);
4335 }
4336 }
4337
Douglas Gregora2813ce2009-10-23 18:54:35 +00004338 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004339 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004340}
Mike Stump1eb44332009-09-09 15:08:12 +00004341
Douglas Gregorb98b1992009-08-11 05:31:07 +00004342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004343ExprResult
John McCall454feb92009-12-08 09:21:05 +00004344TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004345 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004346}
Mike Stump1eb44332009-09-09 15:08:12 +00004347
Douglas Gregorb98b1992009-08-11 05:31:07 +00004348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004349ExprResult
John McCall454feb92009-12-08 09:21:05 +00004350TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004351 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004352}
Mike Stump1eb44332009-09-09 15:08:12 +00004353
Douglas Gregorb98b1992009-08-11 05:31:07 +00004354template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004355ExprResult
John McCall454feb92009-12-08 09:21:05 +00004356TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004357 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004358}
Mike Stump1eb44332009-09-09 15:08:12 +00004359
Douglas Gregorb98b1992009-08-11 05:31:07 +00004360template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004361ExprResult
John McCall454feb92009-12-08 09:21:05 +00004362TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004363 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004364}
Mike Stump1eb44332009-09-09 15:08:12 +00004365
Douglas Gregorb98b1992009-08-11 05:31:07 +00004366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004367ExprResult
John McCall454feb92009-12-08 09:21:05 +00004368TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004369 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004370}
4371
4372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004373ExprResult
John McCall454feb92009-12-08 09:21:05 +00004374TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004375 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004376 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004378
Douglas Gregorb98b1992009-08-11 05:31:07 +00004379 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004380 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004381
John McCall9ae2f072010-08-23 23:25:46 +00004382 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004383 E->getRParen());
4384}
4385
Mike Stump1eb44332009-09-09 15:08:12 +00004386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004387ExprResult
John McCall454feb92009-12-08 09:21:05 +00004388TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004389 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004390 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004392
Douglas Gregorb98b1992009-08-11 05:31:07 +00004393 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004394 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004395
Douglas Gregorb98b1992009-08-11 05:31:07 +00004396 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4397 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004398 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004399}
Mike Stump1eb44332009-09-09 15:08:12 +00004400
Douglas Gregorb98b1992009-08-11 05:31:07 +00004401template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004402ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004403TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4404 // Transform the type.
4405 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4406 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004407 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004408
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004409 // Transform all of the components into components similar to what the
4410 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004411 // FIXME: It would be slightly more efficient in the non-dependent case to
4412 // just map FieldDecls, rather than requiring the rebuilder to look for
4413 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004414 // template code that we don't care.
4415 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004416 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004417 typedef OffsetOfExpr::OffsetOfNode Node;
4418 llvm::SmallVector<Component, 4> Components;
4419 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4420 const Node &ON = E->getComponent(I);
4421 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004422 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004423 Comp.LocStart = ON.getRange().getBegin();
4424 Comp.LocEnd = ON.getRange().getEnd();
4425 switch (ON.getKind()) {
4426 case Node::Array: {
4427 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004428 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004429 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004430 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004431
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004432 ExprChanged = ExprChanged || Index.get() != FromIndex;
4433 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004434 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004435 break;
4436 }
Sean Huntc3021132010-05-05 15:23:54 +00004437
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004438 case Node::Field:
4439 case Node::Identifier:
4440 Comp.isBrackets = false;
4441 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004442 if (!Comp.U.IdentInfo)
4443 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004444
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004445 break;
Sean Huntc3021132010-05-05 15:23:54 +00004446
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004447 case Node::Base:
4448 // Will be recomputed during the rebuild.
4449 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004450 }
Sean Huntc3021132010-05-05 15:23:54 +00004451
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004452 Components.push_back(Comp);
4453 }
Sean Huntc3021132010-05-05 15:23:54 +00004454
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004455 // If nothing changed, retain the existing expression.
4456 if (!getDerived().AlwaysRebuild() &&
4457 Type == E->getTypeSourceInfo() &&
4458 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004459 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00004460
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004461 // Build a new offsetof expression.
4462 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4463 Components.data(), Components.size(),
4464 E->getRParenLoc());
4465}
4466
4467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004468ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00004469TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4470 assert(getDerived().AlreadyTransformed(E->getType()) &&
4471 "opaque value expression requires transformation");
4472 return SemaRef.Owned(E);
4473}
4474
4475template<typename Derived>
4476ExprResult
John McCall454feb92009-12-08 09:21:05 +00004477TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004478 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004479 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004480
John McCalla93c9342009-12-07 02:54:59 +00004481 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004482 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004484
John McCall5ab75172009-11-04 07:28:41 +00004485 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00004486 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004487
John McCall5ab75172009-11-04 07:28:41 +00004488 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004489 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004490 E->getSourceRange());
4491 }
Mike Stump1eb44332009-09-09 15:08:12 +00004492
John McCall60d7b3a2010-08-24 06:29:42 +00004493 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004494 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004495 // C++0x [expr.sizeof]p1:
4496 // The operand is either an expression, which is an unevaluated operand
4497 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004498 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004499
Douglas Gregorb98b1992009-08-11 05:31:07 +00004500 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4501 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004503
Douglas Gregorb98b1992009-08-11 05:31:07 +00004504 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004505 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004506 }
Mike Stump1eb44332009-09-09 15:08:12 +00004507
John McCall9ae2f072010-08-23 23:25:46 +00004508 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 E->isSizeOf(),
4510 E->getSourceRange());
4511}
Mike Stump1eb44332009-09-09 15:08:12 +00004512
Douglas Gregorb98b1992009-08-11 05:31:07 +00004513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004514ExprResult
John McCall454feb92009-12-08 09:21:05 +00004515TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004516 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004517 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004518 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004519
John McCall60d7b3a2010-08-24 06:29:42 +00004520 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004523
4524
Douglas Gregorb98b1992009-08-11 05:31:07 +00004525 if (!getDerived().AlwaysRebuild() &&
4526 LHS.get() == E->getLHS() &&
4527 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004528 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004529
John McCall9ae2f072010-08-23 23:25:46 +00004530 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004531 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004532 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004533 E->getRBracketLoc());
4534}
Mike Stump1eb44332009-09-09 15:08:12 +00004535
4536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004537ExprResult
John McCall454feb92009-12-08 09:21:05 +00004538TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004539 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004540 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004541 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004542 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004543
4544 // Transform arguments.
4545 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004546 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004547 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004548 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004549 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004551
Mike Stump1eb44332009-09-09 15:08:12 +00004552 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004553 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004554 }
Mike Stump1eb44332009-09-09 15:08:12 +00004555
Douglas Gregorb98b1992009-08-11 05:31:07 +00004556 if (!getDerived().AlwaysRebuild() &&
4557 Callee.get() == E->getCallee() &&
4558 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004559 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004560
Douglas Gregorb98b1992009-08-11 05:31:07 +00004561 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004562 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004563 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004564 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004565 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566 E->getRParenLoc());
4567}
Mike Stump1eb44332009-09-09 15:08:12 +00004568
4569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004570ExprResult
John McCall454feb92009-12-08 09:21:05 +00004571TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004572 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004573 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004574 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004575
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004576 NestedNameSpecifier *Qualifier = 0;
4577 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004578 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004579 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004580 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004581 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004582 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004583 }
Mike Stump1eb44332009-09-09 15:08:12 +00004584
Eli Friedmanf595cc42009-12-04 06:40:45 +00004585 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004586 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4587 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004588 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004589 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004590
John McCall6bb80172010-03-30 21:47:33 +00004591 NamedDecl *FoundDecl = E->getFoundDecl();
4592 if (FoundDecl == E->getMemberDecl()) {
4593 FoundDecl = Member;
4594 } else {
4595 FoundDecl = cast_or_null<NamedDecl>(
4596 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4597 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004598 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004599 }
4600
Douglas Gregorb98b1992009-08-11 05:31:07 +00004601 if (!getDerived().AlwaysRebuild() &&
4602 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004603 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004604 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004605 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004606 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004607
Anders Carlsson1f240322009-12-22 05:24:09 +00004608 // Mark it referenced in the new context regardless.
4609 // FIXME: this is a bit instantiation-specific.
4610 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00004611 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00004612 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004613
John McCalld5532b62009-11-23 01:53:49 +00004614 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004615 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004616 TransArgs.setLAngleLoc(E->getLAngleLoc());
4617 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004618 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004619 TemplateArgumentLoc Loc;
4620 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004621 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004622 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004623 }
4624 }
Sean Huntc3021132010-05-05 15:23:54 +00004625
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626 // FIXME: Bogus source location for the operator
4627 SourceLocation FakeOperatorLoc
4628 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4629
John McCallc2233c52010-01-15 08:34:02 +00004630 // FIXME: to do this check properly, we will need to preserve the
4631 // first-qualifier-in-scope here, just in case we had a dependent
4632 // base (and therefore couldn't do the check) and a
4633 // nested-name-qualifier (and therefore could do the lookup).
4634 NamedDecl *FirstQualifierInScope = 0;
4635
John McCall9ae2f072010-08-23 23:25:46 +00004636 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004637 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004638 Qualifier,
4639 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004640 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004641 Member,
John McCall6bb80172010-03-30 21:47:33 +00004642 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004643 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004644 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004645 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004646}
Mike Stump1eb44332009-09-09 15:08:12 +00004647
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004649ExprResult
John McCall454feb92009-12-08 09:21:05 +00004650TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
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 LHS.get() == E->getLHS() &&
4661 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004662 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004663
Douglas Gregorb98b1992009-08-11 05:31:07 +00004664 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004665 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004666}
4667
Mike Stump1eb44332009-09-09 15:08:12 +00004668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004669ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004670TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004671 CompoundAssignOperator *E) {
4672 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004673}
Mike Stump1eb44332009-09-09 15:08:12 +00004674
Douglas Gregorb98b1992009-08-11 05:31:07 +00004675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004676ExprResult
John McCall454feb92009-12-08 09:21:05 +00004677TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004678 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004679 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004680 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004681
John McCall60d7b3a2010-08-24 06:29:42 +00004682 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004683 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004685
John McCall60d7b3a2010-08-24 06:29:42 +00004686 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004687 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004688 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004689
Douglas Gregorb98b1992009-08-11 05:31:07 +00004690 if (!getDerived().AlwaysRebuild() &&
4691 Cond.get() == E->getCond() &&
4692 LHS.get() == E->getLHS() &&
4693 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004694 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004695
John McCall9ae2f072010-08-23 23:25:46 +00004696 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004697 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004698 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004699 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004700 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004701}
Mike Stump1eb44332009-09-09 15:08:12 +00004702
4703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004704ExprResult
John McCall454feb92009-12-08 09:21:05 +00004705TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004706 // Implicit casts are eliminated during transformation, since they
4707 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004708 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004709}
Mike Stump1eb44332009-09-09 15:08:12 +00004710
Douglas Gregorb98b1992009-08-11 05:31:07 +00004711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004712ExprResult
John McCall454feb92009-12-08 09:21:05 +00004713TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004714 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4715 if (!Type)
4716 return ExprError();
4717
John McCall60d7b3a2010-08-24 06:29:42 +00004718 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004719 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004720 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004721 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004722
Douglas Gregorb98b1992009-08-11 05:31:07 +00004723 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004724 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004725 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004726 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004727
John McCall9d125032010-01-15 18:39:57 +00004728 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004729 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004730 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004731 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004732}
Mike Stump1eb44332009-09-09 15:08:12 +00004733
Douglas Gregorb98b1992009-08-11 05:31:07 +00004734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004735ExprResult
John McCall454feb92009-12-08 09:21:05 +00004736TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004737 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4738 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4739 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004740 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004741
John McCall60d7b3a2010-08-24 06:29:42 +00004742 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004743 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004744 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004745
Douglas Gregorb98b1992009-08-11 05:31:07 +00004746 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004747 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004748 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00004749 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004750
John McCall1d7d8d62010-01-19 22:33:45 +00004751 // Note: the expression type doesn't necessarily match the
4752 // type-as-written, but that's okay, because it should always be
4753 // derivable from the initializer.
4754
John McCall42f56b52010-01-18 19:35:47 +00004755 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004756 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004757 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004758}
Mike Stump1eb44332009-09-09 15:08:12 +00004759
Douglas Gregorb98b1992009-08-11 05:31:07 +00004760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004761ExprResult
John McCall454feb92009-12-08 09:21:05 +00004762TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004763 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004764 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004765 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004766
Douglas Gregorb98b1992009-08-11 05:31:07 +00004767 if (!getDerived().AlwaysRebuild() &&
4768 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00004769 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004770
Douglas Gregorb98b1992009-08-11 05:31:07 +00004771 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004772 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004774 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004775 E->getAccessorLoc(),
4776 E->getAccessor());
4777}
Mike Stump1eb44332009-09-09 15:08:12 +00004778
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004780ExprResult
John McCall454feb92009-12-08 09:21:05 +00004781TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004782 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004783
John McCallca0408f2010-08-23 06:44:23 +00004784 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004785 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004786 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004789
Douglas Gregorb98b1992009-08-11 05:31:07 +00004790 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004791 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004792 }
Mike Stump1eb44332009-09-09 15:08:12 +00004793
Douglas Gregorb98b1992009-08-11 05:31:07 +00004794 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004795 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004796
Douglas Gregorb98b1992009-08-11 05:31:07 +00004797 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004798 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004799}
Mike Stump1eb44332009-09-09 15:08:12 +00004800
Douglas Gregorb98b1992009-08-11 05:31:07 +00004801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004802ExprResult
John McCall454feb92009-12-08 09:21:05 +00004803TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004804 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004805
Douglas Gregor43959a92009-08-20 07:17:43 +00004806 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004807 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004808 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004809 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004810
Douglas Gregor43959a92009-08-20 07:17:43 +00004811 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004812 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004813 bool ExprChanged = false;
4814 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4815 DEnd = E->designators_end();
4816 D != DEnd; ++D) {
4817 if (D->isFieldDesignator()) {
4818 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4819 D->getDotLoc(),
4820 D->getFieldLoc()));
4821 continue;
4822 }
Mike Stump1eb44332009-09-09 15:08:12 +00004823
Douglas Gregorb98b1992009-08-11 05:31:07 +00004824 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004825 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004826 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004828
4829 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004830 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004831
Douglas Gregorb98b1992009-08-11 05:31:07 +00004832 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4833 ArrayExprs.push_back(Index.release());
4834 continue;
4835 }
Mike Stump1eb44332009-09-09 15:08:12 +00004836
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004838 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004839 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4840 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004842
John McCall60d7b3a2010-08-24 06:29:42 +00004843 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004844 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004845 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004846
4847 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004848 End.get(),
4849 D->getLBracketLoc(),
4850 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004851
Douglas Gregorb98b1992009-08-11 05:31:07 +00004852 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4853 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004854
Douglas Gregorb98b1992009-08-11 05:31:07 +00004855 ArrayExprs.push_back(Start.release());
4856 ArrayExprs.push_back(End.release());
4857 }
Mike Stump1eb44332009-09-09 15:08:12 +00004858
Douglas Gregorb98b1992009-08-11 05:31:07 +00004859 if (!getDerived().AlwaysRebuild() &&
4860 Init.get() == E->getInit() &&
4861 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004862 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregorb98b1992009-08-11 05:31:07 +00004864 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4865 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004866 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004867}
Mike Stump1eb44332009-09-09 15:08:12 +00004868
Douglas Gregorb98b1992009-08-11 05:31:07 +00004869template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004870ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004871TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004872 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004873 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004874
Douglas Gregor5557b252009-10-28 00:29:27 +00004875 // FIXME: Will we ever have proper type location here? Will we actually
4876 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004877 QualType T = getDerived().TransformType(E->getType());
4878 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004880
Douglas Gregorb98b1992009-08-11 05:31:07 +00004881 if (!getDerived().AlwaysRebuild() &&
4882 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00004883 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004884
Douglas Gregorb98b1992009-08-11 05:31:07 +00004885 return getDerived().RebuildImplicitValueInitExpr(T);
4886}
Mike Stump1eb44332009-09-09 15:08:12 +00004887
Douglas Gregorb98b1992009-08-11 05:31:07 +00004888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004889ExprResult
John McCall454feb92009-12-08 09:21:05 +00004890TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004891 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4892 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004893 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004894
John McCall60d7b3a2010-08-24 06:29:42 +00004895 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004897 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004898
Douglas Gregorb98b1992009-08-11 05:31:07 +00004899 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004900 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004901 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004902 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004903
John McCall9ae2f072010-08-23 23:25:46 +00004904 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004905 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004906}
4907
4908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004909ExprResult
John McCall454feb92009-12-08 09:21:05 +00004910TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004911 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004912 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004913 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004914 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004915 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004916 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004917
Douglas Gregorb98b1992009-08-11 05:31:07 +00004918 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004919 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004920 }
Mike Stump1eb44332009-09-09 15:08:12 +00004921
Douglas Gregorb98b1992009-08-11 05:31:07 +00004922 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4923 move_arg(Inits),
4924 E->getRParenLoc());
4925}
Mike Stump1eb44332009-09-09 15:08:12 +00004926
Douglas Gregorb98b1992009-08-11 05:31:07 +00004927/// \brief Transform an address-of-label expression.
4928///
4929/// By default, the transformation of an address-of-label expression always
4930/// rebuilds the expression, so that the label identifier can be resolved to
4931/// the corresponding label statement by semantic analysis.
4932template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004933ExprResult
John McCall454feb92009-12-08 09:21:05 +00004934TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004935 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4936 E->getLabel());
4937}
Mike Stump1eb44332009-09-09 15:08:12 +00004938
4939template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004940ExprResult
John McCall454feb92009-12-08 09:21:05 +00004941TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004942 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004943 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4944 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004945 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004946
Douglas Gregorb98b1992009-08-11 05:31:07 +00004947 if (!getDerived().AlwaysRebuild() &&
4948 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004949 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004950
4951 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004952 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004953 E->getRParenLoc());
4954}
Mike Stump1eb44332009-09-09 15:08:12 +00004955
Douglas Gregorb98b1992009-08-11 05:31:07 +00004956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004957ExprResult
John McCall454feb92009-12-08 09:21:05 +00004958TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004959 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004960 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004961 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004962
John McCall60d7b3a2010-08-24 06:29:42 +00004963 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004964 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004965 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004966
John McCall60d7b3a2010-08-24 06:29:42 +00004967 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004968 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004969 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004970
Douglas Gregorb98b1992009-08-11 05:31:07 +00004971 if (!getDerived().AlwaysRebuild() &&
4972 Cond.get() == E->getCond() &&
4973 LHS.get() == E->getLHS() &&
4974 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004975 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004976
Douglas Gregorb98b1992009-08-11 05:31:07 +00004977 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004978 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004979 E->getRParenLoc());
4980}
Mike Stump1eb44332009-09-09 15:08:12 +00004981
Douglas Gregorb98b1992009-08-11 05:31:07 +00004982template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004983ExprResult
John McCall454feb92009-12-08 09:21:05 +00004984TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004985 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004986}
4987
4988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004989ExprResult
John McCall454feb92009-12-08 09:21:05 +00004990TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004991 switch (E->getOperator()) {
4992 case OO_New:
4993 case OO_Delete:
4994 case OO_Array_New:
4995 case OO_Array_Delete:
4996 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004997 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004998
Douglas Gregor668d6d92009-12-13 20:44:55 +00004999 case OO_Call: {
5000 // This is a call to an object's operator().
5001 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5002
5003 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005004 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005005 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005006 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005007
5008 // FIXME: Poor location information
5009 SourceLocation FakeLParenLoc
5010 = SemaRef.PP.getLocForEndOfToken(
5011 static_cast<Expr *>(Object.get())->getLocEnd());
5012
5013 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005014 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00005015 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005016 if (getDerived().DropCallArgument(E->getArg(I)))
5017 break;
Sean Huntc3021132010-05-05 15:23:54 +00005018
John McCall60d7b3a2010-08-24 06:29:42 +00005019 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005020 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005021 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005022
Douglas Gregor668d6d92009-12-13 20:44:55 +00005023 Args.push_back(Arg.release());
5024 }
5025
John McCall9ae2f072010-08-23 23:25:46 +00005026 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005027 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005028 E->getLocEnd());
5029 }
5030
5031#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5032 case OO_##Name:
5033#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5034#include "clang/Basic/OperatorKinds.def"
5035 case OO_Subscript:
5036 // Handled below.
5037 break;
5038
5039 case OO_Conditional:
5040 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005041 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005042
5043 case OO_None:
5044 case NUM_OVERLOADED_OPERATORS:
5045 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005046 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005047 }
5048
John McCall60d7b3a2010-08-24 06:29:42 +00005049 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005050 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005051 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005052
John McCall60d7b3a2010-08-24 06:29:42 +00005053 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005054 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005055 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056
John McCall60d7b3a2010-08-24 06:29:42 +00005057 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005058 if (E->getNumArgs() == 2) {
5059 Second = getDerived().TransformExpr(E->getArg(1));
5060 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005061 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005062 }
Mike Stump1eb44332009-09-09 15:08:12 +00005063
Douglas Gregorb98b1992009-08-11 05:31:07 +00005064 if (!getDerived().AlwaysRebuild() &&
5065 Callee.get() == E->getCallee() &&
5066 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005067 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005068 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005069
Douglas Gregorb98b1992009-08-11 05:31:07 +00005070 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5071 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005072 Callee.get(),
5073 First.get(),
5074 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005075}
Mike Stump1eb44332009-09-09 15:08:12 +00005076
Douglas Gregorb98b1992009-08-11 05:31:07 +00005077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005078ExprResult
John McCall454feb92009-12-08 09:21:05 +00005079TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5080 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005081}
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Douglas Gregorb98b1992009-08-11 05:31:07 +00005083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005084ExprResult
John McCall454feb92009-12-08 09:21:05 +00005085TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005086 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5087 if (!Type)
5088 return ExprError();
5089
John McCall60d7b3a2010-08-24 06:29:42 +00005090 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005091 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005093 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005094
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005096 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005098 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Douglas Gregorb98b1992009-08-11 05:31:07 +00005100 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005101 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005102 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5103 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5104 SourceLocation FakeRParenLoc
5105 = SemaRef.PP.getLocForEndOfToken(
5106 E->getSubExpr()->getSourceRange().getEnd());
5107 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005108 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005109 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005110 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111 FakeRAngleLoc,
5112 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005113 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005114 FakeRParenLoc);
5115}
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregorb98b1992009-08-11 05:31:07 +00005117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005118ExprResult
John McCall454feb92009-12-08 09:21:05 +00005119TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5120 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005121}
Mike Stump1eb44332009-09-09 15:08:12 +00005122
5123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005124ExprResult
John McCall454feb92009-12-08 09:21:05 +00005125TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5126 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005127}
5128
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005130ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005131TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005132 CXXReinterpretCastExpr *E) {
5133 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005134}
Mike Stump1eb44332009-09-09 15:08:12 +00005135
Douglas Gregorb98b1992009-08-11 05:31:07 +00005136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005137ExprResult
John McCall454feb92009-12-08 09:21:05 +00005138TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5139 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005140}
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Douglas Gregorb98b1992009-08-11 05:31:07 +00005142template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005143ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005144TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005145 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005146 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5147 if (!Type)
5148 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005149
John McCall60d7b3a2010-08-24 06:29:42 +00005150 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005151 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005152 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005153 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005154
Douglas Gregorb98b1992009-08-11 05:31:07 +00005155 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005156 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005157 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005158 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005159
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005160 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005161 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005162 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005163 E->getRParenLoc());
5164}
Mike Stump1eb44332009-09-09 15:08:12 +00005165
Douglas Gregorb98b1992009-08-11 05:31:07 +00005166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005167ExprResult
John McCall454feb92009-12-08 09:21:05 +00005168TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005169 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005170 TypeSourceInfo *TInfo
5171 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5172 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005174
Douglas Gregorb98b1992009-08-11 05:31:07 +00005175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005176 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005177 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005179 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5180 E->getLocStart(),
5181 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005182 E->getLocEnd());
5183 }
Mike Stump1eb44332009-09-09 15:08:12 +00005184
Douglas Gregorb98b1992009-08-11 05:31:07 +00005185 // We don't know whether the expression is potentially evaluated until
5186 // after we perform semantic analysis, so the expression is potentially
5187 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005188 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005189 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005190
John McCall60d7b3a2010-08-24 06:29:42 +00005191 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005192 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005193 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregorb98b1992009-08-11 05:31:07 +00005195 if (!getDerived().AlwaysRebuild() &&
5196 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005197 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005198
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005199 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5200 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005201 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005202 E->getLocEnd());
5203}
5204
5205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005206ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005207TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5208 if (E->isTypeOperand()) {
5209 TypeSourceInfo *TInfo
5210 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5211 if (!TInfo)
5212 return ExprError();
5213
5214 if (!getDerived().AlwaysRebuild() &&
5215 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005216 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005217
5218 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5219 E->getLocStart(),
5220 TInfo,
5221 E->getLocEnd());
5222 }
5223
5224 // We don't know whether the expression is potentially evaluated until
5225 // after we perform semantic analysis, so the expression is potentially
5226 // potentially evaluated.
5227 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5228
5229 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5230 if (SubExpr.isInvalid())
5231 return ExprError();
5232
5233 if (!getDerived().AlwaysRebuild() &&
5234 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005235 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005236
5237 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5238 E->getLocStart(),
5239 SubExpr.get(),
5240 E->getLocEnd());
5241}
5242
5243template<typename Derived>
5244ExprResult
John McCall454feb92009-12-08 09:21:05 +00005245TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *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
Douglas Gregorb98b1992009-08-11 05:31:07 +00005251TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005252 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005253 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005254}
Mike Stump1eb44332009-09-09 15:08:12 +00005255
Douglas Gregorb98b1992009-08-11 05:31:07 +00005256template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005257ExprResult
John McCall454feb92009-12-08 09:21:05 +00005258TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005259 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5260 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5261 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005262
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005263 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005264 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor828a1972010-01-07 23:12:05 +00005266 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005267}
Mike Stump1eb44332009-09-09 15:08:12 +00005268
Douglas Gregorb98b1992009-08-11 05:31:07 +00005269template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005270ExprResult
John McCall454feb92009-12-08 09:21:05 +00005271TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005272 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005273 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005274 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregorb98b1992009-08-11 05:31:07 +00005276 if (!getDerived().AlwaysRebuild() &&
5277 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005278 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005279
John McCall9ae2f072010-08-23 23:25:46 +00005280 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005281}
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregorb98b1992009-08-11 05:31:07 +00005283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005284ExprResult
John McCall454feb92009-12-08 09:21:05 +00005285TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005286 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005287 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5288 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005289 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005290 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005292 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005293 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005294 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Douglas Gregor036aed12009-12-23 23:03:06 +00005296 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005297}
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregorb98b1992009-08-11 05:31:07 +00005299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005300ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005301TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5302 CXXScalarValueInitExpr *E) {
5303 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5304 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005305 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005306
Douglas Gregorb98b1992009-08-11 05:31:07 +00005307 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005308 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005309 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregorab6677e2010-09-08 00:15:04 +00005311 return getDerived().RebuildCXXScalarValueInitExpr(T,
5312 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005313 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005314}
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregorb98b1992009-08-11 05:31:07 +00005316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005317ExprResult
John McCall454feb92009-12-08 09:21:05 +00005318TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005319 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005320 TypeSourceInfo *AllocTypeInfo
5321 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5322 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005323 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005324
Douglas Gregorb98b1992009-08-11 05:31:07 +00005325 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005326 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005327 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005328 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005329
Douglas Gregorb98b1992009-08-11 05:31:07 +00005330 // Transform the placement arguments (if any).
5331 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005332 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005333 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005334 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5335 ArgumentChanged = true;
5336 break;
5337 }
5338
John McCall60d7b3a2010-08-24 06:29:42 +00005339 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005340 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005342
Douglas Gregorb98b1992009-08-11 05:31:07 +00005343 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5344 PlacementArgs.push_back(Arg.take());
5345 }
Mike Stump1eb44332009-09-09 15:08:12 +00005346
Douglas Gregor43959a92009-08-20 07:17:43 +00005347 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005348 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005349 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005350 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5351 ArgumentChanged = true;
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005352 break;
John McCall63d5fb32010-10-05 22:36:42 +00005353 }
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005354
John McCall60d7b3a2010-08-24 06:29:42 +00005355 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005356 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005358
Douglas Gregorb98b1992009-08-11 05:31:07 +00005359 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5360 ConstructorArgs.push_back(Arg.take());
5361 }
Mike Stump1eb44332009-09-09 15:08:12 +00005362
Douglas Gregor1af74512010-02-26 00:38:10 +00005363 // Transform constructor, new operator, and delete operator.
5364 CXXConstructorDecl *Constructor = 0;
5365 if (E->getConstructor()) {
5366 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005367 getDerived().TransformDecl(E->getLocStart(),
5368 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005369 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005370 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005371 }
5372
5373 FunctionDecl *OperatorNew = 0;
5374 if (E->getOperatorNew()) {
5375 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005376 getDerived().TransformDecl(E->getLocStart(),
5377 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005378 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005379 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005380 }
5381
5382 FunctionDecl *OperatorDelete = 0;
5383 if (E->getOperatorDelete()) {
5384 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005385 getDerived().TransformDecl(E->getLocStart(),
5386 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005387 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005388 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005389 }
Sean Huntc3021132010-05-05 15:23:54 +00005390
Douglas Gregorb98b1992009-08-11 05:31:07 +00005391 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005392 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005393 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005394 Constructor == E->getConstructor() &&
5395 OperatorNew == E->getOperatorNew() &&
5396 OperatorDelete == E->getOperatorDelete() &&
5397 !ArgumentChanged) {
5398 // Mark any declarations we need as referenced.
5399 // FIXME: instantiation-specific.
5400 if (Constructor)
5401 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5402 if (OperatorNew)
5403 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5404 if (OperatorDelete)
5405 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00005406 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005407 }
Mike Stump1eb44332009-09-09 15:08:12 +00005408
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005409 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005410 if (!ArraySize.get()) {
5411 // If no array size was specified, but the new expression was
5412 // instantiated with an array type (e.g., "new T" where T is
5413 // instantiated with "int[4]"), extract the outer bound from the
5414 // array type as our array size. We do this with constant and
5415 // dependently-sized array types.
5416 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5417 if (!ArrayT) {
5418 // Do nothing
5419 } else if (const ConstantArrayType *ConsArrayT
5420 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005421 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005422 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5423 ConsArrayT->getSize(),
5424 SemaRef.Context.getSizeType(),
5425 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005426 AllocType = ConsArrayT->getElementType();
5427 } else if (const DependentSizedArrayType *DepArrayT
5428 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5429 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00005430 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005431 AllocType = DepArrayT->getElementType();
5432 }
5433 }
5434 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005435
Douglas Gregorb98b1992009-08-11 05:31:07 +00005436 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5437 E->isGlobalNew(),
5438 /*FIXME:*/E->getLocStart(),
5439 move_arg(PlacementArgs),
5440 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005441 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005442 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005443 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005444 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005445 /*FIXME:*/E->getLocStart(),
5446 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005447 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005448}
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregorb98b1992009-08-11 05:31:07 +00005450template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005451ExprResult
John McCall454feb92009-12-08 09:21:05 +00005452TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005453 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005454 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005455 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005456
Douglas Gregor1af74512010-02-26 00:38:10 +00005457 // Transform the delete operator, if known.
5458 FunctionDecl *OperatorDelete = 0;
5459 if (E->getOperatorDelete()) {
5460 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005461 getDerived().TransformDecl(E->getLocStart(),
5462 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005463 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005464 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005465 }
Sean Huntc3021132010-05-05 15:23:54 +00005466
Douglas Gregorb98b1992009-08-11 05:31:07 +00005467 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005468 Operand.get() == E->getArgument() &&
5469 OperatorDelete == E->getOperatorDelete()) {
5470 // Mark any declarations we need as referenced.
5471 // FIXME: instantiation-specific.
5472 if (OperatorDelete)
5473 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005474
5475 if (!E->getArgument()->isTypeDependent()) {
5476 QualType Destroyed = SemaRef.Context.getBaseElementType(
5477 E->getDestroyedType());
5478 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5479 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5480 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5481 SemaRef.LookupDestructor(Record));
5482 }
5483 }
5484
John McCall3fa5cae2010-10-26 07:05:15 +00005485 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005486 }
Mike Stump1eb44332009-09-09 15:08:12 +00005487
Douglas Gregorb98b1992009-08-11 05:31:07 +00005488 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5489 E->isGlobalDelete(),
5490 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005491 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005492}
Mike Stump1eb44332009-09-09 15:08:12 +00005493
Douglas Gregorb98b1992009-08-11 05:31:07 +00005494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005495ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005496TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005497 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005498 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005499 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005500 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005501
John McCallb3d87482010-08-24 05:47:05 +00005502 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005503 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005504 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005505 E->getOperatorLoc(),
5506 E->isArrow()? tok::arrow : tok::period,
5507 ObjectTypePtr,
5508 MayBePseudoDestructor);
5509 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005510 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005511
John McCallb3d87482010-08-24 05:47:05 +00005512 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00005513 NestedNameSpecifier *Qualifier = E->getQualifier();
5514 if (Qualifier) {
5515 Qualifier
5516 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5517 E->getQualifierRange(),
5518 ObjectType);
5519 if (!Qualifier)
5520 return ExprError();
5521 }
Mike Stump1eb44332009-09-09 15:08:12 +00005522
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005523 PseudoDestructorTypeStorage Destroyed;
5524 if (E->getDestroyedTypeInfo()) {
5525 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00005526 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5527 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005528 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005529 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005530 Destroyed = DestroyedTypeInfo;
5531 } else if (ObjectType->isDependentType()) {
5532 // We aren't likely to be able to resolve the identifier down to a type
5533 // now anyway, so just retain the identifier.
5534 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5535 E->getDestroyedTypeLoc());
5536 } else {
5537 // Look for a destructor known with the given name.
5538 CXXScopeSpec SS;
5539 if (Qualifier) {
5540 SS.setScopeRep(Qualifier);
5541 SS.setRange(E->getQualifierRange());
5542 }
Sean Huntc3021132010-05-05 15:23:54 +00005543
John McCallb3d87482010-08-24 05:47:05 +00005544 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005545 *E->getDestroyedTypeIdentifier(),
5546 E->getDestroyedTypeLoc(),
5547 /*Scope=*/0,
5548 SS, ObjectTypePtr,
5549 false);
5550 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005551 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005552
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005553 Destroyed
5554 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5555 E->getDestroyedTypeLoc());
5556 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005557
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005558 TypeSourceInfo *ScopeTypeInfo = 0;
5559 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00005560 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005561 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005562 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005563 }
Sean Huntc3021132010-05-05 15:23:54 +00005564
John McCall9ae2f072010-08-23 23:25:46 +00005565 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005566 E->getOperatorLoc(),
5567 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005568 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005569 E->getQualifierRange(),
5570 ScopeTypeInfo,
5571 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005572 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005573 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005574}
Mike Stump1eb44332009-09-09 15:08:12 +00005575
Douglas Gregora71d8192009-09-04 17:36:40 +00005576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005577ExprResult
John McCallba135432009-11-21 08:51:07 +00005578TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005579 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005580 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5581
5582 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5583 Sema::LookupOrdinaryName);
5584
5585 // Transform all the decls.
5586 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5587 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005588 NamedDecl *InstD = static_cast<NamedDecl*>(
5589 getDerived().TransformDecl(Old->getNameLoc(),
5590 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005591 if (!InstD) {
5592 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5593 // This can happen because of dependent hiding.
5594 if (isa<UsingShadowDecl>(*I))
5595 continue;
5596 else
John McCallf312b1e2010-08-26 23:41:50 +00005597 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005598 }
John McCallf7a1a742009-11-24 19:00:30 +00005599
5600 // Expand using declarations.
5601 if (isa<UsingDecl>(InstD)) {
5602 UsingDecl *UD = cast<UsingDecl>(InstD);
5603 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5604 E = UD->shadow_end(); I != E; ++I)
5605 R.addDecl(*I);
5606 continue;
5607 }
5608
5609 R.addDecl(InstD);
5610 }
5611
5612 // Resolve a kind, but don't do any further analysis. If it's
5613 // ambiguous, the callee needs to deal with it.
5614 R.resolveKind();
5615
5616 // Rebuild the nested-name qualifier, if present.
5617 CXXScopeSpec SS;
5618 NestedNameSpecifier *Qualifier = 0;
5619 if (Old->getQualifier()) {
5620 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005621 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005622 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005623 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005624
John McCallf7a1a742009-11-24 19:00:30 +00005625 SS.setScopeRep(Qualifier);
5626 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005627 }
5628
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005629 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005630 CXXRecordDecl *NamingClass
5631 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5632 Old->getNameLoc(),
5633 Old->getNamingClass()));
5634 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005635 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005636
Douglas Gregor66c45152010-04-27 16:10:10 +00005637 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005638 }
5639
5640 // If we have no template arguments, it's a normal declaration name.
5641 if (!Old->hasExplicitTemplateArgs())
5642 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5643
5644 // If we have template arguments, rebuild them, then rebuild the
5645 // templateid expression.
5646 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5647 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5648 TemplateArgumentLoc Loc;
5649 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005650 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005651 TransArgs.addArgument(Loc);
5652 }
5653
5654 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5655 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005656}
Mike Stump1eb44332009-09-09 15:08:12 +00005657
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005659ExprResult
John McCall454feb92009-12-08 09:21:05 +00005660TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005661 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5662 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005663 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005664
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005666 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005667 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Mike Stump1eb44332009-09-09 15:08:12 +00005669 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005670 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005671 T,
5672 E->getLocEnd());
5673}
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregorb98b1992009-08-11 05:31:07 +00005675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005676ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00005677TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
5678 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
5679 if (!LhsT)
5680 return ExprError();
5681
5682 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
5683 if (!RhsT)
5684 return ExprError();
5685
5686 if (!getDerived().AlwaysRebuild() &&
5687 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
5688 return SemaRef.Owned(E);
5689
5690 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
5691 E->getLocStart(),
5692 LhsT, RhsT,
5693 E->getLocEnd());
5694}
5695
5696template<typename Derived>
5697ExprResult
John McCall865d4472009-11-19 22:55:06 +00005698TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005699 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005700 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005701 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005702 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005703 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005704 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005705
John McCall43fed0d2010-11-12 08:19:04 +00005706 // TODO: If this is a conversion-function-id, verify that the
5707 // destination type name (if present) resolves the same way after
5708 // instantiation as it did in the local scope.
5709
Abramo Bagnara25777432010-08-11 22:01:17 +00005710 DeclarationNameInfo NameInfo
5711 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5712 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005714
John McCallf7a1a742009-11-24 19:00:30 +00005715 if (!E->hasExplicitTemplateArgs()) {
5716 if (!getDerived().AlwaysRebuild() &&
5717 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005718 // Note: it is sufficient to compare the Name component of NameInfo:
5719 // if name has not changed, DNLoc has not changed either.
5720 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00005721 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005722
John McCallf7a1a742009-11-24 19:00:30 +00005723 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5724 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005725 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005726 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005727 }
John McCalld5532b62009-11-23 01:53:49 +00005728
5729 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005730 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005731 TemplateArgumentLoc Loc;
5732 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005733 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005734 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005735 }
5736
John McCallf7a1a742009-11-24 19:00:30 +00005737 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5738 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005739 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005740 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005741}
5742
5743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005744ExprResult
John McCall454feb92009-12-08 09:21:05 +00005745TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005746 // CXXConstructExprs are always implicit, so when we have a
5747 // 1-argument construction we just transform that argument.
5748 if (E->getNumArgs() == 1 ||
5749 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5750 return getDerived().TransformExpr(E->getArg(0));
5751
Douglas Gregorb98b1992009-08-11 05:31:07 +00005752 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5753
5754 QualType T = getDerived().TransformType(E->getType());
5755 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005756 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005757
5758 CXXConstructorDecl *Constructor
5759 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005760 getDerived().TransformDecl(E->getLocStart(),
5761 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005762 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005764
Douglas Gregorb98b1992009-08-11 05:31:07 +00005765 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005766 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005767 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005768 ArgEnd = E->arg_end();
5769 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005770 if (getDerived().DropCallArgument(*Arg)) {
5771 ArgumentChanged = true;
5772 break;
5773 }
5774
John McCall60d7b3a2010-08-24 06:29:42 +00005775 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005776 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005777 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005778
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005780 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005781 }
5782
5783 if (!getDerived().AlwaysRebuild() &&
5784 T == E->getType() &&
5785 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005786 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005787 // Mark the constructor as referenced.
5788 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005789 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005790 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00005791 }
Mike Stump1eb44332009-09-09 15:08:12 +00005792
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005793 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5794 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005795 move_arg(Args),
5796 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00005797 E->getConstructionKind(),
5798 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799}
Mike Stump1eb44332009-09-09 15:08:12 +00005800
Douglas Gregorb98b1992009-08-11 05:31:07 +00005801/// \brief Transform a C++ temporary-binding expression.
5802///
Douglas Gregor51326552009-12-24 18:51:59 +00005803/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5804/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005805template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005806ExprResult
John McCall454feb92009-12-08 09:21:05 +00005807TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005808 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005809}
Mike Stump1eb44332009-09-09 15:08:12 +00005810
John McCall4765fa02010-12-06 08:20:24 +00005811/// \brief Transform a C++ expression that contains cleanups that should
5812/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005813///
John McCall4765fa02010-12-06 08:20:24 +00005814/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00005815/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005817ExprResult
John McCall4765fa02010-12-06 08:20:24 +00005818TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005819 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005820}
Mike Stump1eb44332009-09-09 15:08:12 +00005821
Douglas Gregorb98b1992009-08-11 05:31:07 +00005822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005823ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005824TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005825 CXXTemporaryObjectExpr *E) {
5826 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5827 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005828 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005829
Douglas Gregorb98b1992009-08-11 05:31:07 +00005830 CXXConstructorDecl *Constructor
5831 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005832 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005833 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005834 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005835 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005836
Douglas Gregorb98b1992009-08-11 05:31:07 +00005837 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005838 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005839 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005840 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005841 ArgEnd = E->arg_end();
5842 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005843 if (getDerived().DropCallArgument(*Arg)) {
5844 ArgumentChanged = true;
5845 break;
5846 }
5847
John McCall60d7b3a2010-08-24 06:29:42 +00005848 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005849 if (TransArg.isInvalid())
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 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5853 Args.push_back((Expr *)TransArg.release());
5854 }
Mike Stump1eb44332009-09-09 15:08:12 +00005855
Douglas Gregorb98b1992009-08-11 05:31:07 +00005856 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005857 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005858 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005859 !ArgumentChanged) {
5860 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005861 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005862 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00005863 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005864
5865 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5866 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005867 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005868 E->getLocEnd());
5869}
Mike Stump1eb44332009-09-09 15:08:12 +00005870
Douglas Gregorb98b1992009-08-11 05:31:07 +00005871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005872ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005873TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005874 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005875 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5876 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005877 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005878
Douglas Gregorb98b1992009-08-11 05:31:07 +00005879 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005880 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005881 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5882 ArgEnd = E->arg_end();
5883 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005884 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005885 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005886 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005887
Douglas Gregorb98b1992009-08-11 05:31:07 +00005888 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005889 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005890 }
Mike Stump1eb44332009-09-09 15:08:12 +00005891
Douglas Gregorb98b1992009-08-11 05:31:07 +00005892 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005893 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005894 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005895 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005896
Douglas Gregorb98b1992009-08-11 05:31:07 +00005897 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005898 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005899 E->getLParenLoc(),
5900 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005901 E->getRParenLoc());
5902}
Mike Stump1eb44332009-09-09 15:08:12 +00005903
Douglas Gregorb98b1992009-08-11 05:31:07 +00005904template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005905ExprResult
John McCall865d4472009-11-19 22:55:06 +00005906TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005907 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005908 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005909 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005910 Expr *OldBase;
5911 QualType BaseType;
5912 QualType ObjectType;
5913 if (!E->isImplicitAccess()) {
5914 OldBase = E->getBase();
5915 Base = getDerived().TransformExpr(OldBase);
5916 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005917 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005918
John McCallaa81e162009-12-01 22:10:20 +00005919 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005920 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005921 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005922 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005923 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005924 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005925 ObjectTy,
5926 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005927 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005928 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005929
John McCallb3d87482010-08-24 05:47:05 +00005930 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005931 BaseType = ((Expr*) Base.get())->getType();
5932 } else {
5933 OldBase = 0;
5934 BaseType = getDerived().TransformType(E->getBaseType());
5935 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5936 }
Mike Stump1eb44332009-09-09 15:08:12 +00005937
Douglas Gregor6cd21982009-10-20 05:58:46 +00005938 // Transform the first part of the nested-name-specifier that qualifies
5939 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005940 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005941 = getDerived().TransformFirstQualifierInScope(
5942 E->getFirstQualifierFoundInScope(),
5943 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005944
Douglas Gregora38c6872009-09-03 16:14:30 +00005945 NestedNameSpecifier *Qualifier = 0;
5946 if (E->getQualifier()) {
5947 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5948 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005949 ObjectType,
5950 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005951 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005952 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005953 }
Mike Stump1eb44332009-09-09 15:08:12 +00005954
John McCall43fed0d2010-11-12 08:19:04 +00005955 // TODO: If this is a conversion-function-id, verify that the
5956 // destination type name (if present) resolves the same way after
5957 // instantiation as it did in the local scope.
5958
Abramo Bagnara25777432010-08-11 22:01:17 +00005959 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00005960 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00005961 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005962 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005963
John McCallaa81e162009-12-01 22:10:20 +00005964 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005965 // This is a reference to a member without an explicitly-specified
5966 // template argument list. Optimize for this common case.
5967 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005968 Base.get() == OldBase &&
5969 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005970 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005971 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005972 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00005973 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005974
John McCall9ae2f072010-08-23 23:25:46 +00005975 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005976 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005977 E->isArrow(),
5978 E->getOperatorLoc(),
5979 Qualifier,
5980 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005981 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005982 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005983 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005984 }
5985
John McCalld5532b62009-11-23 01:53:49 +00005986 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005987 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005988 TemplateArgumentLoc Loc;
5989 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005990 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005991 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005992 }
Mike Stump1eb44332009-09-09 15:08:12 +00005993
John McCall9ae2f072010-08-23 23:25:46 +00005994 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005995 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005996 E->isArrow(),
5997 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005998 Qualifier,
5999 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006000 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006001 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006002 &TransArgs);
6003}
6004
6005template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006006ExprResult
John McCall454feb92009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006008 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006009 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006010 QualType BaseType;
6011 if (!Old->isImplicitAccess()) {
6012 Base = getDerived().TransformExpr(Old->getBase());
6013 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006014 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006015 BaseType = ((Expr*) Base.get())->getType();
6016 } else {
6017 BaseType = getDerived().TransformType(Old->getBaseType());
6018 }
John McCall129e2df2009-11-30 22:42:35 +00006019
6020 NestedNameSpecifier *Qualifier = 0;
6021 if (Old->getQualifier()) {
6022 Qualifier
6023 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006024 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006025 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006026 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006027 }
6028
Abramo Bagnara25777432010-08-11 22:01:17 +00006029 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006030 Sema::LookupOrdinaryName);
6031
6032 // Transform all the decls.
6033 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6034 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006035 NamedDecl *InstD = static_cast<NamedDecl*>(
6036 getDerived().TransformDecl(Old->getMemberLoc(),
6037 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006038 if (!InstD) {
6039 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6040 // This can happen because of dependent hiding.
6041 if (isa<UsingShadowDecl>(*I))
6042 continue;
6043 else
John McCallf312b1e2010-08-26 23:41:50 +00006044 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006045 }
John McCall129e2df2009-11-30 22:42:35 +00006046
6047 // Expand using declarations.
6048 if (isa<UsingDecl>(InstD)) {
6049 UsingDecl *UD = cast<UsingDecl>(InstD);
6050 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6051 E = UD->shadow_end(); I != E; ++I)
6052 R.addDecl(*I);
6053 continue;
6054 }
6055
6056 R.addDecl(InstD);
6057 }
6058
6059 R.resolveKind();
6060
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006061 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006062 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006063 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006064 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006065 Old->getMemberLoc(),
6066 Old->getNamingClass()));
6067 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006068 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006069
Douglas Gregor66c45152010-04-27 16:10:10 +00006070 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006071 }
Sean Huntc3021132010-05-05 15:23:54 +00006072
John McCall129e2df2009-11-30 22:42:35 +00006073 TemplateArgumentListInfo TransArgs;
6074 if (Old->hasExplicitTemplateArgs()) {
6075 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6076 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6077 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6078 TemplateArgumentLoc Loc;
6079 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6080 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00006081 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006082 TransArgs.addArgument(Loc);
6083 }
6084 }
John McCallc2233c52010-01-15 08:34:02 +00006085
6086 // FIXME: to do this check properly, we will need to preserve the
6087 // first-qualifier-in-scope here, just in case we had a dependent
6088 // base (and therefore couldn't do the check) and a
6089 // nested-name-qualifier (and therefore could do the lookup).
6090 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006091
John McCall9ae2f072010-08-23 23:25:46 +00006092 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006093 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006094 Old->getOperatorLoc(),
6095 Old->isArrow(),
6096 Qualifier,
6097 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006098 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006099 R,
6100 (Old->hasExplicitTemplateArgs()
6101 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006102}
6103
6104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006105ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006106TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6107 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6108 if (SubExpr.isInvalid())
6109 return ExprError();
6110
6111 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006113
6114 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6115}
6116
6117template<typename Derived>
6118ExprResult
John McCall454feb92009-12-08 09:21:05 +00006119TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006120 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121}
6122
Mike Stump1eb44332009-09-09 15:08:12 +00006123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006124ExprResult
John McCall454feb92009-12-08 09:21:05 +00006125TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006126 TypeSourceInfo *EncodedTypeInfo
6127 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6128 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006129 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006130
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006132 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006133 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134
6135 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006136 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137 E->getRParenLoc());
6138}
Mike Stump1eb44332009-09-09 15:08:12 +00006139
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006141ExprResult
John McCall454feb92009-12-08 09:21:05 +00006142TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006143 // Transform arguments.
6144 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006145 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006146 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006147 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006148 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006149 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006150
Douglas Gregor92e986e2010-04-22 16:44:27 +00006151 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006152 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006153 }
6154
6155 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6156 // Class message: transform the receiver type.
6157 TypeSourceInfo *ReceiverTypeInfo
6158 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6159 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006160 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006161
Douglas Gregor92e986e2010-04-22 16:44:27 +00006162 // If nothing changed, just retain the existing message send.
6163 if (!getDerived().AlwaysRebuild() &&
6164 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006165 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006166
6167 // Build a new class message send.
6168 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6169 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006170 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006171 E->getMethodDecl(),
6172 E->getLeftLoc(),
6173 move_arg(Args),
6174 E->getRightLoc());
6175 }
6176
6177 // Instance message: transform the receiver
6178 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6179 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006180 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006181 = getDerived().TransformExpr(E->getInstanceReceiver());
6182 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006183 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006184
6185 // If nothing changed, just retain the existing message send.
6186 if (!getDerived().AlwaysRebuild() &&
6187 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006188 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006189
Douglas Gregor92e986e2010-04-22 16:44:27 +00006190 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006191 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006192 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006193 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006194 E->getMethodDecl(),
6195 E->getLeftLoc(),
6196 move_arg(Args),
6197 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198}
6199
Mike Stump1eb44332009-09-09 15:08:12 +00006200template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006201ExprResult
John McCall454feb92009-12-08 09:21:05 +00006202TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006203 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204}
6205
Mike Stump1eb44332009-09-09 15:08:12 +00006206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006207ExprResult
John McCall454feb92009-12-08 09:21:05 +00006208TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006209 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210}
6211
Mike Stump1eb44332009-09-09 15:08:12 +00006212template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006213ExprResult
John McCall454feb92009-12-08 09:21:05 +00006214TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006215 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006216 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006217 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006218 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006219
6220 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006221
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006222 // If nothing changed, just retain the existing expression.
6223 if (!getDerived().AlwaysRebuild() &&
6224 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006225 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006226
John McCall9ae2f072010-08-23 23:25:46 +00006227 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006228 E->getLocation(),
6229 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230}
6231
Mike Stump1eb44332009-09-09 15:08:12 +00006232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006233ExprResult
John McCall454feb92009-12-08 09:21:05 +00006234TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00006235 // 'super' and types never change. Property never changes. Just
6236 // retain the existing expression.
6237 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006238 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006239
Douglas Gregore3303542010-04-26 20:47:02 +00006240 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006241 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006242 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006243 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006244
Douglas Gregore3303542010-04-26 20:47:02 +00006245 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006246
Douglas Gregore3303542010-04-26 20:47:02 +00006247 // If nothing changed, just retain the existing expression.
6248 if (!getDerived().AlwaysRebuild() &&
6249 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006250 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251
John McCall12f78a62010-12-02 01:19:52 +00006252 if (E->isExplicitProperty())
6253 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6254 E->getExplicitProperty(),
6255 E->getLocation());
6256
6257 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6258 E->getType(),
6259 E->getImplicitPropertyGetter(),
6260 E->getImplicitPropertySetter(),
6261 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006262}
6263
Mike Stump1eb44332009-09-09 15:08:12 +00006264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006265ExprResult
John McCall454feb92009-12-08 09:21:05 +00006266TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006267 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006268 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006269 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006270 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006271
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006272 // If nothing changed, just retain the existing expression.
6273 if (!getDerived().AlwaysRebuild() &&
6274 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006275 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006276
John McCall9ae2f072010-08-23 23:25:46 +00006277 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006278 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006279}
6280
Mike Stump1eb44332009-09-09 15:08:12 +00006281template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006282ExprResult
John McCall454feb92009-12-08 09:21:05 +00006283TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006284 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006285 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006286 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006287 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006289 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006290
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006292 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293 }
Mike Stump1eb44332009-09-09 15:08:12 +00006294
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 if (!getDerived().AlwaysRebuild() &&
6296 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006297 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006298
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6300 move_arg(SubExprs),
6301 E->getRParenLoc());
6302}
6303
Mike Stump1eb44332009-09-09 15:08:12 +00006304template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006305ExprResult
John McCall454feb92009-12-08 09:21:05 +00006306TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006307 SourceLocation CaretLoc(E->getExprLoc());
6308
6309 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6310 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6311 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6312 llvm::SmallVector<ParmVarDecl*, 4> Params;
6313 llvm::SmallVector<QualType, 4> ParamTypes;
6314
6315 // Parameter substitution.
6316 const BlockDecl *BD = E->getBlockDecl();
6317 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6318 EN = BD->param_end(); P != EN; ++P) {
6319 ParmVarDecl *OldParm = (*P);
6320 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6321 QualType NewType = NewParm->getType();
6322 Params.push_back(NewParm);
6323 ParamTypes.push_back(NewParm->getType());
6324 }
6325
6326 const FunctionType *BExprFunctionType = E->getFunctionType();
6327 QualType BExprResultType = BExprFunctionType->getResultType();
6328 if (!BExprResultType.isNull()) {
6329 if (!BExprResultType->isDependentType())
6330 CurBlock->ReturnType = BExprResultType;
6331 else if (BExprResultType != SemaRef.Context.DependentTy)
6332 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6333 }
6334
6335 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006336 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006337 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006338 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006339 // Set the parameters on the block decl.
6340 if (!Params.empty())
6341 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6342
6343 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6344 CurBlock->ReturnType,
6345 ParamTypes.data(),
6346 ParamTypes.size(),
6347 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006348 0,
6349 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006350
6351 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006352 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006353}
6354
Mike Stump1eb44332009-09-09 15:08:12 +00006355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006356ExprResult
John McCall454feb92009-12-08 09:21:05 +00006357TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006358 NestedNameSpecifier *Qualifier = 0;
6359
6360 ValueDecl *ND
6361 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6362 E->getDecl()));
6363 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006364 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006365
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006366 if (!getDerived().AlwaysRebuild() &&
6367 ND == E->getDecl()) {
6368 // Mark it referenced in the new context regardless.
6369 // FIXME: this is a bit instantiation-specific.
6370 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6371
John McCall3fa5cae2010-10-26 07:05:15 +00006372 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006373 }
6374
Abramo Bagnara25777432010-08-11 22:01:17 +00006375 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006376 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006377 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378}
Mike Stump1eb44332009-09-09 15:08:12 +00006379
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006381// Type reconstruction
6382//===----------------------------------------------------------------------===//
6383
Mike Stump1eb44332009-09-09 15:08:12 +00006384template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006385QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6386 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006387 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006388 getDerived().getBaseEntity());
6389}
6390
Mike Stump1eb44332009-09-09 15:08:12 +00006391template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006392QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6393 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006394 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006395 getDerived().getBaseEntity());
6396}
6397
Mike Stump1eb44332009-09-09 15:08:12 +00006398template<typename Derived>
6399QualType
John McCall85737a72009-10-30 00:06:24 +00006400TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6401 bool WrittenAsLValue,
6402 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006403 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006404 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006405}
6406
6407template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006408QualType
John McCall85737a72009-10-30 00:06:24 +00006409TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6410 QualType ClassType,
6411 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006412 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006413 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006414}
6415
6416template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006417QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006418TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6419 ArrayType::ArraySizeModifier SizeMod,
6420 const llvm::APInt *Size,
6421 Expr *SizeExpr,
6422 unsigned IndexTypeQuals,
6423 SourceRange BracketsRange) {
6424 if (SizeExpr || !Size)
6425 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6426 IndexTypeQuals, BracketsRange,
6427 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006428
6429 QualType Types[] = {
6430 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6431 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6432 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006433 };
6434 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6435 QualType SizeType;
6436 for (unsigned I = 0; I != NumTypes; ++I)
6437 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6438 SizeType = Types[I];
6439 break;
6440 }
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006442 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6443 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006444 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006445 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006446 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006447}
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregor577f75a2009-08-04 16:50:30 +00006449template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006450QualType
6451TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006452 ArrayType::ArraySizeModifier SizeMod,
6453 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006454 unsigned IndexTypeQuals,
6455 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006456 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006457 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006458}
6459
6460template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006461QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006462TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006463 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006464 unsigned IndexTypeQuals,
6465 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006466 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006467 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006468}
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Douglas Gregor577f75a2009-08-04 16:50:30 +00006470template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006471QualType
6472TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006473 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006474 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006475 unsigned IndexTypeQuals,
6476 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006477 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006478 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006479 IndexTypeQuals, BracketsRange);
6480}
6481
6482template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006483QualType
6484TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006485 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006486 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006487 unsigned IndexTypeQuals,
6488 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006489 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006490 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006491 IndexTypeQuals, BracketsRange);
6492}
6493
6494template<typename Derived>
6495QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00006496 unsigned NumElements,
6497 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006498 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00006499 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006500}
Mike Stump1eb44332009-09-09 15:08:12 +00006501
Douglas Gregor577f75a2009-08-04 16:50:30 +00006502template<typename Derived>
6503QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6504 unsigned NumElements,
6505 SourceLocation AttributeLoc) {
6506 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6507 NumElements, true);
6508 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006509 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6510 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006511 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006512}
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Douglas Gregor577f75a2009-08-04 16:50:30 +00006514template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006515QualType
6516TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006517 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006518 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006519 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006520}
Mike Stump1eb44332009-09-09 15:08:12 +00006521
Douglas Gregor577f75a2009-08-04 16:50:30 +00006522template<typename Derived>
6523QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006524 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006525 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006526 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006527 unsigned Quals,
6528 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006529 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006530 Quals,
6531 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006532 getDerived().getBaseEntity(),
6533 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006534}
Mike Stump1eb44332009-09-09 15:08:12 +00006535
Douglas Gregor577f75a2009-08-04 16:50:30 +00006536template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006537QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6538 return SemaRef.Context.getFunctionNoProtoType(T);
6539}
6540
6541template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006542QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6543 assert(D && "no decl found");
6544 if (D->isInvalidDecl()) return QualType();
6545
Douglas Gregor92e986e2010-04-22 16:44:27 +00006546 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006547 TypeDecl *Ty;
6548 if (isa<UsingDecl>(D)) {
6549 UsingDecl *Using = cast<UsingDecl>(D);
6550 assert(Using->isTypeName() &&
6551 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6552
6553 // A valid resolved using typename decl points to exactly one type decl.
6554 assert(++Using->shadow_begin() == Using->shadow_end());
6555 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006556
John McCalled976492009-12-04 22:46:56 +00006557 } else {
6558 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6559 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6560 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6561 }
6562
6563 return SemaRef.Context.getTypeDeclType(Ty);
6564}
6565
6566template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006567QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6568 SourceLocation Loc) {
6569 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006570}
6571
6572template<typename Derived>
6573QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6574 return SemaRef.Context.getTypeOfType(Underlying);
6575}
6576
6577template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006578QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6579 SourceLocation Loc) {
6580 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006581}
6582
6583template<typename Derived>
6584QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006585 TemplateName Template,
6586 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006587 const TemplateArgumentListInfo &TemplateArgs) {
6588 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006589}
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregordcee1a12009-08-06 05:28:30 +00006591template<typename Derived>
6592NestedNameSpecifier *
6593TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6594 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006595 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006596 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006597 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006598 CXXScopeSpec SS;
6599 // FIXME: The source location information is all wrong.
6600 SS.setRange(Range);
6601 SS.setScopeRep(Prefix);
6602 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006603 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006604 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006605 ObjectType,
6606 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006607 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006608}
6609
6610template<typename Derived>
6611NestedNameSpecifier *
6612TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6613 SourceRange Range,
6614 NamespaceDecl *NS) {
6615 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6616}
6617
6618template<typename Derived>
6619NestedNameSpecifier *
6620TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6621 SourceRange Range,
6622 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006623 QualType T) {
6624 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006625 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006626 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006627 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6628 T.getTypePtr());
6629 }
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregordcee1a12009-08-06 05:28:30 +00006631 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6632 return 0;
6633}
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregord1067e52009-08-06 06:41:21 +00006635template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006636TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006637TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6638 bool TemplateKW,
6639 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006640 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006641 Template);
6642}
6643
6644template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006645TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006646TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006647 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006648 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00006649 QualType ObjectType,
6650 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006651 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006652 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006653 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006654 UnqualifiedId Name;
6655 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006656 Sema::TemplateTy Template;
6657 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6658 /*FIXME:*/getDerived().getBaseLocation(),
6659 SS,
6660 Name,
John McCallb3d87482010-08-24 05:47:05 +00006661 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006662 /*EnteringContext=*/false,
6663 Template);
John McCall43fed0d2010-11-12 08:19:04 +00006664 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00006665}
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006668TemplateName
6669TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6670 OverloadedOperatorKind Operator,
6671 QualType ObjectType) {
6672 CXXScopeSpec SS;
6673 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6674 SS.setScopeRep(Qualifier);
6675 UnqualifiedId Name;
6676 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6677 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6678 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006679 Sema::TemplateTy Template;
6680 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006681 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006682 SS,
6683 Name,
John McCallb3d87482010-08-24 05:47:05 +00006684 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006685 /*EnteringContext=*/false,
6686 Template);
6687 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006688}
Sean Huntc3021132010-05-05 15:23:54 +00006689
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006691ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6693 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006694 Expr *OrigCallee,
6695 Expr *First,
6696 Expr *Second) {
6697 Expr *Callee = OrigCallee->IgnoreParenCasts();
6698 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006699
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006701 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006702 if (!First->getType()->isOverloadableType() &&
6703 !Second->getType()->isOverloadableType())
6704 return getSema().CreateBuiltinArraySubscriptExpr(First,
6705 Callee->getLocStart(),
6706 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006707 } else if (Op == OO_Arrow) {
6708 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006709 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6710 } else if (Second == 0 || isPostIncDec) {
6711 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 // The argument is not of overloadable type, so try to create a
6713 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006714 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006716
John McCall9ae2f072010-08-23 23:25:46 +00006717 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 }
6719 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006720 if (!First->getType()->isOverloadableType() &&
6721 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 // Neither of the arguments is an overloadable type, so try to
6723 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006724 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006725 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006726 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 return move(Result);
6731 }
6732 }
Mike Stump1eb44332009-09-09 15:08:12 +00006733
6734 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006736 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006737
John McCall9ae2f072010-08-23 23:25:46 +00006738 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006739 assert(ULE->requiresADL());
6740
6741 // FIXME: Do we have to check
6742 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006743 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006744 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006745 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006746 }
Mike Stump1eb44332009-09-09 15:08:12 +00006747
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006749 Expr *Args[2] = { First, Second };
6750 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006751
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 // Create the overloaded operator invocation for unary operators.
6753 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006754 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006756 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 }
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Sebastian Redlf322ed62009-10-29 20:17:01 +00006759 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006760 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006761 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006762 First,
6763 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006764
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006766 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006767 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6769 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006770 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Mike Stump1eb44332009-09-09 15:08:12 +00006772 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773}
Mike Stump1eb44332009-09-09 15:08:12 +00006774
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006775template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006776ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006777TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006778 SourceLocation OperatorLoc,
6779 bool isArrow,
6780 NestedNameSpecifier *Qualifier,
6781 SourceRange QualifierRange,
6782 TypeSourceInfo *ScopeType,
6783 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006784 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006785 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006786 CXXScopeSpec SS;
6787 if (Qualifier) {
6788 SS.setRange(QualifierRange);
6789 SS.setScopeRep(Qualifier);
6790 }
6791
John McCall9ae2f072010-08-23 23:25:46 +00006792 QualType BaseType = Base->getType();
6793 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006794 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006795 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006796 !BaseType->getAs<PointerType>()->getPointeeType()
6797 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006798 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006799 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006800 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006801 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006802 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006803 /*FIXME?*/true);
6804 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006805
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006806 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006807 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6808 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6809 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6810 NameInfo.setNamedTypeInfo(DestroyedType);
6811
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006812 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006813
John McCall9ae2f072010-08-23 23:25:46 +00006814 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006815 OperatorLoc, isArrow,
6816 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006817 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006818 /*TemplateArgs*/ 0);
6819}
6820
Douglas Gregor577f75a2009-08-04 16:50:30 +00006821} // end namespace clang
6822
6823#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H