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 ExprValueKind VK, SourceLocation operatorloc)
55 : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK,
58 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
59 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
62 /// getOperator - Returns the kind of overloaded operator that this
63 /// expression refers to.
64 OverloadedOperatorKind getOperator() const { return Operator; }
65 void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
67 /// getOperatorLoc - Returns the location of the operator symbol in
68 /// the expression. When @c getOperator()==OO_Call, this is the
69 /// location of the right parentheses; when @c
70 /// getOperator()==OO_Subscript, this is the location of the right
72 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
74 SourceRange getSourceRange() const;
76 static bool classof(const Stmt *T) {
77 return T->getStmtClass() == CXXOperatorCallExprClass;
79 static bool classof(const CXXOperatorCallExpr *) { return true; }
82 /// CXXMemberCallExpr - Represents a call to a member function that
83 /// may be written either with member call syntax (e.g., "obj.func()"
84 /// or "objptr->func()") or with normal function-call syntax
85 /// ("func()") within a member function that ends up calling a member
86 /// function. The callee in either case is a MemberExpr that contains
87 /// both the object argument and the member function, while the
88 /// arguments are the arguments within the parentheses (not including
89 /// the object argument).
90 class CXXMemberCallExpr : public CallExpr {
92 CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
93 QualType t, ExprValueKind VK, SourceLocation RP)
94 : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {}
96 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
97 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
99 /// getImplicitObjectArgument - Retrieves the implicit object
100 /// argument for the member call. For example, in "x.f(5)", this
101 /// operation would return "x".
102 Expr *getImplicitObjectArgument();
104 /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
105 /// the implicit object argument. Note that this is may not be the same
106 /// declaration as that of the class context of the CXXMethodDecl which this
107 /// function is calling.
108 /// FIXME: Returns 0 for member pointer call exprs.
109 CXXRecordDecl *getRecordDecl();
111 static bool classof(const Stmt *T) {
112 return T->getStmtClass() == CXXMemberCallExprClass;
114 static bool classof(const CXXMemberCallExpr *) { return true; }
117 /// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
118 class CUDAKernelCallExpr : public CallExpr {
120 enum { CONFIG, END_PREARG };
123 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
124 Expr **args, unsigned numargs, QualType t,
125 ExprValueKind VK, SourceLocation RP)
126 : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK,
131 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
132 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
134 const CallExpr *getConfig() const {
135 return cast_or_null<CallExpr>(getPreArg(CONFIG));
137 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
138 void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
140 static bool classof(const Stmt *T) {
141 return T->getStmtClass() == CUDAKernelCallExprClass;
143 static bool classof(const CUDAKernelCallExpr *) { return true; }
146 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
147 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
150 /// This abstract class is inherited by all of the classes
151 /// representing "named" casts, e.g., CXXStaticCastExpr,
152 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
153 class CXXNamedCastExpr : public ExplicitCastExpr {
155 SourceLocation Loc; // the location of the casting op
156 SourceLocation RParenLoc; // the location of the right parenthesis
159 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
160 CastKind kind, Expr *op, unsigned PathSize,
161 TypeSourceInfo *writtenTy, SourceLocation l,
162 SourceLocation RParenLoc)
163 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
164 RParenLoc(RParenLoc) {}
166 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
167 : ExplicitCastExpr(SC, Shell, PathSize) { }
169 friend class ASTStmtReader;
172 const char *getCastName() const;
174 /// \brief Retrieve the location of the cast operator keyword, e.g.,
176 SourceLocation getOperatorLoc() const { return Loc; }
178 /// \brief Retrieve the location of the closing parenthesis.
179 SourceLocation getRParenLoc() const { return RParenLoc; }
181 SourceRange getSourceRange() const {
182 return SourceRange(Loc, RParenLoc);
184 static bool classof(const Stmt *T) {
185 switch (T->getStmtClass()) {
186 case CXXStaticCastExprClass:
187 case CXXDynamicCastExprClass:
188 case CXXReinterpretCastExprClass:
189 case CXXConstCastExprClass:
195 static bool classof(const CXXNamedCastExpr *) { return true; }
198 /// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
200 /// This expression node represents a C++ static cast, e.g.,
201 /// @c static_cast<int>(1.0).
202 class CXXStaticCastExpr : public CXXNamedCastExpr {
203 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
204 unsigned pathSize, TypeSourceInfo *writtenTy,
205 SourceLocation l, SourceLocation RParenLoc)
206 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
207 writtenTy, l, RParenLoc) {}
209 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
210 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
213 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
214 ExprValueKind VK, CastKind K, Expr *Op,
215 const CXXCastPath *Path,
216 TypeSourceInfo *Written, SourceLocation L,
217 SourceLocation RParenLoc);
218 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
221 static bool classof(const Stmt *T) {
222 return T->getStmtClass() == CXXStaticCastExprClass;
224 static bool classof(const CXXStaticCastExpr *) { return true; }
227 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
228 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
229 /// determine how to perform the type cast.
231 /// This expression node represents a dynamic cast, e.g.,
232 /// @c dynamic_cast<Derived*>(BasePtr).
233 class CXXDynamicCastExpr : public CXXNamedCastExpr {
234 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
235 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
236 SourceLocation l, SourceLocation RParenLoc)
237 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
238 writtenTy, l, RParenLoc) {}
240 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
241 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
244 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
245 ExprValueKind VK, CastKind Kind, Expr *Op,
246 const CXXCastPath *Path,
247 TypeSourceInfo *Written, SourceLocation L,
248 SourceLocation RParenLoc);
250 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
253 static bool classof(const Stmt *T) {
254 return T->getStmtClass() == CXXDynamicCastExprClass;
256 static bool classof(const CXXDynamicCastExpr *) { return true; }
259 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
260 /// [expr.reinterpret.cast]), which provides a differently-typed view
261 /// of a value but performs no actual work at run time.
263 /// This expression node represents a reinterpret cast, e.g.,
264 /// @c reinterpret_cast<int>(VoidPtr).
265 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
266 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
267 Expr *op, unsigned pathSize,
268 TypeSourceInfo *writtenTy, SourceLocation l,
269 SourceLocation RParenLoc)
270 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
271 pathSize, writtenTy, l, RParenLoc) {}
273 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
274 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
277 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
278 ExprValueKind VK, CastKind Kind,
279 Expr *Op, const CXXCastPath *Path,
280 TypeSourceInfo *WrittenTy, SourceLocation L,
281 SourceLocation RParenLoc);
282 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
285 static bool classof(const Stmt *T) {
286 return T->getStmtClass() == CXXReinterpretCastExprClass;
288 static bool classof(const CXXReinterpretCastExpr *) { return true; }
291 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
292 /// which can remove type qualifiers but does not change the underlying value.
294 /// This expression node represents a const cast, e.g.,
295 /// @c const_cast<char*>(PtrToConstChar).
296 class CXXConstCastExpr : public CXXNamedCastExpr {
297 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
298 TypeSourceInfo *writtenTy, SourceLocation l,
299 SourceLocation RParenLoc)
300 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
301 0, writtenTy, l, RParenLoc) {}
303 explicit CXXConstCastExpr(EmptyShell Empty)
304 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
307 static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
308 ExprValueKind VK, Expr *Op,
309 TypeSourceInfo *WrittenTy, SourceLocation L,
310 SourceLocation RParenLoc);
311 static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
313 static bool classof(const Stmt *T) {
314 return T->getStmtClass() == CXXConstCastExprClass;
316 static bool classof(const CXXConstCastExpr *) { return true; }
319 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
321 class CXXBoolLiteralExpr : public Expr {
325 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
326 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
328 Value(val), Loc(l) {}
330 explicit CXXBoolLiteralExpr(EmptyShell Empty)
331 : Expr(CXXBoolLiteralExprClass, Empty) { }
333 bool getValue() const { return Value; }
334 void setValue(bool V) { Value = V; }
336 SourceRange getSourceRange() const { return SourceRange(Loc); }
338 SourceLocation getLocation() const { return Loc; }
339 void setLocation(SourceLocation L) { Loc = L; }
341 static bool classof(const Stmt *T) {
342 return T->getStmtClass() == CXXBoolLiteralExprClass;
344 static bool classof(const CXXBoolLiteralExpr *) { return true; }
347 child_range children() { return child_range(); }
350 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
351 class CXXNullPtrLiteralExpr : public Expr {
354 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
355 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
359 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
360 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
362 SourceRange getSourceRange() const { return SourceRange(Loc); }
364 SourceLocation getLocation() const { return Loc; }
365 void setLocation(SourceLocation L) { Loc = L; }
367 static bool classof(const Stmt *T) {
368 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
370 static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
372 child_range children() { return child_range(); }
375 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
376 /// the type_info that corresponds to the supplied type, or the (possibly
377 /// dynamic) type of the supplied expression.
379 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
380 class CXXTypeidExpr : public Expr {
382 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
386 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
387 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
388 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
390 // typeid is value-dependent if the type or expression are dependent
391 Operand->getType()->isDependentType(),
392 Operand->getType()->containsUnexpandedParameterPack()),
393 Operand(Operand), Range(R) { }
395 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
396 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
397 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
399 // typeid is value-dependent if the type or expression are dependent
400 Operand->isTypeDependent() || Operand->isValueDependent(),
401 Operand->containsUnexpandedParameterPack()),
402 Operand(Operand), Range(R) { }
404 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
405 : Expr(CXXTypeidExprClass, Empty) {
409 Operand = (TypeSourceInfo*)0;
412 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
414 /// \brief Retrieves the type operand of this typeid() expression after
415 /// various required adjustments (removing reference types, cv-qualifiers).
416 QualType getTypeOperand() const;
418 /// \brief Retrieve source information for the type operand.
419 TypeSourceInfo *getTypeOperandSourceInfo() const {
420 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
421 return Operand.get<TypeSourceInfo *>();
424 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
425 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
429 Expr *getExprOperand() const {
430 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
431 return static_cast<Expr*>(Operand.get<Stmt *>());
434 void setExprOperand(Expr *E) {
435 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
439 SourceRange getSourceRange() const { return Range; }
440 void setSourceRange(SourceRange R) { Range = R; }
442 static bool classof(const Stmt *T) {
443 return T->getStmtClass() == CXXTypeidExprClass;
445 static bool classof(const CXXTypeidExpr *) { return true; }
448 child_range children() {
449 if (isTypeOperand()) return child_range();
450 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
451 return child_range(begin, begin + 1);
455 /// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
456 /// the _GUID that corresponds to the supplied type or expression.
458 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
459 class CXXUuidofExpr : public Expr {
461 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
465 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
466 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
467 false, Operand->getType()->isDependentType(),
468 Operand->getType()->containsUnexpandedParameterPack()),
469 Operand(Operand), Range(R) { }
471 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
472 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
473 false, Operand->isTypeDependent(),
474 Operand->containsUnexpandedParameterPack()),
475 Operand(Operand), Range(R) { }
477 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
478 : Expr(CXXUuidofExprClass, Empty) {
482 Operand = (TypeSourceInfo*)0;
485 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
487 /// \brief Retrieves the type operand of this __uuidof() expression after
488 /// various required adjustments (removing reference types, cv-qualifiers).
489 QualType getTypeOperand() const;
491 /// \brief Retrieve source information for the type operand.
492 TypeSourceInfo *getTypeOperandSourceInfo() const {
493 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
494 return Operand.get<TypeSourceInfo *>();
497 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
498 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
502 Expr *getExprOperand() const {
503 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
504 return static_cast<Expr*>(Operand.get<Stmt *>());
507 void setExprOperand(Expr *E) {
508 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
512 SourceRange getSourceRange() const { return Range; }
513 void setSourceRange(SourceRange R) { Range = R; }
515 static bool classof(const Stmt *T) {
516 return T->getStmtClass() == CXXUuidofExprClass;
518 static bool classof(const CXXUuidofExpr *) { return true; }
521 child_range children() {
522 if (isTypeOperand()) return child_range();
523 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
524 return child_range(begin, begin + 1);
528 /// CXXThisExpr - Represents the "this" expression in C++, which is a
529 /// pointer to the object on which the current member function is
530 /// executing (C++ [expr.prim]p3). Example:
536 /// void test() { this->bar(); }
539 class CXXThisExpr : public Expr {
544 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
545 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
546 // 'this' is type-dependent if the class type of the enclosing
547 // member function is dependent (C++ [temp.dep.expr]p2)
548 Type->isDependentType(), Type->isDependentType(),
549 /*ContainsUnexpandedParameterPack=*/false),
550 Loc(L), Implicit(isImplicit) { }
552 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
554 SourceLocation getLocation() const { return Loc; }
555 void setLocation(SourceLocation L) { Loc = L; }
557 SourceRange getSourceRange() const { return SourceRange(Loc); }
559 bool isImplicit() const { return Implicit; }
560 void setImplicit(bool I) { Implicit = I; }
562 static bool classof(const Stmt *T) {
563 return T->getStmtClass() == CXXThisExprClass;
565 static bool classof(const CXXThisExpr *) { return true; }
568 child_range children() { return child_range(); }
571 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
572 /// 'throw' and 'throw' assignment-expression. When
573 /// assignment-expression isn't present, Op will be null.
575 class CXXThrowExpr : public Expr {
577 SourceLocation ThrowLoc;
579 // Ty is the void type which is used as the result type of the
580 // exepression. The l is the location of the throw keyword. expr
581 // can by null, if the optional expression to throw isn't present.
582 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
583 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
584 expr && expr->containsUnexpandedParameterPack()),
585 Op(expr), ThrowLoc(l) {}
586 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
588 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
589 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
590 void setSubExpr(Expr *E) { Op = E; }
592 SourceLocation getThrowLoc() const { return ThrowLoc; }
593 void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
595 SourceRange getSourceRange() const {
596 if (getSubExpr() == 0)
597 return SourceRange(ThrowLoc, ThrowLoc);
598 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
601 static bool classof(const Stmt *T) {
602 return T->getStmtClass() == CXXThrowExprClass;
604 static bool classof(const CXXThrowExpr *) { return true; }
607 child_range children() {
608 return child_range(&Op, Op ? &Op+1 : &Op);
612 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
613 /// function call argument that was created from the corresponding
614 /// parameter's default argument, when the call did not explicitly
615 /// supply arguments for all of the parameters.
616 class CXXDefaultArgExpr : public Expr {
617 /// \brief The parameter whose default is being used.
619 /// When the bit is set, the subexpression is stored after the
620 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
621 /// actual default expression is the subexpression.
622 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
624 /// \brief The location where the default argument expression was used.
627 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
629 param->hasUnparsedDefaultArg()
630 ? param->getType().getNonReferenceType()
631 : param->getDefaultArg()->getType(),
632 param->getDefaultArg()->getValueKind(),
633 param->getDefaultArg()->getObjectKind(), false, false, false),
634 Param(param, false), Loc(Loc) { }
636 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
638 : Expr(SC, SubExpr->getType(),
639 SubExpr->getValueKind(), SubExpr->getObjectKind(),
640 false, false, false),
641 Param(param, true), Loc(Loc) {
642 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
646 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
649 // Param is the parameter whose default argument is used by this
651 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
652 ParmVarDecl *Param) {
653 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
656 // Param is the parameter whose default argument is used by this
657 // expression, and SubExpr is the expression that will actually be used.
658 static CXXDefaultArgExpr *Create(ASTContext &C,
663 // Retrieve the parameter that the argument was created from.
664 const ParmVarDecl *getParam() const { return Param.getPointer(); }
665 ParmVarDecl *getParam() { return Param.getPointer(); }
667 // Retrieve the actual argument to the function call.
668 const Expr *getExpr() const {
670 return *reinterpret_cast<Expr const * const*> (this + 1);
671 return getParam()->getDefaultArg();
675 return *reinterpret_cast<Expr **> (this + 1);
676 return getParam()->getDefaultArg();
679 /// \brief Retrieve the location where this default argument was actually
681 SourceLocation getUsedLocation() const { return Loc; }
683 SourceRange getSourceRange() const {
684 // Default argument expressions have no representation in the
685 // source, so they have an empty source range.
686 return SourceRange();
689 static bool classof(const Stmt *T) {
690 return T->getStmtClass() == CXXDefaultArgExprClass;
692 static bool classof(const CXXDefaultArgExpr *) { return true; }
695 child_range children() { return child_range(); }
697 friend class ASTStmtReader;
698 friend class ASTStmtWriter;
701 /// CXXTemporary - Represents a C++ temporary.
703 /// Destructor - The destructor that needs to be called.
704 const CXXDestructorDecl *Destructor;
706 CXXTemporary(const CXXDestructorDecl *destructor)
707 : Destructor(destructor) { }
710 static CXXTemporary *Create(ASTContext &C,
711 const CXXDestructorDecl *Destructor);
713 const CXXDestructorDecl *getDestructor() const { return Destructor; }
716 /// \brief Represents binding an expression to a temporary.
718 /// This ensures the destructor is called for the temporary. It should only be
719 /// needed for non-POD, non-trivially destructable class types. For example:
723 /// S() { } // User defined constructor makes S non-POD.
724 /// ~S() { } // User defined destructor makes it non-trivial.
727 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
730 class CXXBindTemporaryExpr : public Expr {
735 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
736 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
737 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
738 SubExpr->isValueDependent(),
739 SubExpr->containsUnexpandedParameterPack()),
740 Temp(temp), SubExpr(SubExpr) { }
743 CXXBindTemporaryExpr(EmptyShell Empty)
744 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
746 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
749 CXXTemporary *getTemporary() { return Temp; }
750 const CXXTemporary *getTemporary() const { return Temp; }
751 void setTemporary(CXXTemporary *T) { Temp = T; }
753 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
754 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
755 void setSubExpr(Expr *E) { SubExpr = E; }
757 SourceRange getSourceRange() const {
758 return SubExpr->getSourceRange();
761 // Implement isa/cast/dyncast/etc.
762 static bool classof(const Stmt *T) {
763 return T->getStmtClass() == CXXBindTemporaryExprClass;
765 static bool classof(const CXXBindTemporaryExpr *) { return true; }
768 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
771 /// CXXConstructExpr - Represents a call to a C++ constructor.
772 class CXXConstructExpr : public Expr {
774 enum ConstructionKind {
781 CXXConstructorDecl *Constructor;
784 SourceRange ParenRange;
786 bool ZeroInitialization : 1;
787 unsigned ConstructKind : 2;
792 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
794 CXXConstructorDecl *d, bool elidable,
795 Expr **args, unsigned numargs,
796 bool ZeroInitialization = false,
797 ConstructionKind ConstructKind = CK_Complete,
798 SourceRange ParenRange = SourceRange());
800 /// \brief Construct an empty C++ construction expression.
801 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
802 : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
803 ConstructKind(0), Args(0), NumArgs(0) { }
806 /// \brief Construct an empty C++ construction expression.
807 explicit CXXConstructExpr(EmptyShell Empty)
808 : Expr(CXXConstructExprClass, Empty), Constructor(0),
809 Elidable(0), ZeroInitialization(0),
810 ConstructKind(0), Args(0), NumArgs(0) { }
812 static CXXConstructExpr *Create(ASTContext &C, QualType T,
814 CXXConstructorDecl *D, bool Elidable,
815 Expr **Args, unsigned NumArgs,
816 bool ZeroInitialization = false,
817 ConstructionKind ConstructKind = CK_Complete,
818 SourceRange ParenRange = SourceRange());
821 CXXConstructorDecl* getConstructor() const { return Constructor; }
822 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
824 SourceLocation getLocation() const { return Loc; }
825 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
827 /// \brief Whether this construction is elidable.
828 bool isElidable() const { return Elidable; }
829 void setElidable(bool E) { Elidable = E; }
831 /// \brief Whether this construction first requires
832 /// zero-initialization before the initializer is called.
833 bool requiresZeroInitialization() const { return ZeroInitialization; }
834 void setRequiresZeroInitialization(bool ZeroInit) {
835 ZeroInitialization = ZeroInit;
838 /// \brief Determines whether this constructor is actually constructing
839 /// a base class (rather than a complete object).
840 ConstructionKind getConstructionKind() const {
841 return (ConstructionKind)ConstructKind;
843 void setConstructionKind(ConstructionKind CK) {
847 typedef ExprIterator arg_iterator;
848 typedef ConstExprIterator const_arg_iterator;
850 arg_iterator arg_begin() { return Args; }
851 arg_iterator arg_end() { return Args + NumArgs; }
852 const_arg_iterator arg_begin() const { return Args; }
853 const_arg_iterator arg_end() const { return Args + NumArgs; }
855 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
856 unsigned getNumArgs() const { return NumArgs; }
858 /// getArg - Return the specified argument.
859 Expr *getArg(unsigned Arg) {
860 assert(Arg < NumArgs && "Arg access out of range!");
861 return cast<Expr>(Args[Arg]);
863 const Expr *getArg(unsigned Arg) const {
864 assert(Arg < NumArgs && "Arg access out of range!");
865 return cast<Expr>(Args[Arg]);
868 /// setArg - Set the specified argument.
869 void setArg(unsigned Arg, Expr *ArgExpr) {
870 assert(Arg < NumArgs && "Arg access out of range!");
874 SourceRange getSourceRange() const;
875 SourceRange getParenRange() const { return ParenRange; }
877 static bool classof(const Stmt *T) {
878 return T->getStmtClass() == CXXConstructExprClass ||
879 T->getStmtClass() == CXXTemporaryObjectExprClass;
881 static bool classof(const CXXConstructExpr *) { return true; }
884 child_range children() {
885 return child_range(&Args[0], &Args[0]+NumArgs);
888 friend class ASTStmtReader;
891 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
892 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
894 class CXXFunctionalCastExpr : public ExplicitCastExpr {
895 SourceLocation TyBeginLoc;
896 SourceLocation RParenLoc;
898 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
899 TypeSourceInfo *writtenTy,
900 SourceLocation tyBeginLoc, CastKind kind,
901 Expr *castExpr, unsigned pathSize,
902 SourceLocation rParenLoc)
903 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
904 castExpr, pathSize, writtenTy),
905 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
907 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
908 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
911 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
913 TypeSourceInfo *Written,
914 SourceLocation TyBeginLoc,
915 CastKind Kind, Expr *Op,
916 const CXXCastPath *Path,
917 SourceLocation RPLoc);
918 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
921 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
922 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
923 SourceLocation getRParenLoc() const { return RParenLoc; }
924 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
926 SourceRange getSourceRange() const {
927 return SourceRange(TyBeginLoc, RParenLoc);
929 static bool classof(const Stmt *T) {
930 return T->getStmtClass() == CXXFunctionalCastExprClass;
932 static bool classof(const CXXFunctionalCastExpr *) { return true; }
935 /// @brief Represents a C++ functional cast expression that builds a
936 /// temporary object.
938 /// This expression type represents a C++ "functional" cast
939 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
940 /// constructor to build a temporary object. With N == 1 arguments the
941 /// functional cast expression will be represented by CXXFunctionalCastExpr.
944 /// struct X { X(int, float); }
947 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
950 class CXXTemporaryObjectExpr : public CXXConstructExpr {
951 TypeSourceInfo *Type;
954 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
955 TypeSourceInfo *Type,
956 Expr **Args,unsigned NumArgs,
957 SourceRange parenRange,
958 bool ZeroInitialization = false);
959 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
960 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
962 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
964 SourceRange getSourceRange() const;
966 static bool classof(const Stmt *T) {
967 return T->getStmtClass() == CXXTemporaryObjectExprClass;
969 static bool classof(const CXXTemporaryObjectExpr *) { return true; }
971 friend class ASTStmtReader;
974 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
975 /// Expression "T()" which creates a value-initialized rvalue of type
976 /// T, which is a non-class type.
978 class CXXScalarValueInitExpr : public Expr {
979 SourceLocation RParenLoc;
980 TypeSourceInfo *TypeInfo;
982 friend class ASTStmtReader;
985 /// \brief Create an explicitly-written scalar-value initialization
987 CXXScalarValueInitExpr(QualType Type,
988 TypeSourceInfo *TypeInfo,
989 SourceLocation rParenLoc ) :
990 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
991 false, false, false),
992 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
994 explicit CXXScalarValueInitExpr(EmptyShell Shell)
995 : Expr(CXXScalarValueInitExprClass, Shell) { }
997 TypeSourceInfo *getTypeSourceInfo() const {
1001 SourceLocation getRParenLoc() const { return RParenLoc; }
1003 SourceRange getSourceRange() const;
1005 static bool classof(const Stmt *T) {
1006 return T->getStmtClass() == CXXScalarValueInitExprClass;
1008 static bool classof(const CXXScalarValueInitExpr *) { return true; }
1011 child_range children() { return child_range(); }
1014 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
1015 /// e.g: "new CXXNewExpr(foo)".
1016 class CXXNewExpr : public Expr {
1017 // Was the usage ::new, i.e. is the global new to be used?
1019 // Is there an initializer? If not, built-ins are uninitialized, else they're
1020 // value-initialized.
1021 bool Initializer : 1;
1022 // Do we allocate an array? If so, the first SubExpr is the size expression.
1024 // If this is an array allocation, does the usual deallocation
1025 // function for the allocated type want to know the allocated size?
1026 bool UsualArrayDeleteWantsSize : 1;
1027 // The number of placement new arguments.
1028 unsigned NumPlacementArgs : 14;
1029 // The number of constructor arguments. This may be 1 even for non-class
1030 // types; use the pseudo copy constructor.
1031 unsigned NumConstructorArgs : 14;
1032 // Contains an optional array size expression, any number of optional
1033 // placement arguments, and any number of optional constructor arguments,
1036 // Points to the allocation function used.
1037 FunctionDecl *OperatorNew;
1038 // Points to the deallocation function used in case of error. May be null.
1039 FunctionDecl *OperatorDelete;
1040 // Points to the constructor used. Cannot be null if AllocType is a record;
1041 // it would still point at the default constructor (even an implicit one).
1042 // Must be null for all other types.
1043 CXXConstructorDecl *Constructor;
1045 /// \brief The allocated type-source information, as written in the source.
1046 TypeSourceInfo *AllocatedTypeInfo;
1048 /// \brief If the allocated type was expressed as a parenthesized type-id,
1049 /// the source range covering the parenthesized type-id.
1050 SourceRange TypeIdParens;
1052 SourceLocation StartLoc;
1053 SourceLocation EndLoc;
1054 SourceLocation ConstructorLParen;
1055 SourceLocation ConstructorRParen;
1057 friend class ASTStmtReader;
1059 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1060 Expr **placementArgs, unsigned numPlaceArgs,
1061 SourceRange TypeIdParens,
1062 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
1063 Expr **constructorArgs, unsigned numConsArgs,
1064 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1065 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1066 SourceLocation startLoc, SourceLocation endLoc,
1067 SourceLocation constructorLParen,
1068 SourceLocation constructorRParen);
1069 explicit CXXNewExpr(EmptyShell Shell)
1070 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1072 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1073 unsigned numConsArgs);
1075 QualType getAllocatedType() const {
1076 assert(getType()->isPointerType());
1077 return getType()->getAs<PointerType>()->getPointeeType();
1080 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1081 return AllocatedTypeInfo;
1084 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1085 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1086 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1087 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1088 CXXConstructorDecl *getConstructor() const { return Constructor; }
1089 void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
1091 bool isArray() const { return Array; }
1092 Expr *getArraySize() {
1093 return Array ? cast<Expr>(SubExprs[0]) : 0;
1095 const Expr *getArraySize() const {
1096 return Array ? cast<Expr>(SubExprs[0]) : 0;
1099 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1100 Expr **getPlacementArgs() {
1101 return reinterpret_cast<Expr **>(SubExprs + Array);
1104 Expr *getPlacementArg(unsigned i) {
1105 assert(i < NumPlacementArgs && "Index out of range");
1106 return cast<Expr>(SubExprs[Array + i]);
1108 const Expr *getPlacementArg(unsigned i) const {
1109 assert(i < NumPlacementArgs && "Index out of range");
1110 return cast<Expr>(SubExprs[Array + i]);
1113 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1114 SourceRange getTypeIdParens() const { return TypeIdParens; }
1116 bool isGlobalNew() const { return GlobalNew; }
1117 bool hasInitializer() const { return Initializer; }
1119 /// Answers whether the usual array deallocation function for the
1120 /// allocated type expects the size of the allocation as a
1122 bool doesUsualArrayDeleteWantSize() const {
1123 return UsualArrayDeleteWantsSize;
1126 unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1128 Expr **getConstructorArgs() {
1129 return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs);
1132 Expr *getConstructorArg(unsigned i) {
1133 assert(i < NumConstructorArgs && "Index out of range");
1134 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1136 const Expr *getConstructorArg(unsigned i) const {
1137 assert(i < NumConstructorArgs && "Index out of range");
1138 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1141 typedef ExprIterator arg_iterator;
1142 typedef ConstExprIterator const_arg_iterator;
1144 arg_iterator placement_arg_begin() {
1145 return SubExprs + Array;
1147 arg_iterator placement_arg_end() {
1148 return SubExprs + Array + getNumPlacementArgs();
1150 const_arg_iterator placement_arg_begin() const {
1151 return SubExprs + Array;
1153 const_arg_iterator placement_arg_end() const {
1154 return SubExprs + Array + getNumPlacementArgs();
1157 arg_iterator constructor_arg_begin() {
1158 return SubExprs + Array + getNumPlacementArgs();
1160 arg_iterator constructor_arg_end() {
1161 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1163 const_arg_iterator constructor_arg_begin() const {
1164 return SubExprs + Array + getNumPlacementArgs();
1166 const_arg_iterator constructor_arg_end() const {
1167 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1170 typedef Stmt **raw_arg_iterator;
1171 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1172 raw_arg_iterator raw_arg_end() {
1173 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1175 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1176 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
1178 SourceLocation getStartLoc() const { return StartLoc; }
1179 SourceLocation getEndLoc() const { return EndLoc; }
1181 SourceLocation getConstructorLParen() const { return ConstructorLParen; }
1182 SourceLocation getConstructorRParen() const { return ConstructorRParen; }
1184 SourceRange getSourceRange() const {
1185 return SourceRange(StartLoc, EndLoc);
1188 static bool classof(const Stmt *T) {
1189 return T->getStmtClass() == CXXNewExprClass;
1191 static bool classof(const CXXNewExpr *) { return true; }
1194 child_range children() {
1195 return child_range(&SubExprs[0],
1196 &SubExprs[0] + Array + getNumPlacementArgs()
1197 + getNumConstructorArgs());
1201 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1202 /// calls, e.g. "delete[] pArray".
1203 class CXXDeleteExpr : public Expr {
1204 // Is this a forced global delete, i.e. "::delete"?
1205 bool GlobalDelete : 1;
1206 // Is this the array form of delete, i.e. "delete[]"?
1208 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1209 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1211 bool ArrayFormAsWritten : 1;
1212 // Does the usual deallocation function for the element type require
1213 // a size_t argument?
1214 bool UsualArrayDeleteWantsSize : 1;
1215 // Points to the operator delete overload that is used. Could be a member.
1216 FunctionDecl *OperatorDelete;
1217 // The pointer expression to be deleted.
1219 // Location of the expression.
1222 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1223 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1224 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1225 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1226 arg->containsUnexpandedParameterPack()),
1227 GlobalDelete(globalDelete),
1228 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1229 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
1230 OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
1231 explicit CXXDeleteExpr(EmptyShell Shell)
1232 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1234 bool isGlobalDelete() const { return GlobalDelete; }
1235 bool isArrayForm() const { return ArrayForm; }
1236 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1238 /// Answers whether the usual array deallocation function for the
1239 /// allocated type expects the size of the allocation as a
1240 /// parameter. This can be true even if the actual deallocation
1241 /// function that we're using doesn't want a size.
1242 bool doesUsualArrayDeleteWantSize() const {
1243 return UsualArrayDeleteWantsSize;
1246 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1248 Expr *getArgument() { return cast<Expr>(Argument); }
1249 const Expr *getArgument() const { return cast<Expr>(Argument); }
1251 /// \brief Retrieve the type being destroyed. If the type being
1252 /// destroyed is a dependent type which may or may not be a pointer,
1253 /// return an invalid type.
1254 QualType getDestroyedType() const;
1256 SourceRange getSourceRange() const {
1257 return SourceRange(Loc, Argument->getLocEnd());
1260 static bool classof(const Stmt *T) {
1261 return T->getStmtClass() == CXXDeleteExprClass;
1263 static bool classof(const CXXDeleteExpr *) { return true; }
1266 child_range children() { return child_range(&Argument, &Argument+1); }
1268 friend class ASTStmtReader;
1271 /// \brief Structure used to store the type being destroyed by a
1272 /// pseudo-destructor expression.
1273 class PseudoDestructorTypeStorage {
1274 /// \brief Either the type source information or the name of the type, if
1275 /// it couldn't be resolved due to type-dependence.
1276 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1278 /// \brief The starting source location of the pseudo-destructor type.
1279 SourceLocation Location;
1282 PseudoDestructorTypeStorage() { }
1284 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1285 : Type(II), Location(Loc) { }
1287 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1289 TypeSourceInfo *getTypeSourceInfo() const {
1290 return Type.dyn_cast<TypeSourceInfo *>();
1293 IdentifierInfo *getIdentifier() const {
1294 return Type.dyn_cast<IdentifierInfo *>();
1297 SourceLocation getLocation() const { return Location; }
1300 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1302 /// A pseudo-destructor is an expression that looks like a member access to a
1303 /// destructor of a scalar type, except that scalar types don't have
1304 /// destructors. For example:
1308 /// void f(int *p) {
1313 /// Pseudo-destructors typically occur when instantiating templates such as:
1316 /// template<typename T>
1317 /// void destroy(T* ptr) {
1322 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1323 /// beyond evaluating the base expression.
1324 class CXXPseudoDestructorExpr : public Expr {
1325 /// \brief The base expression (that is being destroyed).
1328 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1332 /// \brief The location of the '.' or '->' operator.
1333 SourceLocation OperatorLoc;
1335 /// \brief The nested-name-specifier that follows the operator, if present.
1336 NestedNameSpecifierLoc QualifierLoc;
1338 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1340 TypeSourceInfo *ScopeType;
1342 /// \brief The location of the '::' in a qualified pseudo-destructor
1344 SourceLocation ColonColonLoc;
1346 /// \brief The location of the '~'.
1347 SourceLocation TildeLoc;
1349 /// \brief The type being destroyed, or its name if we were unable to
1350 /// resolve the name.
1351 PseudoDestructorTypeStorage DestroyedType;
1353 friend class ASTStmtReader;
1356 CXXPseudoDestructorExpr(ASTContext &Context,
1357 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1358 NestedNameSpecifierLoc QualifierLoc,
1359 TypeSourceInfo *ScopeType,
1360 SourceLocation ColonColonLoc,
1361 SourceLocation TildeLoc,
1362 PseudoDestructorTypeStorage DestroyedType);
1364 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1365 : Expr(CXXPseudoDestructorExprClass, Shell),
1366 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1368 Expr *getBase() const { return cast<Expr>(Base); }
1370 /// \brief Determines whether this member expression actually had
1371 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1373 bool hasQualifier() const { return QualifierLoc; }
1375 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1376 /// with source-location information.
1377 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1379 /// \brief If the member name was qualified, retrieves the
1380 /// nested-name-specifier that precedes the member name. Otherwise, returns
1382 NestedNameSpecifier *getQualifier() const {
1383 return QualifierLoc.getNestedNameSpecifier();
1386 /// \brief Determine whether this pseudo-destructor expression was written
1387 /// using an '->' (otherwise, it used a '.').
1388 bool isArrow() const { return IsArrow; }
1390 /// \brief Retrieve the location of the '.' or '->' operator.
1391 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1393 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1396 /// Pseudo-destructor expressions can have extra qualification within them
1397 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1398 /// Here, if the object type of the expression is (or may be) a scalar type,
1399 /// \p T may also be a scalar type and, therefore, cannot be part of a
1400 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1401 /// destructor expression.
1402 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1404 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1406 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1408 /// \brief Retrieve the location of the '~'.
1409 SourceLocation getTildeLoc() const { return TildeLoc; }
1411 /// \brief Retrieve the source location information for the type
1412 /// being destroyed.
1414 /// This type-source information is available for non-dependent
1415 /// pseudo-destructor expressions and some dependent pseudo-destructor
1416 /// expressions. Returns NULL if we only have the identifier for a
1417 /// dependent pseudo-destructor expression.
1418 TypeSourceInfo *getDestroyedTypeInfo() const {
1419 return DestroyedType.getTypeSourceInfo();
1422 /// \brief In a dependent pseudo-destructor expression for which we do not
1423 /// have full type information on the destroyed type, provides the name
1424 /// of the destroyed type.
1425 IdentifierInfo *getDestroyedTypeIdentifier() const {
1426 return DestroyedType.getIdentifier();
1429 /// \brief Retrieve the type being destroyed.
1430 QualType getDestroyedType() const;
1432 /// \brief Retrieve the starting location of the type being destroyed.
1433 SourceLocation getDestroyedTypeLoc() const {
1434 return DestroyedType.getLocation();
1437 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1439 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1440 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1443 /// \brief Set the destroyed type.
1444 void setDestroyedType(TypeSourceInfo *Info) {
1445 DestroyedType = PseudoDestructorTypeStorage(Info);
1448 SourceRange getSourceRange() const;
1450 static bool classof(const Stmt *T) {
1451 return T->getStmtClass() == CXXPseudoDestructorExprClass;
1453 static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1456 child_range children() { return child_range(&Base, &Base + 1); }
1459 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1460 /// implementation of TR1/C++0x type trait templates.
1462 /// __is_pod(int) == true
1463 /// __is_enum(std::string) == false
1464 class UnaryTypeTraitExpr : public Expr {
1465 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
1467 /// The value of the type trait. Unspecified if dependent.
1470 /// Loc - The location of the type trait keyword.
1473 /// RParen - The location of the closing paren.
1474 SourceLocation RParen;
1476 /// The type being queried.
1477 TypeSourceInfo *QueriedType;
1480 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1481 TypeSourceInfo *queried, bool value,
1482 SourceLocation rparen, QualType ty)
1483 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1484 false, queried->getType()->isDependentType(),
1485 queried->getType()->containsUnexpandedParameterPack()),
1486 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
1488 explicit UnaryTypeTraitExpr(EmptyShell Empty)
1489 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
1492 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1494 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
1496 QualType getQueriedType() const { return QueriedType->getType(); }
1498 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1500 bool getValue() const { return Value; }
1502 static bool classof(const Stmt *T) {
1503 return T->getStmtClass() == UnaryTypeTraitExprClass;
1505 static bool classof(const UnaryTypeTraitExpr *) { return true; }
1508 child_range children() { return child_range(); }
1510 friend class ASTStmtReader;
1513 /// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
1514 /// implementation of TR1/C++0x type trait templates.
1516 /// __is_base_of(Base, Derived) == true
1517 class BinaryTypeTraitExpr : public Expr {
1518 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
1521 /// The value of the type trait. Unspecified if dependent.
1524 /// Loc - The location of the type trait keyword.
1527 /// RParen - The location of the closing paren.
1528 SourceLocation RParen;
1530 /// The lhs type being queried.
1531 TypeSourceInfo *LhsType;
1533 /// The rhs type being queried.
1534 TypeSourceInfo *RhsType;
1537 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1538 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
1539 bool value, SourceLocation rparen, QualType ty)
1540 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
1541 lhsType->getType()->isDependentType() ||
1542 rhsType->getType()->isDependentType(),
1543 (lhsType->getType()->containsUnexpandedParameterPack() ||
1544 rhsType->getType()->containsUnexpandedParameterPack())),
1545 BTT(btt), Value(value), Loc(loc), RParen(rparen),
1546 LhsType(lhsType), RhsType(rhsType) { }
1549 explicit BinaryTypeTraitExpr(EmptyShell Empty)
1550 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1551 LhsType(), RhsType() { }
1553 SourceRange getSourceRange() const {
1554 return SourceRange(Loc, RParen);
1557 BinaryTypeTrait getTrait() const {
1558 return static_cast<BinaryTypeTrait>(BTT);
1561 QualType getLhsType() const { return LhsType->getType(); }
1562 QualType getRhsType() const { return RhsType->getType(); }
1564 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
1565 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
1567 bool getValue() const { assert(!isTypeDependent()); return Value; }
1569 static bool classof(const Stmt *T) {
1570 return T->getStmtClass() == BinaryTypeTraitExprClass;
1572 static bool classof(const BinaryTypeTraitExpr *) { return true; }
1575 child_range children() { return child_range(); }
1577 friend class ASTStmtReader;
1580 /// \brief A reference to an overloaded function set, either an
1581 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1582 class OverloadExpr : public Expr {
1583 /// The results. These are undesugared, which is to say, they may
1584 /// include UsingShadowDecls. Access is relative to the naming
1586 // FIXME: Allocate this data after the OverloadExpr subclass.
1587 DeclAccessPair *Results;
1588 unsigned NumResults;
1590 /// The common name of these declarations.
1591 DeclarationNameInfo NameInfo;
1593 /// The scope specifier, if any.
1594 NestedNameSpecifier *Qualifier;
1596 /// The source range of the scope specifier.
1597 SourceRange QualifierRange;
1600 /// True if the name was a template-id.
1601 bool HasExplicitTemplateArgs;
1603 OverloadExpr(StmtClass K, ASTContext &C,
1604 NestedNameSpecifier *Qualifier, SourceRange QRange,
1605 const DeclarationNameInfo &NameInfo,
1606 const TemplateArgumentListInfo *TemplateArgs,
1607 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1608 bool KnownDependent = false,
1609 bool KnownContainsUnexpandedParameterPack = false);
1611 OverloadExpr(StmtClass K, EmptyShell Empty)
1612 : Expr(K, Empty), Results(0), NumResults(0),
1613 Qualifier(0), HasExplicitTemplateArgs(false) { }
1615 void initializeResults(ASTContext &C,
1616 UnresolvedSetIterator Begin,
1617 UnresolvedSetIterator End);
1621 OverloadExpr *Expression;
1622 bool IsAddressOfOperand;
1623 bool HasFormOfMemberPointer;
1626 /// Finds the overloaded expression in the given expression of
1629 /// \return the expression (which must be there) and true if it has
1630 /// the particular form of a member pointer expression
1631 static FindResult find(Expr *E) {
1632 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1636 E = E->IgnoreParens();
1637 if (isa<UnaryOperator>(E)) {
1638 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
1639 E = cast<UnaryOperator>(E)->getSubExpr();
1640 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
1642 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
1643 Result.IsAddressOfOperand = true;
1644 Result.Expression = Ovl;
1646 Result.HasFormOfMemberPointer = false;
1647 Result.IsAddressOfOperand = false;
1648 Result.Expression = cast<OverloadExpr>(E);
1654 /// Gets the naming class of this lookup, if any.
1655 CXXRecordDecl *getNamingClass() const;
1657 typedef UnresolvedSetImpl::iterator decls_iterator;
1658 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1659 decls_iterator decls_end() const {
1660 return UnresolvedSetIterator(Results + NumResults);
1663 /// Gets the number of declarations in the unresolved set.
1664 unsigned getNumDecls() const { return NumResults; }
1666 /// Gets the full name info.
1667 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1668 void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; }
1670 /// Gets the name looked up.
1671 DeclarationName getName() const { return NameInfo.getName(); }
1672 void setName(DeclarationName N) { NameInfo.setName(N); }
1674 /// Gets the location of the name.
1675 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
1676 void setNameLoc(SourceLocation Loc) { NameInfo.setLoc(Loc); }
1678 /// Fetches the nested-name qualifier, if one was given.
1679 NestedNameSpecifier *getQualifier() const { return Qualifier; }
1680 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1682 /// Fetches the range of the nested-name qualifier.
1683 SourceRange getQualifierRange() const { return QualifierRange; }
1684 void setQualifierRange(SourceRange R) { QualifierRange = R; }
1686 /// \brief Determines whether this expression had an explicit
1687 /// template argument list, e.g. f<int>.
1688 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1690 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1692 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1693 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1696 /// \brief Retrieves the optional explicit template arguments.
1697 /// This points to the same data as getExplicitTemplateArgs(), but
1698 /// returns null if there are no explicit template arguments.
1699 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1700 if (!hasExplicitTemplateArgs()) return 0;
1701 return &getExplicitTemplateArgs();
1704 static bool classof(const Stmt *T) {
1705 return T->getStmtClass() == UnresolvedLookupExprClass ||
1706 T->getStmtClass() == UnresolvedMemberExprClass;
1708 static bool classof(const OverloadExpr *) { return true; }
1710 friend class ASTStmtReader;
1711 friend class ASTStmtWriter;
1714 /// \brief A reference to a name which we were able to look up during
1715 /// parsing but could not resolve to a specific declaration. This
1716 /// arises in several ways:
1717 /// * we might be waiting for argument-dependent lookup
1718 /// * the name might resolve to an overloaded function
1720 /// * the lookup might have included a function template
1721 /// These never include UnresolvedUsingValueDecls, which are always
1722 /// class members and therefore appear only in
1723 /// UnresolvedMemberLookupExprs.
1724 class UnresolvedLookupExpr : public OverloadExpr {
1725 /// True if these lookup results should be extended by
1726 /// argument-dependent lookup if this is the operand of a function
1730 /// True if these lookup results are overloaded. This is pretty
1731 /// trivially rederivable if we urgently need to kill this field.
1734 /// The naming class (C++ [class.access.base]p5) of the lookup, if
1735 /// any. This can generally be recalculated from the context chain,
1736 /// but that can be fairly expensive for unqualified lookups. If we
1737 /// want to improve memory use here, this could go in a union
1738 /// against the qualified-lookup bits.
1739 CXXRecordDecl *NamingClass;
1741 UnresolvedLookupExpr(ASTContext &C,
1742 CXXRecordDecl *NamingClass,
1743 NestedNameSpecifier *Qualifier, SourceRange QRange,
1744 const DeclarationNameInfo &NameInfo,
1745 bool RequiresADL, bool Overloaded,
1746 const TemplateArgumentListInfo *TemplateArgs,
1747 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
1748 : OverloadExpr(UnresolvedLookupExprClass, C, Qualifier, QRange, NameInfo,
1749 TemplateArgs, Begin, End),
1750 RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1753 UnresolvedLookupExpr(EmptyShell Empty)
1754 : OverloadExpr(UnresolvedLookupExprClass, Empty),
1755 RequiresADL(false), Overloaded(false), NamingClass(0)
1759 static UnresolvedLookupExpr *Create(ASTContext &C,
1760 CXXRecordDecl *NamingClass,
1761 NestedNameSpecifier *Qualifier,
1762 SourceRange QualifierRange,
1763 const DeclarationNameInfo &NameInfo,
1764 bool ADL, bool Overloaded,
1765 UnresolvedSetIterator Begin,
1766 UnresolvedSetIterator End) {
1767 return new(C) UnresolvedLookupExpr(C, NamingClass, Qualifier,
1768 QualifierRange, NameInfo, ADL,
1769 Overloaded, 0, Begin, End);
1772 static UnresolvedLookupExpr *Create(ASTContext &C,
1773 CXXRecordDecl *NamingClass,
1774 NestedNameSpecifier *Qualifier,
1775 SourceRange QualifierRange,
1776 const DeclarationNameInfo &NameInfo,
1778 const TemplateArgumentListInfo &Args,
1779 UnresolvedSetIterator Begin,
1780 UnresolvedSetIterator End);
1782 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1783 bool HasExplicitTemplateArgs,
1784 unsigned NumTemplateArgs);
1786 /// True if this declaration should be extended by
1787 /// argument-dependent lookup.
1788 bool requiresADL() const { return RequiresADL; }
1789 void setRequiresADL(bool V) { RequiresADL = V; }
1791 /// True if this lookup is overloaded.
1792 bool isOverloaded() const { return Overloaded; }
1793 void setOverloaded(bool V) { Overloaded = V; }
1795 /// Gets the 'naming class' (in the sense of C++0x
1796 /// [class.access.base]p5) of the lookup. This is the scope
1797 /// that was looked in to find these results.
1798 CXXRecordDecl *getNamingClass() const { return NamingClass; }
1799 void setNamingClass(CXXRecordDecl *D) { NamingClass = D; }
1801 // Note that, inconsistently with the explicit-template-argument AST
1802 // nodes, users are *forbidden* from calling these methods on objects
1803 // without explicit template arguments.
1805 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1806 assert(hasExplicitTemplateArgs());
1807 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1810 /// Gets a reference to the explicit template argument list.
1811 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1812 assert(hasExplicitTemplateArgs());
1813 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1816 /// \brief Retrieves the optional explicit template arguments.
1817 /// This points to the same data as getExplicitTemplateArgs(), but
1818 /// returns null if there are no explicit template arguments.
1819 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1820 if (!hasExplicitTemplateArgs()) return 0;
1821 return &getExplicitTemplateArgs();
1824 /// \brief Copies the template arguments (if present) into the given
1826 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1827 getExplicitTemplateArgs().copyInto(List);
1830 SourceLocation getLAngleLoc() const {
1831 return getExplicitTemplateArgs().LAngleLoc;
1834 SourceLocation getRAngleLoc() const {
1835 return getExplicitTemplateArgs().RAngleLoc;
1838 TemplateArgumentLoc const *getTemplateArgs() const {
1839 return getExplicitTemplateArgs().getTemplateArgs();
1842 unsigned getNumTemplateArgs() const {
1843 return getExplicitTemplateArgs().NumTemplateArgs;
1846 SourceRange getSourceRange() const {
1847 SourceRange Range(getNameInfo().getSourceRange());
1848 if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1849 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1853 child_range children() { return child_range(); }
1855 static bool classof(const Stmt *T) {
1856 return T->getStmtClass() == UnresolvedLookupExprClass;
1858 static bool classof(const UnresolvedLookupExpr *) { return true; }
1861 /// \brief A qualified reference to a name whose declaration cannot
1862 /// yet be resolved.
1864 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1865 /// it expresses a reference to a declaration such as
1866 /// X<T>::value. The difference, however, is that an
1867 /// DependentScopeDeclRefExpr node is used only within C++ templates when
1868 /// the qualification (e.g., X<T>::) refers to a dependent type. In
1869 /// this case, X<T>::value cannot resolve to a declaration because the
1870 /// declaration will differ from on instantiation of X<T> to the
1871 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1872 /// qualifier (X<T>::) and the name of the entity being referenced
1873 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1874 /// declaration can be found.
1875 class DependentScopeDeclRefExpr : public Expr {
1876 /// \brief The nested-name-specifier that qualifies this unresolved
1877 /// declaration name.
1878 NestedNameSpecifierLoc QualifierLoc;
1880 /// The name of the entity we will be referencing.
1881 DeclarationNameInfo NameInfo;
1883 /// \brief Whether the name includes explicit template arguments.
1884 bool HasExplicitTemplateArgs;
1886 DependentScopeDeclRefExpr(QualType T,
1887 NestedNameSpecifierLoc QualifierLoc,
1888 const DeclarationNameInfo &NameInfo,
1889 const TemplateArgumentListInfo *Args);
1892 static DependentScopeDeclRefExpr *Create(ASTContext &C,
1893 NestedNameSpecifierLoc QualifierLoc,
1894 const DeclarationNameInfo &NameInfo,
1895 const TemplateArgumentListInfo *TemplateArgs = 0);
1897 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
1898 bool HasExplicitTemplateArgs,
1899 unsigned NumTemplateArgs);
1901 /// \brief Retrieve the name that this expression refers to.
1902 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1904 /// \brief Retrieve the name that this expression refers to.
1905 DeclarationName getDeclName() const { return NameInfo.getName(); }
1907 /// \brief Retrieve the location of the name within the expression.
1908 SourceLocation getLocation() const { return NameInfo.getLoc(); }
1910 /// \brief Retrieve the nested-name-specifier that qualifies the
1911 /// name, with source location information.
1912 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1915 /// \brief Retrieve the nested-name-specifier that qualifies this
1917 NestedNameSpecifier *getQualifier() const {
1918 return QualifierLoc.getNestedNameSpecifier();
1921 /// Determines whether this lookup had explicit template arguments.
1922 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1924 // Note that, inconsistently with the explicit-template-argument AST
1925 // nodes, users are *forbidden* from calling these methods on objects
1926 // without explicit template arguments.
1928 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1929 assert(hasExplicitTemplateArgs());
1930 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1933 /// Gets a reference to the explicit template argument list.
1934 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1935 assert(hasExplicitTemplateArgs());
1936 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1939 /// \brief Retrieves the optional explicit template arguments.
1940 /// This points to the same data as getExplicitTemplateArgs(), but
1941 /// returns null if there are no explicit template arguments.
1942 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1943 if (!hasExplicitTemplateArgs()) return 0;
1944 return &getExplicitTemplateArgs();
1947 /// \brief Copies the template arguments (if present) into the given
1949 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1950 getExplicitTemplateArgs().copyInto(List);
1953 SourceLocation getLAngleLoc() const {
1954 return getExplicitTemplateArgs().LAngleLoc;
1957 SourceLocation getRAngleLoc() const {
1958 return getExplicitTemplateArgs().RAngleLoc;
1961 TemplateArgumentLoc const *getTemplateArgs() const {
1962 return getExplicitTemplateArgs().getTemplateArgs();
1965 unsigned getNumTemplateArgs() const {
1966 return getExplicitTemplateArgs().NumTemplateArgs;
1969 SourceRange getSourceRange() const {
1970 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
1971 if (hasExplicitTemplateArgs())
1972 Range.setEnd(getRAngleLoc());
1976 static bool classof(const Stmt *T) {
1977 return T->getStmtClass() == DependentScopeDeclRefExprClass;
1979 static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1981 child_range children() { return child_range(); }
1983 friend class ASTStmtReader;
1984 friend class ASTStmtWriter;
1987 /// Represents an expression --- generally a full-expression --- which
1988 /// introduces cleanups to be run at the end of the sub-expression's
1989 /// evaluation. The most common source of expression-introduced
1990 /// cleanups is temporary objects in C++, but several other C++
1991 /// expressions can create cleanups.
1992 class ExprWithCleanups : public Expr {
1995 CXXTemporary **Temps;
1998 ExprWithCleanups(ASTContext &C, Expr *SubExpr,
1999 CXXTemporary **Temps, unsigned NumTemps);
2002 ExprWithCleanups(EmptyShell Empty)
2003 : Expr(ExprWithCleanupsClass, Empty),
2004 SubExpr(0), Temps(0), NumTemps(0) {}
2006 static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr,
2007 CXXTemporary **Temps,
2010 unsigned getNumTemporaries() const { return NumTemps; }
2011 void setNumTemporaries(ASTContext &C, unsigned N);
2013 CXXTemporary *getTemporary(unsigned i) {
2014 assert(i < NumTemps && "Index out of range");
2017 const CXXTemporary *getTemporary(unsigned i) const {
2018 return const_cast<ExprWithCleanups*>(this)->getTemporary(i);
2020 void setTemporary(unsigned i, CXXTemporary *T) {
2021 assert(i < NumTemps && "Index out of range");
2025 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2026 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2027 void setSubExpr(Expr *E) { SubExpr = E; }
2029 SourceRange getSourceRange() const {
2030 return SubExpr->getSourceRange();
2033 // Implement isa/cast/dyncast/etc.
2034 static bool classof(const Stmt *T) {
2035 return T->getStmtClass() == ExprWithCleanupsClass;
2037 static bool classof(const ExprWithCleanups *) { return true; }
2040 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2043 /// \brief Describes an explicit type conversion that uses functional
2044 /// notion but could not be resolved because one or more arguments are
2047 /// The explicit type conversions expressed by
2048 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2049 /// where \c T is some type and \c a1, a2, ..., aN are values, and
2050 /// either \C T is a dependent type or one or more of the \c a's is
2051 /// type-dependent. For example, this would occur in a template such
2055 /// template<typename T, typename A1>
2056 /// inline T make_a(const A1& a1) {
2061 /// When the returned expression is instantiated, it may resolve to a
2062 /// constructor call, conversion function call, or some kind of type
2064 class CXXUnresolvedConstructExpr : public Expr {
2065 /// \brief The type being constructed.
2066 TypeSourceInfo *Type;
2068 /// \brief The location of the left parentheses ('(').
2069 SourceLocation LParenLoc;
2071 /// \brief The location of the right parentheses (')').
2072 SourceLocation RParenLoc;
2074 /// \brief The number of arguments used to construct the type.
2077 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2078 SourceLocation LParenLoc,
2081 SourceLocation RParenLoc);
2083 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2084 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2086 friend class ASTStmtReader;
2089 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2090 TypeSourceInfo *Type,
2091 SourceLocation LParenLoc,
2094 SourceLocation RParenLoc);
2096 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2099 /// \brief Retrieve the type that is being constructed, as specified
2100 /// in the source code.
2101 QualType getTypeAsWritten() const { return Type->getType(); }
2103 /// \brief Retrieve the type source information for the type being
2105 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2107 /// \brief Retrieve the location of the left parentheses ('(') that
2108 /// precedes the argument list.
2109 SourceLocation getLParenLoc() const { return LParenLoc; }
2110 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2112 /// \brief Retrieve the location of the right parentheses (')') that
2113 /// follows the argument list.
2114 SourceLocation getRParenLoc() const { return RParenLoc; }
2115 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2117 /// \brief Retrieve the number of arguments.
2118 unsigned arg_size() const { return NumArgs; }
2120 typedef Expr** arg_iterator;
2121 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2122 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2124 typedef const Expr* const * const_arg_iterator;
2125 const_arg_iterator arg_begin() const {
2126 return reinterpret_cast<const Expr* const *>(this + 1);
2128 const_arg_iterator arg_end() const {
2129 return arg_begin() + NumArgs;
2132 Expr *getArg(unsigned I) {
2133 assert(I < NumArgs && "Argument index out-of-range");
2134 return *(arg_begin() + I);
2137 const Expr *getArg(unsigned I) const {
2138 assert(I < NumArgs && "Argument index out-of-range");
2139 return *(arg_begin() + I);
2142 void setArg(unsigned I, Expr *E) {
2143 assert(I < NumArgs && "Argument index out-of-range");
2144 *(arg_begin() + I) = E;
2147 SourceRange getSourceRange() const;
2149 static bool classof(const Stmt *T) {
2150 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2152 static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2155 child_range children() {
2156 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2157 return child_range(begin, begin + NumArgs);
2161 /// \brief Represents a C++ member access expression where the actual
2162 /// member referenced could not be resolved because the base
2163 /// expression or the member name was dependent.
2165 /// Like UnresolvedMemberExprs, these can be either implicit or
2166 /// explicit accesses. It is only possible to get one of these with
2167 /// an implicit access if a qualifier is provided.
2168 class CXXDependentScopeMemberExpr : public Expr {
2169 /// \brief The expression for the base pointer or class reference,
2170 /// e.g., the \c x in x.f. Can be null in implicit accesses.
2173 /// \brief The type of the base expression. Never null, even for
2174 /// implicit accesses.
2177 /// \brief Whether this member expression used the '->' operator or
2178 /// the '.' operator.
2181 /// \brief Whether this member expression has explicitly-specified template
2183 bool HasExplicitTemplateArgs : 1;
2185 /// \brief The location of the '->' or '.' operator.
2186 SourceLocation OperatorLoc;
2188 /// \brief The nested-name-specifier that precedes the member name, if any.
2189 NestedNameSpecifier *Qualifier;
2191 /// \brief The source range covering the nested name specifier.
2192 SourceRange QualifierRange;
2194 /// \brief In a qualified member access expression such as t->Base::f, this
2195 /// member stores the resolves of name lookup in the context of the member
2196 /// access expression, to be used at instantiation time.
2198 /// FIXME: This member, along with the Qualifier and QualifierRange, could
2199 /// be stuck into a structure that is optionally allocated at the end of
2200 /// the CXXDependentScopeMemberExpr, to save space in the common case.
2201 NamedDecl *FirstQualifierFoundInScope;
2203 /// \brief The member to which this member expression refers, which
2204 /// can be name, overloaded operator, or destructor.
2205 /// FIXME: could also be a template-id
2206 DeclarationNameInfo MemberNameInfo;
2208 CXXDependentScopeMemberExpr(ASTContext &C,
2209 Expr *Base, QualType BaseType, bool IsArrow,
2210 SourceLocation OperatorLoc,
2211 NestedNameSpecifier *Qualifier,
2212 SourceRange QualifierRange,
2213 NamedDecl *FirstQualifierFoundInScope,
2214 DeclarationNameInfo MemberNameInfo,
2215 const TemplateArgumentListInfo *TemplateArgs);
2218 CXXDependentScopeMemberExpr(ASTContext &C,
2219 Expr *Base, QualType BaseType,
2221 SourceLocation OperatorLoc,
2222 NestedNameSpecifier *Qualifier,
2223 SourceRange QualifierRange,
2224 NamedDecl *FirstQualifierFoundInScope,
2225 DeclarationNameInfo MemberNameInfo);
2227 static CXXDependentScopeMemberExpr *
2228 Create(ASTContext &C,
2229 Expr *Base, QualType BaseType, bool IsArrow,
2230 SourceLocation OperatorLoc,
2231 NestedNameSpecifier *Qualifier,
2232 SourceRange QualifierRange,
2233 NamedDecl *FirstQualifierFoundInScope,
2234 DeclarationNameInfo MemberNameInfo,
2235 const TemplateArgumentListInfo *TemplateArgs);
2237 static CXXDependentScopeMemberExpr *
2238 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2239 unsigned NumTemplateArgs);
2241 /// \brief True if this is an implicit access, i.e. one in which the
2242 /// member being accessed was not written in the source. The source
2243 /// location of the operator is invalid in this case.
2244 bool isImplicitAccess() const { return Base == 0; }
2246 /// \brief Retrieve the base object of this member expressions,
2247 /// e.g., the \c x in \c x.m.
2248 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 this member expression used the '->'
2258 /// operator; otherwise, it used the '.' operator.
2259 bool isArrow() const { return IsArrow; }
2260 void setArrow(bool A) { IsArrow = A; }
2262 /// \brief Retrieve the location of the '->' or '.' operator.
2263 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2264 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2266 /// \brief Retrieve the nested-name-specifier that qualifies the member
2268 NestedNameSpecifier *getQualifier() const { return Qualifier; }
2269 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
2271 /// \brief Retrieve the source range covering the nested-name-specifier
2272 /// that qualifies the member name.
2273 SourceRange getQualifierRange() const { return QualifierRange; }
2274 void setQualifierRange(SourceRange R) { QualifierRange = R; }
2276 /// \brief Retrieve the first part of the nested-name-specifier that was
2277 /// found in the scope of the member access expression when the member access
2278 /// was initially parsed.
2280 /// This function only returns a useful result when member access expression
2281 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2282 /// returned by this function describes what was found by unqualified name
2283 /// lookup for the identifier "Base" within the scope of the member access
2284 /// expression itself. At template instantiation time, this information is
2285 /// combined with the results of name lookup into the type of the object
2286 /// expression itself (the class type of x).
2287 NamedDecl *getFirstQualifierFoundInScope() const {
2288 return FirstQualifierFoundInScope;
2290 void setFirstQualifierFoundInScope(NamedDecl *D) {
2291 FirstQualifierFoundInScope = D;
2294 /// \brief Retrieve the name of the member that this expression
2296 const DeclarationNameInfo &getMemberNameInfo() const {
2297 return MemberNameInfo;
2299 void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; }
2301 /// \brief Retrieve the name of the member that this expression
2303 DeclarationName getMember() const { return MemberNameInfo.getName(); }
2304 void setMember(DeclarationName N) { MemberNameInfo.setName(N); }
2306 // \brief Retrieve the location of the name of the member that this
2307 // expression refers to.
2308 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2309 void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); }
2311 /// \brief Determines whether this member expression actually had a C++
2312 /// template argument list explicitly specified, e.g., x.f<int>.
2313 bool hasExplicitTemplateArgs() const {
2314 return HasExplicitTemplateArgs;
2317 /// \brief Retrieve the explicit template argument list that followed the
2318 /// member template name, if any.
2319 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2320 assert(HasExplicitTemplateArgs);
2321 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2324 /// \brief Retrieve the explicit template argument list that followed the
2325 /// member template name, if any.
2326 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2327 return const_cast<CXXDependentScopeMemberExpr *>(this)
2328 ->getExplicitTemplateArgs();
2331 /// \brief Retrieves the optional explicit template arguments.
2332 /// This points to the same data as getExplicitTemplateArgs(), but
2333 /// returns null if there are no explicit template arguments.
2334 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2335 if (!hasExplicitTemplateArgs()) return 0;
2336 return &getExplicitTemplateArgs();
2339 /// \brief Copies the template arguments (if present) into the given
2341 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2342 getExplicitTemplateArgs().copyInto(List);
2345 /// \brief Initializes the template arguments using the given structure.
2346 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2347 getExplicitTemplateArgs().initializeFrom(List);
2350 /// \brief Retrieve the location of the left angle bracket following the
2351 /// member name ('<'), if any.
2352 SourceLocation getLAngleLoc() const {
2353 return getExplicitTemplateArgs().LAngleLoc;
2356 /// \brief Retrieve the template arguments provided as part of this
2358 const TemplateArgumentLoc *getTemplateArgs() const {
2359 return getExplicitTemplateArgs().getTemplateArgs();
2362 /// \brief Retrieve the number of template arguments provided as part of this
2364 unsigned getNumTemplateArgs() const {
2365 return getExplicitTemplateArgs().NumTemplateArgs;
2368 /// \brief Retrieve the location of the right angle bracket following the
2369 /// template arguments ('>').
2370 SourceLocation getRAngleLoc() const {
2371 return getExplicitTemplateArgs().RAngleLoc;
2374 SourceRange getSourceRange() const {
2376 if (!isImplicitAccess())
2377 Range.setBegin(Base->getSourceRange().getBegin());
2378 else if (getQualifier())
2379 Range.setBegin(getQualifierRange().getBegin());
2381 Range.setBegin(MemberNameInfo.getBeginLoc());
2383 if (hasExplicitTemplateArgs())
2384 Range.setEnd(getRAngleLoc());
2386 Range.setEnd(MemberNameInfo.getEndLoc());
2390 static bool classof(const Stmt *T) {
2391 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2393 static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2396 child_range children() {
2397 if (isImplicitAccess()) return child_range();
2398 return child_range(&Base, &Base + 1);
2401 friend class ASTStmtReader;
2402 friend class ASTStmtWriter;
2405 /// \brief Represents a C++ member access expression for which lookup
2406 /// produced a set of overloaded functions.
2408 /// The member access may be explicit or implicit:
2411 /// int explicitAccess() { return this->a + this->A::b; }
2412 /// int implicitAccess() { return a + A::b; }
2415 /// In the final AST, an explicit access always becomes a MemberExpr.
2416 /// An implicit access may become either a MemberExpr or a
2417 /// DeclRefExpr, depending on whether the member is static.
2418 class UnresolvedMemberExpr : public OverloadExpr {
2419 /// \brief Whether this member expression used the '->' operator or
2420 /// the '.' operator.
2423 /// \brief Whether the lookup results contain an unresolved using
2425 bool HasUnresolvedUsing : 1;
2427 /// \brief The expression for the base pointer or class reference,
2428 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
2429 /// member expression
2432 /// \brief The type of the base expression; never null.
2435 /// \brief The location of the '->' or '.' operator.
2436 SourceLocation OperatorLoc;
2438 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
2439 Expr *Base, QualType BaseType, bool IsArrow,
2440 SourceLocation OperatorLoc,
2441 NestedNameSpecifier *Qualifier,
2442 SourceRange QualifierRange,
2443 const DeclarationNameInfo &MemberNameInfo,
2444 const TemplateArgumentListInfo *TemplateArgs,
2445 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2447 UnresolvedMemberExpr(EmptyShell Empty)
2448 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2449 HasUnresolvedUsing(false), Base(0) { }
2452 static UnresolvedMemberExpr *
2453 Create(ASTContext &C, bool HasUnresolvedUsing,
2454 Expr *Base, QualType BaseType, bool IsArrow,
2455 SourceLocation OperatorLoc,
2456 NestedNameSpecifier *Qualifier,
2457 SourceRange QualifierRange,
2458 const DeclarationNameInfo &MemberNameInfo,
2459 const TemplateArgumentListInfo *TemplateArgs,
2460 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2462 static UnresolvedMemberExpr *
2463 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2464 unsigned NumTemplateArgs);
2466 /// \brief True if this is an implicit access, i.e. one in which the
2467 /// member being accessed was not written in the source. The source
2468 /// location of the operator is invalid in this case.
2469 bool isImplicitAccess() const { return Base == 0; }
2471 /// \brief Retrieve the base object of this member expressions,
2472 /// e.g., the \c x in \c x.m.
2474 assert(!isImplicitAccess());
2475 return cast<Expr>(Base);
2477 const Expr *getBase() const {
2478 assert(!isImplicitAccess());
2479 return cast<Expr>(Base);
2481 void setBase(Expr *E) { Base = E; }
2483 QualType getBaseType() const { return BaseType; }
2484 void setBaseType(QualType T) { BaseType = T; }
2486 /// \brief Determine whether the lookup results contain an unresolved using
2488 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2489 void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; }
2491 /// \brief Determine whether this member expression used the '->'
2492 /// operator; otherwise, it used the '.' operator.
2493 bool isArrow() const { return IsArrow; }
2494 void setArrow(bool A) { IsArrow = A; }
2496 /// \brief Retrieve the location of the '->' or '.' operator.
2497 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2498 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2500 /// \brief Retrieves the naming class of this lookup.
2501 CXXRecordDecl *getNamingClass() const;
2503 /// \brief Retrieve the full name info for the member that this expression
2505 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
2506 void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); }
2508 /// \brief Retrieve the name of the member that this expression
2510 DeclarationName getMemberName() const { return getName(); }
2511 void setMemberName(DeclarationName N) { setName(N); }
2513 // \brief Retrieve the location of the name of the member that this
2514 // expression refers to.
2515 SourceLocation getMemberLoc() const { return getNameLoc(); }
2516 void setMemberLoc(SourceLocation L) { setNameLoc(L); }
2518 /// \brief Retrieve the explicit template argument list that followed the
2519 /// member template name.
2520 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2521 assert(hasExplicitTemplateArgs());
2522 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2525 /// \brief Retrieve the explicit template argument list that followed the
2526 /// member template name, if any.
2527 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2528 assert(hasExplicitTemplateArgs());
2529 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2532 /// \brief Retrieves the optional explicit template arguments.
2533 /// This points to the same data as getExplicitTemplateArgs(), but
2534 /// returns null if there are no explicit template arguments.
2535 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2536 if (!hasExplicitTemplateArgs()) return 0;
2537 return &getExplicitTemplateArgs();
2540 /// \brief Copies the template arguments into the given structure.
2541 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2542 getExplicitTemplateArgs().copyInto(List);
2545 /// \brief Retrieve the location of the left angle bracket following
2546 /// the member name ('<').
2547 SourceLocation getLAngleLoc() const {
2548 return getExplicitTemplateArgs().LAngleLoc;
2551 /// \brief Retrieve the template arguments provided as part of this
2553 const TemplateArgumentLoc *getTemplateArgs() const {
2554 return getExplicitTemplateArgs().getTemplateArgs();
2557 /// \brief Retrieve the number of template arguments provided as
2558 /// part of this template-id.
2559 unsigned getNumTemplateArgs() const {
2560 return getExplicitTemplateArgs().NumTemplateArgs;
2563 /// \brief Retrieve the location of the right angle bracket
2564 /// following the template arguments ('>').
2565 SourceLocation getRAngleLoc() const {
2566 return getExplicitTemplateArgs().RAngleLoc;
2569 SourceRange getSourceRange() const {
2570 SourceRange Range = getMemberNameInfo().getSourceRange();
2571 if (!isImplicitAccess())
2572 Range.setBegin(Base->getSourceRange().getBegin());
2573 else if (getQualifier())
2574 Range.setBegin(getQualifierRange().getBegin());
2576 if (hasExplicitTemplateArgs())
2577 Range.setEnd(getRAngleLoc());
2581 static bool classof(const Stmt *T) {
2582 return T->getStmtClass() == UnresolvedMemberExprClass;
2584 static bool classof(const UnresolvedMemberExpr *) { return true; }
2587 child_range children() {
2588 if (isImplicitAccess()) return child_range();
2589 return child_range(&Base, &Base + 1);
2593 /// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
2595 /// The noexcept expression tests whether a given expression might throw. Its
2596 /// result is a boolean constant.
2597 class CXXNoexceptExpr : public Expr {
2602 friend class ASTStmtReader;
2605 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
2606 SourceLocation Keyword, SourceLocation RParen)
2607 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
2608 /*TypeDependent*/false,
2609 /*ValueDependent*/Val == CT_Dependent,
2610 Operand->containsUnexpandedParameterPack()),
2611 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
2614 CXXNoexceptExpr(EmptyShell Empty)
2615 : Expr(CXXNoexceptExprClass, Empty)
2618 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
2620 SourceRange getSourceRange() const { return Range; }
2622 bool getValue() const { return Value; }
2624 static bool classof(const Stmt *T) {
2625 return T->getStmtClass() == CXXNoexceptExprClass;
2627 static bool classof(const CXXNoexceptExpr *) { return true; }
2630 child_range children() { return child_range(&Operand, &Operand + 1); }
2633 /// \brief Represents a C++0x pack expansion that produces a sequence of
2636 /// A pack expansion expression contains a pattern (which itself is an
2637 /// expression) followed by an ellipsis. For example:
2640 /// template<typename F, typename ...Types>
2641 /// void forward(F f, Types &&...args) {
2642 /// f(static_cast<Types&&>(args)...);
2646 /// Here, the argument to the function object \c f is a pack expansion whose
2647 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
2648 /// template is instantiated, the pack expansion will instantiate to zero or
2649 /// or more function arguments to the function object \c f.
2650 class PackExpansionExpr : public Expr {
2651 SourceLocation EllipsisLoc;
2653 /// \brief The number of expansions that will be produced by this pack
2654 /// expansion expression, if known.
2656 /// When zero, the number of expansions is not known. Otherwise, this value
2657 /// is the number of expansions + 1.
2658 unsigned NumExpansions;
2662 friend class ASTStmtReader;
2663 friend class ASTStmtWriter;
2666 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
2667 llvm::Optional<unsigned> NumExpansions)
2668 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
2669 Pattern->getObjectKind(), /*TypeDependent=*/true,
2670 /*ValueDependent=*/true, /*ContainsUnexpandedParameterPack=*/false),
2671 EllipsisLoc(EllipsisLoc),
2672 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
2673 Pattern(Pattern) { }
2675 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
2677 /// \brief Retrieve the pattern of the pack expansion.
2678 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
2680 /// \brief Retrieve the pattern of the pack expansion.
2681 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
2683 /// \brief Retrieve the location of the ellipsis that describes this pack
2685 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2687 /// \brief Determine the number of expansions that will be produced when
2688 /// this pack expansion is instantiated, if already known.
2689 llvm::Optional<unsigned> getNumExpansions() const {
2691 return NumExpansions - 1;
2693 return llvm::Optional<unsigned>();
2696 SourceRange getSourceRange() const {
2697 return SourceRange(Pattern->getLocStart(), EllipsisLoc);
2700 static bool classof(const Stmt *T) {
2701 return T->getStmtClass() == PackExpansionExprClass;
2703 static bool classof(const PackExpansionExpr *) { return true; }
2706 child_range children() {
2707 return child_range(&Pattern, &Pattern + 1);
2711 inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2712 if (isa<UnresolvedLookupExpr>(this))
2713 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2715 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2718 /// \brief Represents an expression that computes the length of a parameter
2722 /// template<typename ...Types>
2724 /// static const unsigned value = sizeof...(Types);
2727 class SizeOfPackExpr : public Expr {
2728 /// \brief The location of the 'sizeof' keyword.
2729 SourceLocation OperatorLoc;
2731 /// \brief The location of the name of the parameter pack.
2732 SourceLocation PackLoc;
2734 /// \brief The location of the closing parenthesis.
2735 SourceLocation RParenLoc;
2737 /// \brief The length of the parameter pack, if known.
2739 /// When this expression is value-dependent, the length of the parameter pack
2740 /// is unknown. When this expression is not value-dependent, the length is
2744 /// \brief The parameter pack itself.
2747 friend class ASTStmtReader;
2748 friend class ASTStmtWriter;
2751 /// \brief Creates a value-dependent expression that computes the length of
2752 /// the given parameter pack.
2753 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2754 SourceLocation PackLoc, SourceLocation RParenLoc)
2755 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2756 /*TypeDependent=*/false, /*ValueDependent=*/true,
2757 /*ContainsUnexpandedParameterPack=*/false),
2758 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2759 Length(0), Pack(Pack) { }
2761 /// \brief Creates an expression that computes the length of
2762 /// the given parameter pack, which is already known.
2763 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2764 SourceLocation PackLoc, SourceLocation RParenLoc,
2766 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2767 /*TypeDependent=*/false, /*ValueDependent=*/false,
2768 /*ContainsUnexpandedParameterPack=*/false),
2769 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2770 Length(Length), Pack(Pack) { }
2772 /// \brief Create an empty expression.
2773 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
2775 /// \brief Determine the location of the 'sizeof' keyword.
2776 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2778 /// \brief Determine the location of the parameter pack.
2779 SourceLocation getPackLoc() const { return PackLoc; }
2781 /// \brief Determine the location of the right parenthesis.
2782 SourceLocation getRParenLoc() const { return RParenLoc; }
2784 /// \brief Retrieve the parameter pack.
2785 NamedDecl *getPack() const { return Pack; }
2787 /// \brief Retrieve the length of the parameter pack.
2789 /// This routine may only be invoked when the expression is not
2790 /// value-dependent.
2791 unsigned getPackLength() const {
2792 assert(!isValueDependent() &&
2793 "Cannot get the length of a value-dependent pack size expression");
2797 SourceRange getSourceRange() const {
2798 return SourceRange(OperatorLoc, RParenLoc);
2801 static bool classof(const Stmt *T) {
2802 return T->getStmtClass() == SizeOfPackExprClass;
2804 static bool classof(const SizeOfPackExpr *) { return true; }
2807 child_range children() { return child_range(); }
2810 /// \brief Represents a reference to a non-type template parameter pack that
2811 /// has been substituted with a non-template argument pack.
2813 /// When a pack expansion in the source code contains multiple parameter packs
2814 /// and those parameter packs correspond to different levels of template
2815 /// parameter lists, this node node is used to represent a non-type template
2816 /// parameter pack from an outer level, which has already had its argument pack
2817 /// substituted but that still lives within a pack expansion that itself
2818 /// could not be instantiated. When actually performing a substitution into
2819 /// that pack expansion (e.g., when all template parameters have corresponding
2820 /// arguments), this type will be replaced with the appropriate underlying
2821 /// expression at the current pack substitution index.
2822 class SubstNonTypeTemplateParmPackExpr : public Expr {
2823 /// \brief The non-type template parameter pack itself.
2824 NonTypeTemplateParmDecl *Param;
2826 /// \brief A pointer to the set of template arguments that this
2827 /// parameter pack is instantiated with.
2828 const TemplateArgument *Arguments;
2830 /// \brief The number of template arguments in \c Arguments.
2831 unsigned NumArguments;
2833 /// \brief The location of the non-type template parameter pack reference.
2834 SourceLocation NameLoc;
2836 friend class ASTStmtReader;
2837 friend class ASTStmtWriter;
2840 SubstNonTypeTemplateParmPackExpr(QualType T,
2841 NonTypeTemplateParmDecl *Param,
2842 SourceLocation NameLoc,
2843 const TemplateArgument &ArgPack);
2845 SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
2846 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
2848 /// \brief Retrieve the non-type template parameter pack being substituted.
2849 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
2851 /// \brief Retrieve the location of the parameter pack name.
2852 SourceLocation getParameterPackLocation() const { return NameLoc; }
2854 /// \brief Retrieve the template argument pack containing the substituted
2855 /// template arguments.
2856 TemplateArgument getArgumentPack() const;
2858 SourceRange getSourceRange() const { return NameLoc; }
2860 static bool classof(const Stmt *T) {
2861 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
2863 static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
2868 child_range children() { return child_range(); }
2871 } // end namespace clang