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 unsigned PathSize, TypeSourceInfo *writtenTy,
126 : ExplicitCastExpr(SC, ty, kind, op, PathSize, writtenTy), Loc(l) {}
128 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
129 : ExplicitCastExpr(SC, Shell, PathSize) { }
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 {
161 CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op,
162 unsigned pathSize, TypeSourceInfo *writtenTy,
164 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, pathSize,
167 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
168 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
171 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
172 CastKind K, Expr *Op,
173 const CXXCastPath *Path,
174 TypeSourceInfo *Written, SourceLocation L);
175 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
178 static bool classof(const Stmt *T) {
179 return T->getStmtClass() == CXXStaticCastExprClass;
181 static bool classof(const CXXStaticCastExpr *) { return true; }
184 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
185 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
186 /// determine how to perform the type cast.
188 /// This expression node represents a dynamic cast, e.g.,
189 /// @c dynamic_cast<Derived*>(BasePtr).
190 class CXXDynamicCastExpr : public CXXNamedCastExpr {
191 CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op,
192 unsigned pathSize, TypeSourceInfo *writtenTy,
194 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, pathSize,
197 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
198 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
201 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
202 CastKind Kind, Expr *Op,
203 const CXXCastPath *Path,
204 TypeSourceInfo *Written, SourceLocation L);
206 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
209 static bool classof(const Stmt *T) {
210 return T->getStmtClass() == CXXDynamicCastExprClass;
212 static bool classof(const CXXDynamicCastExpr *) { return true; }
215 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
216 /// [expr.reinterpret.cast]), which provides a differently-typed view
217 /// of a value but performs no actual work at run time.
219 /// This expression node represents a reinterpret cast, e.g.,
220 /// @c reinterpret_cast<int>(VoidPtr).
221 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
222 CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op,
224 TypeSourceInfo *writtenTy, SourceLocation l)
225 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, pathSize,
228 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
229 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
232 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
233 CastKind Kind, Expr *Op,
234 const CXXCastPath *Path,
235 TypeSourceInfo *WrittenTy, SourceLocation L);
236 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
239 static bool classof(const Stmt *T) {
240 return T->getStmtClass() == CXXReinterpretCastExprClass;
242 static bool classof(const CXXReinterpretCastExpr *) { return true; }
245 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
246 /// which can remove type qualifiers but does not change the underlying value.
248 /// This expression node represents a const cast, e.g.,
249 /// @c const_cast<char*>(PtrToConstChar).
250 class CXXConstCastExpr : public CXXNamedCastExpr {
251 CXXConstCastExpr(QualType ty, Expr *op, TypeSourceInfo *writtenTy,
253 : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op,
256 explicit CXXConstCastExpr(EmptyShell Empty)
257 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
260 static CXXConstCastExpr *Create(ASTContext &Context, QualType T, Expr *Op,
261 TypeSourceInfo *WrittenTy, SourceLocation L);
262 static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
264 static bool classof(const Stmt *T) {
265 return T->getStmtClass() == CXXConstCastExprClass;
267 static bool classof(const CXXConstCastExpr *) { return true; }
270 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
272 class CXXBoolLiteralExpr : public Expr {
276 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
277 Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
279 explicit CXXBoolLiteralExpr(EmptyShell Empty)
280 : Expr(CXXBoolLiteralExprClass, Empty) { }
282 bool getValue() const { return Value; }
283 void setValue(bool V) { Value = V; }
285 virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
287 SourceLocation getLocation() const { return Loc; }
288 void setLocation(SourceLocation L) { Loc = L; }
290 static bool classof(const Stmt *T) {
291 return T->getStmtClass() == CXXBoolLiteralExprClass;
293 static bool classof(const CXXBoolLiteralExpr *) { return true; }
296 virtual child_iterator child_begin();
297 virtual child_iterator child_end();
300 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
301 class CXXNullPtrLiteralExpr : public Expr {
304 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
305 Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
307 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
308 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
310 virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
312 SourceLocation getLocation() const { return Loc; }
313 void setLocation(SourceLocation L) { Loc = L; }
315 static bool classof(const Stmt *T) {
316 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
318 static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
320 virtual child_iterator child_begin();
321 virtual child_iterator child_end();
324 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
325 /// the type_info that corresponds to the supplied type, or the (possibly
326 /// dynamic) type of the supplied expression.
328 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
329 class CXXTypeidExpr : public Expr {
331 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
335 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
336 : Expr(CXXTypeidExprClass, Ty,
337 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
339 // typeid is value-dependent if the type or expression are dependent
340 Operand->getType()->isDependentType()),
341 Operand(Operand), Range(R) { }
343 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
344 : Expr(CXXTypeidExprClass, Ty,
345 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
347 // typeid is value-dependent if the type or expression are dependent
348 Operand->isTypeDependent() || Operand->isValueDependent()),
349 Operand(Operand), Range(R) { }
351 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
352 : Expr(CXXTypeidExprClass, Empty) {
356 Operand = (TypeSourceInfo*)0;
359 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
361 /// \brief Retrieves the type operand of this typeid() expression after
362 /// various required adjustments (removing reference types, cv-qualifiers).
363 QualType getTypeOperand() const;
365 /// \brief Retrieve source information for the type operand.
366 TypeSourceInfo *getTypeOperandSourceInfo() const {
367 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
368 return Operand.get<TypeSourceInfo *>();
371 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
372 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
376 Expr *getExprOperand() const {
377 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
378 return static_cast<Expr*>(Operand.get<Stmt *>());
381 void setExprOperand(Expr *E) {
382 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
386 virtual SourceRange getSourceRange() const { return Range; }
387 void setSourceRange(SourceRange R) { Range = R; }
389 static bool classof(const Stmt *T) {
390 return T->getStmtClass() == CXXTypeidExprClass;
392 static bool classof(const CXXTypeidExpr *) { return true; }
395 virtual child_iterator child_begin();
396 virtual child_iterator child_end();
399 /// CXXThisExpr - Represents the "this" expression in C++, which is a
400 /// pointer to the object on which the current member function is
401 /// executing (C++ [expr.prim]p3). Example:
407 /// void test() { this->bar(); }
410 class CXXThisExpr : public Expr {
415 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
416 : Expr(CXXThisExprClass, Type,
417 // 'this' is type-dependent if the class type of the enclosing
418 // member function is dependent (C++ [temp.dep.expr]p2)
419 Type->isDependentType(), Type->isDependentType()),
420 Loc(L), Implicit(isImplicit) { }
422 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
424 SourceLocation getLocation() const { return Loc; }
425 void setLocation(SourceLocation L) { Loc = L; }
427 virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
429 bool isImplicit() const { return Implicit; }
430 void setImplicit(bool I) { Implicit = I; }
432 static bool classof(const Stmt *T) {
433 return T->getStmtClass() == CXXThisExprClass;
435 static bool classof(const CXXThisExpr *) { return true; }
438 virtual child_iterator child_begin();
439 virtual child_iterator child_end();
442 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
443 /// 'throw' and 'throw' assignment-expression. When
444 /// assignment-expression isn't present, Op will be null.
446 class CXXThrowExpr : public Expr {
448 SourceLocation ThrowLoc;
450 // Ty is the void type which is used as the result type of the
451 // exepression. The l is the location of the throw keyword. expr
452 // can by null, if the optional expression to throw isn't present.
453 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
454 Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
455 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
457 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
458 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
459 void setSubExpr(Expr *E) { Op = E; }
461 SourceLocation getThrowLoc() const { return ThrowLoc; }
462 void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
464 virtual SourceRange getSourceRange() const {
465 if (getSubExpr() == 0)
466 return SourceRange(ThrowLoc, ThrowLoc);
467 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
470 static bool classof(const Stmt *T) {
471 return T->getStmtClass() == CXXThrowExprClass;
473 static bool classof(const CXXThrowExpr *) { return true; }
476 virtual child_iterator child_begin();
477 virtual child_iterator child_end();
480 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
481 /// function call argument that was created from the corresponding
482 /// parameter's default argument, when the call did not explicitly
483 /// supply arguments for all of the parameters.
484 class CXXDefaultArgExpr : public Expr {
485 /// \brief The parameter whose default is being used.
487 /// When the bit is set, the subexpression is stored after the
488 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
489 /// actual default expression is the subexpression.
490 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
492 /// \brief The location where the default argument expression was used.
495 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
497 param->hasUnparsedDefaultArg()
498 ? param->getType().getNonReferenceType()
499 : param->getDefaultArg()->getType(),
501 Param(param, false), Loc(Loc) { }
503 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
505 : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc) {
506 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
510 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
513 // Param is the parameter whose default argument is used by this
515 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
516 ParmVarDecl *Param) {
517 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
520 // Param is the parameter whose default argument is used by this
521 // expression, and SubExpr is the expression that will actually be used.
522 static CXXDefaultArgExpr *Create(ASTContext &C,
527 // Retrieve the parameter that the argument was created from.
528 const ParmVarDecl *getParam() const { return Param.getPointer(); }
529 ParmVarDecl *getParam() { return Param.getPointer(); }
531 // Retrieve the actual argument to the function call.
532 const Expr *getExpr() const {
534 return *reinterpret_cast<Expr const * const*> (this + 1);
535 return getParam()->getDefaultArg();
539 return *reinterpret_cast<Expr **> (this + 1);
540 return getParam()->getDefaultArg();
543 /// \brief Retrieve the location where this default argument was actually
545 SourceLocation getUsedLocation() const { return Loc; }
547 virtual SourceRange getSourceRange() const {
548 // Default argument expressions have no representation in the
549 // source, so they have an empty source range.
550 return SourceRange();
553 static bool classof(const Stmt *T) {
554 return T->getStmtClass() == CXXDefaultArgExprClass;
556 static bool classof(const CXXDefaultArgExpr *) { return true; }
559 virtual child_iterator child_begin();
560 virtual child_iterator child_end();
562 friend class ASTStmtReader;
563 friend class ASTStmtWriter;
566 /// CXXTemporary - Represents a C++ temporary.
568 /// Destructor - The destructor that needs to be called.
569 const CXXDestructorDecl *Destructor;
571 CXXTemporary(const CXXDestructorDecl *destructor)
572 : Destructor(destructor) { }
575 static CXXTemporary *Create(ASTContext &C,
576 const CXXDestructorDecl *Destructor);
578 const CXXDestructorDecl *getDestructor() const { return Destructor; }
581 /// \brief Represents binding an expression to a temporary.
583 /// This ensures the destructor is called for the temporary. It should only be
584 /// needed for non-POD, non-trivially destructable class types. For example:
588 /// S() { } // User defined constructor makes S non-POD.
589 /// ~S() { } // User defined destructor makes it non-trivial.
592 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
595 class CXXBindTemporaryExpr : public Expr {
600 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
601 : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false),
602 Temp(temp), SubExpr(subexpr) { }
605 CXXBindTemporaryExpr(EmptyShell Empty)
606 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
608 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
611 CXXTemporary *getTemporary() { return Temp; }
612 const CXXTemporary *getTemporary() const { return Temp; }
613 void setTemporary(CXXTemporary *T) { Temp = T; }
615 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
616 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
617 void setSubExpr(Expr *E) { SubExpr = E; }
619 virtual SourceRange getSourceRange() const {
620 return SubExpr->getSourceRange();
623 // Implement isa/cast/dyncast/etc.
624 static bool classof(const Stmt *T) {
625 return T->getStmtClass() == CXXBindTemporaryExprClass;
627 static bool classof(const CXXBindTemporaryExpr *) { return true; }
630 virtual child_iterator child_begin();
631 virtual child_iterator child_end();
634 /// CXXConstructExpr - Represents a call to a C++ constructor.
635 class CXXConstructExpr : public Expr {
637 enum ConstructionKind {
644 CXXConstructorDecl *Constructor;
648 bool ZeroInitialization : 1;
649 unsigned ConstructKind : 2;
654 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
656 CXXConstructorDecl *d, bool elidable,
657 Expr **args, unsigned numargs,
658 bool ZeroInitialization = false,
659 ConstructionKind ConstructKind = CK_Complete);
661 /// \brief Construct an empty C++ construction expression.
662 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
663 : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
664 ConstructKind(0), Args(0), NumArgs(0) { }
667 /// \brief Construct an empty C++ construction expression.
668 explicit CXXConstructExpr(EmptyShell Empty)
669 : Expr(CXXConstructExprClass, Empty), Constructor(0),
670 Elidable(0), ZeroInitialization(0),
671 ConstructKind(0), Args(0), NumArgs(0) { }
673 static CXXConstructExpr *Create(ASTContext &C, QualType T,
675 CXXConstructorDecl *D, bool Elidable,
676 Expr **Args, unsigned NumArgs,
677 bool ZeroInitialization = false,
678 ConstructionKind ConstructKind = CK_Complete);
681 CXXConstructorDecl* getConstructor() const { return Constructor; }
682 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
684 SourceLocation getLocation() const { return Loc; }
685 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
687 /// \brief Whether this construction is elidable.
688 bool isElidable() const { return Elidable; }
689 void setElidable(bool E) { Elidable = E; }
691 /// \brief Whether this construction first requires
692 /// zero-initialization before the initializer is called.
693 bool requiresZeroInitialization() const { return ZeroInitialization; }
694 void setRequiresZeroInitialization(bool ZeroInit) {
695 ZeroInitialization = ZeroInit;
698 /// \brief Determines whether this constructor is actually constructing
699 /// a base class (rather than a complete object).
700 ConstructionKind getConstructionKind() const {
701 return (ConstructionKind)ConstructKind;
703 void setConstructionKind(ConstructionKind CK) {
707 typedef ExprIterator arg_iterator;
708 typedef ConstExprIterator const_arg_iterator;
710 arg_iterator arg_begin() { return Args; }
711 arg_iterator arg_end() { return Args + NumArgs; }
712 const_arg_iterator arg_begin() const { return Args; }
713 const_arg_iterator arg_end() const { return Args + NumArgs; }
715 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
716 unsigned getNumArgs() const { return NumArgs; }
718 /// getArg - Return the specified argument.
719 Expr *getArg(unsigned Arg) {
720 assert(Arg < NumArgs && "Arg access out of range!");
721 return cast<Expr>(Args[Arg]);
723 const Expr *getArg(unsigned Arg) const {
724 assert(Arg < NumArgs && "Arg access out of range!");
725 return cast<Expr>(Args[Arg]);
728 /// setArg - Set the specified argument.
729 void setArg(unsigned Arg, Expr *ArgExpr) {
730 assert(Arg < NumArgs && "Arg access out of range!");
734 virtual SourceRange getSourceRange() const;
736 static bool classof(const Stmt *T) {
737 return T->getStmtClass() == CXXConstructExprClass ||
738 T->getStmtClass() == CXXTemporaryObjectExprClass;
740 static bool classof(const CXXConstructExpr *) { return true; }
743 virtual child_iterator child_begin();
744 virtual child_iterator child_end();
746 friend class ASTStmtReader;
749 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
750 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
752 class CXXFunctionalCastExpr : public ExplicitCastExpr {
753 SourceLocation TyBeginLoc;
754 SourceLocation RParenLoc;
756 CXXFunctionalCastExpr(QualType ty, TypeSourceInfo *writtenTy,
757 SourceLocation tyBeginLoc, CastKind kind,
758 Expr *castExpr, unsigned pathSize,
759 SourceLocation rParenLoc)
760 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr,
761 pathSize, writtenTy),
762 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
764 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
765 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
768 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
769 TypeSourceInfo *Written,
770 SourceLocation TyBeginLoc,
771 CastKind Kind, Expr *Op,
772 const CXXCastPath *Path,
773 SourceLocation RPLoc);
774 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
777 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
778 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
779 SourceLocation getRParenLoc() const { return RParenLoc; }
780 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
782 virtual SourceRange getSourceRange() const {
783 return SourceRange(TyBeginLoc, RParenLoc);
785 static bool classof(const Stmt *T) {
786 return T->getStmtClass() == CXXFunctionalCastExprClass;
788 static bool classof(const CXXFunctionalCastExpr *) { return true; }
791 /// @brief Represents a C++ functional cast expression that builds a
792 /// temporary object.
794 /// This expression type represents a C++ "functional" cast
795 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
796 /// constructor to build a temporary object. With N == 1 arguments the
797 /// functional cast expression will be represented by CXXFunctionalCastExpr.
800 /// struct X { X(int, float); }
803 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
806 class CXXTemporaryObjectExpr : public CXXConstructExpr {
807 SourceLocation TyBeginLoc;
808 SourceLocation RParenLoc;
811 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
812 QualType writtenTy, SourceLocation tyBeginLoc,
813 Expr **Args,unsigned NumArgs,
814 SourceLocation rParenLoc,
815 bool ZeroInitialization = false);
816 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
817 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty) { }
819 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
820 SourceLocation getRParenLoc() const { return RParenLoc; }
822 virtual SourceRange getSourceRange() const {
823 return SourceRange(TyBeginLoc, RParenLoc);
825 static bool classof(const Stmt *T) {
826 return T->getStmtClass() == CXXTemporaryObjectExprClass;
828 static bool classof(const CXXTemporaryObjectExpr *) { return true; }
830 friend class ASTStmtReader;
833 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
834 /// Expression "T()" which creates a value-initialized rvalue of type
835 /// T, which is a non-class type.
837 class CXXScalarValueInitExpr : public Expr {
838 SourceLocation TyBeginLoc;
839 SourceLocation RParenLoc;
842 CXXScalarValueInitExpr(QualType ty, SourceLocation tyBeginLoc,
843 SourceLocation rParenLoc ) :
844 Expr(CXXScalarValueInitExprClass, ty, false, false),
845 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
846 explicit CXXScalarValueInitExpr(EmptyShell Shell)
847 : Expr(CXXScalarValueInitExprClass, Shell) { }
849 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
850 SourceLocation getRParenLoc() const { return RParenLoc; }
852 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
853 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
855 /// @brief Whether this initialization expression was
856 /// implicitly-generated.
857 bool isImplicit() const {
858 return TyBeginLoc.isInvalid() && RParenLoc.isInvalid();
861 virtual SourceRange getSourceRange() const {
862 return SourceRange(TyBeginLoc, RParenLoc);
865 static bool classof(const Stmt *T) {
866 return T->getStmtClass() == CXXScalarValueInitExprClass;
868 static bool classof(const CXXScalarValueInitExpr *) { return true; }
871 virtual child_iterator child_begin();
872 virtual child_iterator child_end();
875 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
876 /// e.g: "new CXXNewExpr(foo)".
877 class CXXNewExpr : public Expr {
878 // Was the usage ::new, i.e. is the global new to be used?
880 // Is there an initializer? If not, built-ins are uninitialized, else they're
881 // value-initialized.
882 bool Initializer : 1;
883 // Do we allocate an array? If so, the first SubExpr is the size expression.
885 // The number of placement new arguments.
886 unsigned NumPlacementArgs : 15;
887 // The number of constructor arguments. This may be 1 even for non-class
888 // types; use the pseudo copy constructor.
889 unsigned NumConstructorArgs : 14;
890 // Contains an optional array size expression, any number of optional
891 // placement arguments, and any number of optional constructor arguments,
894 // Points to the allocation function used.
895 FunctionDecl *OperatorNew;
896 // Points to the deallocation function used in case of error. May be null.
897 FunctionDecl *OperatorDelete;
898 // Points to the constructor used. Cannot be null if AllocType is a record;
899 // it would still point at the default constructor (even an implicit one).
900 // Must be null for all other types.
901 CXXConstructorDecl *Constructor;
903 /// \brief If the allocated type was expressed as a parenthesized type-id,
904 /// the source range covering the parenthesized type-id.
905 SourceRange TypeIdParens;
907 SourceLocation StartLoc;
908 SourceLocation EndLoc;
910 friend class ASTStmtReader;
912 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
913 Expr **placementArgs, unsigned numPlaceArgs,
914 SourceRange TypeIdParens,
915 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
916 Expr **constructorArgs, unsigned numConsArgs,
917 FunctionDecl *operatorDelete, QualType ty,
918 SourceLocation startLoc, SourceLocation endLoc);
919 explicit CXXNewExpr(EmptyShell Shell)
920 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
922 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
923 unsigned numConsArgs);
925 QualType getAllocatedType() const {
926 assert(getType()->isPointerType());
927 return getType()->getAs<PointerType>()->getPointeeType();
930 FunctionDecl *getOperatorNew() const { return OperatorNew; }
931 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
932 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
933 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
934 CXXConstructorDecl *getConstructor() const { return Constructor; }
935 void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
937 bool isArray() const { return Array; }
938 Expr *getArraySize() {
939 return Array ? cast<Expr>(SubExprs[0]) : 0;
941 const Expr *getArraySize() const {
942 return Array ? cast<Expr>(SubExprs[0]) : 0;
945 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
946 Expr *getPlacementArg(unsigned i) {
947 assert(i < NumPlacementArgs && "Index out of range");
948 return cast<Expr>(SubExprs[Array + i]);
950 const Expr *getPlacementArg(unsigned i) const {
951 assert(i < NumPlacementArgs && "Index out of range");
952 return cast<Expr>(SubExprs[Array + i]);
955 bool isParenTypeId() const { return TypeIdParens.isValid(); }
956 SourceRange getTypeIdParens() const { return TypeIdParens; }
958 bool isGlobalNew() const { return GlobalNew; }
959 void setGlobalNew(bool V) { GlobalNew = V; }
960 bool hasInitializer() const { return Initializer; }
961 void setHasInitializer(bool V) { Initializer = V; }
963 unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
964 Expr *getConstructorArg(unsigned i) {
965 assert(i < NumConstructorArgs && "Index out of range");
966 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
968 const Expr *getConstructorArg(unsigned i) const {
969 assert(i < NumConstructorArgs && "Index out of range");
970 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
973 typedef ExprIterator arg_iterator;
974 typedef ConstExprIterator const_arg_iterator;
976 arg_iterator placement_arg_begin() {
977 return SubExprs + Array;
979 arg_iterator placement_arg_end() {
980 return SubExprs + Array + getNumPlacementArgs();
982 const_arg_iterator placement_arg_begin() const {
983 return SubExprs + Array;
985 const_arg_iterator placement_arg_end() const {
986 return SubExprs + Array + getNumPlacementArgs();
989 arg_iterator constructor_arg_begin() {
990 return SubExprs + Array + getNumPlacementArgs();
992 arg_iterator constructor_arg_end() {
993 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
995 const_arg_iterator constructor_arg_begin() const {
996 return SubExprs + Array + getNumPlacementArgs();
998 const_arg_iterator constructor_arg_end() const {
999 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1002 typedef Stmt **raw_arg_iterator;
1003 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1004 raw_arg_iterator raw_arg_end() {
1005 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1007 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1008 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
1011 SourceLocation getStartLoc() const { return StartLoc; }
1012 void setStartLoc(SourceLocation L) { StartLoc = L; }
1013 SourceLocation getEndLoc() const { return EndLoc; }
1014 void setEndLoc(SourceLocation L) { EndLoc = L; }
1016 virtual SourceRange getSourceRange() const {
1017 return SourceRange(StartLoc, EndLoc);
1020 static bool classof(const Stmt *T) {
1021 return T->getStmtClass() == CXXNewExprClass;
1023 static bool classof(const CXXNewExpr *) { return true; }
1026 virtual child_iterator child_begin();
1027 virtual child_iterator child_end();
1030 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1031 /// calls, e.g. "delete[] pArray".
1032 class CXXDeleteExpr : public Expr {
1033 // Is this a forced global delete, i.e. "::delete"?
1034 bool GlobalDelete : 1;
1035 // Is this the array form of delete, i.e. "delete[]"?
1037 // Points to the operator delete overload that is used. Could be a member.
1038 FunctionDecl *OperatorDelete;
1039 // The pointer expression to be deleted.
1041 // Location of the expression.
1044 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1045 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1046 : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
1047 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
1049 explicit CXXDeleteExpr(EmptyShell Shell)
1050 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1052 bool isGlobalDelete() const { return GlobalDelete; }
1053 bool isArrayForm() const { return ArrayForm; }
1055 void setGlobalDelete(bool V) { GlobalDelete = V; }
1056 void setArrayForm(bool V) { ArrayForm = V; }
1058 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1059 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1061 Expr *getArgument() { return cast<Expr>(Argument); }
1062 const Expr *getArgument() const { return cast<Expr>(Argument); }
1063 void setArgument(Expr *E) { Argument = E; }
1065 virtual SourceRange getSourceRange() const {
1066 return SourceRange(Loc, Argument->getLocEnd());
1068 void setStartLoc(SourceLocation L) { Loc = L; }
1070 static bool classof(const Stmt *T) {
1071 return T->getStmtClass() == CXXDeleteExprClass;
1073 static bool classof(const CXXDeleteExpr *) { return true; }
1076 virtual child_iterator child_begin();
1077 virtual child_iterator child_end();
1080 /// \brief Structure used to store the type being destroyed by a
1081 /// pseudo-destructor expression.
1082 class PseudoDestructorTypeStorage {
1083 /// \brief Either the type source information or the name of the type, if
1084 /// it couldn't be resolved due to type-dependence.
1085 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1087 /// \brief The starting source location of the pseudo-destructor type.
1088 SourceLocation Location;
1091 PseudoDestructorTypeStorage() { }
1093 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1094 : Type(II), Location(Loc) { }
1096 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1098 TypeSourceInfo *getTypeSourceInfo() const {
1099 return Type.dyn_cast<TypeSourceInfo *>();
1102 IdentifierInfo *getIdentifier() const {
1103 return Type.dyn_cast<IdentifierInfo *>();
1106 SourceLocation getLocation() const { return Location; }
1109 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1111 /// A pseudo-destructor is an expression that looks like a member access to a
1112 /// destructor of a scalar type, except that scalar types don't have
1113 /// destructors. For example:
1117 /// void f(int *p) {
1122 /// Pseudo-destructors typically occur when instantiating templates such as:
1125 /// template<typename T>
1126 /// void destroy(T* ptr) {
1131 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1132 /// beyond evaluating the base expression.
1133 class CXXPseudoDestructorExpr : public Expr {
1134 /// \brief The base expression (that is being destroyed).
1137 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1141 /// \brief The location of the '.' or '->' operator.
1142 SourceLocation OperatorLoc;
1144 /// \brief The nested-name-specifier that follows the operator, if present.
1145 NestedNameSpecifier *Qualifier;
1147 /// \brief The source range that covers the nested-name-specifier, if
1149 SourceRange QualifierRange;
1151 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1153 TypeSourceInfo *ScopeType;
1155 /// \brief The location of the '::' in a qualified pseudo-destructor
1157 SourceLocation ColonColonLoc;
1159 /// \brief The location of the '~'.
1160 SourceLocation TildeLoc;
1162 /// \brief The type being destroyed, or its name if we were unable to
1163 /// resolve the name.
1164 PseudoDestructorTypeStorage DestroyedType;
1167 CXXPseudoDestructorExpr(ASTContext &Context,
1168 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1169 NestedNameSpecifier *Qualifier,
1170 SourceRange QualifierRange,
1171 TypeSourceInfo *ScopeType,
1172 SourceLocation ColonColonLoc,
1173 SourceLocation TildeLoc,
1174 PseudoDestructorTypeStorage DestroyedType)
1175 : Expr(CXXPseudoDestructorExprClass,
1176 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
1179 FunctionType::ExtInfo())),
1180 /*isTypeDependent=*/(Base->isTypeDependent() ||
1181 (DestroyedType.getTypeSourceInfo() &&
1182 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
1183 /*isValueDependent=*/Base->isValueDependent()),
1184 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
1185 OperatorLoc(OperatorLoc), Qualifier(Qualifier),
1186 QualifierRange(QualifierRange),
1187 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
1188 DestroyedType(DestroyedType) { }
1190 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1191 : Expr(CXXPseudoDestructorExprClass, Shell),
1192 Base(0), IsArrow(false), Qualifier(0), ScopeType(0) { }
1194 void setBase(Expr *E) { Base = E; }
1195 Expr *getBase() const { return cast<Expr>(Base); }
1197 /// \brief Determines whether this member expression actually had
1198 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1200 bool hasQualifier() const { return Qualifier != 0; }
1202 /// \brief If the member name was qualified, retrieves the source range of
1203 /// the nested-name-specifier that precedes the member name. Otherwise,
1204 /// returns an empty source range.
1205 SourceRange getQualifierRange() const { return QualifierRange; }
1206 void setQualifierRange(SourceRange R) { QualifierRange = R; }
1208 /// \brief If the member name was qualified, retrieves the
1209 /// nested-name-specifier that precedes the member name. Otherwise, returns
1211 NestedNameSpecifier *getQualifier() const { return Qualifier; }
1212 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1214 /// \brief Determine whether this pseudo-destructor expression was written
1215 /// using an '->' (otherwise, it used a '.').
1216 bool isArrow() const { return IsArrow; }
1217 void setArrow(bool A) { IsArrow = A; }
1219 /// \brief Retrieve the location of the '.' or '->' operator.
1220 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1221 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1223 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1226 /// Pseudo-destructor expressions can have extra qualification within them
1227 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1228 /// Here, if the object type of the expression is (or may be) a scalar type,
1229 /// \p T may also be a scalar type and, therefore, cannot be part of a
1230 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1231 /// destructor expression.
1232 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1233 void setScopeTypeInfo(TypeSourceInfo *Info) { ScopeType = Info; }
1235 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1237 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1238 void setColonColonLoc(SourceLocation L) { ColonColonLoc = L; }
1240 /// \brief Retrieve the location of the '~'.
1241 SourceLocation getTildeLoc() const { return TildeLoc; }
1242 void setTildeLoc(SourceLocation L) { TildeLoc = L; }
1244 /// \brief Retrieve the source location information for the type
1245 /// being destroyed.
1247 /// This type-source information is available for non-dependent
1248 /// pseudo-destructor expressions and some dependent pseudo-destructor
1249 /// expressions. Returns NULL if we only have the identifier for a
1250 /// dependent pseudo-destructor expression.
1251 TypeSourceInfo *getDestroyedTypeInfo() const {
1252 return DestroyedType.getTypeSourceInfo();
1255 /// \brief In a dependent pseudo-destructor expression for which we do not
1256 /// have full type information on the destroyed type, provides the name
1257 /// of the destroyed type.
1258 IdentifierInfo *getDestroyedTypeIdentifier() const {
1259 return DestroyedType.getIdentifier();
1262 /// \brief Retrieve the type being destroyed.
1263 QualType getDestroyedType() const;
1265 /// \brief Retrieve the starting location of the type being destroyed.
1266 SourceLocation getDestroyedTypeLoc() const {
1267 return DestroyedType.getLocation();
1270 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1272 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1273 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1276 /// \brief Set the destroyed type.
1277 void setDestroyedType(TypeSourceInfo *Info) {
1278 DestroyedType = PseudoDestructorTypeStorage(Info);
1281 virtual SourceRange getSourceRange() const;
1283 static bool classof(const Stmt *T) {
1284 return T->getStmtClass() == CXXPseudoDestructorExprClass;
1286 static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1289 virtual child_iterator child_begin();
1290 virtual child_iterator child_end();
1293 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1294 /// implementation of TR1/C++0x type trait templates.
1296 /// __is_pod(int) == true
1297 /// __is_enum(std::string) == false
1298 class UnaryTypeTraitExpr : public Expr {
1299 /// UTT - The trait.
1302 /// Loc - The location of the type trait keyword.
1305 /// RParen - The location of the closing paren.
1306 SourceLocation RParen;
1308 /// QueriedType - The type we're testing.
1309 QualType QueriedType;
1312 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
1313 SourceLocation rparen, QualType ty)
1314 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
1315 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
1317 explicit UnaryTypeTraitExpr(EmptyShell Empty)
1318 : Expr(UnaryTypeTraitExprClass, Empty), UTT((UnaryTypeTrait)0) { }
1320 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1322 UnaryTypeTrait getTrait() const { return UTT; }
1324 QualType getQueriedType() const { return QueriedType; }
1326 bool EvaluateTrait(ASTContext&) const;
1328 static bool classof(const Stmt *T) {
1329 return T->getStmtClass() == UnaryTypeTraitExprClass;
1331 static bool classof(const UnaryTypeTraitExpr *) { return true; }
1334 virtual child_iterator child_begin();
1335 virtual child_iterator child_end();
1337 friend class ASTStmtReader;
1340 /// \brief A reference to an overloaded function set, either an
1341 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1342 class OverloadExpr : public Expr {
1343 /// The results. These are undesugared, which is to say, they may
1344 /// include UsingShadowDecls. Access is relative to the naming
1346 // FIXME: Allocate this data after the OverloadExpr subclass.
1347 DeclAccessPair *Results;
1348 unsigned NumResults;
1350 /// The common name of these declarations.
1351 DeclarationNameInfo NameInfo;
1353 /// The scope specifier, if any.
1354 NestedNameSpecifier *Qualifier;
1356 /// The source range of the scope specifier.
1357 SourceRange QualifierRange;
1360 /// True if the name was a template-id.
1361 bool HasExplicitTemplateArgs;
1363 OverloadExpr(StmtClass K, ASTContext &C, QualType T, bool Dependent,
1364 NestedNameSpecifier *Qualifier, SourceRange QRange,
1365 const DeclarationNameInfo &NameInfo,
1366 bool HasTemplateArgs,
1367 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
1369 OverloadExpr(StmtClass K, EmptyShell Empty)
1370 : Expr(K, Empty), Results(0), NumResults(0),
1371 Qualifier(0), HasExplicitTemplateArgs(false) { }
1374 /// Computes whether an unresolved lookup on the given declarations
1375 /// and optional template arguments is type- and value-dependent.
1376 static bool ComputeDependence(UnresolvedSetIterator Begin,
1377 UnresolvedSetIterator End,
1378 const TemplateArgumentListInfo *Args);
1381 OverloadExpr *Expression;
1382 bool IsAddressOfOperand;
1383 bool HasFormOfMemberPointer;
1386 /// Finds the overloaded expression in the given expression of
1389 /// \return the expression (which must be there) and true if it has
1390 /// the particular form of a member pointer expression
1391 static FindResult find(Expr *E) {
1392 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1396 E = E->IgnoreParens();
1397 if (isa<UnaryOperator>(E)) {
1398 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
1399 E = cast<UnaryOperator>(E)->getSubExpr();
1400 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
1402 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
1403 Result.IsAddressOfOperand = true;
1404 Result.Expression = Ovl;
1406 Result.HasFormOfMemberPointer = false;
1407 Result.IsAddressOfOperand = false;
1408 Result.Expression = cast<OverloadExpr>(E);
1414 /// Gets the naming class of this lookup, if any.
1415 CXXRecordDecl *getNamingClass() const;
1417 typedef UnresolvedSetImpl::iterator decls_iterator;
1418 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1419 decls_iterator decls_end() const {
1420 return UnresolvedSetIterator(Results + NumResults);
1423 void initializeResults(ASTContext &C,
1424 UnresolvedSetIterator Begin,UnresolvedSetIterator End);
1426 /// Gets the number of declarations in the unresolved set.
1427 unsigned getNumDecls() const { return NumResults; }
1429 /// Gets the full name info.
1430 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1431 void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; }
1433 /// Gets the name looked up.
1434 DeclarationName getName() const { return NameInfo.getName(); }
1435 void setName(DeclarationName N) { NameInfo.setName(N); }
1437 /// Gets the location of the name.
1438 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
1439 void setNameLoc(SourceLocation Loc) { NameInfo.setLoc(Loc); }
1441 /// Fetches the nested-name qualifier, if one was given.
1442 NestedNameSpecifier *getQualifier() const { return Qualifier; }
1443 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1445 /// Fetches the range of the nested-name qualifier.
1446 SourceRange getQualifierRange() const { return QualifierRange; }
1447 void setQualifierRange(SourceRange R) { QualifierRange = R; }
1449 /// \brief Determines whether this expression had an explicit
1450 /// template argument list, e.g. f<int>.
1451 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1453 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1455 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1456 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1459 /// \brief Retrieves the optional explicit template arguments.
1460 /// This points to the same data as getExplicitTemplateArgs(), but
1461 /// returns null if there are no explicit template arguments.
1462 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1463 if (!hasExplicitTemplateArgs()) return 0;
1464 return &getExplicitTemplateArgs();
1467 static bool classof(const Stmt *T) {
1468 return T->getStmtClass() == UnresolvedLookupExprClass ||
1469 T->getStmtClass() == UnresolvedMemberExprClass;
1471 static bool classof(const OverloadExpr *) { return true; }
1474 /// \brief A reference to a name which we were able to look up during
1475 /// parsing but could not resolve to a specific declaration. This
1476 /// arises in several ways:
1477 /// * we might be waiting for argument-dependent lookup
1478 /// * the name might resolve to an overloaded function
1480 /// * the lookup might have included a function template
1481 /// These never include UnresolvedUsingValueDecls, which are always
1482 /// class members and therefore appear only in
1483 /// UnresolvedMemberLookupExprs.
1484 class UnresolvedLookupExpr : public OverloadExpr {
1485 /// True if these lookup results should be extended by
1486 /// argument-dependent lookup if this is the operand of a function
1490 /// True if these lookup results are overloaded. This is pretty
1491 /// trivially rederivable if we urgently need to kill this field.
1494 /// The naming class (C++ [class.access.base]p5) of the lookup, if
1495 /// any. This can generally be recalculated from the context chain,
1496 /// but that can be fairly expensive for unqualified lookups. If we
1497 /// want to improve memory use here, this could go in a union
1498 /// against the qualified-lookup bits.
1499 CXXRecordDecl *NamingClass;
1501 UnresolvedLookupExpr(ASTContext &C, QualType T, bool Dependent,
1502 CXXRecordDecl *NamingClass,
1503 NestedNameSpecifier *Qualifier, SourceRange QRange,
1504 const DeclarationNameInfo &NameInfo,
1505 bool RequiresADL, bool Overloaded, bool HasTemplateArgs,
1506 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
1507 : OverloadExpr(UnresolvedLookupExprClass, C, T, Dependent, Qualifier,
1508 QRange, NameInfo, HasTemplateArgs, Begin, End),
1509 RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1512 UnresolvedLookupExpr(EmptyShell Empty)
1513 : OverloadExpr(UnresolvedLookupExprClass, Empty),
1514 RequiresADL(false), Overloaded(false), NamingClass(0)
1518 static UnresolvedLookupExpr *Create(ASTContext &C,
1520 CXXRecordDecl *NamingClass,
1521 NestedNameSpecifier *Qualifier,
1522 SourceRange QualifierRange,
1523 const DeclarationNameInfo &NameInfo,
1524 bool ADL, bool Overloaded,
1525 UnresolvedSetIterator Begin,
1526 UnresolvedSetIterator End) {
1527 return new(C) UnresolvedLookupExpr(C,
1528 Dependent ? C.DependentTy : C.OverloadTy,
1529 Dependent, NamingClass,
1530 Qualifier, QualifierRange, NameInfo,
1531 ADL, Overloaded, false,
1535 static UnresolvedLookupExpr *Create(ASTContext &C,
1537 CXXRecordDecl *NamingClass,
1538 NestedNameSpecifier *Qualifier,
1539 SourceRange QualifierRange,
1540 const DeclarationNameInfo &NameInfo,
1542 const TemplateArgumentListInfo &Args,
1543 UnresolvedSetIterator Begin,
1544 UnresolvedSetIterator End);
1546 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1547 unsigned NumTemplateArgs);
1549 /// True if this declaration should be extended by
1550 /// argument-dependent lookup.
1551 bool requiresADL() const { return RequiresADL; }
1552 void setRequiresADL(bool V) { RequiresADL = V; }
1554 /// True if this lookup is overloaded.
1555 bool isOverloaded() const { return Overloaded; }
1556 void setOverloaded(bool V) { Overloaded = V; }
1558 /// Gets the 'naming class' (in the sense of C++0x
1559 /// [class.access.base]p5) of the lookup. This is the scope
1560 /// that was looked in to find these results.
1561 CXXRecordDecl *getNamingClass() const { return NamingClass; }
1562 void setNamingClass(CXXRecordDecl *D) { NamingClass = D; }
1564 // Note that, inconsistently with the explicit-template-argument AST
1565 // nodes, users are *forbidden* from calling these methods on objects
1566 // without explicit template arguments.
1568 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1569 assert(hasExplicitTemplateArgs());
1570 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1573 /// Gets a reference to the explicit template argument list.
1574 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1575 assert(hasExplicitTemplateArgs());
1576 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1579 /// \brief Retrieves the optional explicit template arguments.
1580 /// This points to the same data as getExplicitTemplateArgs(), but
1581 /// returns null if there are no explicit template arguments.
1582 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1583 if (!hasExplicitTemplateArgs()) return 0;
1584 return &getExplicitTemplateArgs();
1587 /// \brief Copies the template arguments (if present) into the given
1589 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1590 getExplicitTemplateArgs().copyInto(List);
1593 SourceLocation getLAngleLoc() const {
1594 return getExplicitTemplateArgs().LAngleLoc;
1597 SourceLocation getRAngleLoc() const {
1598 return getExplicitTemplateArgs().RAngleLoc;
1601 TemplateArgumentLoc const *getTemplateArgs() const {
1602 return getExplicitTemplateArgs().getTemplateArgs();
1605 unsigned getNumTemplateArgs() const {
1606 return getExplicitTemplateArgs().NumTemplateArgs;
1609 virtual SourceRange getSourceRange() const {
1610 SourceRange Range(getNameInfo().getSourceRange());
1611 if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1612 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1616 virtual StmtIterator child_begin();
1617 virtual StmtIterator child_end();
1619 static bool classof(const Stmt *T) {
1620 return T->getStmtClass() == UnresolvedLookupExprClass;
1622 static bool classof(const UnresolvedLookupExpr *) { return true; }
1625 /// \brief A qualified reference to a name whose declaration cannot
1626 /// yet be resolved.
1628 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1629 /// it expresses a reference to a declaration such as
1630 /// X<T>::value. The difference, however, is that an
1631 /// DependentScopeDeclRefExpr node is used only within C++ templates when
1632 /// the qualification (e.g., X<T>::) refers to a dependent type. In
1633 /// this case, X<T>::value cannot resolve to a declaration because the
1634 /// declaration will differ from on instantiation of X<T> to the
1635 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1636 /// qualifier (X<T>::) and the name of the entity being referenced
1637 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1638 /// declaration can be found.
1639 class DependentScopeDeclRefExpr : public Expr {
1640 /// The name of the entity we will be referencing.
1641 DeclarationNameInfo NameInfo;
1643 /// QualifierRange - The source range that covers the
1644 /// nested-name-specifier.
1645 SourceRange QualifierRange;
1647 /// \brief The nested-name-specifier that qualifies this unresolved
1648 /// declaration name.
1649 NestedNameSpecifier *Qualifier;
1651 /// \brief Whether the name includes explicit template arguments.
1652 bool HasExplicitTemplateArgs;
1654 DependentScopeDeclRefExpr(QualType T,
1655 NestedNameSpecifier *Qualifier,
1656 SourceRange QualifierRange,
1657 const DeclarationNameInfo &NameInfo,
1658 bool HasExplicitTemplateArgs)
1659 : Expr(DependentScopeDeclRefExprClass, T, true, true),
1660 NameInfo(NameInfo), QualifierRange(QualifierRange), Qualifier(Qualifier),
1661 HasExplicitTemplateArgs(HasExplicitTemplateArgs)
1665 static DependentScopeDeclRefExpr *Create(ASTContext &C,
1666 NestedNameSpecifier *Qualifier,
1667 SourceRange QualifierRange,
1668 const DeclarationNameInfo &NameInfo,
1669 const TemplateArgumentListInfo *TemplateArgs = 0);
1671 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
1672 unsigned NumTemplateArgs);
1674 /// \brief Retrieve the name that this expression refers to.
1675 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1676 void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; }
1678 /// \brief Retrieve the name that this expression refers to.
1679 DeclarationName getDeclName() const { return NameInfo.getName(); }
1680 void setDeclName(DeclarationName N) { NameInfo.setName(N); }
1682 /// \brief Retrieve the location of the name within the expression.
1683 SourceLocation getLocation() const { return NameInfo.getLoc(); }
1684 void setLocation(SourceLocation L) { NameInfo.setLoc(L); }
1686 /// \brief Retrieve the source range of the nested-name-specifier.
1687 SourceRange getQualifierRange() const { return QualifierRange; }
1688 void setQualifierRange(SourceRange R) { QualifierRange = R; }
1690 /// \brief Retrieve the nested-name-specifier that qualifies this
1692 NestedNameSpecifier *getQualifier() const { return Qualifier; }
1693 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1695 /// Determines whether this lookup had explicit template arguments.
1696 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1698 // Note that, inconsistently with the explicit-template-argument AST
1699 // nodes, users are *forbidden* from calling these methods on objects
1700 // without explicit template arguments.
1702 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1703 assert(hasExplicitTemplateArgs());
1704 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1707 /// Gets a reference to the explicit template argument list.
1708 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1709 assert(hasExplicitTemplateArgs());
1710 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1713 /// \brief Retrieves the optional explicit template arguments.
1714 /// This points to the same data as getExplicitTemplateArgs(), but
1715 /// returns null if there are no explicit template arguments.
1716 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1717 if (!hasExplicitTemplateArgs()) return 0;
1718 return &getExplicitTemplateArgs();
1721 /// \brief Copies the template arguments (if present) into the given
1723 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1724 getExplicitTemplateArgs().copyInto(List);
1727 SourceLocation getLAngleLoc() const {
1728 return getExplicitTemplateArgs().LAngleLoc;
1731 SourceLocation getRAngleLoc() const {
1732 return getExplicitTemplateArgs().RAngleLoc;
1735 TemplateArgumentLoc const *getTemplateArgs() const {
1736 return getExplicitTemplateArgs().getTemplateArgs();
1739 unsigned getNumTemplateArgs() const {
1740 return getExplicitTemplateArgs().NumTemplateArgs;
1743 virtual SourceRange getSourceRange() const {
1744 SourceRange Range(QualifierRange.getBegin(), getLocation());
1745 if (hasExplicitTemplateArgs())
1746 Range.setEnd(getRAngleLoc());
1750 static bool classof(const Stmt *T) {
1751 return T->getStmtClass() == DependentScopeDeclRefExprClass;
1753 static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1755 virtual StmtIterator child_begin();
1756 virtual StmtIterator child_end();
1759 class CXXExprWithTemporaries : public Expr {
1762 CXXTemporary **Temps;
1765 CXXExprWithTemporaries(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps,
1769 CXXExprWithTemporaries(EmptyShell Empty)
1770 : Expr(CXXExprWithTemporariesClass, Empty),
1771 SubExpr(0), Temps(0), NumTemps(0) {}
1773 static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1774 CXXTemporary **Temps,
1777 unsigned getNumTemporaries() const { return NumTemps; }
1778 void setNumTemporaries(ASTContext &C, unsigned N);
1780 CXXTemporary *getTemporary(unsigned i) {
1781 assert(i < NumTemps && "Index out of range");
1784 const CXXTemporary *getTemporary(unsigned i) const {
1785 return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
1787 void setTemporary(unsigned i, CXXTemporary *T) {
1788 assert(i < NumTemps && "Index out of range");
1792 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1793 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1794 void setSubExpr(Expr *E) { SubExpr = E; }
1796 virtual SourceRange getSourceRange() const {
1797 return SubExpr->getSourceRange();
1800 // Implement isa/cast/dyncast/etc.
1801 static bool classof(const Stmt *T) {
1802 return T->getStmtClass() == CXXExprWithTemporariesClass;
1804 static bool classof(const CXXExprWithTemporaries *) { return true; }
1807 virtual child_iterator child_begin();
1808 virtual child_iterator child_end();
1811 /// \brief Describes an explicit type conversion that uses functional
1812 /// notion but could not be resolved because one or more arguments are
1815 /// The explicit type conversions expressed by
1816 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1817 /// where \c T is some type and \c a1, a2, ..., aN are values, and
1818 /// either \C T is a dependent type or one or more of the \c a's is
1819 /// type-dependent. For example, this would occur in a template such
1823 /// template<typename T, typename A1>
1824 /// inline T make_a(const A1& a1) {
1829 /// When the returned expression is instantiated, it may resolve to a
1830 /// constructor call, conversion function call, or some kind of type
1832 class CXXUnresolvedConstructExpr : public Expr {
1833 /// \brief The starting location of the type
1834 SourceLocation TyBeginLoc;
1836 /// \brief The type being constructed.
1839 /// \brief The location of the left parentheses ('(').
1840 SourceLocation LParenLoc;
1842 /// \brief The location of the right parentheses (')').
1843 SourceLocation RParenLoc;
1845 /// \brief The number of arguments used to construct the type.
1848 CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1850 SourceLocation LParenLoc,
1853 SourceLocation RParenLoc);
1855 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
1856 : Expr(CXXUnresolvedConstructExprClass, Empty), NumArgs(NumArgs) { }
1859 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1860 SourceLocation TyBegin,
1862 SourceLocation LParenLoc,
1865 SourceLocation RParenLoc);
1867 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
1870 /// \brief Retrieve the source location where the type begins.
1871 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1872 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1874 /// \brief Retrieve the type that is being constructed, as specified
1875 /// in the source code.
1876 QualType getTypeAsWritten() const { return Type; }
1877 void setTypeAsWritten(QualType T) { Type = T; }
1879 /// \brief Retrieve the location of the left parentheses ('(') that
1880 /// precedes the argument list.
1881 SourceLocation getLParenLoc() const { return LParenLoc; }
1882 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1884 /// \brief Retrieve the location of the right parentheses (')') that
1885 /// follows the argument list.
1886 SourceLocation getRParenLoc() const { return RParenLoc; }
1887 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1889 /// \brief Retrieve the number of arguments.
1890 unsigned arg_size() const { return NumArgs; }
1892 typedef Expr** arg_iterator;
1893 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1894 arg_iterator arg_end() { return arg_begin() + NumArgs; }
1896 typedef const Expr* const * const_arg_iterator;
1897 const_arg_iterator arg_begin() const {
1898 return reinterpret_cast<const Expr* const *>(this + 1);
1900 const_arg_iterator arg_end() const {
1901 return arg_begin() + NumArgs;
1904 Expr *getArg(unsigned I) {
1905 assert(I < NumArgs && "Argument index out-of-range");
1906 return *(arg_begin() + I);
1909 const Expr *getArg(unsigned I) const {
1910 assert(I < NumArgs && "Argument index out-of-range");
1911 return *(arg_begin() + I);
1914 void setArg(unsigned I, Expr *E) {
1915 assert(I < NumArgs && "Argument index out-of-range");
1916 *(arg_begin() + I) = E;
1919 virtual SourceRange getSourceRange() const {
1920 return SourceRange(TyBeginLoc, RParenLoc);
1922 static bool classof(const Stmt *T) {
1923 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1925 static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1928 virtual child_iterator child_begin();
1929 virtual child_iterator child_end();
1932 /// \brief Represents a C++ member access expression where the actual
1933 /// member referenced could not be resolved because the base
1934 /// expression or the member name was dependent.
1936 /// Like UnresolvedMemberExprs, these can be either implicit or
1937 /// explicit accesses. It is only possible to get one of these with
1938 /// an implicit access if a qualifier is provided.
1939 class CXXDependentScopeMemberExpr : public Expr {
1940 /// \brief The expression for the base pointer or class reference,
1941 /// e.g., the \c x in x.f. Can be null in implicit accesses.
1944 /// \brief The type of the base expression. Never null, even for
1945 /// implicit accesses.
1948 /// \brief Whether this member expression used the '->' operator or
1949 /// the '.' operator.
1952 /// \brief Whether this member expression has explicitly-specified template
1954 bool HasExplicitTemplateArgs : 1;
1956 /// \brief The location of the '->' or '.' operator.
1957 SourceLocation OperatorLoc;
1959 /// \brief The nested-name-specifier that precedes the member name, if any.
1960 NestedNameSpecifier *Qualifier;
1962 /// \brief The source range covering the nested name specifier.
1963 SourceRange QualifierRange;
1965 /// \brief In a qualified member access expression such as t->Base::f, this
1966 /// member stores the resolves of name lookup in the context of the member
1967 /// access expression, to be used at instantiation time.
1969 /// FIXME: This member, along with the Qualifier and QualifierRange, could
1970 /// be stuck into a structure that is optionally allocated at the end of
1971 /// the CXXDependentScopeMemberExpr, to save space in the common case.
1972 NamedDecl *FirstQualifierFoundInScope;
1974 /// \brief The member to which this member expression refers, which
1975 /// can be name, overloaded operator, or destructor.
1976 /// FIXME: could also be a template-id
1977 DeclarationNameInfo MemberNameInfo;
1979 CXXDependentScopeMemberExpr(ASTContext &C,
1980 Expr *Base, QualType BaseType, bool IsArrow,
1981 SourceLocation OperatorLoc,
1982 NestedNameSpecifier *Qualifier,
1983 SourceRange QualifierRange,
1984 NamedDecl *FirstQualifierFoundInScope,
1985 DeclarationNameInfo MemberNameInfo,
1986 const TemplateArgumentListInfo *TemplateArgs);
1989 CXXDependentScopeMemberExpr(ASTContext &C,
1990 Expr *Base, QualType BaseType,
1992 SourceLocation OperatorLoc,
1993 NestedNameSpecifier *Qualifier,
1994 SourceRange QualifierRange,
1995 NamedDecl *FirstQualifierFoundInScope,
1996 DeclarationNameInfo MemberNameInfo)
1997 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
1998 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1999 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
2000 Qualifier(Qualifier), QualifierRange(QualifierRange),
2001 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
2002 MemberNameInfo(MemberNameInfo) { }
2004 static CXXDependentScopeMemberExpr *
2005 Create(ASTContext &C,
2006 Expr *Base, QualType BaseType, bool IsArrow,
2007 SourceLocation OperatorLoc,
2008 NestedNameSpecifier *Qualifier,
2009 SourceRange QualifierRange,
2010 NamedDecl *FirstQualifierFoundInScope,
2011 DeclarationNameInfo MemberNameInfo,
2012 const TemplateArgumentListInfo *TemplateArgs);
2014 static CXXDependentScopeMemberExpr *
2015 CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
2017 /// \brief True if this is an implicit access, i.e. one in which the
2018 /// member being accessed was not written in the source. The source
2019 /// location of the operator is invalid in this case.
2020 bool isImplicitAccess() const { return Base == 0; }
2022 /// \brief Retrieve the base object of this member expressions,
2023 /// e.g., the \c x in \c x.m.
2024 Expr *getBase() const {
2025 assert(!isImplicitAccess());
2026 return cast<Expr>(Base);
2028 void setBase(Expr *E) { Base = E; }
2030 QualType getBaseType() const { return BaseType; }
2031 void setBaseType(QualType T) { BaseType = T; }
2033 /// \brief Determine whether this member expression used the '->'
2034 /// operator; otherwise, it used the '.' operator.
2035 bool isArrow() const { return IsArrow; }
2036 void setArrow(bool A) { IsArrow = A; }
2038 /// \brief Retrieve the location of the '->' or '.' operator.
2039 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2040 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2042 /// \brief Retrieve the nested-name-specifier that qualifies the member
2044 NestedNameSpecifier *getQualifier() const { return Qualifier; }
2045 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
2047 /// \brief Retrieve the source range covering the nested-name-specifier
2048 /// that qualifies the member name.
2049 SourceRange getQualifierRange() const { return QualifierRange; }
2050 void setQualifierRange(SourceRange R) { QualifierRange = R; }
2052 /// \brief Retrieve the first part of the nested-name-specifier that was
2053 /// found in the scope of the member access expression when the member access
2054 /// was initially parsed.
2056 /// This function only returns a useful result when member access expression
2057 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2058 /// returned by this function describes what was found by unqualified name
2059 /// lookup for the identifier "Base" within the scope of the member access
2060 /// expression itself. At template instantiation time, this information is
2061 /// combined with the results of name lookup into the type of the object
2062 /// expression itself (the class type of x).
2063 NamedDecl *getFirstQualifierFoundInScope() const {
2064 return FirstQualifierFoundInScope;
2066 void setFirstQualifierFoundInScope(NamedDecl *D) {
2067 FirstQualifierFoundInScope = D;
2070 /// \brief Retrieve the name of the member that this expression
2072 const DeclarationNameInfo &getMemberNameInfo() const {
2073 return MemberNameInfo;
2075 void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; }
2077 /// \brief Retrieve the name of the member that this expression
2079 DeclarationName getMember() const { return MemberNameInfo.getName(); }
2080 void setMember(DeclarationName N) { MemberNameInfo.setName(N); }
2082 // \brief Retrieve the location of the name of the member that this
2083 // expression refers to.
2084 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2085 void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); }
2087 /// \brief Determines whether this member expression actually had a C++
2088 /// template argument list explicitly specified, e.g., x.f<int>.
2089 bool hasExplicitTemplateArgs() const {
2090 return HasExplicitTemplateArgs;
2093 /// \brief Retrieve the explicit template argument list that followed the
2094 /// member template name, if any.
2095 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2096 assert(HasExplicitTemplateArgs);
2097 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2100 /// \brief Retrieve the explicit template argument list that followed the
2101 /// member template name, if any.
2102 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2103 return const_cast<CXXDependentScopeMemberExpr *>(this)
2104 ->getExplicitTemplateArgs();
2107 /// \brief Retrieves the optional explicit template arguments.
2108 /// This points to the same data as getExplicitTemplateArgs(), but
2109 /// returns null if there are no explicit template arguments.
2110 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2111 if (!hasExplicitTemplateArgs()) return 0;
2112 return &getExplicitTemplateArgs();
2115 /// \brief Copies the template arguments (if present) into the given
2117 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2118 getExplicitTemplateArgs().copyInto(List);
2121 /// \brief Initializes the template arguments using the given structure.
2122 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2123 getExplicitTemplateArgs().initializeFrom(List);
2126 /// \brief Retrieve the location of the left angle bracket following the
2127 /// member name ('<'), if any.
2128 SourceLocation getLAngleLoc() const {
2129 return getExplicitTemplateArgs().LAngleLoc;
2132 /// \brief Retrieve the template arguments provided as part of this
2134 const TemplateArgumentLoc *getTemplateArgs() const {
2135 return getExplicitTemplateArgs().getTemplateArgs();
2138 /// \brief Retrieve the number of template arguments provided as part of this
2140 unsigned getNumTemplateArgs() const {
2141 return getExplicitTemplateArgs().NumTemplateArgs;
2144 /// \brief Retrieve the location of the right angle bracket following the
2145 /// template arguments ('>').
2146 SourceLocation getRAngleLoc() const {
2147 return getExplicitTemplateArgs().RAngleLoc;
2150 virtual SourceRange getSourceRange() const {
2152 if (!isImplicitAccess())
2153 Range.setBegin(Base->getSourceRange().getBegin());
2154 else if (getQualifier())
2155 Range.setBegin(getQualifierRange().getBegin());
2157 Range.setBegin(MemberNameInfo.getBeginLoc());
2159 if (hasExplicitTemplateArgs())
2160 Range.setEnd(getRAngleLoc());
2162 Range.setEnd(MemberNameInfo.getEndLoc());
2166 static bool classof(const Stmt *T) {
2167 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2169 static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2172 virtual child_iterator child_begin();
2173 virtual child_iterator child_end();
2176 /// \brief Represents a C++ member access expression for which lookup
2177 /// produced a set of overloaded functions.
2179 /// The member access may be explicit or implicit:
2182 /// int explicitAccess() { return this->a + this->A::b; }
2183 /// int implicitAccess() { return a + A::b; }
2186 /// In the final AST, an explicit access always becomes a MemberExpr.
2187 /// An implicit access may become either a MemberExpr or a
2188 /// DeclRefExpr, depending on whether the member is static.
2189 class UnresolvedMemberExpr : public OverloadExpr {
2190 /// \brief Whether this member expression used the '->' operator or
2191 /// the '.' operator.
2194 /// \brief Whether the lookup results contain an unresolved using
2196 bool HasUnresolvedUsing : 1;
2198 /// \brief The expression for the base pointer or class reference,
2199 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
2200 /// member expression
2203 /// \brief The type of the base expression; never null.
2206 /// \brief The location of the '->' or '.' operator.
2207 SourceLocation OperatorLoc;
2209 UnresolvedMemberExpr(ASTContext &C, QualType T, bool Dependent,
2210 bool HasUnresolvedUsing,
2211 Expr *Base, QualType BaseType, bool IsArrow,
2212 SourceLocation OperatorLoc,
2213 NestedNameSpecifier *Qualifier,
2214 SourceRange QualifierRange,
2215 const DeclarationNameInfo &MemberNameInfo,
2216 const TemplateArgumentListInfo *TemplateArgs,
2217 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2219 UnresolvedMemberExpr(EmptyShell Empty)
2220 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2221 HasUnresolvedUsing(false), Base(0) { }
2224 static UnresolvedMemberExpr *
2225 Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
2226 Expr *Base, QualType BaseType, bool IsArrow,
2227 SourceLocation OperatorLoc,
2228 NestedNameSpecifier *Qualifier,
2229 SourceRange QualifierRange,
2230 const DeclarationNameInfo &MemberNameInfo,
2231 const TemplateArgumentListInfo *TemplateArgs,
2232 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2234 static UnresolvedMemberExpr *
2235 CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
2237 /// \brief True if this is an implicit access, i.e. one in which the
2238 /// member being accessed was not written in the source. The source
2239 /// location of the operator is invalid in this case.
2240 bool isImplicitAccess() const { return Base == 0; }
2242 /// \brief Retrieve the base object of this member expressions,
2243 /// e.g., the \c x in \c x.m.
2245 assert(!isImplicitAccess());
2246 return cast<Expr>(Base);
2248 const Expr *getBase() const {
2249 assert(!isImplicitAccess());
2250 return cast<Expr>(Base);
2252 void setBase(Expr *E) { Base = E; }
2254 QualType getBaseType() const { return BaseType; }
2255 void setBaseType(QualType T) { BaseType = T; }
2257 /// \brief Determine whether the lookup results contain an unresolved using
2259 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2260 void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; }
2262 /// \brief Determine whether this member expression used the '->'
2263 /// operator; otherwise, it used the '.' operator.
2264 bool isArrow() const { return IsArrow; }
2265 void setArrow(bool A) { IsArrow = A; }
2267 /// \brief Retrieve the location of the '->' or '.' operator.
2268 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2269 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2271 /// \brief Retrieves the naming class of this lookup.
2272 CXXRecordDecl *getNamingClass() const;
2274 /// \brief Retrieve the full name info for the member that this expression
2276 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
2277 void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); }
2279 /// \brief Retrieve the name of the member that this expression
2281 DeclarationName getMemberName() const { return getName(); }
2282 void setMemberName(DeclarationName N) { setName(N); }
2284 // \brief Retrieve the location of the name of the member that this
2285 // expression refers to.
2286 SourceLocation getMemberLoc() const { return getNameLoc(); }
2287 void setMemberLoc(SourceLocation L) { setNameLoc(L); }
2289 /// \brief Retrieve the explicit template argument list that followed the
2290 /// member template name.
2291 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2292 assert(hasExplicitTemplateArgs());
2293 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2296 /// \brief Retrieve the explicit template argument list that followed the
2297 /// member template name, if any.
2298 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2299 assert(hasExplicitTemplateArgs());
2300 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2303 /// \brief Retrieves the optional explicit template arguments.
2304 /// This points to the same data as getExplicitTemplateArgs(), but
2305 /// returns null if there are no explicit template arguments.
2306 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2307 if (!hasExplicitTemplateArgs()) return 0;
2308 return &getExplicitTemplateArgs();
2311 /// \brief Copies the template arguments into the given structure.
2312 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2313 getExplicitTemplateArgs().copyInto(List);
2316 /// \brief Retrieve the location of the left angle bracket following
2317 /// the member name ('<').
2318 SourceLocation getLAngleLoc() const {
2319 return getExplicitTemplateArgs().LAngleLoc;
2322 /// \brief Retrieve the template arguments provided as part of this
2324 const TemplateArgumentLoc *getTemplateArgs() const {
2325 return getExplicitTemplateArgs().getTemplateArgs();
2328 /// \brief Retrieve the number of template arguments provided as
2329 /// part of this template-id.
2330 unsigned getNumTemplateArgs() const {
2331 return getExplicitTemplateArgs().NumTemplateArgs;
2334 /// \brief Retrieve the location of the right angle bracket
2335 /// following the template arguments ('>').
2336 SourceLocation getRAngleLoc() const {
2337 return getExplicitTemplateArgs().RAngleLoc;
2340 virtual SourceRange getSourceRange() const {
2341 SourceRange Range = getMemberNameInfo().getSourceRange();
2342 if (!isImplicitAccess())
2343 Range.setBegin(Base->getSourceRange().getBegin());
2344 else if (getQualifier())
2345 Range.setBegin(getQualifierRange().getBegin());
2347 if (hasExplicitTemplateArgs())
2348 Range.setEnd(getRAngleLoc());
2352 static bool classof(const Stmt *T) {
2353 return T->getStmtClass() == UnresolvedMemberExprClass;
2355 static bool classof(const UnresolvedMemberExpr *) { return true; }
2358 virtual child_iterator child_begin();
2359 virtual child_iterator child_end();
2362 inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2363 if (isa<UnresolvedLookupExpr>(this))
2364 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2366 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2369 } // end namespace clang