1 //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Expr interface and subclasses for C++ expressions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_EXPRCXX_H
15 #define LLVM_CLANG_AST_EXPRCXX_H
17 #include "clang/Basic/TypeTraits.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/UnresolvedSet.h"
20 #include "clang/AST/TemplateBase.h"
24 class CXXConstructorDecl
;
25 class CXXDestructorDecl
;
28 class TemplateArgumentListInfo
;
30 //===--------------------------------------------------------------------===//
32 //===--------------------------------------------------------------------===//
34 /// \brief A call to an overloaded operator written using operator
37 /// Represents a call to an overloaded operator written using operator
38 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
39 /// normal call, this AST node provides better information about the
40 /// syntactic representation of the call.
42 /// In a C++ template, this expression node kind will be used whenever
43 /// any of the arguments are type-dependent. In this case, the
44 /// function itself will be a (possibly empty) set of functions and
45 /// function templates that were found by name lookup at template
47 class CXXOperatorCallExpr
: public CallExpr
{
48 /// \brief The overloaded operator.
49 OverloadedOperatorKind Operator
;
52 CXXOperatorCallExpr(ASTContext
& C
, OverloadedOperatorKind Op
, Expr
*fn
,
53 Expr
**args
, unsigned numargs
, QualType t
,
54 SourceLocation operatorloc
)
55 : CallExpr(C
, CXXOperatorCallExprClass
, fn
, args
, numargs
, t
, operatorloc
),
57 explicit CXXOperatorCallExpr(ASTContext
& C
, EmptyShell Empty
) :
58 CallExpr(C
, CXXOperatorCallExprClass
, Empty
) { }
61 /// getOperator - Returns the kind of overloaded operator that this
62 /// expression refers to.
63 OverloadedOperatorKind
getOperator() const { return Operator
; }
64 void setOperator(OverloadedOperatorKind Kind
) { Operator
= Kind
; }
66 /// getOperatorLoc - Returns the location of the operator symbol in
67 /// the expression. When @c getOperator()==OO_Call, this is the
68 /// location of the right parentheses; when @c
69 /// getOperator()==OO_Subscript, this is the location of the right
71 SourceLocation
getOperatorLoc() const { return getRParenLoc(); }
73 virtual SourceRange
getSourceRange() const;
75 static bool classof(const Stmt
*T
) {
76 return T
->getStmtClass() == CXXOperatorCallExprClass
;
78 static bool classof(const CXXOperatorCallExpr
*) { return true; }
81 /// CXXMemberCallExpr - Represents a call to a member function that
82 /// may be written either with member call syntax (e.g., "obj.func()"
83 /// or "objptr->func()") or with normal function-call syntax
84 /// ("func()") within a member function that ends up calling a member
85 /// function. The callee in either case is a MemberExpr that contains
86 /// both the object argument and the member function, while the
87 /// arguments are the arguments within the parentheses (not including
88 /// the object argument).
89 class CXXMemberCallExpr
: public CallExpr
{
91 CXXMemberCallExpr(ASTContext
&C
, Expr
*fn
, Expr
**args
, unsigned numargs
,
92 QualType t
, SourceLocation rparenloc
)
93 : CallExpr(C
, CXXMemberCallExprClass
, fn
, args
, numargs
, t
, rparenloc
) {}
95 CXXMemberCallExpr(ASTContext
&C
, EmptyShell Empty
)
96 : CallExpr(C
, CXXMemberCallExprClass
, Empty
) { }
98 /// getImplicitObjectArgument - Retrieves the implicit object
99 /// argument for the member call. For example, in "x.f(5)", this
100 /// operation would return "x".
101 Expr
*getImplicitObjectArgument();
103 virtual SourceRange
getSourceRange() const;
105 static bool classof(const Stmt
*T
) {
106 return T
->getStmtClass() == CXXMemberCallExprClass
;
108 static bool classof(const CXXMemberCallExpr
*) { return true; }
111 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
112 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
115 /// This abstract class is inherited by all of the classes
116 /// representing "named" casts, e.g., CXXStaticCastExpr,
117 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
118 class CXXNamedCastExpr
: public ExplicitCastExpr
{
120 SourceLocation Loc
; // the location of the casting op
123 CXXNamedCastExpr(StmtClass SC
, QualType ty
, CastKind kind
, Expr
*op
,
124 CXXBaseSpecifierArray BasePath
, TypeSourceInfo
*writtenTy
,
126 : ExplicitCastExpr(SC
, ty
, kind
, op
, BasePath
, writtenTy
), Loc(l
) {}
128 explicit CXXNamedCastExpr(StmtClass SC
, EmptyShell Shell
)
129 : ExplicitCastExpr(SC
, Shell
) { }
132 const char *getCastName() const;
134 /// \brief Retrieve the location of the cast operator keyword, e.g.,
136 SourceLocation
getOperatorLoc() const { return Loc
; }
137 void setOperatorLoc(SourceLocation L
) { Loc
= L
; }
139 virtual SourceRange
getSourceRange() const {
140 return SourceRange(Loc
, getSubExpr()->getSourceRange().getEnd());
142 static bool classof(const Stmt
*T
) {
143 switch (T
->getStmtClass()) {
144 case CXXStaticCastExprClass
:
145 case CXXDynamicCastExprClass
:
146 case CXXReinterpretCastExprClass
:
147 case CXXConstCastExprClass
:
153 static bool classof(const CXXNamedCastExpr
*) { return true; }
156 /// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
158 /// This expression node represents a C++ static cast, e.g.,
159 /// @c static_cast<int>(1.0).
160 class CXXStaticCastExpr
: public CXXNamedCastExpr
{
162 CXXStaticCastExpr(QualType ty
, CastKind kind
, Expr
*op
,
163 CXXBaseSpecifierArray BasePath
, TypeSourceInfo
*writtenTy
,
165 : CXXNamedCastExpr(CXXStaticCastExprClass
, ty
, kind
, op
, BasePath
, writtenTy
, l
) {}
167 explicit CXXStaticCastExpr(EmptyShell Empty
)
168 : CXXNamedCastExpr(CXXStaticCastExprClass
, Empty
) { }
170 static bool classof(const Stmt
*T
) {
171 return T
->getStmtClass() == CXXStaticCastExprClass
;
173 static bool classof(const CXXStaticCastExpr
*) { return true; }
176 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
177 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
178 /// determine how to perform the type cast.
180 /// This expression node represents a dynamic cast, e.g.,
181 /// @c dynamic_cast<Derived*>(BasePtr).
182 class CXXDynamicCastExpr
: public CXXNamedCastExpr
{
184 CXXDynamicCastExpr(QualType ty
, CastKind kind
, Expr
*op
,
185 CXXBaseSpecifierArray BasePath
, TypeSourceInfo
*writtenTy
,
187 : CXXNamedCastExpr(CXXDynamicCastExprClass
, ty
, kind
, op
, BasePath
,
190 explicit CXXDynamicCastExpr(EmptyShell Empty
)
191 : CXXNamedCastExpr(CXXDynamicCastExprClass
, Empty
) { }
193 static bool classof(const Stmt
*T
) {
194 return T
->getStmtClass() == CXXDynamicCastExprClass
;
196 static bool classof(const CXXDynamicCastExpr
*) { return true; }
199 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
200 /// [expr.reinterpret.cast]), which provides a differently-typed view
201 /// of a value but performs no actual work at run time.
203 /// This expression node represents a reinterpret cast, e.g.,
204 /// @c reinterpret_cast<int>(VoidPtr).
205 class CXXReinterpretCastExpr
: public CXXNamedCastExpr
{
207 CXXReinterpretCastExpr(QualType ty
, CastKind kind
, Expr
*op
,
208 CXXBaseSpecifierArray BasePath
,
209 TypeSourceInfo
*writtenTy
, SourceLocation l
)
210 : CXXNamedCastExpr(CXXReinterpretCastExprClass
, ty
, kind
, op
, BasePath
,
213 explicit CXXReinterpretCastExpr(EmptyShell Empty
)
214 : CXXNamedCastExpr(CXXReinterpretCastExprClass
, Empty
) { }
216 static bool classof(const Stmt
*T
) {
217 return T
->getStmtClass() == CXXReinterpretCastExprClass
;
219 static bool classof(const CXXReinterpretCastExpr
*) { return true; }
222 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
223 /// which can remove type qualifiers but does not change the underlying value.
225 /// This expression node represents a const cast, e.g.,
226 /// @c const_cast<char*>(PtrToConstChar).
227 class CXXConstCastExpr
: public CXXNamedCastExpr
{
229 CXXConstCastExpr(QualType ty
, Expr
*op
, TypeSourceInfo
*writtenTy
,
231 : CXXNamedCastExpr(CXXConstCastExprClass
, ty
, CK_NoOp
, op
,
232 CXXBaseSpecifierArray(), writtenTy
, l
) {}
234 explicit CXXConstCastExpr(EmptyShell Empty
)
235 : CXXNamedCastExpr(CXXConstCastExprClass
, Empty
) { }
237 static bool classof(const Stmt
*T
) {
238 return T
->getStmtClass() == CXXConstCastExprClass
;
240 static bool classof(const CXXConstCastExpr
*) { return true; }
243 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
245 class CXXBoolLiteralExpr
: public Expr
{
249 CXXBoolLiteralExpr(bool val
, QualType Ty
, SourceLocation l
) :
250 Expr(CXXBoolLiteralExprClass
, Ty
, false, false), Value(val
), Loc(l
) {}
252 explicit CXXBoolLiteralExpr(EmptyShell Empty
)
253 : Expr(CXXBoolLiteralExprClass
, Empty
) { }
255 bool getValue() const { return Value
; }
256 void setValue(bool V
) { Value
= V
; }
258 virtual SourceRange
getSourceRange() const { return SourceRange(Loc
); }
260 SourceLocation
getLocation() const { return Loc
; }
261 void setLocation(SourceLocation L
) { Loc
= L
; }
263 static bool classof(const Stmt
*T
) {
264 return T
->getStmtClass() == CXXBoolLiteralExprClass
;
266 static bool classof(const CXXBoolLiteralExpr
*) { return true; }
269 virtual child_iterator
child_begin();
270 virtual child_iterator
child_end();
273 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
274 class CXXNullPtrLiteralExpr
: public Expr
{
277 CXXNullPtrLiteralExpr(QualType Ty
, SourceLocation l
) :
278 Expr(CXXNullPtrLiteralExprClass
, Ty
, false, false), Loc(l
) {}
280 explicit CXXNullPtrLiteralExpr(EmptyShell Empty
)
281 : Expr(CXXNullPtrLiteralExprClass
, Empty
) { }
283 virtual SourceRange
getSourceRange() const { return SourceRange(Loc
); }
285 SourceLocation
getLocation() const { return Loc
; }
286 void setLocation(SourceLocation L
) { Loc
= L
; }
288 static bool classof(const Stmt
*T
) {
289 return T
->getStmtClass() == CXXNullPtrLiteralExprClass
;
291 static bool classof(const CXXNullPtrLiteralExpr
*) { return true; }
293 virtual child_iterator
child_begin();
294 virtual child_iterator
child_end();
297 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
298 /// the type_info that corresponds to the supplied type, or the (possibly
299 /// dynamic) type of the supplied expression.
301 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
302 class CXXTypeidExpr
: public Expr
{
304 llvm::PointerUnion
<Stmt
*, TypeSourceInfo
*> Operand
;
308 CXXTypeidExpr(QualType Ty
, TypeSourceInfo
*Operand
, SourceRange R
)
309 : Expr(CXXTypeidExprClass
, Ty
,
310 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
312 // typeid is value-dependent if the type or expression are dependent
313 Operand
->getType()->isDependentType()),
314 Operand(Operand
), Range(R
) { }
316 CXXTypeidExpr(QualType Ty
, Expr
*Operand
, SourceRange R
)
317 : Expr(CXXTypeidExprClass
, Ty
,
318 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
320 // typeid is value-dependent if the type or expression are dependent
321 Operand
->isTypeDependent() || Operand
->isValueDependent()),
322 Operand(Operand
), Range(R
) { }
324 CXXTypeidExpr(EmptyShell Empty
, bool isExpr
)
325 : Expr(CXXTypeidExprClass
, Empty
) {
329 Operand
= (TypeSourceInfo
*)0;
332 bool isTypeOperand() const { return Operand
.is
<TypeSourceInfo
*>(); }
334 /// \brief Retrieves the type operand of this typeid() expression after
335 /// various required adjustments (removing reference types, cv-qualifiers).
336 QualType
getTypeOperand() const;
338 /// \brief Retrieve source information for the type operand.
339 TypeSourceInfo
*getTypeOperandSourceInfo() const {
340 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
341 return Operand
.get
<TypeSourceInfo
*>();
344 void setTypeOperandSourceInfo(TypeSourceInfo
*TSI
) {
345 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
349 Expr
*getExprOperand() const {
350 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
351 return static_cast<Expr
*>(Operand
.get
<Stmt
*>());
354 void setExprOperand(Expr
*E
) {
355 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
359 virtual SourceRange
getSourceRange() const { return Range
; }
360 void setSourceRange(SourceRange R
) { Range
= R
; }
362 static bool classof(const Stmt
*T
) {
363 return T
->getStmtClass() == CXXTypeidExprClass
;
365 static bool classof(const CXXTypeidExpr
*) { return true; }
368 virtual child_iterator
child_begin();
369 virtual child_iterator
child_end();
372 /// CXXThisExpr - Represents the "this" expression in C++, which is a
373 /// pointer to the object on which the current member function is
374 /// executing (C++ [expr.prim]p3). Example:
380 /// void test() { this->bar(); }
383 class CXXThisExpr
: public Expr
{
388 CXXThisExpr(SourceLocation L
, QualType Type
, bool isImplicit
)
389 : Expr(CXXThisExprClass
, Type
,
390 // 'this' is type-dependent if the class type of the enclosing
391 // member function is dependent (C++ [temp.dep.expr]p2)
392 Type
->isDependentType(), Type
->isDependentType()),
393 Loc(L
), Implicit(isImplicit
) { }
395 CXXThisExpr(EmptyShell Empty
) : Expr(CXXThisExprClass
, Empty
) {}
397 SourceLocation
getLocation() const { return Loc
; }
398 void setLocation(SourceLocation L
) { Loc
= L
; }
400 virtual SourceRange
getSourceRange() const { return SourceRange(Loc
); }
402 bool isImplicit() const { return Implicit
; }
403 void setImplicit(bool I
) { Implicit
= I
; }
405 static bool classof(const Stmt
*T
) {
406 return T
->getStmtClass() == CXXThisExprClass
;
408 static bool classof(const CXXThisExpr
*) { return true; }
411 virtual child_iterator
child_begin();
412 virtual child_iterator
child_end();
415 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
416 /// 'throw' and 'throw' assignment-expression. When
417 /// assignment-expression isn't present, Op will be null.
419 class CXXThrowExpr
: public Expr
{
421 SourceLocation ThrowLoc
;
423 // Ty is the void type which is used as the result type of the
424 // exepression. The l is the location of the throw keyword. expr
425 // can by null, if the optional expression to throw isn't present.
426 CXXThrowExpr(Expr
*expr
, QualType Ty
, SourceLocation l
) :
427 Expr(CXXThrowExprClass
, Ty
, false, false), Op(expr
), ThrowLoc(l
) {}
428 CXXThrowExpr(EmptyShell Empty
) : Expr(CXXThrowExprClass
, Empty
) {}
430 const Expr
*getSubExpr() const { return cast_or_null
<Expr
>(Op
); }
431 Expr
*getSubExpr() { return cast_or_null
<Expr
>(Op
); }
432 void setSubExpr(Expr
*E
) { Op
= E
; }
434 SourceLocation
getThrowLoc() const { return ThrowLoc
; }
435 void setThrowLoc(SourceLocation L
) { ThrowLoc
= L
; }
437 virtual SourceRange
getSourceRange() const {
438 if (getSubExpr() == 0)
439 return SourceRange(ThrowLoc
, ThrowLoc
);
440 return SourceRange(ThrowLoc
, getSubExpr()->getSourceRange().getEnd());
443 static bool classof(const Stmt
*T
) {
444 return T
->getStmtClass() == CXXThrowExprClass
;
446 static bool classof(const CXXThrowExpr
*) { return true; }
449 virtual child_iterator
child_begin();
450 virtual child_iterator
child_end();
453 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
454 /// function call argument that was created from the corresponding
455 /// parameter's default argument, when the call did not explicitly
456 /// supply arguments for all of the parameters.
457 class CXXDefaultArgExpr
: public Expr
{
458 /// \brief The parameter whose default is being used.
460 /// When the bit is set, the subexpression is stored after the
461 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
462 /// actual default expression is the subexpression.
463 llvm::PointerIntPair
<ParmVarDecl
*, 1, bool> Param
;
465 /// \brief The location where the default argument expression was used.
469 CXXDefaultArgExpr(StmtClass SC
, SourceLocation Loc
, ParmVarDecl
*param
)
471 param
->hasUnparsedDefaultArg()
472 ? param
->getType().getNonReferenceType()
473 : param
->getDefaultArg()->getType(),
475 Param(param
, false), Loc(Loc
) { }
477 CXXDefaultArgExpr(StmtClass SC
, SourceLocation Loc
, ParmVarDecl
*param
,
479 : Expr(SC
, SubExpr
->getType(), false, false), Param(param
, true), Loc(Loc
) {
480 *reinterpret_cast<Expr
**>(this + 1) = SubExpr
;
484 virtual void DoDestroy(ASTContext
&C
);
487 CXXDefaultArgExpr(EmptyShell Empty
) : Expr(CXXDefaultArgExprClass
, Empty
) {}
490 // Param is the parameter whose default argument is used by this
492 static CXXDefaultArgExpr
*Create(ASTContext
&C
, SourceLocation Loc
,
493 ParmVarDecl
*Param
) {
494 return new (C
) CXXDefaultArgExpr(CXXDefaultArgExprClass
, Loc
, Param
);
497 // Param is the parameter whose default argument is used by this
498 // expression, and SubExpr is the expression that will actually be used.
499 static CXXDefaultArgExpr
*Create(ASTContext
&C
,
504 // Retrieve the parameter that the argument was created from.
505 const ParmVarDecl
*getParam() const { return Param
.getPointer(); }
506 ParmVarDecl
*getParam() { return Param
.getPointer(); }
508 /// isExprStored - Return true if this expression owns the expression.
509 bool isExprStored() const { return Param
.getInt(); }
511 // Retrieve the actual argument to the function call.
512 const Expr
*getExpr() const {
514 return *reinterpret_cast<Expr
const * const*> (this + 1);
515 return getParam()->getDefaultArg();
519 return *reinterpret_cast<Expr
**> (this + 1);
520 return getParam()->getDefaultArg();
523 void setExpr(Expr
*E
) {
525 Param
.setPointer((ParmVarDecl
*)E
);
528 /// \brief Retrieve the location where this default argument was actually
530 SourceLocation
getUsedLocation() const { return Loc
; }
531 void setUsedLocation(SourceLocation L
) { Loc
= L
; }
533 virtual SourceRange
getSourceRange() const {
534 // Default argument expressions have no representation in the
535 // source, so they have an empty source range.
536 return SourceRange();
539 static bool classof(const Stmt
*T
) {
540 return T
->getStmtClass() == CXXDefaultArgExprClass
;
542 static bool classof(const CXXDefaultArgExpr
*) { return true; }
545 virtual child_iterator
child_begin();
546 virtual child_iterator
child_end();
549 /// CXXTemporary - Represents a C++ temporary.
551 /// Destructor - The destructor that needs to be called.
552 const CXXDestructorDecl
*Destructor
;
554 CXXTemporary(const CXXDestructorDecl
*destructor
)
555 : Destructor(destructor
) { }
559 static CXXTemporary
*Create(ASTContext
&C
,
560 const CXXDestructorDecl
*Destructor
);
562 void Destroy(ASTContext
&Ctx
);
564 const CXXDestructorDecl
*getDestructor() const { return Destructor
; }
567 /// \brief Represents binding an expression to a temporary.
569 /// This ensures the destructor is called for the temporary. It should only be
570 /// needed for non-POD, non-trivially destructable class types. For example:
574 /// S() { } // User defined constructor makes S non-POD.
575 /// ~S() { } // User defined destructor makes it non-trivial.
578 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
581 class CXXBindTemporaryExpr
: public Expr
{
586 CXXBindTemporaryExpr(CXXTemporary
*temp
, Expr
* subexpr
)
587 : Expr(CXXBindTemporaryExprClass
, subexpr
->getType(), false, false),
588 Temp(temp
), SubExpr(subexpr
) { }
589 ~CXXBindTemporaryExpr() { }
592 virtual void DoDestroy(ASTContext
&C
);
595 CXXBindTemporaryExpr(EmptyShell Empty
)
596 : Expr(CXXBindTemporaryExprClass
, Empty
), Temp(0), SubExpr(0) {}
598 static CXXBindTemporaryExpr
*Create(ASTContext
&C
, CXXTemporary
*Temp
,
601 CXXTemporary
*getTemporary() { return Temp
; }
602 const CXXTemporary
*getTemporary() const { return Temp
; }
603 void setTemporary(CXXTemporary
*T
) { Temp
= T
; }
605 const Expr
*getSubExpr() const { return cast
<Expr
>(SubExpr
); }
606 Expr
*getSubExpr() { return cast
<Expr
>(SubExpr
); }
607 void setSubExpr(Expr
*E
) { SubExpr
= E
; }
609 virtual SourceRange
getSourceRange() const {
610 return SubExpr
->getSourceRange();
613 // Implement isa/cast/dyncast/etc.
614 static bool classof(const Stmt
*T
) {
615 return T
->getStmtClass() == CXXBindTemporaryExprClass
;
617 static bool classof(const CXXBindTemporaryExpr
*) { return true; }
620 virtual child_iterator
child_begin();
621 virtual child_iterator
child_end();
624 /// CXXBindReferenceExpr - Represents binding an expression to a reference.
627 /// const int &i = 10;
629 /// a bind reference expression is inserted to indicate that 10 is bound to
630 /// a reference, and that a temporary needs to be created to hold the
632 class CXXBindReferenceExpr
: public Expr
{
633 // SubExpr - The expression being bound.
636 // ExtendsLifetime - Whether binding this reference extends the lifetime of
637 // the expression being bound. FIXME: Add C++ reference.
638 bool ExtendsLifetime
;
640 /// RequiresTemporaryCopy - Whether binding the subexpression requires a
642 bool RequiresTemporaryCopy
;
644 CXXBindReferenceExpr(Expr
*subexpr
, bool ExtendsLifetime
,
645 bool RequiresTemporaryCopy
)
646 : Expr(CXXBindReferenceExprClass
, subexpr
->getType(), false, false),
647 SubExpr(subexpr
), ExtendsLifetime(ExtendsLifetime
),
648 RequiresTemporaryCopy(RequiresTemporaryCopy
) { }
649 ~CXXBindReferenceExpr() { }
652 virtual void DoDestroy(ASTContext
&C
);
655 static CXXBindReferenceExpr
*Create(ASTContext
&C
, Expr
*SubExpr
,
656 bool ExtendsLifetime
,
657 bool RequiresTemporaryCopy
);
659 const Expr
*getSubExpr() const { return cast
<Expr
>(SubExpr
); }
660 Expr
*getSubExpr() { return cast
<Expr
>(SubExpr
); }
661 void setSubExpr(Expr
*E
) { SubExpr
= E
; }
663 virtual SourceRange
getSourceRange() const {
664 return SubExpr
->getSourceRange();
667 /// requiresTemporaryCopy - Whether binding the subexpression requires a
669 bool requiresTemporaryCopy() const { return RequiresTemporaryCopy
; }
671 // extendsLifetime - Whether binding this reference extends the lifetime of
672 // the expression being bound. FIXME: Add C++ reference.
673 bool extendsLifetime() { return ExtendsLifetime
; }
675 // Implement isa/cast/dyncast/etc.
676 static bool classof(const Stmt
*T
) {
677 return T
->getStmtClass() == CXXBindReferenceExprClass
;
679 static bool classof(const CXXBindReferenceExpr
*) { return true; }
682 virtual child_iterator
child_begin();
683 virtual child_iterator
child_end();
686 /// CXXConstructExpr - Represents a call to a C++ constructor.
687 class CXXConstructExpr
: public Expr
{
689 enum ConstructionKind
{
696 CXXConstructorDecl
*Constructor
;
700 bool ZeroInitialization
: 1;
701 unsigned ConstructKind
: 2;
706 CXXConstructExpr(ASTContext
&C
, StmtClass SC
, QualType T
,
708 CXXConstructorDecl
*d
, bool elidable
,
709 Expr
**args
, unsigned numargs
,
710 bool ZeroInitialization
= false,
711 ConstructionKind ConstructKind
= CK_Complete
);
712 ~CXXConstructExpr() { }
714 virtual void DoDestroy(ASTContext
&C
);
717 /// \brief Construct an empty C++ construction expression that will store
718 /// \p numargs arguments.
719 CXXConstructExpr(EmptyShell Empty
, ASTContext
&C
, unsigned numargs
);
721 static CXXConstructExpr
*Create(ASTContext
&C
, QualType T
,
723 CXXConstructorDecl
*D
, bool Elidable
,
724 Expr
**Args
, unsigned NumArgs
,
725 bool ZeroInitialization
= false,
726 ConstructionKind ConstructKind
= CK_Complete
);
729 CXXConstructorDecl
* getConstructor() const { return Constructor
; }
730 void setConstructor(CXXConstructorDecl
*C
) { Constructor
= C
; }
732 SourceLocation
getLocation() const { return Loc
; }
733 void setLocation(SourceLocation Loc
) { this->Loc
= Loc
; }
735 /// \brief Whether this construction is elidable.
736 bool isElidable() const { return Elidable
; }
737 void setElidable(bool E
) { Elidable
= E
; }
739 /// \brief Whether this construction first requires
740 /// zero-initialization before the initializer is called.
741 bool requiresZeroInitialization() const { return ZeroInitialization
; }
742 void setRequiresZeroInitialization(bool ZeroInit
) {
743 ZeroInitialization
= ZeroInit
;
746 /// \brief Determines whether this constructor is actually constructing
747 /// a base class (rather than a complete object).
748 ConstructionKind
getConstructionKind() const {
749 return (ConstructionKind
)ConstructKind
;
751 void setConstructionKind(ConstructionKind CK
) {
755 typedef ExprIterator arg_iterator
;
756 typedef ConstExprIterator const_arg_iterator
;
758 arg_iterator
arg_begin() { return Args
; }
759 arg_iterator
arg_end() { return Args
+ NumArgs
; }
760 const_arg_iterator
arg_begin() const { return Args
; }
761 const_arg_iterator
arg_end() const { return Args
+ NumArgs
; }
763 Expr
**getArgs() const { return reinterpret_cast<Expr
**>(Args
); }
764 unsigned getNumArgs() const { return NumArgs
; }
766 /// getArg - Return the specified argument.
767 Expr
*getArg(unsigned Arg
) {
768 assert(Arg
< NumArgs
&& "Arg access out of range!");
769 return cast
<Expr
>(Args
[Arg
]);
771 const Expr
*getArg(unsigned Arg
) const {
772 assert(Arg
< NumArgs
&& "Arg access out of range!");
773 return cast
<Expr
>(Args
[Arg
]);
776 /// setArg - Set the specified argument.
777 void setArg(unsigned Arg
, Expr
*ArgExpr
) {
778 assert(Arg
< NumArgs
&& "Arg access out of range!");
782 virtual SourceRange
getSourceRange() const;
784 static bool classof(const Stmt
*T
) {
785 return T
->getStmtClass() == CXXConstructExprClass
||
786 T
->getStmtClass() == CXXTemporaryObjectExprClass
;
788 static bool classof(const CXXConstructExpr
*) { return true; }
791 virtual child_iterator
child_begin();
792 virtual child_iterator
child_end();
795 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
796 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
798 class CXXFunctionalCastExpr
: public ExplicitCastExpr
{
799 SourceLocation TyBeginLoc
;
800 SourceLocation RParenLoc
;
802 CXXFunctionalCastExpr(QualType ty
, TypeSourceInfo
*writtenTy
,
803 SourceLocation tyBeginLoc
, CastKind kind
,
804 Expr
*castExpr
, CXXBaseSpecifierArray BasePath
,
805 SourceLocation rParenLoc
)
806 : ExplicitCastExpr(CXXFunctionalCastExprClass
, ty
, kind
, castExpr
,
807 BasePath
, writtenTy
),
808 TyBeginLoc(tyBeginLoc
), RParenLoc(rParenLoc
) {}
810 explicit CXXFunctionalCastExpr(EmptyShell Shell
)
811 : ExplicitCastExpr(CXXFunctionalCastExprClass
, Shell
) { }
813 SourceLocation
getTypeBeginLoc() const { return TyBeginLoc
; }
814 void setTypeBeginLoc(SourceLocation L
) { TyBeginLoc
= L
; }
815 SourceLocation
getRParenLoc() const { return RParenLoc
; }
816 void setRParenLoc(SourceLocation L
) { RParenLoc
= L
; }
818 virtual SourceRange
getSourceRange() const {
819 return SourceRange(TyBeginLoc
, RParenLoc
);
821 static bool classof(const Stmt
*T
) {
822 return T
->getStmtClass() == CXXFunctionalCastExprClass
;
824 static bool classof(const CXXFunctionalCastExpr
*) { return true; }
827 /// @brief Represents a C++ functional cast expression that builds a
828 /// temporary object.
830 /// This expression type represents a C++ "functional" cast
831 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
832 /// constructor to build a temporary object. If N == 0 but no
833 /// constructor will be called (because the functional cast is
834 /// performing a value-initialized an object whose class type has no
835 /// user-declared constructors), CXXZeroInitValueExpr will represent
836 /// the functional cast. Finally, with N == 1 arguments the functional
837 /// cast expression will be represented by CXXFunctionalCastExpr.
840 /// struct X { X(int, float); }
843 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
846 class CXXTemporaryObjectExpr
: public CXXConstructExpr
{
847 SourceLocation TyBeginLoc
;
848 SourceLocation RParenLoc
;
851 CXXTemporaryObjectExpr(ASTContext
&C
, CXXConstructorDecl
*Cons
,
852 QualType writtenTy
, SourceLocation tyBeginLoc
,
853 Expr
**Args
,unsigned NumArgs
,
854 SourceLocation rParenLoc
,
855 bool ZeroInitialization
= false);
857 ~CXXTemporaryObjectExpr() { }
859 SourceLocation
getTypeBeginLoc() const { return TyBeginLoc
; }
860 SourceLocation
getRParenLoc() const { return RParenLoc
; }
862 virtual SourceRange
getSourceRange() const {
863 return SourceRange(TyBeginLoc
, RParenLoc
);
865 static bool classof(const Stmt
*T
) {
866 return T
->getStmtClass() == CXXTemporaryObjectExprClass
;
868 static bool classof(const CXXTemporaryObjectExpr
*) { return true; }
871 /// CXXZeroInitValueExpr - [C++ 5.2.3p2]
872 /// Expression "T()" which creates a value-initialized rvalue of type
873 /// T, which is either a non-class type or a class type without any
874 /// user-defined constructors.
876 class CXXZeroInitValueExpr
: public Expr
{
877 SourceLocation TyBeginLoc
;
878 SourceLocation RParenLoc
;
881 CXXZeroInitValueExpr(QualType ty
, SourceLocation tyBeginLoc
,
882 SourceLocation rParenLoc
) :
883 Expr(CXXZeroInitValueExprClass
, ty
, false, false),
884 TyBeginLoc(tyBeginLoc
), RParenLoc(rParenLoc
) {}
885 explicit CXXZeroInitValueExpr(EmptyShell Shell
)
886 : Expr(CXXZeroInitValueExprClass
, Shell
) { }
888 SourceLocation
getTypeBeginLoc() const { return TyBeginLoc
; }
889 SourceLocation
getRParenLoc() const { return RParenLoc
; }
891 void setTypeBeginLoc(SourceLocation L
) { TyBeginLoc
= L
; }
892 void setRParenLoc(SourceLocation L
) { RParenLoc
= L
; }
894 /// @brief Whether this initialization expression was
895 /// implicitly-generated.
896 bool isImplicit() const {
897 return TyBeginLoc
.isInvalid() && RParenLoc
.isInvalid();
900 virtual SourceRange
getSourceRange() const {
901 return SourceRange(TyBeginLoc
, RParenLoc
);
904 static bool classof(const Stmt
*T
) {
905 return T
->getStmtClass() == CXXZeroInitValueExprClass
;
907 static bool classof(const CXXZeroInitValueExpr
*) { return true; }
910 virtual child_iterator
child_begin();
911 virtual child_iterator
child_end();
914 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
915 /// e.g: "new CXXNewExpr(foo)".
916 class CXXNewExpr
: public Expr
{
917 // Was the usage ::new, i.e. is the global new to be used?
919 // Was the form (type-id) used? Otherwise, it was new-type-id.
920 bool ParenTypeId
: 1;
921 // Is there an initializer? If not, built-ins are uninitialized, else they're
922 // value-initialized.
923 bool Initializer
: 1;
924 // Do we allocate an array? If so, the first SubExpr is the size expression.
926 // The number of placement new arguments.
927 unsigned NumPlacementArgs
: 14;
928 // The number of constructor arguments. This may be 1 even for non-class
929 // types; use the pseudo copy constructor.
930 unsigned NumConstructorArgs
: 14;
931 // Contains an optional array size expression, any number of optional
932 // placement arguments, and any number of optional constructor arguments,
935 // Points to the allocation function used.
936 FunctionDecl
*OperatorNew
;
937 // Points to the deallocation function used in case of error. May be null.
938 FunctionDecl
*OperatorDelete
;
939 // Points to the constructor used. Cannot be null if AllocType is a record;
940 // it would still point at the default constructor (even an implicit one).
941 // Must be null for all other types.
942 CXXConstructorDecl
*Constructor
;
944 SourceLocation StartLoc
;
945 SourceLocation EndLoc
;
948 CXXNewExpr(ASTContext
&C
, bool globalNew
, FunctionDecl
*operatorNew
,
949 Expr
**placementArgs
, unsigned numPlaceArgs
, bool ParenTypeId
,
950 Expr
*arraySize
, CXXConstructorDecl
*constructor
, bool initializer
,
951 Expr
**constructorArgs
, unsigned numConsArgs
,
952 FunctionDecl
*operatorDelete
, QualType ty
,
953 SourceLocation startLoc
, SourceLocation endLoc
);
954 explicit CXXNewExpr(EmptyShell Shell
)
955 : Expr(CXXNewExprClass
, Shell
), SubExprs(0) { }
957 void AllocateArgsArray(ASTContext
&C
, bool isArray
, unsigned numPlaceArgs
,
958 unsigned numConsArgs
);
960 virtual void DoDestroy(ASTContext
&C
);
962 QualType
getAllocatedType() const {
963 assert(getType()->isPointerType());
964 return getType()->getAs
<PointerType
>()->getPointeeType();
967 FunctionDecl
*getOperatorNew() const { return OperatorNew
; }
968 void setOperatorNew(FunctionDecl
*D
) { OperatorNew
= D
; }
969 FunctionDecl
*getOperatorDelete() const { return OperatorDelete
; }
970 void setOperatorDelete(FunctionDecl
*D
) { OperatorDelete
= D
; }
971 CXXConstructorDecl
*getConstructor() const { return Constructor
; }
972 void setConstructor(CXXConstructorDecl
*D
) { Constructor
= D
; }
974 bool isArray() const { return Array
; }
975 Expr
*getArraySize() {
976 return Array
? cast
<Expr
>(SubExprs
[0]) : 0;
978 const Expr
*getArraySize() const {
979 return Array
? cast
<Expr
>(SubExprs
[0]) : 0;
982 unsigned getNumPlacementArgs() const { return NumPlacementArgs
; }
983 Expr
*getPlacementArg(unsigned i
) {
984 assert(i
< NumPlacementArgs
&& "Index out of range");
985 return cast
<Expr
>(SubExprs
[Array
+ i
]);
987 const Expr
*getPlacementArg(unsigned i
) const {
988 assert(i
< NumPlacementArgs
&& "Index out of range");
989 return cast
<Expr
>(SubExprs
[Array
+ i
]);
992 bool isGlobalNew() const { return GlobalNew
; }
993 void setGlobalNew(bool V
) { GlobalNew
= V
; }
994 bool isParenTypeId() const { return ParenTypeId
; }
995 void setParenTypeId(bool V
) { ParenTypeId
= V
; }
996 bool hasInitializer() const { return Initializer
; }
997 void setHasInitializer(bool V
) { Initializer
= V
; }
999 unsigned getNumConstructorArgs() const { return NumConstructorArgs
; }
1000 Expr
*getConstructorArg(unsigned i
) {
1001 assert(i
< NumConstructorArgs
&& "Index out of range");
1002 return cast
<Expr
>(SubExprs
[Array
+ NumPlacementArgs
+ i
]);
1004 const Expr
*getConstructorArg(unsigned i
) const {
1005 assert(i
< NumConstructorArgs
&& "Index out of range");
1006 return cast
<Expr
>(SubExprs
[Array
+ NumPlacementArgs
+ i
]);
1009 typedef ExprIterator arg_iterator
;
1010 typedef ConstExprIterator const_arg_iterator
;
1012 arg_iterator
placement_arg_begin() {
1013 return SubExprs
+ Array
;
1015 arg_iterator
placement_arg_end() {
1016 return SubExprs
+ Array
+ getNumPlacementArgs();
1018 const_arg_iterator
placement_arg_begin() const {
1019 return SubExprs
+ Array
;
1021 const_arg_iterator
placement_arg_end() const {
1022 return SubExprs
+ Array
+ getNumPlacementArgs();
1025 arg_iterator
constructor_arg_begin() {
1026 return SubExprs
+ Array
+ getNumPlacementArgs();
1028 arg_iterator
constructor_arg_end() {
1029 return SubExprs
+ Array
+ getNumPlacementArgs() + getNumConstructorArgs();
1031 const_arg_iterator
constructor_arg_begin() const {
1032 return SubExprs
+ Array
+ getNumPlacementArgs();
1034 const_arg_iterator
constructor_arg_end() const {
1035 return SubExprs
+ Array
+ getNumPlacementArgs() + getNumConstructorArgs();
1038 typedef Stmt
**raw_arg_iterator
;
1039 raw_arg_iterator
raw_arg_begin() { return SubExprs
; }
1040 raw_arg_iterator
raw_arg_end() {
1041 return SubExprs
+ Array
+ getNumPlacementArgs() + getNumConstructorArgs();
1043 const_arg_iterator
raw_arg_begin() const { return SubExprs
; }
1044 const_arg_iterator
raw_arg_end() const { return constructor_arg_end(); }
1047 SourceLocation
getStartLoc() const { return StartLoc
; }
1048 void setStartLoc(SourceLocation L
) { StartLoc
= L
; }
1049 SourceLocation
getEndLoc() const { return EndLoc
; }
1050 void setEndLoc(SourceLocation L
) { EndLoc
= L
; }
1052 virtual SourceRange
getSourceRange() const {
1053 return SourceRange(StartLoc
, EndLoc
);
1056 static bool classof(const Stmt
*T
) {
1057 return T
->getStmtClass() == CXXNewExprClass
;
1059 static bool classof(const CXXNewExpr
*) { return true; }
1062 virtual child_iterator
child_begin();
1063 virtual child_iterator
child_end();
1066 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1067 /// calls, e.g. "delete[] pArray".
1068 class CXXDeleteExpr
: public Expr
{
1069 // Is this a forced global delete, i.e. "::delete"?
1070 bool GlobalDelete
: 1;
1071 // Is this the array form of delete, i.e. "delete[]"?
1073 // Points to the operator delete overload that is used. Could be a member.
1074 FunctionDecl
*OperatorDelete
;
1075 // The pointer expression to be deleted.
1077 // Location of the expression.
1080 CXXDeleteExpr(QualType ty
, bool globalDelete
, bool arrayForm
,
1081 FunctionDecl
*operatorDelete
, Expr
*arg
, SourceLocation loc
)
1082 : Expr(CXXDeleteExprClass
, ty
, false, false), GlobalDelete(globalDelete
),
1083 ArrayForm(arrayForm
), OperatorDelete(operatorDelete
), Argument(arg
),
1085 explicit CXXDeleteExpr(EmptyShell Shell
)
1086 : Expr(CXXDeleteExprClass
, Shell
), OperatorDelete(0), Argument(0) { }
1088 bool isGlobalDelete() const { return GlobalDelete
; }
1089 bool isArrayForm() const { return ArrayForm
; }
1091 void setGlobalDelete(bool V
) { GlobalDelete
= V
; }
1092 void setArrayForm(bool V
) { ArrayForm
= V
; }
1094 FunctionDecl
*getOperatorDelete() const { return OperatorDelete
; }
1095 void setOperatorDelete(FunctionDecl
*D
) { OperatorDelete
= D
; }
1097 Expr
*getArgument() { return cast
<Expr
>(Argument
); }
1098 const Expr
*getArgument() const { return cast
<Expr
>(Argument
); }
1099 void setArgument(Expr
*E
) { Argument
= E
; }
1101 virtual SourceRange
getSourceRange() const {
1102 return SourceRange(Loc
, Argument
->getLocEnd());
1104 void setStartLoc(SourceLocation L
) { Loc
= L
; }
1106 static bool classof(const Stmt
*T
) {
1107 return T
->getStmtClass() == CXXDeleteExprClass
;
1109 static bool classof(const CXXDeleteExpr
*) { return true; }
1112 virtual child_iterator
child_begin();
1113 virtual child_iterator
child_end();
1116 /// \brief Structure used to store the type being destroyed by a
1117 /// pseudo-destructor expression.
1118 class PseudoDestructorTypeStorage
{
1119 /// \brief Either the type source information or the name of the type, if
1120 /// it couldn't be resolved due to type-dependence.
1121 llvm::PointerUnion
<TypeSourceInfo
*, IdentifierInfo
*> Type
;
1123 /// \brief The starting source location of the pseudo-destructor type.
1124 SourceLocation Location
;
1127 PseudoDestructorTypeStorage() { }
1129 PseudoDestructorTypeStorage(IdentifierInfo
*II
, SourceLocation Loc
)
1130 : Type(II
), Location(Loc
) { }
1132 PseudoDestructorTypeStorage(TypeSourceInfo
*Info
);
1134 TypeSourceInfo
*getTypeSourceInfo() const {
1135 return Type
.dyn_cast
<TypeSourceInfo
*>();
1138 IdentifierInfo
*getIdentifier() const {
1139 return Type
.dyn_cast
<IdentifierInfo
*>();
1142 SourceLocation
getLocation() const { return Location
; }
1145 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1147 /// A pseudo-destructor is an expression that looks like a member access to a
1148 /// destructor of a scalar type, except that scalar types don't have
1149 /// destructors. For example:
1153 /// void f(int *p) {
1158 /// Pseudo-destructors typically occur when instantiating templates such as:
1161 /// template<typename T>
1162 /// void destroy(T* ptr) {
1167 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1168 /// beyond evaluating the base expression.
1169 class CXXPseudoDestructorExpr
: public Expr
{
1170 /// \brief The base expression (that is being destroyed).
1173 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1177 /// \brief The location of the '.' or '->' operator.
1178 SourceLocation OperatorLoc
;
1180 /// \brief The nested-name-specifier that follows the operator, if present.
1181 NestedNameSpecifier
*Qualifier
;
1183 /// \brief The source range that covers the nested-name-specifier, if
1185 SourceRange QualifierRange
;
1187 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1189 TypeSourceInfo
*ScopeType
;
1191 /// \brief The location of the '::' in a qualified pseudo-destructor
1193 SourceLocation ColonColonLoc
;
1195 /// \brief The location of the '~'.
1196 SourceLocation TildeLoc
;
1198 /// \brief The type being destroyed, or its name if we were unable to
1199 /// resolve the name.
1200 PseudoDestructorTypeStorage DestroyedType
;
1203 CXXPseudoDestructorExpr(ASTContext
&Context
,
1204 Expr
*Base
, bool isArrow
, SourceLocation OperatorLoc
,
1205 NestedNameSpecifier
*Qualifier
,
1206 SourceRange QualifierRange
,
1207 TypeSourceInfo
*ScopeType
,
1208 SourceLocation ColonColonLoc
,
1209 SourceLocation TildeLoc
,
1210 PseudoDestructorTypeStorage DestroyedType
)
1211 : Expr(CXXPseudoDestructorExprClass
,
1212 Context
.getPointerType(Context
.getFunctionType(Context
.VoidTy
, 0, 0,
1215 FunctionType::ExtInfo())),
1216 /*isTypeDependent=*/(Base
->isTypeDependent() ||
1217 (DestroyedType
.getTypeSourceInfo() &&
1218 DestroyedType
.getTypeSourceInfo()->getType()->isDependentType())),
1219 /*isValueDependent=*/Base
->isValueDependent()),
1220 Base(static_cast<Stmt
*>(Base
)), IsArrow(isArrow
),
1221 OperatorLoc(OperatorLoc
), Qualifier(Qualifier
),
1222 QualifierRange(QualifierRange
),
1223 ScopeType(ScopeType
), ColonColonLoc(ColonColonLoc
), TildeLoc(TildeLoc
),
1224 DestroyedType(DestroyedType
) { }
1226 void setBase(Expr
*E
) { Base
= E
; }
1227 Expr
*getBase() const { return cast
<Expr
>(Base
); }
1229 /// \brief Determines whether this member expression actually had
1230 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1232 bool hasQualifier() const { return Qualifier
!= 0; }
1234 /// \brief If the member name was qualified, retrieves the source range of
1235 /// the nested-name-specifier that precedes the member name. Otherwise,
1236 /// returns an empty source range.
1237 SourceRange
getQualifierRange() const { return QualifierRange
; }
1239 /// \brief If the member name was qualified, retrieves the
1240 /// nested-name-specifier that precedes the member name. Otherwise, returns
1242 NestedNameSpecifier
*getQualifier() const { return Qualifier
; }
1244 /// \brief Determine whether this pseudo-destructor expression was written
1245 /// using an '->' (otherwise, it used a '.').
1246 bool isArrow() const { return IsArrow
; }
1247 void setArrow(bool A
) { IsArrow
= A
; }
1249 /// \brief Retrieve the location of the '.' or '->' operator.
1250 SourceLocation
getOperatorLoc() const { return OperatorLoc
; }
1252 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1255 /// Pseudo-destructor expressions can have extra qualification within them
1256 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1257 /// Here, if the object type of the expression is (or may be) a scalar type,
1258 /// \p T may also be a scalar type and, therefore, cannot be part of a
1259 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1260 /// destructor expression.
1261 TypeSourceInfo
*getScopeTypeInfo() const { return ScopeType
; }
1263 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1265 SourceLocation
getColonColonLoc() const { return ColonColonLoc
; }
1267 /// \brief Retrieve the location of the '~'.
1268 SourceLocation
getTildeLoc() const { return TildeLoc
; }
1270 /// \brief Retrieve the source location information for the type
1271 /// being destroyed.
1273 /// This type-source information is available for non-dependent
1274 /// pseudo-destructor expressions and some dependent pseudo-destructor
1275 /// expressions. Returns NULL if we only have the identifier for a
1276 /// dependent pseudo-destructor expression.
1277 TypeSourceInfo
*getDestroyedTypeInfo() const {
1278 return DestroyedType
.getTypeSourceInfo();
1281 /// \brief In a dependent pseudo-destructor expression for which we do not
1282 /// have full type information on the destroyed type, provides the name
1283 /// of the destroyed type.
1284 IdentifierInfo
*getDestroyedTypeIdentifier() const {
1285 return DestroyedType
.getIdentifier();
1288 /// \brief Retrieve the type being destroyed.
1289 QualType
getDestroyedType() const;
1291 /// \brief Retrieve the starting location of the type being destroyed.
1292 SourceLocation
getDestroyedTypeLoc() const {
1293 return DestroyedType
.getLocation();
1296 virtual SourceRange
getSourceRange() const;
1298 static bool classof(const Stmt
*T
) {
1299 return T
->getStmtClass() == CXXPseudoDestructorExprClass
;
1301 static bool classof(const CXXPseudoDestructorExpr
*) { return true; }
1304 virtual child_iterator
child_begin();
1305 virtual child_iterator
child_end();
1308 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1309 /// implementation of TR1/C++0x type trait templates.
1311 /// __is_pod(int) == true
1312 /// __is_enum(std::string) == false
1313 class UnaryTypeTraitExpr
: public Expr
{
1314 /// UTT - The trait.
1317 /// Loc - The location of the type trait keyword.
1320 /// RParen - The location of the closing paren.
1321 SourceLocation RParen
;
1323 /// QueriedType - The type we're testing.
1324 QualType QueriedType
;
1327 UnaryTypeTraitExpr(SourceLocation loc
, UnaryTypeTrait utt
, QualType queried
,
1328 SourceLocation rparen
, QualType ty
)
1329 : Expr(UnaryTypeTraitExprClass
, ty
, false, queried
->isDependentType()),
1330 UTT(utt
), Loc(loc
), RParen(rparen
), QueriedType(queried
) { }
1332 virtual SourceRange
getSourceRange() const { return SourceRange(Loc
, RParen
);}
1334 UnaryTypeTrait
getTrait() const { return UTT
; }
1336 QualType
getQueriedType() const { return QueriedType
; }
1338 bool EvaluateTrait(ASTContext
&) const;
1340 static bool classof(const Stmt
*T
) {
1341 return T
->getStmtClass() == UnaryTypeTraitExprClass
;
1343 static bool classof(const UnaryTypeTraitExpr
*) { return true; }
1346 virtual child_iterator
child_begin();
1347 virtual child_iterator
child_end();
1350 /// \brief A reference to an overloaded function set, either an
1351 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1352 class OverloadExpr
: public Expr
{
1353 /// The results. These are undesugared, which is to say, they may
1354 /// include UsingShadowDecls. Access is relative to the naming
1356 // FIXME: Allocate this data after the OverloadExpr subclass.
1357 DeclAccessPair
*Results
;
1358 unsigned NumResults
;
1360 /// The common name of these declarations.
1361 DeclarationName Name
;
1363 /// The scope specifier, if any.
1364 NestedNameSpecifier
*Qualifier
;
1366 /// The source range of the scope specifier.
1367 SourceRange QualifierRange
;
1369 /// The location of the name.
1370 SourceLocation NameLoc
;
1373 /// True if the name was a template-id.
1374 bool HasExplicitTemplateArgs
;
1376 OverloadExpr(StmtClass K
, ASTContext
&C
, QualType T
, bool Dependent
,
1377 NestedNameSpecifier
*Qualifier
, SourceRange QRange
,
1378 DeclarationName Name
, SourceLocation NameLoc
,
1379 bool HasTemplateArgs
,
1380 UnresolvedSetIterator Begin
, UnresolvedSetIterator End
);
1382 OverloadExpr(StmtClass K
, EmptyShell Empty
)
1383 : Expr(K
, Empty
), Results(0), NumResults(0),
1384 Qualifier(0), HasExplicitTemplateArgs(false) { }
1387 /// Computes whether an unresolved lookup on the given declarations
1388 /// and optional template arguments is type- and value-dependent.
1389 static bool ComputeDependence(UnresolvedSetIterator Begin
,
1390 UnresolvedSetIterator End
,
1391 const TemplateArgumentListInfo
*Args
);
1393 /// Finds the overloaded expression in the given expression of
1396 /// \return the expression (which must be there) and true if it is
1397 /// within an address-of operator.
1398 static llvm::PointerIntPair
<OverloadExpr
*,1> find(Expr
*E
) {
1399 assert(E
->getType()->isSpecificBuiltinType(BuiltinType::Overload
));
1402 E
= E
->IgnoreParens();
1403 if (isa
<UnaryOperator
>(E
))
1404 op
= true, E
= cast
<UnaryOperator
>(E
)->getSubExpr()->IgnoreParens();
1405 return llvm::PointerIntPair
<OverloadExpr
*,1>(cast
<OverloadExpr
>(E
), op
);
1408 /// Gets the naming class of this lookup, if any.
1409 CXXRecordDecl
*getNamingClass() const;
1411 typedef UnresolvedSetImpl::iterator decls_iterator
;
1412 decls_iterator
decls_begin() const { return UnresolvedSetIterator(Results
); }
1413 decls_iterator
decls_end() const {
1414 return UnresolvedSetIterator(Results
+ NumResults
);
1417 void initializeResults(ASTContext
&C
,
1418 UnresolvedSetIterator Begin
,UnresolvedSetIterator End
);
1420 /// Gets the number of declarations in the unresolved set.
1421 unsigned getNumDecls() const { return NumResults
; }
1423 /// Gets the name looked up.
1424 DeclarationName
getName() const { return Name
; }
1425 void setName(DeclarationName N
) { Name
= N
; }
1427 /// Gets the location of the name.
1428 SourceLocation
getNameLoc() const { return NameLoc
; }
1429 void setNameLoc(SourceLocation Loc
) { NameLoc
= Loc
; }
1431 /// Fetches the nested-name qualifier, if one was given.
1432 NestedNameSpecifier
*getQualifier() const { return Qualifier
; }
1433 void setQualifier(NestedNameSpecifier
*NNS
) { Qualifier
= NNS
; }
1435 /// Fetches the range of the nested-name qualifier.
1436 SourceRange
getQualifierRange() const { return QualifierRange
; }
1437 void setQualifierRange(SourceRange R
) { QualifierRange
= R
; }
1439 /// \brief Determines whether this expression had an explicit
1440 /// template argument list, e.g. f<int>.
1441 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs
; }
1443 ExplicitTemplateArgumentList
&getExplicitTemplateArgs(); // defined far below
1445 const ExplicitTemplateArgumentList
&getExplicitTemplateArgs() const {
1446 return const_cast<OverloadExpr
*>(this)->getExplicitTemplateArgs();
1449 ExplicitTemplateArgumentList
*getOptionalExplicitTemplateArgs() {
1450 if (hasExplicitTemplateArgs())
1451 return &getExplicitTemplateArgs();
1455 static bool classof(const Stmt
*T
) {
1456 return T
->getStmtClass() == UnresolvedLookupExprClass
||
1457 T
->getStmtClass() == UnresolvedMemberExprClass
;
1459 static bool classof(const OverloadExpr
*) { return true; }
1462 /// \brief A reference to a name which we were able to look up during
1463 /// parsing but could not resolve to a specific declaration. This
1464 /// arises in several ways:
1465 /// * we might be waiting for argument-dependent lookup
1466 /// * the name might resolve to an overloaded function
1468 /// * the lookup might have included a function template
1469 /// These never include UnresolvedUsingValueDecls, which are always
1470 /// class members and therefore appear only in
1471 /// UnresolvedMemberLookupExprs.
1472 class UnresolvedLookupExpr
: public OverloadExpr
{
1473 /// True if these lookup results should be extended by
1474 /// argument-dependent lookup if this is the operand of a function
1478 /// True if these lookup results are overloaded. This is pretty
1479 /// trivially rederivable if we urgently need to kill this field.
1482 /// The naming class (C++ [class.access.base]p5) of the lookup, if
1483 /// any. This can generally be recalculated from the context chain,
1484 /// but that can be fairly expensive for unqualified lookups. If we
1485 /// want to improve memory use here, this could go in a union
1486 /// against the qualified-lookup bits.
1487 CXXRecordDecl
*NamingClass
;
1489 UnresolvedLookupExpr(ASTContext
&C
, QualType T
, bool Dependent
,
1490 CXXRecordDecl
*NamingClass
,
1491 NestedNameSpecifier
*Qualifier
, SourceRange QRange
,
1492 DeclarationName Name
, SourceLocation NameLoc
,
1493 bool RequiresADL
, bool Overloaded
, bool HasTemplateArgs
,
1494 UnresolvedSetIterator Begin
, UnresolvedSetIterator End
)
1495 : OverloadExpr(UnresolvedLookupExprClass
, C
, T
, Dependent
, Qualifier
,
1496 QRange
, Name
, NameLoc
, HasTemplateArgs
, Begin
, End
),
1497 RequiresADL(RequiresADL
), Overloaded(Overloaded
), NamingClass(NamingClass
)
1501 static UnresolvedLookupExpr
*Create(ASTContext
&C
,
1503 CXXRecordDecl
*NamingClass
,
1504 NestedNameSpecifier
*Qualifier
,
1505 SourceRange QualifierRange
,
1506 DeclarationName Name
,
1507 SourceLocation NameLoc
,
1508 bool ADL
, bool Overloaded
,
1509 UnresolvedSetIterator Begin
,
1510 UnresolvedSetIterator End
) {
1511 return new(C
) UnresolvedLookupExpr(C
,
1512 Dependent
? C
.DependentTy
: C
.OverloadTy
,
1513 Dependent
, NamingClass
,
1514 Qualifier
, QualifierRange
,
1515 Name
, NameLoc
, ADL
, Overloaded
, false,
1519 static UnresolvedLookupExpr
*Create(ASTContext
&C
,
1521 CXXRecordDecl
*NamingClass
,
1522 NestedNameSpecifier
*Qualifier
,
1523 SourceRange QualifierRange
,
1524 DeclarationName Name
,
1525 SourceLocation NameLoc
,
1527 const TemplateArgumentListInfo
&Args
,
1528 UnresolvedSetIterator Begin
,
1529 UnresolvedSetIterator End
);
1531 /// True if this declaration should be extended by
1532 /// argument-dependent lookup.
1533 bool requiresADL() const { return RequiresADL
; }
1535 /// True if this lookup is overloaded.
1536 bool isOverloaded() const { return Overloaded
; }
1538 /// Gets the 'naming class' (in the sense of C++0x
1539 /// [class.access.base]p5) of the lookup. This is the scope
1540 /// that was looked in to find these results.
1541 CXXRecordDecl
*getNamingClass() const { return NamingClass
; }
1543 // Note that, inconsistently with the explicit-template-argument AST
1544 // nodes, users are *forbidden* from calling these methods on objects
1545 // without explicit template arguments.
1547 ExplicitTemplateArgumentList
&getExplicitTemplateArgs() {
1548 assert(hasExplicitTemplateArgs());
1549 return *reinterpret_cast<ExplicitTemplateArgumentList
*>(this + 1);
1552 /// Gets a reference to the explicit template argument list.
1553 const ExplicitTemplateArgumentList
&getExplicitTemplateArgs() const {
1554 assert(hasExplicitTemplateArgs());
1555 return *reinterpret_cast<const ExplicitTemplateArgumentList
*>(this + 1);
1558 /// \brief Copies the template arguments (if present) into the given
1560 void copyTemplateArgumentsInto(TemplateArgumentListInfo
&List
) const {
1561 getExplicitTemplateArgs().copyInto(List
);
1564 SourceLocation
getLAngleLoc() const {
1565 return getExplicitTemplateArgs().LAngleLoc
;
1568 SourceLocation
getRAngleLoc() const {
1569 return getExplicitTemplateArgs().RAngleLoc
;
1572 TemplateArgumentLoc
const *getTemplateArgs() const {
1573 return getExplicitTemplateArgs().getTemplateArgs();
1576 unsigned getNumTemplateArgs() const {
1577 return getExplicitTemplateArgs().NumTemplateArgs
;
1580 virtual SourceRange
getSourceRange() const {
1581 SourceRange
Range(getNameLoc());
1582 if (getQualifier()) Range
.setBegin(getQualifierRange().getBegin());
1583 if (hasExplicitTemplateArgs()) Range
.setEnd(getRAngleLoc());
1587 virtual StmtIterator
child_begin();
1588 virtual StmtIterator
child_end();
1590 static bool classof(const Stmt
*T
) {
1591 return T
->getStmtClass() == UnresolvedLookupExprClass
;
1593 static bool classof(const UnresolvedLookupExpr
*) { return true; }
1596 /// \brief A qualified reference to a name whose declaration cannot
1597 /// yet be resolved.
1599 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1600 /// it expresses a reference to a declaration such as
1601 /// X<T>::value. The difference, however, is that an
1602 /// DependentScopeDeclRefExpr node is used only within C++ templates when
1603 /// the qualification (e.g., X<T>::) refers to a dependent type. In
1604 /// this case, X<T>::value cannot resolve to a declaration because the
1605 /// declaration will differ from on instantiation of X<T> to the
1606 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1607 /// qualifier (X<T>::) and the name of the entity being referenced
1608 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1609 /// declaration can be found.
1610 class DependentScopeDeclRefExpr
: public Expr
{
1611 /// The name of the entity we will be referencing.
1612 DeclarationName Name
;
1614 /// Location of the name of the declaration we're referencing.
1617 /// QualifierRange - The source range that covers the
1618 /// nested-name-specifier.
1619 SourceRange QualifierRange
;
1621 /// \brief The nested-name-specifier that qualifies this unresolved
1622 /// declaration name.
1623 NestedNameSpecifier
*Qualifier
;
1625 /// \brief Whether the name includes explicit template arguments.
1626 bool HasExplicitTemplateArgs
;
1628 DependentScopeDeclRefExpr(QualType T
,
1629 NestedNameSpecifier
*Qualifier
,
1630 SourceRange QualifierRange
,
1631 DeclarationName Name
,
1632 SourceLocation NameLoc
,
1633 bool HasExplicitTemplateArgs
)
1634 : Expr(DependentScopeDeclRefExprClass
, T
, true, true),
1635 Name(Name
), Loc(NameLoc
),
1636 QualifierRange(QualifierRange
), Qualifier(Qualifier
),
1637 HasExplicitTemplateArgs(HasExplicitTemplateArgs
)
1641 static DependentScopeDeclRefExpr
*Create(ASTContext
&C
,
1642 NestedNameSpecifier
*Qualifier
,
1643 SourceRange QualifierRange
,
1644 DeclarationName Name
,
1645 SourceLocation NameLoc
,
1646 const TemplateArgumentListInfo
*TemplateArgs
= 0);
1648 /// \brief Retrieve the name that this expression refers to.
1649 DeclarationName
getDeclName() const { return Name
; }
1651 /// \brief Retrieve the location of the name within the expression.
1652 SourceLocation
getLocation() const { return Loc
; }
1654 /// \brief Retrieve the source range of the nested-name-specifier.
1655 SourceRange
getQualifierRange() const { return QualifierRange
; }
1657 /// \brief Retrieve the nested-name-specifier that qualifies this
1659 NestedNameSpecifier
*getQualifier() const { return Qualifier
; }
1661 /// Determines whether this lookup had explicit template arguments.
1662 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs
; }
1664 // Note that, inconsistently with the explicit-template-argument AST
1665 // nodes, users are *forbidden* from calling these methods on objects
1666 // without explicit template arguments.
1668 /// Gets a reference to the explicit template argument list.
1669 const ExplicitTemplateArgumentList
&getExplicitTemplateArgs() const {
1670 assert(hasExplicitTemplateArgs());
1671 return *reinterpret_cast<const ExplicitTemplateArgumentList
*>(this + 1);
1674 /// \brief Copies the template arguments (if present) into the given
1676 void copyTemplateArgumentsInto(TemplateArgumentListInfo
&List
) const {
1677 getExplicitTemplateArgs().copyInto(List
);
1680 SourceLocation
getLAngleLoc() const {
1681 return getExplicitTemplateArgs().LAngleLoc
;
1684 SourceLocation
getRAngleLoc() const {
1685 return getExplicitTemplateArgs().RAngleLoc
;
1688 TemplateArgumentLoc
const *getTemplateArgs() const {
1689 return getExplicitTemplateArgs().getTemplateArgs();
1692 unsigned getNumTemplateArgs() const {
1693 return getExplicitTemplateArgs().NumTemplateArgs
;
1696 virtual SourceRange
getSourceRange() const {
1697 SourceRange
Range(QualifierRange
.getBegin(), getLocation());
1698 if (hasExplicitTemplateArgs())
1699 Range
.setEnd(getRAngleLoc());
1703 static bool classof(const Stmt
*T
) {
1704 return T
->getStmtClass() == DependentScopeDeclRefExprClass
;
1706 static bool classof(const DependentScopeDeclRefExpr
*) { return true; }
1708 virtual StmtIterator
child_begin();
1709 virtual StmtIterator
child_end();
1712 class CXXExprWithTemporaries
: public Expr
{
1715 CXXTemporary
**Temps
;
1718 CXXExprWithTemporaries(ASTContext
&C
, Expr
*SubExpr
, CXXTemporary
**Temps
,
1720 ~CXXExprWithTemporaries();
1723 virtual void DoDestroy(ASTContext
&C
);
1726 CXXExprWithTemporaries(EmptyShell Empty
)
1727 : Expr(CXXExprWithTemporariesClass
, Empty
),
1728 SubExpr(0), Temps(0), NumTemps(0) {}
1730 static CXXExprWithTemporaries
*Create(ASTContext
&C
, Expr
*SubExpr
,
1731 CXXTemporary
**Temps
,
1734 unsigned getNumTemporaries() const { return NumTemps
; }
1735 void setNumTemporaries(ASTContext
&C
, unsigned N
);
1737 CXXTemporary
*getTemporary(unsigned i
) {
1738 assert(i
< NumTemps
&& "Index out of range");
1741 const CXXTemporary
*getTemporary(unsigned i
) const {
1742 return const_cast<CXXExprWithTemporaries
*>(this)->getTemporary(i
);
1744 void setTemporary(unsigned i
, CXXTemporary
*T
) {
1745 assert(i
< NumTemps
&& "Index out of range");
1749 Expr
*getSubExpr() { return cast
<Expr
>(SubExpr
); }
1750 const Expr
*getSubExpr() const { return cast
<Expr
>(SubExpr
); }
1751 void setSubExpr(Expr
*E
) { SubExpr
= E
; }
1753 virtual SourceRange
getSourceRange() const {
1754 return SubExpr
->getSourceRange();
1757 // Implement isa/cast/dyncast/etc.
1758 static bool classof(const Stmt
*T
) {
1759 return T
->getStmtClass() == CXXExprWithTemporariesClass
;
1761 static bool classof(const CXXExprWithTemporaries
*) { return true; }
1764 virtual child_iterator
child_begin();
1765 virtual child_iterator
child_end();
1768 /// \brief Describes an explicit type conversion that uses functional
1769 /// notion but could not be resolved because one or more arguments are
1772 /// The explicit type conversions expressed by
1773 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1774 /// where \c T is some type and \c a1, a2, ..., aN are values, and
1775 /// either \C T is a dependent type or one or more of the \c a's is
1776 /// type-dependent. For example, this would occur in a template such
1780 /// template<typename T, typename A1>
1781 /// inline T make_a(const A1& a1) {
1786 /// When the returned expression is instantiated, it may resolve to a
1787 /// constructor call, conversion function call, or some kind of type
1789 class CXXUnresolvedConstructExpr
: public Expr
{
1790 /// \brief The starting location of the type
1791 SourceLocation TyBeginLoc
;
1793 /// \brief The type being constructed.
1796 /// \brief The location of the left parentheses ('(').
1797 SourceLocation LParenLoc
;
1799 /// \brief The location of the right parentheses (')').
1800 SourceLocation RParenLoc
;
1802 /// \brief The number of arguments used to construct the type.
1805 CXXUnresolvedConstructExpr(SourceLocation TyBegin
,
1807 SourceLocation LParenLoc
,
1810 SourceLocation RParenLoc
);
1812 CXXUnresolvedConstructExpr(EmptyShell Empty
, unsigned NumArgs
)
1813 : Expr(CXXUnresolvedConstructExprClass
, Empty
), NumArgs(NumArgs
) { }
1816 static CXXUnresolvedConstructExpr
*Create(ASTContext
&C
,
1817 SourceLocation TyBegin
,
1819 SourceLocation LParenLoc
,
1822 SourceLocation RParenLoc
);
1824 static CXXUnresolvedConstructExpr
*CreateEmpty(ASTContext
&C
,
1827 /// \brief Retrieve the source location where the type begins.
1828 SourceLocation
getTypeBeginLoc() const { return TyBeginLoc
; }
1829 void setTypeBeginLoc(SourceLocation L
) { TyBeginLoc
= L
; }
1831 /// \brief Retrieve the type that is being constructed, as specified
1832 /// in the source code.
1833 QualType
getTypeAsWritten() const { return Type
; }
1834 void setTypeAsWritten(QualType T
) { Type
= T
; }
1836 /// \brief Retrieve the location of the left parentheses ('(') that
1837 /// precedes the argument list.
1838 SourceLocation
getLParenLoc() const { return LParenLoc
; }
1839 void setLParenLoc(SourceLocation L
) { LParenLoc
= L
; }
1841 /// \brief Retrieve the location of the right parentheses (')') that
1842 /// follows the argument list.
1843 SourceLocation
getRParenLoc() const { return RParenLoc
; }
1844 void setRParenLoc(SourceLocation L
) { RParenLoc
= L
; }
1846 /// \brief Retrieve the number of arguments.
1847 unsigned arg_size() const { return NumArgs
; }
1849 typedef Expr
** arg_iterator
;
1850 arg_iterator
arg_begin() { return reinterpret_cast<Expr
**>(this + 1); }
1851 arg_iterator
arg_end() { return arg_begin() + NumArgs
; }
1853 typedef const Expr
* const * const_arg_iterator
;
1854 const_arg_iterator
arg_begin() const {
1855 return reinterpret_cast<const Expr
* const *>(this + 1);
1857 const_arg_iterator
arg_end() const {
1858 return arg_begin() + NumArgs
;
1861 Expr
*getArg(unsigned I
) {
1862 assert(I
< NumArgs
&& "Argument index out-of-range");
1863 return *(arg_begin() + I
);
1866 const Expr
*getArg(unsigned I
) const {
1867 assert(I
< NumArgs
&& "Argument index out-of-range");
1868 return *(arg_begin() + I
);
1871 void setArg(unsigned I
, Expr
*E
) {
1872 assert(I
< NumArgs
&& "Argument index out-of-range");
1873 *(arg_begin() + I
) = E
;
1876 virtual SourceRange
getSourceRange() const {
1877 return SourceRange(TyBeginLoc
, RParenLoc
);
1879 static bool classof(const Stmt
*T
) {
1880 return T
->getStmtClass() == CXXUnresolvedConstructExprClass
;
1882 static bool classof(const CXXUnresolvedConstructExpr
*) { return true; }
1885 virtual child_iterator
child_begin();
1886 virtual child_iterator
child_end();
1889 /// \brief Represents a C++ member access expression where the actual
1890 /// member referenced could not be resolved because the base
1891 /// expression or the member name was dependent.
1893 /// Like UnresolvedMemberExprs, these can be either implicit or
1894 /// explicit accesses. It is only possible to get one of these with
1895 /// an implicit access if a qualifier is provided.
1896 class CXXDependentScopeMemberExpr
: public Expr
{
1897 /// \brief The expression for the base pointer or class reference,
1898 /// e.g., the \c x in x.f. Can be null in implicit accesses.
1901 /// \brief The type of the base expression. Never null, even for
1902 /// implicit accesses.
1905 /// \brief Whether this member expression used the '->' operator or
1906 /// the '.' operator.
1909 /// \brief Whether this member expression has explicitly-specified template
1911 bool HasExplicitTemplateArgs
: 1;
1913 /// \brief The location of the '->' or '.' operator.
1914 SourceLocation OperatorLoc
;
1916 /// \brief The nested-name-specifier that precedes the member name, if any.
1917 NestedNameSpecifier
*Qualifier
;
1919 /// \brief The source range covering the nested name specifier.
1920 SourceRange QualifierRange
;
1922 /// \brief In a qualified member access expression such as t->Base::f, this
1923 /// member stores the resolves of name lookup in the context of the member
1924 /// access expression, to be used at instantiation time.
1926 /// FIXME: This member, along with the Qualifier and QualifierRange, could
1927 /// be stuck into a structure that is optionally allocated at the end of
1928 /// the CXXDependentScopeMemberExpr, to save space in the common case.
1929 NamedDecl
*FirstQualifierFoundInScope
;
1931 /// \brief The member to which this member expression refers, which
1932 /// can be name, overloaded operator, or destructor.
1933 /// FIXME: could also be a template-id
1934 DeclarationName Member
;
1936 /// \brief The location of the member name.
1937 SourceLocation MemberLoc
;
1939 /// \brief Retrieve the explicit template argument list that followed the
1940 /// member template name, if any.
1941 ExplicitTemplateArgumentList
*getExplicitTemplateArgumentList() {
1942 assert(HasExplicitTemplateArgs
);
1943 return reinterpret_cast<ExplicitTemplateArgumentList
*>(this + 1);
1946 /// \brief Retrieve the explicit template argument list that followed the
1947 /// member template name, if any.
1948 const ExplicitTemplateArgumentList
*getExplicitTemplateArgumentList() const {
1949 return const_cast<CXXDependentScopeMemberExpr
*>(this)
1950 ->getExplicitTemplateArgumentList();
1953 CXXDependentScopeMemberExpr(ASTContext
&C
,
1954 Expr
*Base
, QualType BaseType
, bool IsArrow
,
1955 SourceLocation OperatorLoc
,
1956 NestedNameSpecifier
*Qualifier
,
1957 SourceRange QualifierRange
,
1958 NamedDecl
*FirstQualifierFoundInScope
,
1959 DeclarationName Member
,
1960 SourceLocation MemberLoc
,
1961 const TemplateArgumentListInfo
*TemplateArgs
);
1964 CXXDependentScopeMemberExpr(ASTContext
&C
,
1965 Expr
*Base
, QualType BaseType
,
1967 SourceLocation OperatorLoc
,
1968 NestedNameSpecifier
*Qualifier
,
1969 SourceRange QualifierRange
,
1970 NamedDecl
*FirstQualifierFoundInScope
,
1971 DeclarationName Member
,
1972 SourceLocation MemberLoc
)
1973 : Expr(CXXDependentScopeMemberExprClass
, C
.DependentTy
, true, true),
1974 Base(Base
), BaseType(BaseType
), IsArrow(IsArrow
),
1975 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc
),
1976 Qualifier(Qualifier
), QualifierRange(QualifierRange
),
1977 FirstQualifierFoundInScope(FirstQualifierFoundInScope
),
1978 Member(Member
), MemberLoc(MemberLoc
) { }
1980 static CXXDependentScopeMemberExpr
*
1981 Create(ASTContext
&C
,
1982 Expr
*Base
, QualType BaseType
, bool IsArrow
,
1983 SourceLocation OperatorLoc
,
1984 NestedNameSpecifier
*Qualifier
,
1985 SourceRange QualifierRange
,
1986 NamedDecl
*FirstQualifierFoundInScope
,
1987 DeclarationName Member
,
1988 SourceLocation MemberLoc
,
1989 const TemplateArgumentListInfo
*TemplateArgs
);
1991 static CXXDependentScopeMemberExpr
*
1992 CreateEmpty(ASTContext
&C
, unsigned NumTemplateArgs
);
1994 /// \brief True if this is an implicit access, i.e. one in which the
1995 /// member being accessed was not written in the source. The source
1996 /// location of the operator is invalid in this case.
1997 bool isImplicitAccess() const { return Base
== 0; }
1999 /// \brief Retrieve the base object of this member expressions,
2000 /// e.g., the \c x in \c x.m.
2001 Expr
*getBase() const {
2002 assert(!isImplicitAccess());
2003 return cast
<Expr
>(Base
);
2005 void setBase(Expr
*E
) { Base
= E
; }
2007 QualType
getBaseType() const { return BaseType
; }
2008 void setBaseType(QualType T
) { BaseType
= T
; }
2010 /// \brief Determine whether this member expression used the '->'
2011 /// operator; otherwise, it used the '.' operator.
2012 bool isArrow() const { return IsArrow
; }
2013 void setArrow(bool A
) { IsArrow
= A
; }
2015 /// \brief Retrieve the location of the '->' or '.' operator.
2016 SourceLocation
getOperatorLoc() const { return OperatorLoc
; }
2017 void setOperatorLoc(SourceLocation L
) { OperatorLoc
= L
; }
2019 /// \brief Retrieve the nested-name-specifier that qualifies the member
2021 NestedNameSpecifier
*getQualifier() const { return Qualifier
; }
2022 void setQualifier(NestedNameSpecifier
*NNS
) { Qualifier
= NNS
; }
2024 /// \brief Retrieve the source range covering the nested-name-specifier
2025 /// that qualifies the member name.
2026 SourceRange
getQualifierRange() const { return QualifierRange
; }
2027 void setQualifierRange(SourceRange R
) { QualifierRange
= R
; }
2029 /// \brief Retrieve the first part of the nested-name-specifier that was
2030 /// found in the scope of the member access expression when the member access
2031 /// was initially parsed.
2033 /// This function only returns a useful result when member access expression
2034 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2035 /// returned by this function describes what was found by unqualified name
2036 /// lookup for the identifier "Base" within the scope of the member access
2037 /// expression itself. At template instantiation time, this information is
2038 /// combined with the results of name lookup into the type of the object
2039 /// expression itself (the class type of x).
2040 NamedDecl
*getFirstQualifierFoundInScope() const {
2041 return FirstQualifierFoundInScope
;
2043 void setFirstQualifierFoundInScope(NamedDecl
*D
) {
2044 FirstQualifierFoundInScope
= D
;
2047 /// \brief Retrieve the name of the member that this expression
2049 DeclarationName
getMember() const { return Member
; }
2050 void setMember(DeclarationName N
) { Member
= N
; }
2052 // \brief Retrieve the location of the name of the member that this
2053 // expression refers to.
2054 SourceLocation
getMemberLoc() const { return MemberLoc
; }
2055 void setMemberLoc(SourceLocation L
) { MemberLoc
= L
; }
2057 /// \brief Determines whether this member expression actually had a C++
2058 /// template argument list explicitly specified, e.g., x.f<int>.
2059 bool hasExplicitTemplateArgs() const {
2060 return HasExplicitTemplateArgs
;
2063 /// \brief Copies the template arguments (if present) into the given
2065 void copyTemplateArgumentsInto(TemplateArgumentListInfo
&List
) const {
2066 assert(HasExplicitTemplateArgs
);
2067 getExplicitTemplateArgumentList()->copyInto(List
);
2070 /// \brief Initializes the template arguments using the given structure.
2071 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo
&List
) {
2072 assert(HasExplicitTemplateArgs
);
2073 getExplicitTemplateArgumentList()->initializeFrom(List
);
2076 /// \brief Retrieve the location of the left angle bracket following the
2077 /// member name ('<'), if any.
2078 SourceLocation
getLAngleLoc() const {
2079 assert(HasExplicitTemplateArgs
);
2080 return getExplicitTemplateArgumentList()->LAngleLoc
;
2083 /// \brief Retrieve the template arguments provided as part of this
2085 const TemplateArgumentLoc
*getTemplateArgs() const {
2086 assert(HasExplicitTemplateArgs
);
2087 return getExplicitTemplateArgumentList()->getTemplateArgs();
2090 /// \brief Retrieve the number of template arguments provided as part of this
2092 unsigned getNumTemplateArgs() const {
2093 assert(HasExplicitTemplateArgs
);
2094 return getExplicitTemplateArgumentList()->NumTemplateArgs
;
2097 /// \brief Retrieve the location of the right angle bracket following the
2098 /// template arguments ('>').
2099 SourceLocation
getRAngleLoc() const {
2100 assert(HasExplicitTemplateArgs
);
2101 return getExplicitTemplateArgumentList()->RAngleLoc
;
2104 virtual SourceRange
getSourceRange() const {
2106 if (!isImplicitAccess())
2107 Range
.setBegin(Base
->getSourceRange().getBegin());
2108 else if (getQualifier())
2109 Range
.setBegin(getQualifierRange().getBegin());
2111 Range
.setBegin(MemberLoc
);
2113 if (hasExplicitTemplateArgs())
2114 Range
.setEnd(getRAngleLoc());
2116 Range
.setEnd(MemberLoc
);
2120 static bool classof(const Stmt
*T
) {
2121 return T
->getStmtClass() == CXXDependentScopeMemberExprClass
;
2123 static bool classof(const CXXDependentScopeMemberExpr
*) { return true; }
2126 virtual child_iterator
child_begin();
2127 virtual child_iterator
child_end();
2130 /// \brief Represents a C++ member access expression for which lookup
2131 /// produced a set of overloaded functions.
2133 /// The member access may be explicit or implicit:
2136 /// int explicitAccess() { return this->a + this->A::b; }
2137 /// int implicitAccess() { return a + A::b; }
2140 /// In the final AST, an explicit access always becomes a MemberExpr.
2141 /// An implicit access may become either a MemberExpr or a
2142 /// DeclRefExpr, depending on whether the member is static.
2143 class UnresolvedMemberExpr
: public OverloadExpr
{
2144 /// \brief Whether this member expression used the '->' operator or
2145 /// the '.' operator.
2148 /// \brief Whether the lookup results contain an unresolved using
2150 bool HasUnresolvedUsing
: 1;
2152 /// \brief The expression for the base pointer or class reference,
2153 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
2154 /// member expression
2157 /// \brief The type of the base expression; never null.
2160 /// \brief The location of the '->' or '.' operator.
2161 SourceLocation OperatorLoc
;
2163 UnresolvedMemberExpr(ASTContext
&C
, QualType T
, bool Dependent
,
2164 bool HasUnresolvedUsing
,
2165 Expr
*Base
, QualType BaseType
, bool IsArrow
,
2166 SourceLocation OperatorLoc
,
2167 NestedNameSpecifier
*Qualifier
,
2168 SourceRange QualifierRange
,
2169 DeclarationName Member
,
2170 SourceLocation MemberLoc
,
2171 const TemplateArgumentListInfo
*TemplateArgs
,
2172 UnresolvedSetIterator Begin
, UnresolvedSetIterator End
);
2174 UnresolvedMemberExpr(EmptyShell Empty
)
2175 : OverloadExpr(UnresolvedMemberExprClass
, Empty
), IsArrow(false),
2176 HasUnresolvedUsing(false), Base(0) { }
2179 static UnresolvedMemberExpr
*
2180 Create(ASTContext
&C
, bool Dependent
, bool HasUnresolvedUsing
,
2181 Expr
*Base
, QualType BaseType
, bool IsArrow
,
2182 SourceLocation OperatorLoc
,
2183 NestedNameSpecifier
*Qualifier
,
2184 SourceRange QualifierRange
,
2185 DeclarationName Member
,
2186 SourceLocation MemberLoc
,
2187 const TemplateArgumentListInfo
*TemplateArgs
,
2188 UnresolvedSetIterator Begin
, UnresolvedSetIterator End
);
2190 static UnresolvedMemberExpr
*
2191 CreateEmpty(ASTContext
&C
, unsigned NumTemplateArgs
);
2193 /// \brief True if this is an implicit access, i.e. one in which the
2194 /// member being accessed was not written in the source. The source
2195 /// location of the operator is invalid in this case.
2196 bool isImplicitAccess() const { return Base
== 0; }
2198 /// \brief Retrieve the base object of this member expressions,
2199 /// e.g., the \c x in \c x.m.
2201 assert(!isImplicitAccess());
2202 return cast
<Expr
>(Base
);
2204 const Expr
*getBase() const {
2205 assert(!isImplicitAccess());
2206 return cast
<Expr
>(Base
);
2208 void setBase(Expr
*E
) { Base
= E
; }
2210 QualType
getBaseType() const { return BaseType
; }
2211 void setBaseType(QualType T
) { BaseType
= T
; }
2213 /// \brief Determine whether the lookup results contain an unresolved using
2215 bool hasUnresolvedUsing() const { return HasUnresolvedUsing
; }
2216 void setHasUnresolvedUsing(bool V
) { HasUnresolvedUsing
= V
; }
2218 /// \brief Determine whether this member expression used the '->'
2219 /// operator; otherwise, it used the '.' operator.
2220 bool isArrow() const { return IsArrow
; }
2221 void setArrow(bool A
) { IsArrow
= A
; }
2223 /// \brief Retrieve the location of the '->' or '.' operator.
2224 SourceLocation
getOperatorLoc() const { return OperatorLoc
; }
2225 void setOperatorLoc(SourceLocation L
) { OperatorLoc
= L
; }
2227 /// \brief Retrieves the naming class of this lookup.
2228 CXXRecordDecl
*getNamingClass() const;
2230 /// \brief Retrieve the name of the member that this expression
2232 DeclarationName
getMemberName() const { return getName(); }
2233 void setMemberName(DeclarationName N
) { setName(N
); }
2235 // \brief Retrieve the location of the name of the member that this
2236 // expression refers to.
2237 SourceLocation
getMemberLoc() const { return getNameLoc(); }
2238 void setMemberLoc(SourceLocation L
) { setNameLoc(L
); }
2240 /// \brief Retrieve the explicit template argument list that followed the
2241 /// member template name.
2242 ExplicitTemplateArgumentList
&getExplicitTemplateArgs() {
2243 assert(hasExplicitTemplateArgs());
2244 return *reinterpret_cast<ExplicitTemplateArgumentList
*>(this + 1);
2247 /// \brief Retrieve the explicit template argument list that followed the
2248 /// member template name, if any.
2249 const ExplicitTemplateArgumentList
&getExplicitTemplateArgs() const {
2250 assert(hasExplicitTemplateArgs());
2251 return *reinterpret_cast<const ExplicitTemplateArgumentList
*>(this + 1);
2254 /// \brief Copies the template arguments into the given structure.
2255 void copyTemplateArgumentsInto(TemplateArgumentListInfo
&List
) const {
2256 getExplicitTemplateArgs().copyInto(List
);
2259 /// \brief Retrieve the location of the left angle bracket following
2260 /// the member name ('<').
2261 SourceLocation
getLAngleLoc() const {
2262 return getExplicitTemplateArgs().LAngleLoc
;
2265 /// \brief Retrieve the template arguments provided as part of this
2267 const TemplateArgumentLoc
*getTemplateArgs() const {
2268 return getExplicitTemplateArgs().getTemplateArgs();
2271 /// \brief Retrieve the number of template arguments provided as
2272 /// part of this template-id.
2273 unsigned getNumTemplateArgs() const {
2274 return getExplicitTemplateArgs().NumTemplateArgs
;
2277 /// \brief Retrieve the location of the right angle bracket
2278 /// following the template arguments ('>').
2279 SourceLocation
getRAngleLoc() const {
2280 return getExplicitTemplateArgs().RAngleLoc
;
2283 virtual SourceRange
getSourceRange() const {
2285 if (!isImplicitAccess())
2286 Range
.setBegin(Base
->getSourceRange().getBegin());
2287 else if (getQualifier())
2288 Range
.setBegin(getQualifierRange().getBegin());
2290 Range
.setBegin(getMemberLoc());
2292 if (hasExplicitTemplateArgs())
2293 Range
.setEnd(getRAngleLoc());
2295 Range
.setEnd(getMemberLoc());
2299 static bool classof(const Stmt
*T
) {
2300 return T
->getStmtClass() == UnresolvedMemberExprClass
;
2302 static bool classof(const UnresolvedMemberExpr
*) { return true; }
2305 virtual child_iterator
child_begin();
2306 virtual child_iterator
child_end();
2309 inline ExplicitTemplateArgumentList
&OverloadExpr::getExplicitTemplateArgs() {
2310 if (isa
<UnresolvedLookupExpr
>(this))
2311 return cast
<UnresolvedLookupExpr
>(this)->getExplicitTemplateArgs();
2313 return cast
<UnresolvedMemberExpr
>(this)->getExplicitTemplateArgs();
2316 } // end namespace clang