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/Basic/ExpressionTraits.h"
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/UnresolvedSet.h"
21 #include "clang/AST/TemplateBase.h"
25 class CXXConstructorDecl;
26 class CXXDestructorDecl;
29 class TemplateArgumentListInfo;
31 //===--------------------------------------------------------------------===//
33 //===--------------------------------------------------------------------===//
35 /// \brief A call to an overloaded operator written using operator
38 /// Represents a call to an overloaded operator written using operator
39 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
40 /// normal call, this AST node provides better information about the
41 /// syntactic representation of the call.
43 /// In a C++ template, this expression node kind will be used whenever
44 /// any of the arguments are type-dependent. In this case, the
45 /// function itself will be a (possibly empty) set of functions and
46 /// function templates that were found by name lookup at template
48 class CXXOperatorCallExpr : public CallExpr {
49 /// \brief The overloaded operator.
50 OverloadedOperatorKind Operator;
53 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
54 Expr **args, unsigned numargs, QualType t,
55 ExprValueKind VK, SourceLocation operatorloc)
56 : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK,
59 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
60 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
63 /// getOperator - Returns the kind of overloaded operator that this
64 /// expression refers to.
65 OverloadedOperatorKind getOperator() const { return Operator; }
66 void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
68 /// getOperatorLoc - Returns the location of the operator symbol in
69 /// the expression. When @c getOperator()==OO_Call, this is the
70 /// location of the right parentheses; when @c
71 /// getOperator()==OO_Subscript, this is the location of the right
73 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
75 SourceRange getSourceRange() const;
77 static bool classof(const Stmt *T) {
78 return T->getStmtClass() == CXXOperatorCallExprClass;
80 static bool classof(const CXXOperatorCallExpr *) { return true; }
83 /// CXXMemberCallExpr - Represents a call to a member function that
84 /// may be written either with member call syntax (e.g., "obj.func()"
85 /// or "objptr->func()") or with normal function-call syntax
86 /// ("func()") within a member function that ends up calling a member
87 /// function. The callee in either case is a MemberExpr that contains
88 /// both the object argument and the member function, while the
89 /// arguments are the arguments within the parentheses (not including
90 /// the object argument).
91 class CXXMemberCallExpr : public CallExpr {
93 CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
94 QualType t, ExprValueKind VK, SourceLocation RP)
95 : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {}
97 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
98 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
100 /// getImplicitObjectArgument - Retrieves the implicit object
101 /// argument for the member call. For example, in "x.f(5)", this
102 /// operation would return "x".
103 Expr *getImplicitObjectArgument() const;
105 /// Retrieves the declaration of the called method.
106 CXXMethodDecl *getMethodDecl() const;
108 /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
109 /// the implicit object argument. Note that this is may not be the same
110 /// declaration as that of the class context of the CXXMethodDecl which this
111 /// function is calling.
112 /// FIXME: Returns 0 for member pointer call exprs.
113 CXXRecordDecl *getRecordDecl();
115 static bool classof(const Stmt *T) {
116 return T->getStmtClass() == CXXMemberCallExprClass;
118 static bool classof(const CXXMemberCallExpr *) { return true; }
121 /// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
122 class CUDAKernelCallExpr : public CallExpr {
124 enum { CONFIG, END_PREARG };
127 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
128 Expr **args, unsigned numargs, QualType t,
129 ExprValueKind VK, SourceLocation RP)
130 : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK,
135 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
136 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
138 const CallExpr *getConfig() const {
139 return cast_or_null<CallExpr>(getPreArg(CONFIG));
141 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
142 void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
144 static bool classof(const Stmt *T) {
145 return T->getStmtClass() == CUDAKernelCallExprClass;
147 static bool classof(const CUDAKernelCallExpr *) { return true; }
150 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
151 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
154 /// This abstract class is inherited by all of the classes
155 /// representing "named" casts, e.g., CXXStaticCastExpr,
156 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
157 class CXXNamedCastExpr : public ExplicitCastExpr {
159 SourceLocation Loc; // the location of the casting op
160 SourceLocation RParenLoc; // the location of the right parenthesis
163 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
164 CastKind kind, Expr *op, unsigned PathSize,
165 TypeSourceInfo *writtenTy, SourceLocation l,
166 SourceLocation RParenLoc)
167 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
168 RParenLoc(RParenLoc) {}
170 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
171 : ExplicitCastExpr(SC, Shell, PathSize) { }
173 friend class ASTStmtReader;
176 const char *getCastName() const;
178 /// \brief Retrieve the location of the cast operator keyword, e.g.,
180 SourceLocation getOperatorLoc() const { return Loc; }
182 /// \brief Retrieve the location of the closing parenthesis.
183 SourceLocation getRParenLoc() const { return RParenLoc; }
185 SourceRange getSourceRange() const {
186 return SourceRange(Loc, RParenLoc);
188 static bool classof(const Stmt *T) {
189 switch (T->getStmtClass()) {
190 case CXXStaticCastExprClass:
191 case CXXDynamicCastExprClass:
192 case CXXReinterpretCastExprClass:
193 case CXXConstCastExprClass:
199 static bool classof(const CXXNamedCastExpr *) { return true; }
202 /// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
204 /// This expression node represents a C++ static cast, e.g.,
205 /// @c static_cast<int>(1.0).
206 class CXXStaticCastExpr : public CXXNamedCastExpr {
207 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
208 unsigned pathSize, TypeSourceInfo *writtenTy,
209 SourceLocation l, SourceLocation RParenLoc)
210 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
211 writtenTy, l, RParenLoc) {}
213 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
214 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
217 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
218 ExprValueKind VK, CastKind K, Expr *Op,
219 const CXXCastPath *Path,
220 TypeSourceInfo *Written, SourceLocation L,
221 SourceLocation RParenLoc);
222 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
225 static bool classof(const Stmt *T) {
226 return T->getStmtClass() == CXXStaticCastExprClass;
228 static bool classof(const CXXStaticCastExpr *) { return true; }
231 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
232 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
233 /// determine how to perform the type cast.
235 /// This expression node represents a dynamic cast, e.g.,
236 /// @c dynamic_cast<Derived*>(BasePtr).
237 class CXXDynamicCastExpr : public CXXNamedCastExpr {
238 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
239 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
240 SourceLocation l, SourceLocation RParenLoc)
241 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
242 writtenTy, l, RParenLoc) {}
244 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
245 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
248 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
249 ExprValueKind VK, CastKind Kind, Expr *Op,
250 const CXXCastPath *Path,
251 TypeSourceInfo *Written, SourceLocation L,
252 SourceLocation RParenLoc);
254 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
257 bool isAlwaysNull() const;
259 static bool classof(const Stmt *T) {
260 return T->getStmtClass() == CXXDynamicCastExprClass;
262 static bool classof(const CXXDynamicCastExpr *) { return true; }
265 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
266 /// [expr.reinterpret.cast]), which provides a differently-typed view
267 /// of a value but performs no actual work at run time.
269 /// This expression node represents a reinterpret cast, e.g.,
270 /// @c reinterpret_cast<int>(VoidPtr).
271 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
272 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
273 Expr *op, unsigned pathSize,
274 TypeSourceInfo *writtenTy, SourceLocation l,
275 SourceLocation RParenLoc)
276 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
277 pathSize, writtenTy, l, RParenLoc) {}
279 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
280 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
283 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
284 ExprValueKind VK, CastKind Kind,
285 Expr *Op, const CXXCastPath *Path,
286 TypeSourceInfo *WrittenTy, SourceLocation L,
287 SourceLocation RParenLoc);
288 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
291 static bool classof(const Stmt *T) {
292 return T->getStmtClass() == CXXReinterpretCastExprClass;
294 static bool classof(const CXXReinterpretCastExpr *) { return true; }
297 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
298 /// which can remove type qualifiers but does not change the underlying value.
300 /// This expression node represents a const cast, e.g.,
301 /// @c const_cast<char*>(PtrToConstChar).
302 class CXXConstCastExpr : public CXXNamedCastExpr {
303 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
304 TypeSourceInfo *writtenTy, SourceLocation l,
305 SourceLocation RParenLoc)
306 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
307 0, writtenTy, l, RParenLoc) {}
309 explicit CXXConstCastExpr(EmptyShell Empty)
310 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
313 static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
314 ExprValueKind VK, Expr *Op,
315 TypeSourceInfo *WrittenTy, SourceLocation L,
316 SourceLocation RParenLoc);
317 static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
319 static bool classof(const Stmt *T) {
320 return T->getStmtClass() == CXXConstCastExprClass;
322 static bool classof(const CXXConstCastExpr *) { return true; }
325 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
327 class CXXBoolLiteralExpr : public Expr {
331 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
332 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
334 Value(val), Loc(l) {}
336 explicit CXXBoolLiteralExpr(EmptyShell Empty)
337 : Expr(CXXBoolLiteralExprClass, Empty) { }
339 bool getValue() const { return Value; }
340 void setValue(bool V) { Value = V; }
342 SourceRange getSourceRange() const { return SourceRange(Loc); }
344 SourceLocation getLocation() const { return Loc; }
345 void setLocation(SourceLocation L) { Loc = L; }
347 static bool classof(const Stmt *T) {
348 return T->getStmtClass() == CXXBoolLiteralExprClass;
350 static bool classof(const CXXBoolLiteralExpr *) { return true; }
353 child_range children() { return child_range(); }
356 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
357 class CXXNullPtrLiteralExpr : public Expr {
360 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
361 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
365 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
366 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
368 SourceRange getSourceRange() const { return SourceRange(Loc); }
370 SourceLocation getLocation() const { return Loc; }
371 void setLocation(SourceLocation L) { Loc = L; }
373 static bool classof(const Stmt *T) {
374 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
376 static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
378 child_range children() { return child_range(); }
381 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
382 /// the type_info that corresponds to the supplied type, or the (possibly
383 /// dynamic) type of the supplied expression.
385 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
386 class CXXTypeidExpr : public Expr {
388 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
392 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
393 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
394 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
396 // typeid is value-dependent if the type or expression are dependent
397 Operand->getType()->isDependentType(),
398 Operand->getType()->containsUnexpandedParameterPack()),
399 Operand(Operand), Range(R) { }
401 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
402 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
403 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
405 // typeid is value-dependent if the type or expression are dependent
406 Operand->isTypeDependent() || Operand->isValueDependent(),
407 Operand->containsUnexpandedParameterPack()),
408 Operand(Operand), Range(R) { }
410 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
411 : Expr(CXXTypeidExprClass, Empty) {
415 Operand = (TypeSourceInfo*)0;
418 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
420 /// \brief Retrieves the type operand of this typeid() expression after
421 /// various required adjustments (removing reference types, cv-qualifiers).
422 QualType getTypeOperand() const;
424 /// \brief Retrieve source information for the type operand.
425 TypeSourceInfo *getTypeOperandSourceInfo() const {
426 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
427 return Operand.get<TypeSourceInfo *>();
430 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
431 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
435 Expr *getExprOperand() const {
436 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
437 return static_cast<Expr*>(Operand.get<Stmt *>());
440 void setExprOperand(Expr *E) {
441 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
445 SourceRange getSourceRange() const { return Range; }
446 void setSourceRange(SourceRange R) { Range = R; }
448 static bool classof(const Stmt *T) {
449 return T->getStmtClass() == CXXTypeidExprClass;
451 static bool classof(const CXXTypeidExpr *) { return true; }
454 child_range children() {
455 if (isTypeOperand()) return child_range();
456 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
457 return child_range(begin, begin + 1);
461 /// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
462 /// the _GUID that corresponds to the supplied type or expression.
464 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
465 class CXXUuidofExpr : public Expr {
467 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
471 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
472 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
473 false, Operand->getType()->isDependentType(),
474 Operand->getType()->containsUnexpandedParameterPack()),
475 Operand(Operand), Range(R) { }
477 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
478 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
479 false, Operand->isTypeDependent(),
480 Operand->containsUnexpandedParameterPack()),
481 Operand(Operand), Range(R) { }
483 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
484 : Expr(CXXUuidofExprClass, Empty) {
488 Operand = (TypeSourceInfo*)0;
491 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
493 /// \brief Retrieves the type operand of this __uuidof() expression after
494 /// various required adjustments (removing reference types, cv-qualifiers).
495 QualType getTypeOperand() const;
497 /// \brief Retrieve source information for the type operand.
498 TypeSourceInfo *getTypeOperandSourceInfo() const {
499 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
500 return Operand.get<TypeSourceInfo *>();
503 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
504 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
508 Expr *getExprOperand() const {
509 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
510 return static_cast<Expr*>(Operand.get<Stmt *>());
513 void setExprOperand(Expr *E) {
514 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
518 SourceRange getSourceRange() const { return Range; }
519 void setSourceRange(SourceRange R) { Range = R; }
521 static bool classof(const Stmt *T) {
522 return T->getStmtClass() == CXXUuidofExprClass;
524 static bool classof(const CXXUuidofExpr *) { return true; }
527 child_range children() {
528 if (isTypeOperand()) return child_range();
529 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
530 return child_range(begin, begin + 1);
534 /// CXXThisExpr - Represents the "this" expression in C++, which is a
535 /// pointer to the object on which the current member function is
536 /// executing (C++ [expr.prim]p3). Example:
542 /// void test() { this->bar(); }
545 class CXXThisExpr : public Expr {
550 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
551 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
552 // 'this' is type-dependent if the class type of the enclosing
553 // member function is dependent (C++ [temp.dep.expr]p2)
554 Type->isDependentType(), Type->isDependentType(),
555 /*ContainsUnexpandedParameterPack=*/false),
556 Loc(L), Implicit(isImplicit) { }
558 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
560 SourceLocation getLocation() const { return Loc; }
561 void setLocation(SourceLocation L) { Loc = L; }
563 SourceRange getSourceRange() const { return SourceRange(Loc); }
565 bool isImplicit() const { return Implicit; }
566 void setImplicit(bool I) { Implicit = I; }
568 static bool classof(const Stmt *T) {
569 return T->getStmtClass() == CXXThisExprClass;
571 static bool classof(const CXXThisExpr *) { return true; }
574 child_range children() { return child_range(); }
577 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
578 /// 'throw' and 'throw' assignment-expression. When
579 /// assignment-expression isn't present, Op will be null.
581 class CXXThrowExpr : public Expr {
583 SourceLocation ThrowLoc;
585 // Ty is the void type which is used as the result type of the
586 // exepression. The l is the location of the throw keyword. expr
587 // can by null, if the optional expression to throw isn't present.
588 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
589 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
590 expr && expr->containsUnexpandedParameterPack()),
591 Op(expr), ThrowLoc(l) {}
592 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
594 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
595 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
596 void setSubExpr(Expr *E) { Op = E; }
598 SourceLocation getThrowLoc() const { return ThrowLoc; }
599 void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
601 SourceRange getSourceRange() const {
602 if (getSubExpr() == 0)
603 return SourceRange(ThrowLoc, ThrowLoc);
604 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
607 static bool classof(const Stmt *T) {
608 return T->getStmtClass() == CXXThrowExprClass;
610 static bool classof(const CXXThrowExpr *) { return true; }
613 child_range children() {
614 return child_range(&Op, Op ? &Op+1 : &Op);
618 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
619 /// function call argument that was created from the corresponding
620 /// parameter's default argument, when the call did not explicitly
621 /// supply arguments for all of the parameters.
622 class CXXDefaultArgExpr : public Expr {
623 /// \brief The parameter whose default is being used.
625 /// When the bit is set, the subexpression is stored after the
626 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
627 /// actual default expression is the subexpression.
628 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
630 /// \brief The location where the default argument expression was used.
633 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
635 param->hasUnparsedDefaultArg()
636 ? param->getType().getNonReferenceType()
637 : param->getDefaultArg()->getType(),
638 param->getDefaultArg()->getValueKind(),
639 param->getDefaultArg()->getObjectKind(), false, false, false),
640 Param(param, false), Loc(Loc) { }
642 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
644 : Expr(SC, SubExpr->getType(),
645 SubExpr->getValueKind(), SubExpr->getObjectKind(),
646 false, false, false),
647 Param(param, true), Loc(Loc) {
648 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
652 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
655 // Param is the parameter whose default argument is used by this
657 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
658 ParmVarDecl *Param) {
659 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
662 // Param is the parameter whose default argument is used by this
663 // expression, and SubExpr is the expression that will actually be used.
664 static CXXDefaultArgExpr *Create(ASTContext &C,
669 // Retrieve the parameter that the argument was created from.
670 const ParmVarDecl *getParam() const { return Param.getPointer(); }
671 ParmVarDecl *getParam() { return Param.getPointer(); }
673 // Retrieve the actual argument to the function call.
674 const Expr *getExpr() const {
676 return *reinterpret_cast<Expr const * const*> (this + 1);
677 return getParam()->getDefaultArg();
681 return *reinterpret_cast<Expr **> (this + 1);
682 return getParam()->getDefaultArg();
685 /// \brief Retrieve the location where this default argument was actually
687 SourceLocation getUsedLocation() const { return Loc; }
689 SourceRange getSourceRange() const {
690 // Default argument expressions have no representation in the
691 // source, so they have an empty source range.
692 return SourceRange();
695 static bool classof(const Stmt *T) {
696 return T->getStmtClass() == CXXDefaultArgExprClass;
698 static bool classof(const CXXDefaultArgExpr *) { return true; }
701 child_range children() { return child_range(); }
703 friend class ASTStmtReader;
704 friend class ASTStmtWriter;
707 /// CXXTemporary - Represents a C++ temporary.
709 /// Destructor - The destructor that needs to be called.
710 const CXXDestructorDecl *Destructor;
712 CXXTemporary(const CXXDestructorDecl *destructor)
713 : Destructor(destructor) { }
716 static CXXTemporary *Create(ASTContext &C,
717 const CXXDestructorDecl *Destructor);
719 const CXXDestructorDecl *getDestructor() const { return Destructor; }
722 /// \brief Represents binding an expression to a temporary.
724 /// This ensures the destructor is called for the temporary. It should only be
725 /// needed for non-POD, non-trivially destructable class types. For example:
729 /// S() { } // User defined constructor makes S non-POD.
730 /// ~S() { } // User defined destructor makes it non-trivial.
733 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
736 class CXXBindTemporaryExpr : public Expr {
741 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
742 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
743 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
744 SubExpr->isValueDependent(),
745 SubExpr->containsUnexpandedParameterPack()),
746 Temp(temp), SubExpr(SubExpr) { }
749 CXXBindTemporaryExpr(EmptyShell Empty)
750 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
752 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
755 CXXTemporary *getTemporary() { return Temp; }
756 const CXXTemporary *getTemporary() const { return Temp; }
757 void setTemporary(CXXTemporary *T) { Temp = T; }
759 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
760 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
761 void setSubExpr(Expr *E) { SubExpr = E; }
763 SourceRange getSourceRange() const {
764 return SubExpr->getSourceRange();
767 // Implement isa/cast/dyncast/etc.
768 static bool classof(const Stmt *T) {
769 return T->getStmtClass() == CXXBindTemporaryExprClass;
771 static bool classof(const CXXBindTemporaryExpr *) { return true; }
774 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
777 /// CXXConstructExpr - Represents a call to a C++ constructor.
778 class CXXConstructExpr : public Expr {
780 enum ConstructionKind {
788 CXXConstructorDecl *Constructor;
791 SourceRange ParenRange;
793 bool ZeroInitialization : 1;
794 unsigned ConstructKind : 2;
799 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
801 CXXConstructorDecl *d, bool elidable,
802 Expr **args, unsigned numargs,
803 bool ZeroInitialization = false,
804 ConstructionKind ConstructKind = CK_Complete,
805 SourceRange ParenRange = SourceRange());
807 /// \brief Construct an empty C++ construction expression.
808 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
809 : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
810 ConstructKind(0), Args(0), NumArgs(0) { }
813 /// \brief Construct an empty C++ construction expression.
814 explicit CXXConstructExpr(EmptyShell Empty)
815 : Expr(CXXConstructExprClass, Empty), Constructor(0),
816 Elidable(0), ZeroInitialization(0),
817 ConstructKind(0), Args(0), NumArgs(0) { }
819 static CXXConstructExpr *Create(ASTContext &C, QualType T,
821 CXXConstructorDecl *D, bool Elidable,
822 Expr **Args, unsigned NumArgs,
823 bool ZeroInitialization = false,
824 ConstructionKind ConstructKind = CK_Complete,
825 SourceRange ParenRange = SourceRange());
828 CXXConstructorDecl* getConstructor() const { return Constructor; }
829 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
831 SourceLocation getLocation() const { return Loc; }
832 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
834 /// \brief Whether this construction is elidable.
835 bool isElidable() const { return Elidable; }
836 void setElidable(bool E) { Elidable = E; }
838 /// \brief Whether this construction first requires
839 /// zero-initialization before the initializer is called.
840 bool requiresZeroInitialization() const { return ZeroInitialization; }
841 void setRequiresZeroInitialization(bool ZeroInit) {
842 ZeroInitialization = ZeroInit;
845 /// \brief Determines whether this constructor is actually constructing
846 /// a base class (rather than a complete object).
847 ConstructionKind getConstructionKind() const {
848 return (ConstructionKind)ConstructKind;
850 void setConstructionKind(ConstructionKind CK) {
854 typedef ExprIterator arg_iterator;
855 typedef ConstExprIterator const_arg_iterator;
857 arg_iterator arg_begin() { return Args; }
858 arg_iterator arg_end() { return Args + NumArgs; }
859 const_arg_iterator arg_begin() const { return Args; }
860 const_arg_iterator arg_end() const { return Args + NumArgs; }
862 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
863 unsigned getNumArgs() const { return NumArgs; }
865 /// getArg - Return the specified argument.
866 Expr *getArg(unsigned Arg) {
867 assert(Arg < NumArgs && "Arg access out of range!");
868 return cast<Expr>(Args[Arg]);
870 const Expr *getArg(unsigned Arg) const {
871 assert(Arg < NumArgs && "Arg access out of range!");
872 return cast<Expr>(Args[Arg]);
875 /// setArg - Set the specified argument.
876 void setArg(unsigned Arg, Expr *ArgExpr) {
877 assert(Arg < NumArgs && "Arg access out of range!");
881 SourceRange getSourceRange() const;
882 SourceRange getParenRange() const { return ParenRange; }
884 static bool classof(const Stmt *T) {
885 return T->getStmtClass() == CXXConstructExprClass ||
886 T->getStmtClass() == CXXTemporaryObjectExprClass;
888 static bool classof(const CXXConstructExpr *) { return true; }
891 child_range children() {
892 return child_range(&Args[0], &Args[0]+NumArgs);
895 friend class ASTStmtReader;
898 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
899 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
901 class CXXFunctionalCastExpr : public ExplicitCastExpr {
902 SourceLocation TyBeginLoc;
903 SourceLocation RParenLoc;
905 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
906 TypeSourceInfo *writtenTy,
907 SourceLocation tyBeginLoc, CastKind kind,
908 Expr *castExpr, unsigned pathSize,
909 SourceLocation rParenLoc)
910 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
911 castExpr, pathSize, writtenTy),
912 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
914 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
915 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
918 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
920 TypeSourceInfo *Written,
921 SourceLocation TyBeginLoc,
922 CastKind Kind, Expr *Op,
923 const CXXCastPath *Path,
924 SourceLocation RPLoc);
925 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
928 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
929 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
930 SourceLocation getRParenLoc() const { return RParenLoc; }
931 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
933 SourceRange getSourceRange() const {
934 return SourceRange(TyBeginLoc, RParenLoc);
936 static bool classof(const Stmt *T) {
937 return T->getStmtClass() == CXXFunctionalCastExprClass;
939 static bool classof(const CXXFunctionalCastExpr *) { return true; }
942 /// @brief Represents a C++ functional cast expression that builds a
943 /// temporary object.
945 /// This expression type represents a C++ "functional" cast
946 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
947 /// constructor to build a temporary object. With N == 1 arguments the
948 /// functional cast expression will be represented by CXXFunctionalCastExpr.
951 /// struct X { X(int, float); }
954 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
957 class CXXTemporaryObjectExpr : public CXXConstructExpr {
958 TypeSourceInfo *Type;
961 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
962 TypeSourceInfo *Type,
963 Expr **Args,unsigned NumArgs,
964 SourceRange parenRange,
965 bool ZeroInitialization = false);
966 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
967 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
969 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
971 SourceRange getSourceRange() const;
973 static bool classof(const Stmt *T) {
974 return T->getStmtClass() == CXXTemporaryObjectExprClass;
976 static bool classof(const CXXTemporaryObjectExpr *) { return true; }
978 friend class ASTStmtReader;
981 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
982 /// Expression "T()" which creates a value-initialized rvalue of type
983 /// T, which is a non-class type.
985 class CXXScalarValueInitExpr : public Expr {
986 SourceLocation RParenLoc;
987 TypeSourceInfo *TypeInfo;
989 friend class ASTStmtReader;
992 /// \brief Create an explicitly-written scalar-value initialization
994 CXXScalarValueInitExpr(QualType Type,
995 TypeSourceInfo *TypeInfo,
996 SourceLocation rParenLoc ) :
997 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
998 false, false, false),
999 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1001 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1002 : Expr(CXXScalarValueInitExprClass, Shell) { }
1004 TypeSourceInfo *getTypeSourceInfo() const {
1008 SourceLocation getRParenLoc() const { return RParenLoc; }
1010 SourceRange getSourceRange() const;
1012 static bool classof(const Stmt *T) {
1013 return T->getStmtClass() == CXXScalarValueInitExprClass;
1015 static bool classof(const CXXScalarValueInitExpr *) { return true; }
1018 child_range children() { return child_range(); }
1021 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
1022 /// e.g: "new CXXNewExpr(foo)".
1023 class CXXNewExpr : public Expr {
1024 // Was the usage ::new, i.e. is the global new to be used?
1026 // Is there an initializer? If not, built-ins are uninitialized, else they're
1027 // value-initialized.
1028 bool Initializer : 1;
1029 // Do we allocate an array? If so, the first SubExpr is the size expression.
1031 // If this is an array allocation, does the usual deallocation
1032 // function for the allocated type want to know the allocated size?
1033 bool UsualArrayDeleteWantsSize : 1;
1034 // The number of placement new arguments.
1035 unsigned NumPlacementArgs : 14;
1036 // The number of constructor arguments. This may be 1 even for non-class
1037 // types; use the pseudo copy constructor.
1038 unsigned NumConstructorArgs : 14;
1039 // Contains an optional array size expression, any number of optional
1040 // placement arguments, and any number of optional constructor arguments,
1043 // Points to the allocation function used.
1044 FunctionDecl *OperatorNew;
1045 // Points to the deallocation function used in case of error. May be null.
1046 FunctionDecl *OperatorDelete;
1047 // Points to the constructor used. Cannot be null if AllocType is a record;
1048 // it would still point at the default constructor (even an implicit one).
1049 // Must be null for all other types.
1050 CXXConstructorDecl *Constructor;
1052 /// \brief The allocated type-source information, as written in the source.
1053 TypeSourceInfo *AllocatedTypeInfo;
1055 /// \brief If the allocated type was expressed as a parenthesized type-id,
1056 /// the source range covering the parenthesized type-id.
1057 SourceRange TypeIdParens;
1059 SourceLocation StartLoc;
1060 SourceLocation EndLoc;
1061 SourceLocation ConstructorLParen;
1062 SourceLocation ConstructorRParen;
1064 friend class ASTStmtReader;
1066 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1067 Expr **placementArgs, unsigned numPlaceArgs,
1068 SourceRange TypeIdParens,
1069 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
1070 Expr **constructorArgs, unsigned numConsArgs,
1071 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1072 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1073 SourceLocation startLoc, SourceLocation endLoc,
1074 SourceLocation constructorLParen,
1075 SourceLocation constructorRParen);
1076 explicit CXXNewExpr(EmptyShell Shell)
1077 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1079 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1080 unsigned numConsArgs);
1082 QualType getAllocatedType() const {
1083 assert(getType()->isPointerType());
1084 return getType()->getAs<PointerType>()->getPointeeType();
1087 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1088 return AllocatedTypeInfo;
1091 /// \brief True if the allocation result needs to be null-checked.
1092 /// C++0x [expr.new]p13:
1093 /// If the allocation function returns null, initialization shall
1094 /// not be done, the deallocation function shall not be called,
1095 /// and the value of the new-expression shall be null.
1096 /// An allocation function is not allowed to return null unless it
1097 /// has a non-throwing exception-specification. The '03 rule is
1098 /// identical except that the definition of a non-throwing
1099 /// exception specification is just "is it throw()?".
1100 bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1102 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1103 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1104 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1105 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1106 CXXConstructorDecl *getConstructor() const { return Constructor; }
1107 void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
1109 bool isArray() const { return Array; }
1110 Expr *getArraySize() {
1111 return Array ? cast<Expr>(SubExprs[0]) : 0;
1113 const Expr *getArraySize() const {
1114 return Array ? cast<Expr>(SubExprs[0]) : 0;
1117 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1118 Expr **getPlacementArgs() {
1119 return reinterpret_cast<Expr **>(SubExprs + Array);
1122 Expr *getPlacementArg(unsigned i) {
1123 assert(i < NumPlacementArgs && "Index out of range");
1124 return cast<Expr>(SubExprs[Array + i]);
1126 const Expr *getPlacementArg(unsigned i) const {
1127 assert(i < NumPlacementArgs && "Index out of range");
1128 return cast<Expr>(SubExprs[Array + i]);
1131 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1132 SourceRange getTypeIdParens() const { return TypeIdParens; }
1134 bool isGlobalNew() const { return GlobalNew; }
1135 bool hasInitializer() const { return Initializer; }
1137 /// Answers whether the usual array deallocation function for the
1138 /// allocated type expects the size of the allocation as a
1140 bool doesUsualArrayDeleteWantSize() const {
1141 return UsualArrayDeleteWantsSize;
1144 unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1146 Expr **getConstructorArgs() {
1147 return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs);
1150 Expr *getConstructorArg(unsigned i) {
1151 assert(i < NumConstructorArgs && "Index out of range");
1152 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1154 const Expr *getConstructorArg(unsigned i) const {
1155 assert(i < NumConstructorArgs && "Index out of range");
1156 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1159 typedef ExprIterator arg_iterator;
1160 typedef ConstExprIterator const_arg_iterator;
1162 arg_iterator placement_arg_begin() {
1163 return SubExprs + Array;
1165 arg_iterator placement_arg_end() {
1166 return SubExprs + Array + getNumPlacementArgs();
1168 const_arg_iterator placement_arg_begin() const {
1169 return SubExprs + Array;
1171 const_arg_iterator placement_arg_end() const {
1172 return SubExprs + Array + getNumPlacementArgs();
1175 arg_iterator constructor_arg_begin() {
1176 return SubExprs + Array + getNumPlacementArgs();
1178 arg_iterator constructor_arg_end() {
1179 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1181 const_arg_iterator constructor_arg_begin() const {
1182 return SubExprs + Array + getNumPlacementArgs();
1184 const_arg_iterator constructor_arg_end() const {
1185 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1188 typedef Stmt **raw_arg_iterator;
1189 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1190 raw_arg_iterator raw_arg_end() {
1191 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1193 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1194 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
1196 SourceLocation getStartLoc() const { return StartLoc; }
1197 SourceLocation getEndLoc() const { return EndLoc; }
1199 SourceLocation getConstructorLParen() const { return ConstructorLParen; }
1200 SourceLocation getConstructorRParen() const { return ConstructorRParen; }
1202 SourceRange getSourceRange() const {
1203 return SourceRange(StartLoc, EndLoc);
1206 static bool classof(const Stmt *T) {
1207 return T->getStmtClass() == CXXNewExprClass;
1209 static bool classof(const CXXNewExpr *) { return true; }
1212 child_range children() {
1213 return child_range(&SubExprs[0],
1214 &SubExprs[0] + Array + getNumPlacementArgs()
1215 + getNumConstructorArgs());
1219 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1220 /// calls, e.g. "delete[] pArray".
1221 class CXXDeleteExpr : public Expr {
1222 // Is this a forced global delete, i.e. "::delete"?
1223 bool GlobalDelete : 1;
1224 // Is this the array form of delete, i.e. "delete[]"?
1226 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1227 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1229 bool ArrayFormAsWritten : 1;
1230 // Does the usual deallocation function for the element type require
1231 // a size_t argument?
1232 bool UsualArrayDeleteWantsSize : 1;
1233 // Points to the operator delete overload that is used. Could be a member.
1234 FunctionDecl *OperatorDelete;
1235 // The pointer expression to be deleted.
1237 // Location of the expression.
1240 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1241 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1242 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1243 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1244 arg->containsUnexpandedParameterPack()),
1245 GlobalDelete(globalDelete),
1246 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1247 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
1248 OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
1249 explicit CXXDeleteExpr(EmptyShell Shell)
1250 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1252 bool isGlobalDelete() const { return GlobalDelete; }
1253 bool isArrayForm() const { return ArrayForm; }
1254 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1256 /// Answers whether the usual array deallocation function for the
1257 /// allocated type expects the size of the allocation as a
1258 /// parameter. This can be true even if the actual deallocation
1259 /// function that we're using doesn't want a size.
1260 bool doesUsualArrayDeleteWantSize() const {
1261 return UsualArrayDeleteWantsSize;
1264 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1266 Expr *getArgument() { return cast<Expr>(Argument); }
1267 const Expr *getArgument() const { return cast<Expr>(Argument); }
1269 /// \brief Retrieve the type being destroyed. If the type being
1270 /// destroyed is a dependent type which may or may not be a pointer,
1271 /// return an invalid type.
1272 QualType getDestroyedType() const;
1274 SourceRange getSourceRange() const {
1275 return SourceRange(Loc, Argument->getLocEnd());
1278 static bool classof(const Stmt *T) {
1279 return T->getStmtClass() == CXXDeleteExprClass;
1281 static bool classof(const CXXDeleteExpr *) { return true; }
1284 child_range children() { return child_range(&Argument, &Argument+1); }
1286 friend class ASTStmtReader;
1289 /// \brief Structure used to store the type being destroyed by a
1290 /// pseudo-destructor expression.
1291 class PseudoDestructorTypeStorage {
1292 /// \brief Either the type source information or the name of the type, if
1293 /// it couldn't be resolved due to type-dependence.
1294 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1296 /// \brief The starting source location of the pseudo-destructor type.
1297 SourceLocation Location;
1300 PseudoDestructorTypeStorage() { }
1302 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1303 : Type(II), Location(Loc) { }
1305 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1307 TypeSourceInfo *getTypeSourceInfo() const {
1308 return Type.dyn_cast<TypeSourceInfo *>();
1311 IdentifierInfo *getIdentifier() const {
1312 return Type.dyn_cast<IdentifierInfo *>();
1315 SourceLocation getLocation() const { return Location; }
1318 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1320 /// A pseudo-destructor is an expression that looks like a member access to a
1321 /// destructor of a scalar type, except that scalar types don't have
1322 /// destructors. For example:
1326 /// void f(int *p) {
1331 /// Pseudo-destructors typically occur when instantiating templates such as:
1334 /// template<typename T>
1335 /// void destroy(T* ptr) {
1340 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1341 /// beyond evaluating the base expression.
1342 class CXXPseudoDestructorExpr : public Expr {
1343 /// \brief The base expression (that is being destroyed).
1346 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1350 /// \brief The location of the '.' or '->' operator.
1351 SourceLocation OperatorLoc;
1353 /// \brief The nested-name-specifier that follows the operator, if present.
1354 NestedNameSpecifierLoc QualifierLoc;
1356 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1358 TypeSourceInfo *ScopeType;
1360 /// \brief The location of the '::' in a qualified pseudo-destructor
1362 SourceLocation ColonColonLoc;
1364 /// \brief The location of the '~'.
1365 SourceLocation TildeLoc;
1367 /// \brief The type being destroyed, or its name if we were unable to
1368 /// resolve the name.
1369 PseudoDestructorTypeStorage DestroyedType;
1371 friend class ASTStmtReader;
1374 CXXPseudoDestructorExpr(ASTContext &Context,
1375 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1376 NestedNameSpecifierLoc QualifierLoc,
1377 TypeSourceInfo *ScopeType,
1378 SourceLocation ColonColonLoc,
1379 SourceLocation TildeLoc,
1380 PseudoDestructorTypeStorage DestroyedType);
1382 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1383 : Expr(CXXPseudoDestructorExprClass, Shell),
1384 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1386 Expr *getBase() const { return cast<Expr>(Base); }
1388 /// \brief Determines whether this member expression actually had
1389 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1391 bool hasQualifier() const { return QualifierLoc; }
1393 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1394 /// with source-location information.
1395 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1397 /// \brief If the member name was qualified, retrieves the
1398 /// nested-name-specifier that precedes the member name. Otherwise, returns
1400 NestedNameSpecifier *getQualifier() const {
1401 return QualifierLoc.getNestedNameSpecifier();
1404 /// \brief Determine whether this pseudo-destructor expression was written
1405 /// using an '->' (otherwise, it used a '.').
1406 bool isArrow() const { return IsArrow; }
1408 /// \brief Retrieve the location of the '.' or '->' operator.
1409 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1411 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1414 /// Pseudo-destructor expressions can have extra qualification within them
1415 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1416 /// Here, if the object type of the expression is (or may be) a scalar type,
1417 /// \p T may also be a scalar type and, therefore, cannot be part of a
1418 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1419 /// destructor expression.
1420 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1422 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1424 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1426 /// \brief Retrieve the location of the '~'.
1427 SourceLocation getTildeLoc() const { return TildeLoc; }
1429 /// \brief Retrieve the source location information for the type
1430 /// being destroyed.
1432 /// This type-source information is available for non-dependent
1433 /// pseudo-destructor expressions and some dependent pseudo-destructor
1434 /// expressions. Returns NULL if we only have the identifier for a
1435 /// dependent pseudo-destructor expression.
1436 TypeSourceInfo *getDestroyedTypeInfo() const {
1437 return DestroyedType.getTypeSourceInfo();
1440 /// \brief In a dependent pseudo-destructor expression for which we do not
1441 /// have full type information on the destroyed type, provides the name
1442 /// of the destroyed type.
1443 IdentifierInfo *getDestroyedTypeIdentifier() const {
1444 return DestroyedType.getIdentifier();
1447 /// \brief Retrieve the type being destroyed.
1448 QualType getDestroyedType() const;
1450 /// \brief Retrieve the starting location of the type being destroyed.
1451 SourceLocation getDestroyedTypeLoc() const {
1452 return DestroyedType.getLocation();
1455 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1457 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1458 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1461 /// \brief Set the destroyed type.
1462 void setDestroyedType(TypeSourceInfo *Info) {
1463 DestroyedType = PseudoDestructorTypeStorage(Info);
1466 SourceRange getSourceRange() const;
1468 static bool classof(const Stmt *T) {
1469 return T->getStmtClass() == CXXPseudoDestructorExprClass;
1471 static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1474 child_range children() { return child_range(&Base, &Base + 1); }
1477 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1478 /// implementation of TR1/C++0x type trait templates.
1480 /// __is_pod(int) == true
1481 /// __is_enum(std::string) == false
1482 class UnaryTypeTraitExpr : public Expr {
1483 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
1485 /// The value of the type trait. Unspecified if dependent.
1488 /// Loc - The location of the type trait keyword.
1491 /// RParen - The location of the closing paren.
1492 SourceLocation RParen;
1494 /// The type being queried.
1495 TypeSourceInfo *QueriedType;
1498 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1499 TypeSourceInfo *queried, bool value,
1500 SourceLocation rparen, QualType ty)
1501 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1502 false, queried->getType()->isDependentType(),
1503 queried->getType()->containsUnexpandedParameterPack()),
1504 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
1506 explicit UnaryTypeTraitExpr(EmptyShell Empty)
1507 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
1510 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1512 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
1514 QualType getQueriedType() const { return QueriedType->getType(); }
1516 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1518 bool getValue() const { return Value; }
1520 static bool classof(const Stmt *T) {
1521 return T->getStmtClass() == UnaryTypeTraitExprClass;
1523 static bool classof(const UnaryTypeTraitExpr *) { return true; }
1526 child_range children() { return child_range(); }
1528 friend class ASTStmtReader;
1531 /// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
1532 /// implementation of TR1/C++0x type trait templates.
1534 /// __is_base_of(Base, Derived) == true
1535 class BinaryTypeTraitExpr : public Expr {
1536 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
1539 /// The value of the type trait. Unspecified if dependent.
1542 /// Loc - The location of the type trait keyword.
1545 /// RParen - The location of the closing paren.
1546 SourceLocation RParen;
1548 /// The lhs type being queried.
1549 TypeSourceInfo *LhsType;
1551 /// The rhs type being queried.
1552 TypeSourceInfo *RhsType;
1555 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1556 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
1557 bool value, SourceLocation rparen, QualType ty)
1558 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
1559 lhsType->getType()->isDependentType() ||
1560 rhsType->getType()->isDependentType(),
1561 (lhsType->getType()->containsUnexpandedParameterPack() ||
1562 rhsType->getType()->containsUnexpandedParameterPack())),
1563 BTT(btt), Value(value), Loc(loc), RParen(rparen),
1564 LhsType(lhsType), RhsType(rhsType) { }
1567 explicit BinaryTypeTraitExpr(EmptyShell Empty)
1568 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1569 LhsType(), RhsType() { }
1571 SourceRange getSourceRange() const {
1572 return SourceRange(Loc, RParen);
1575 BinaryTypeTrait getTrait() const {
1576 return static_cast<BinaryTypeTrait>(BTT);
1579 QualType getLhsType() const { return LhsType->getType(); }
1580 QualType getRhsType() const { return RhsType->getType(); }
1582 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
1583 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
1585 bool getValue() const { assert(!isTypeDependent()); return Value; }
1587 static bool classof(const Stmt *T) {
1588 return T->getStmtClass() == BinaryTypeTraitExprClass;
1590 static bool classof(const BinaryTypeTraitExpr *) { return true; }
1593 child_range children() { return child_range(); }
1595 friend class ASTStmtReader;
1598 /// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the
1599 /// implementation of __array_rank and __array_extent.
1601 /// __array_rank(int[10][20]) == 2
1602 /// __array_extent(int, 1) == 20
1603 class ArrayTypeTraitExpr : public Expr {
1604 /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
1607 /// The value of the type trait. Unspecified if dependent.
1610 /// The array dimension being queried, or -1 if not used
1613 /// Loc - The location of the type trait keyword.
1616 /// RParen - The location of the closing paren.
1617 SourceLocation RParen;
1619 /// The type being queried.
1620 TypeSourceInfo *QueriedType;
1623 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
1624 TypeSourceInfo *queried, uint64_t value,
1625 Expr *dimension, SourceLocation rparen, QualType ty)
1626 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1627 false, queried->getType()->isDependentType(),
1628 queried->getType()->containsUnexpandedParameterPack()),
1629 ATT(att), Value(value), Dimension(dimension),
1630 Loc(loc), RParen(rparen), QueriedType(queried) { }
1633 explicit ArrayTypeTraitExpr(EmptyShell Empty)
1634 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
1637 virtual ~ArrayTypeTraitExpr() { }
1639 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen); }
1641 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
1643 QualType getQueriedType() const { return QueriedType->getType(); }
1645 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1647 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
1649 Expr *getDimensionExpression() const { return Dimension; }
1651 static bool classof(const Stmt *T) {
1652 return T->getStmtClass() == ArrayTypeTraitExprClass;
1654 static bool classof(const ArrayTypeTraitExpr *) { return true; }
1657 child_range children() { return child_range(); }
1659 friend class ASTStmtReader;
1662 /// ExpressionTraitExpr - An expression trait intrinsic
1664 /// __is_lvalue_expr(std::cout) == true
1665 /// __is_lvalue_expr(1) == false
1666 class ExpressionTraitExpr : public Expr {
1667 /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned.
1669 /// The value of the type trait. Unspecified if dependent.
1672 /// Loc - The location of the type trait keyword.
1675 /// RParen - The location of the closing paren.
1676 SourceLocation RParen;
1678 Expr* QueriedExpression;
1680 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
1681 Expr *queried, bool value,
1682 SourceLocation rparen, QualType resultType)
1683 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1684 false, // Not type-dependent
1685 // Value-dependent if the argument is type-dependent.
1686 queried->isTypeDependent(),
1687 queried->containsUnexpandedParameterPack()),
1688 ET(et), Value(value), Loc(loc), RParen(rparen), QueriedExpression(queried) { }
1690 explicit ExpressionTraitExpr(EmptyShell Empty)
1691 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
1692 QueriedExpression() { }
1694 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1696 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
1698 Expr *getQueriedExpression() const { return QueriedExpression; }
1700 bool getValue() const { return Value; }
1702 static bool classof(const Stmt *T) {
1703 return T->getStmtClass() == ExpressionTraitExprClass;
1705 static bool classof(const ExpressionTraitExpr *) { return true; }
1708 child_range children() { return child_range(); }
1710 friend class ASTStmtReader;
1714 /// \brief A reference to an overloaded function set, either an
1715 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1716 class OverloadExpr : public Expr {
1717 /// The results. These are undesugared, which is to say, they may
1718 /// include UsingShadowDecls. Access is relative to the naming
1720 // FIXME: Allocate this data after the OverloadExpr subclass.
1721 DeclAccessPair *Results;
1722 unsigned NumResults;
1724 /// The common name of these declarations.
1725 DeclarationNameInfo NameInfo;
1727 /// \brief The nested-name-specifier that qualifies the name, if any.
1728 NestedNameSpecifierLoc QualifierLoc;
1731 /// True if the name was a template-id.
1732 bool HasExplicitTemplateArgs;
1734 OverloadExpr(StmtClass K, ASTContext &C,
1735 NestedNameSpecifierLoc QualifierLoc,
1736 const DeclarationNameInfo &NameInfo,
1737 const TemplateArgumentListInfo *TemplateArgs,
1738 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1739 bool KnownDependent = false,
1740 bool KnownContainsUnexpandedParameterPack = false);
1742 OverloadExpr(StmtClass K, EmptyShell Empty)
1743 : Expr(K, Empty), Results(0), NumResults(0),
1744 QualifierLoc(), HasExplicitTemplateArgs(false) { }
1746 void initializeResults(ASTContext &C,
1747 UnresolvedSetIterator Begin,
1748 UnresolvedSetIterator End);
1752 OverloadExpr *Expression;
1753 bool IsAddressOfOperand;
1754 bool HasFormOfMemberPointer;
1757 /// Finds the overloaded expression in the given expression of
1760 /// \return the expression (which must be there) and true if it has
1761 /// the particular form of a member pointer expression
1762 static FindResult find(Expr *E) {
1763 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1767 E = E->IgnoreParens();
1768 if (isa<UnaryOperator>(E)) {
1769 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
1770 E = cast<UnaryOperator>(E)->getSubExpr();
1771 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
1773 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
1774 Result.IsAddressOfOperand = true;
1775 Result.Expression = Ovl;
1777 Result.HasFormOfMemberPointer = false;
1778 Result.IsAddressOfOperand = false;
1779 Result.Expression = cast<OverloadExpr>(E);
1785 /// Gets the naming class of this lookup, if any.
1786 CXXRecordDecl *getNamingClass() const;
1788 typedef UnresolvedSetImpl::iterator decls_iterator;
1789 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1790 decls_iterator decls_end() const {
1791 return UnresolvedSetIterator(Results + NumResults);
1794 /// Gets the number of declarations in the unresolved set.
1795 unsigned getNumDecls() const { return NumResults; }
1797 /// Gets the full name info.
1798 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1800 /// Gets the name looked up.
1801 DeclarationName getName() const { return NameInfo.getName(); }
1803 /// Gets the location of the name.
1804 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
1806 /// Fetches the nested-name qualifier, if one was given.
1807 NestedNameSpecifier *getQualifier() const {
1808 return QualifierLoc.getNestedNameSpecifier();
1811 /// Fetches the nested-name qualifier with source-location information, if
1813 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1815 /// \brief Determines whether this expression had an explicit
1816 /// template argument list, e.g. f<int>.
1817 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1819 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1821 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1822 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1825 /// \brief Retrieves the optional explicit template arguments.
1826 /// This points to the same data as getExplicitTemplateArgs(), but
1827 /// returns null if there are no explicit template arguments.
1828 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1829 if (!hasExplicitTemplateArgs()) return 0;
1830 return &getExplicitTemplateArgs();
1833 static bool classof(const Stmt *T) {
1834 return T->getStmtClass() == UnresolvedLookupExprClass ||
1835 T->getStmtClass() == UnresolvedMemberExprClass;
1837 static bool classof(const OverloadExpr *) { return true; }
1839 friend class ASTStmtReader;
1840 friend class ASTStmtWriter;
1843 /// \brief A reference to a name which we were able to look up during
1844 /// parsing but could not resolve to a specific declaration. This
1845 /// arises in several ways:
1846 /// * we might be waiting for argument-dependent lookup
1847 /// * the name might resolve to an overloaded function
1849 /// * the lookup might have included a function template
1850 /// These never include UnresolvedUsingValueDecls, which are always
1851 /// class members and therefore appear only in
1852 /// UnresolvedMemberLookupExprs.
1853 class UnresolvedLookupExpr : public OverloadExpr {
1854 /// True if these lookup results should be extended by
1855 /// argument-dependent lookup if this is the operand of a function
1859 /// True if namespace ::std should be considered an associated namespace
1860 /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
1861 bool StdIsAssociatedNamespace;
1863 /// True if these lookup results are overloaded. This is pretty
1864 /// trivially rederivable if we urgently need to kill this field.
1867 /// The naming class (C++ [class.access.base]p5) of the lookup, if
1868 /// any. This can generally be recalculated from the context chain,
1869 /// but that can be fairly expensive for unqualified lookups. If we
1870 /// want to improve memory use here, this could go in a union
1871 /// against the qualified-lookup bits.
1872 CXXRecordDecl *NamingClass;
1874 UnresolvedLookupExpr(ASTContext &C,
1875 CXXRecordDecl *NamingClass,
1876 NestedNameSpecifierLoc QualifierLoc,
1877 const DeclarationNameInfo &NameInfo,
1878 bool RequiresADL, bool Overloaded,
1879 const TemplateArgumentListInfo *TemplateArgs,
1880 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1881 bool StdIsAssociatedNamespace)
1882 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, NameInfo,
1883 TemplateArgs, Begin, End),
1884 RequiresADL(RequiresADL),
1885 StdIsAssociatedNamespace(StdIsAssociatedNamespace),
1886 Overloaded(Overloaded), NamingClass(NamingClass)
1889 UnresolvedLookupExpr(EmptyShell Empty)
1890 : OverloadExpr(UnresolvedLookupExprClass, Empty),
1891 RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
1895 friend class ASTStmtReader;
1898 static UnresolvedLookupExpr *Create(ASTContext &C,
1899 CXXRecordDecl *NamingClass,
1900 NestedNameSpecifierLoc QualifierLoc,
1901 const DeclarationNameInfo &NameInfo,
1902 bool ADL, bool Overloaded,
1903 UnresolvedSetIterator Begin,
1904 UnresolvedSetIterator End,
1905 bool StdIsAssociatedNamespace = false) {
1906 assert((ADL || !StdIsAssociatedNamespace) &&
1907 "std considered associated namespace when not performing ADL");
1908 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
1909 ADL, Overloaded, 0, Begin, End,
1910 StdIsAssociatedNamespace);
1913 static UnresolvedLookupExpr *Create(ASTContext &C,
1914 CXXRecordDecl *NamingClass,
1915 NestedNameSpecifierLoc QualifierLoc,
1916 const DeclarationNameInfo &NameInfo,
1918 const TemplateArgumentListInfo &Args,
1919 UnresolvedSetIterator Begin,
1920 UnresolvedSetIterator End);
1922 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1923 bool HasExplicitTemplateArgs,
1924 unsigned NumTemplateArgs);
1926 /// True if this declaration should be extended by
1927 /// argument-dependent lookup.
1928 bool requiresADL() const { return RequiresADL; }
1930 /// True if namespace ::std should be artificially added to the set of
1931 /// associated namespaecs for argument-dependent lookup purposes.
1932 bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
1934 /// True if this lookup is overloaded.
1935 bool isOverloaded() const { return Overloaded; }
1937 /// Gets the 'naming class' (in the sense of C++0x
1938 /// [class.access.base]p5) of the lookup. This is the scope
1939 /// that was looked in to find these results.
1940 CXXRecordDecl *getNamingClass() const { return NamingClass; }
1942 // Note that, inconsistently with the explicit-template-argument AST
1943 // nodes, users are *forbidden* from calling these methods on objects
1944 // without explicit template arguments.
1946 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1947 assert(hasExplicitTemplateArgs());
1948 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1951 /// Gets a reference to the explicit template argument list.
1952 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1953 assert(hasExplicitTemplateArgs());
1954 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1957 /// \brief Retrieves the optional explicit template arguments.
1958 /// This points to the same data as getExplicitTemplateArgs(), but
1959 /// returns null if there are no explicit template arguments.
1960 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1961 if (!hasExplicitTemplateArgs()) return 0;
1962 return &getExplicitTemplateArgs();
1965 /// \brief Copies the template arguments (if present) into the given
1967 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1968 getExplicitTemplateArgs().copyInto(List);
1971 SourceLocation getLAngleLoc() const {
1972 return getExplicitTemplateArgs().LAngleLoc;
1975 SourceLocation getRAngleLoc() const {
1976 return getExplicitTemplateArgs().RAngleLoc;
1979 TemplateArgumentLoc const *getTemplateArgs() const {
1980 return getExplicitTemplateArgs().getTemplateArgs();
1983 unsigned getNumTemplateArgs() const {
1984 return getExplicitTemplateArgs().NumTemplateArgs;
1987 SourceRange getSourceRange() const {
1988 SourceRange Range(getNameInfo().getSourceRange());
1989 if (getQualifierLoc())
1990 Range.setBegin(getQualifierLoc().getBeginLoc());
1991 if (hasExplicitTemplateArgs())
1992 Range.setEnd(getRAngleLoc());
1996 child_range children() { return child_range(); }
1998 static bool classof(const Stmt *T) {
1999 return T->getStmtClass() == UnresolvedLookupExprClass;
2001 static bool classof(const UnresolvedLookupExpr *) { return true; }
2004 /// \brief A qualified reference to a name whose declaration cannot
2005 /// yet be resolved.
2007 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2008 /// it expresses a reference to a declaration such as
2009 /// X<T>::value. The difference, however, is that an
2010 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2011 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2012 /// this case, X<T>::value cannot resolve to a declaration because the
2013 /// declaration will differ from on instantiation of X<T> to the
2014 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2015 /// qualifier (X<T>::) and the name of the entity being referenced
2016 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2017 /// declaration can be found.
2018 class DependentScopeDeclRefExpr : public Expr {
2019 /// \brief The nested-name-specifier that qualifies this unresolved
2020 /// declaration name.
2021 NestedNameSpecifierLoc QualifierLoc;
2023 /// The name of the entity we will be referencing.
2024 DeclarationNameInfo NameInfo;
2026 /// \brief Whether the name includes explicit template arguments.
2027 bool HasExplicitTemplateArgs;
2029 DependentScopeDeclRefExpr(QualType T,
2030 NestedNameSpecifierLoc QualifierLoc,
2031 const DeclarationNameInfo &NameInfo,
2032 const TemplateArgumentListInfo *Args);
2035 static DependentScopeDeclRefExpr *Create(ASTContext &C,
2036 NestedNameSpecifierLoc QualifierLoc,
2037 const DeclarationNameInfo &NameInfo,
2038 const TemplateArgumentListInfo *TemplateArgs = 0);
2040 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2041 bool HasExplicitTemplateArgs,
2042 unsigned NumTemplateArgs);
2044 /// \brief Retrieve the name that this expression refers to.
2045 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2047 /// \brief Retrieve the name that this expression refers to.
2048 DeclarationName getDeclName() const { return NameInfo.getName(); }
2050 /// \brief Retrieve the location of the name within the expression.
2051 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2053 /// \brief Retrieve the nested-name-specifier that qualifies the
2054 /// name, with source location information.
2055 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2058 /// \brief Retrieve the nested-name-specifier that qualifies this
2060 NestedNameSpecifier *getQualifier() const {
2061 return QualifierLoc.getNestedNameSpecifier();
2064 /// Determines whether this lookup had explicit template arguments.
2065 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
2067 // Note that, inconsistently with the explicit-template-argument AST
2068 // nodes, users are *forbidden* from calling these methods on objects
2069 // without explicit template arguments.
2071 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2072 assert(hasExplicitTemplateArgs());
2073 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
2076 /// Gets a reference to the explicit template argument list.
2077 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2078 assert(hasExplicitTemplateArgs());
2079 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
2082 /// \brief Retrieves the optional explicit template arguments.
2083 /// This points to the same data as getExplicitTemplateArgs(), but
2084 /// returns null if there are no explicit template arguments.
2085 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2086 if (!hasExplicitTemplateArgs()) return 0;
2087 return &getExplicitTemplateArgs();
2090 /// \brief Copies the template arguments (if present) into the given
2092 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2093 getExplicitTemplateArgs().copyInto(List);
2096 SourceLocation getLAngleLoc() const {
2097 return getExplicitTemplateArgs().LAngleLoc;
2100 SourceLocation getRAngleLoc() const {
2101 return getExplicitTemplateArgs().RAngleLoc;
2104 TemplateArgumentLoc const *getTemplateArgs() const {
2105 return getExplicitTemplateArgs().getTemplateArgs();
2108 unsigned getNumTemplateArgs() const {
2109 return getExplicitTemplateArgs().NumTemplateArgs;
2112 SourceRange getSourceRange() const {
2113 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2114 if (hasExplicitTemplateArgs())
2115 Range.setEnd(getRAngleLoc());
2119 static bool classof(const Stmt *T) {
2120 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2122 static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2124 child_range children() { return child_range(); }
2126 friend class ASTStmtReader;
2127 friend class ASTStmtWriter;
2130 /// Represents an expression --- generally a full-expression --- which
2131 /// introduces cleanups to be run at the end of the sub-expression's
2132 /// evaluation. The most common source of expression-introduced
2133 /// cleanups is temporary objects in C++, but several other C++
2134 /// expressions can create cleanups.
2135 class ExprWithCleanups : public Expr {
2138 CXXTemporary **Temps;
2141 ExprWithCleanups(ASTContext &C, Expr *SubExpr,
2142 CXXTemporary **Temps, unsigned NumTemps);
2145 ExprWithCleanups(EmptyShell Empty)
2146 : Expr(ExprWithCleanupsClass, Empty),
2147 SubExpr(0), Temps(0), NumTemps(0) {}
2149 static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr,
2150 CXXTemporary **Temps,
2153 unsigned getNumTemporaries() const { return NumTemps; }
2154 void setNumTemporaries(ASTContext &C, unsigned N);
2156 CXXTemporary *getTemporary(unsigned i) {
2157 assert(i < NumTemps && "Index out of range");
2160 const CXXTemporary *getTemporary(unsigned i) const {
2161 return const_cast<ExprWithCleanups*>(this)->getTemporary(i);
2163 void setTemporary(unsigned i, CXXTemporary *T) {
2164 assert(i < NumTemps && "Index out of range");
2168 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2169 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2170 void setSubExpr(Expr *E) { SubExpr = E; }
2172 SourceRange getSourceRange() const {
2173 return SubExpr->getSourceRange();
2176 // Implement isa/cast/dyncast/etc.
2177 static bool classof(const Stmt *T) {
2178 return T->getStmtClass() == ExprWithCleanupsClass;
2180 static bool classof(const ExprWithCleanups *) { return true; }
2183 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2186 /// \brief Describes an explicit type conversion that uses functional
2187 /// notion but could not be resolved because one or more arguments are
2190 /// The explicit type conversions expressed by
2191 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2192 /// where \c T is some type and \c a1, a2, ..., aN are values, and
2193 /// either \C T is a dependent type or one or more of the \c a's is
2194 /// type-dependent. For example, this would occur in a template such
2198 /// template<typename T, typename A1>
2199 /// inline T make_a(const A1& a1) {
2204 /// When the returned expression is instantiated, it may resolve to a
2205 /// constructor call, conversion function call, or some kind of type
2207 class CXXUnresolvedConstructExpr : public Expr {
2208 /// \brief The type being constructed.
2209 TypeSourceInfo *Type;
2211 /// \brief The location of the left parentheses ('(').
2212 SourceLocation LParenLoc;
2214 /// \brief The location of the right parentheses (')').
2215 SourceLocation RParenLoc;
2217 /// \brief The number of arguments used to construct the type.
2220 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2221 SourceLocation LParenLoc,
2224 SourceLocation RParenLoc);
2226 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2227 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2229 friend class ASTStmtReader;
2232 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2233 TypeSourceInfo *Type,
2234 SourceLocation LParenLoc,
2237 SourceLocation RParenLoc);
2239 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2242 /// \brief Retrieve the type that is being constructed, as specified
2243 /// in the source code.
2244 QualType getTypeAsWritten() const { return Type->getType(); }
2246 /// \brief Retrieve the type source information for the type being
2248 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2250 /// \brief Retrieve the location of the left parentheses ('(') that
2251 /// precedes the argument list.
2252 SourceLocation getLParenLoc() const { return LParenLoc; }
2253 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2255 /// \brief Retrieve the location of the right parentheses (')') that
2256 /// follows the argument list.
2257 SourceLocation getRParenLoc() const { return RParenLoc; }
2258 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2260 /// \brief Retrieve the number of arguments.
2261 unsigned arg_size() const { return NumArgs; }
2263 typedef Expr** arg_iterator;
2264 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2265 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2267 typedef const Expr* const * const_arg_iterator;
2268 const_arg_iterator arg_begin() const {
2269 return reinterpret_cast<const Expr* const *>(this + 1);
2271 const_arg_iterator arg_end() const {
2272 return arg_begin() + NumArgs;
2275 Expr *getArg(unsigned I) {
2276 assert(I < NumArgs && "Argument index out-of-range");
2277 return *(arg_begin() + I);
2280 const Expr *getArg(unsigned I) const {
2281 assert(I < NumArgs && "Argument index out-of-range");
2282 return *(arg_begin() + I);
2285 void setArg(unsigned I, Expr *E) {
2286 assert(I < NumArgs && "Argument index out-of-range");
2287 *(arg_begin() + I) = E;
2290 SourceRange getSourceRange() const;
2292 static bool classof(const Stmt *T) {
2293 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2295 static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2298 child_range children() {
2299 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2300 return child_range(begin, begin + NumArgs);
2304 /// \brief Represents a C++ member access expression where the actual
2305 /// member referenced could not be resolved because the base
2306 /// expression or the member name was dependent.
2308 /// Like UnresolvedMemberExprs, these can be either implicit or
2309 /// explicit accesses. It is only possible to get one of these with
2310 /// an implicit access if a qualifier is provided.
2311 class CXXDependentScopeMemberExpr : public Expr {
2312 /// \brief The expression for the base pointer or class reference,
2313 /// e.g., the \c x in x.f. Can be null in implicit accesses.
2316 /// \brief The type of the base expression. Never null, even for
2317 /// implicit accesses.
2320 /// \brief Whether this member expression used the '->' operator or
2321 /// the '.' operator.
2324 /// \brief Whether this member expression has explicitly-specified template
2326 bool HasExplicitTemplateArgs : 1;
2328 /// \brief The location of the '->' or '.' operator.
2329 SourceLocation OperatorLoc;
2331 /// \brief The nested-name-specifier that precedes the member name, if any.
2332 NestedNameSpecifierLoc QualifierLoc;
2334 /// \brief In a qualified member access expression such as t->Base::f, this
2335 /// member stores the resolves of name lookup in the context of the member
2336 /// access expression, to be used at instantiation time.
2338 /// FIXME: This member, along with the QualifierLoc, could
2339 /// be stuck into a structure that is optionally allocated at the end of
2340 /// the CXXDependentScopeMemberExpr, to save space in the common case.
2341 NamedDecl *FirstQualifierFoundInScope;
2343 /// \brief The member to which this member expression refers, which
2344 /// can be name, overloaded operator, or destructor.
2345 /// FIXME: could also be a template-id
2346 DeclarationNameInfo MemberNameInfo;
2348 CXXDependentScopeMemberExpr(ASTContext &C,
2349 Expr *Base, QualType BaseType, bool IsArrow,
2350 SourceLocation OperatorLoc,
2351 NestedNameSpecifierLoc QualifierLoc,
2352 NamedDecl *FirstQualifierFoundInScope,
2353 DeclarationNameInfo MemberNameInfo,
2354 const TemplateArgumentListInfo *TemplateArgs);
2357 CXXDependentScopeMemberExpr(ASTContext &C,
2358 Expr *Base, QualType BaseType,
2360 SourceLocation OperatorLoc,
2361 NestedNameSpecifierLoc QualifierLoc,
2362 NamedDecl *FirstQualifierFoundInScope,
2363 DeclarationNameInfo MemberNameInfo);
2365 static CXXDependentScopeMemberExpr *
2366 Create(ASTContext &C,
2367 Expr *Base, QualType BaseType, bool IsArrow,
2368 SourceLocation OperatorLoc,
2369 NestedNameSpecifierLoc QualifierLoc,
2370 NamedDecl *FirstQualifierFoundInScope,
2371 DeclarationNameInfo MemberNameInfo,
2372 const TemplateArgumentListInfo *TemplateArgs);
2374 static CXXDependentScopeMemberExpr *
2375 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2376 unsigned NumTemplateArgs);
2378 /// \brief True if this is an implicit access, i.e. one in which the
2379 /// member being accessed was not written in the source. The source
2380 /// location of the operator is invalid in this case.
2381 bool isImplicitAccess() const;
2383 /// \brief Retrieve the base object of this member expressions,
2384 /// e.g., the \c x in \c x.m.
2385 Expr *getBase() const {
2386 assert(!isImplicitAccess());
2387 return cast<Expr>(Base);
2390 QualType getBaseType() const { return BaseType; }
2392 /// \brief Determine whether this member expression used the '->'
2393 /// operator; otherwise, it used the '.' operator.
2394 bool isArrow() const { return IsArrow; }
2396 /// \brief Retrieve the location of the '->' or '.' operator.
2397 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2399 /// \brief Retrieve the nested-name-specifier that qualifies the member
2401 NestedNameSpecifier *getQualifier() const {
2402 return QualifierLoc.getNestedNameSpecifier();
2405 /// \brief Retrieve the nested-name-specifier that qualifies the member
2406 /// name, with source location information.
2407 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2410 /// \brief Retrieve the first part of the nested-name-specifier that was
2411 /// found in the scope of the member access expression when the member access
2412 /// was initially parsed.
2414 /// This function only returns a useful result when member access expression
2415 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2416 /// returned by this function describes what was found by unqualified name
2417 /// lookup for the identifier "Base" within the scope of the member access
2418 /// expression itself. At template instantiation time, this information is
2419 /// combined with the results of name lookup into the type of the object
2420 /// expression itself (the class type of x).
2421 NamedDecl *getFirstQualifierFoundInScope() const {
2422 return FirstQualifierFoundInScope;
2425 /// \brief Retrieve the name of the member that this expression
2427 const DeclarationNameInfo &getMemberNameInfo() const {
2428 return MemberNameInfo;
2431 /// \brief Retrieve the name of the member that this expression
2433 DeclarationName getMember() const { return MemberNameInfo.getName(); }
2435 // \brief Retrieve the location of the name of the member that this
2436 // expression refers to.
2437 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2439 /// \brief Determines whether this member expression actually had a C++
2440 /// template argument list explicitly specified, e.g., x.f<int>.
2441 bool hasExplicitTemplateArgs() const {
2442 return HasExplicitTemplateArgs;
2445 /// \brief Retrieve the explicit template argument list that followed the
2446 /// member template name, if any.
2447 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2448 assert(HasExplicitTemplateArgs);
2449 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2452 /// \brief Retrieve the explicit template argument list that followed the
2453 /// member template name, if any.
2454 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2455 return const_cast<CXXDependentScopeMemberExpr *>(this)
2456 ->getExplicitTemplateArgs();
2459 /// \brief Retrieves the optional explicit template arguments.
2460 /// This points to the same data as getExplicitTemplateArgs(), but
2461 /// returns null if there are no explicit template arguments.
2462 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2463 if (!hasExplicitTemplateArgs()) return 0;
2464 return &getExplicitTemplateArgs();
2467 /// \brief Copies the template arguments (if present) into the given
2469 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2470 getExplicitTemplateArgs().copyInto(List);
2473 /// \brief Initializes the template arguments using the given structure.
2474 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2475 getExplicitTemplateArgs().initializeFrom(List);
2478 /// \brief Retrieve the location of the left angle bracket following the
2479 /// member name ('<'), if any.
2480 SourceLocation getLAngleLoc() const {
2481 return getExplicitTemplateArgs().LAngleLoc;
2484 /// \brief Retrieve the template arguments provided as part of this
2486 const TemplateArgumentLoc *getTemplateArgs() const {
2487 return getExplicitTemplateArgs().getTemplateArgs();
2490 /// \brief Retrieve the number of template arguments provided as part of this
2492 unsigned getNumTemplateArgs() const {
2493 return getExplicitTemplateArgs().NumTemplateArgs;
2496 /// \brief Retrieve the location of the right angle bracket following the
2497 /// template arguments ('>').
2498 SourceLocation getRAngleLoc() const {
2499 return getExplicitTemplateArgs().RAngleLoc;
2502 SourceRange getSourceRange() const {
2504 if (!isImplicitAccess())
2505 Range.setBegin(Base->getSourceRange().getBegin());
2506 else if (getQualifier())
2507 Range.setBegin(getQualifierLoc().getBeginLoc());
2509 Range.setBegin(MemberNameInfo.getBeginLoc());
2511 if (hasExplicitTemplateArgs())
2512 Range.setEnd(getRAngleLoc());
2514 Range.setEnd(MemberNameInfo.getEndLoc());
2518 static bool classof(const Stmt *T) {
2519 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2521 static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2524 child_range children() {
2525 if (isImplicitAccess()) return child_range();
2526 return child_range(&Base, &Base + 1);
2529 friend class ASTStmtReader;
2530 friend class ASTStmtWriter;
2533 /// \brief Represents a C++ member access expression for which lookup
2534 /// produced a set of overloaded functions.
2536 /// The member access may be explicit or implicit:
2539 /// int explicitAccess() { return this->a + this->A::b; }
2540 /// int implicitAccess() { return a + A::b; }
2543 /// In the final AST, an explicit access always becomes a MemberExpr.
2544 /// An implicit access may become either a MemberExpr or a
2545 /// DeclRefExpr, depending on whether the member is static.
2546 class UnresolvedMemberExpr : public OverloadExpr {
2547 /// \brief Whether this member expression used the '->' operator or
2548 /// the '.' operator.
2551 /// \brief Whether the lookup results contain an unresolved using
2553 bool HasUnresolvedUsing : 1;
2555 /// \brief The expression for the base pointer or class reference,
2556 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
2557 /// member expression
2560 /// \brief The type of the base expression; never null.
2563 /// \brief The location of the '->' or '.' operator.
2564 SourceLocation OperatorLoc;
2566 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
2567 Expr *Base, QualType BaseType, bool IsArrow,
2568 SourceLocation OperatorLoc,
2569 NestedNameSpecifierLoc QualifierLoc,
2570 const DeclarationNameInfo &MemberNameInfo,
2571 const TemplateArgumentListInfo *TemplateArgs,
2572 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2574 UnresolvedMemberExpr(EmptyShell Empty)
2575 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2576 HasUnresolvedUsing(false), Base(0) { }
2578 friend class ASTStmtReader;
2581 static UnresolvedMemberExpr *
2582 Create(ASTContext &C, bool HasUnresolvedUsing,
2583 Expr *Base, QualType BaseType, bool IsArrow,
2584 SourceLocation OperatorLoc,
2585 NestedNameSpecifierLoc QualifierLoc,
2586 const DeclarationNameInfo &MemberNameInfo,
2587 const TemplateArgumentListInfo *TemplateArgs,
2588 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2590 static UnresolvedMemberExpr *
2591 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2592 unsigned NumTemplateArgs);
2594 /// \brief True if this is an implicit access, i.e. one in which the
2595 /// member being accessed was not written in the source. The source
2596 /// location of the operator is invalid in this case.
2597 bool isImplicitAccess() const;
2599 /// \brief Retrieve the base object of this member expressions,
2600 /// e.g., the \c x in \c x.m.
2602 assert(!isImplicitAccess());
2603 return cast<Expr>(Base);
2605 const Expr *getBase() const {
2606 assert(!isImplicitAccess());
2607 return cast<Expr>(Base);
2610 QualType getBaseType() const { return BaseType; }
2612 /// \brief Determine whether the lookup results contain an unresolved using
2614 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2616 /// \brief Determine whether this member expression used the '->'
2617 /// operator; otherwise, it used the '.' operator.
2618 bool isArrow() const { return IsArrow; }
2620 /// \brief Retrieve the location of the '->' or '.' operator.
2621 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2623 /// \brief Retrieves the naming class of this lookup.
2624 CXXRecordDecl *getNamingClass() const;
2626 /// \brief Retrieve the full name info for the member that this expression
2628 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
2630 /// \brief Retrieve the name of the member that this expression
2632 DeclarationName getMemberName() const { return getName(); }
2634 // \brief Retrieve the location of the name of the member that this
2635 // expression refers to.
2636 SourceLocation getMemberLoc() const { return getNameLoc(); }
2638 /// \brief Retrieve the explicit template argument list that followed the
2639 /// member template name.
2640 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2641 assert(hasExplicitTemplateArgs());
2642 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2645 /// \brief Retrieve the explicit template argument list that followed the
2646 /// member template name, if any.
2647 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2648 assert(hasExplicitTemplateArgs());
2649 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2652 /// \brief Retrieves the optional explicit template arguments.
2653 /// This points to the same data as getExplicitTemplateArgs(), but
2654 /// returns null if there are no explicit template arguments.
2655 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2656 if (!hasExplicitTemplateArgs()) return 0;
2657 return &getExplicitTemplateArgs();
2660 /// \brief Copies the template arguments into the given structure.
2661 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2662 getExplicitTemplateArgs().copyInto(List);
2665 /// \brief Retrieve the location of the left angle bracket following
2666 /// the member name ('<').
2667 SourceLocation getLAngleLoc() const {
2668 return getExplicitTemplateArgs().LAngleLoc;
2671 /// \brief Retrieve the template arguments provided as part of this
2673 const TemplateArgumentLoc *getTemplateArgs() const {
2674 return getExplicitTemplateArgs().getTemplateArgs();
2677 /// \brief Retrieve the number of template arguments provided as
2678 /// part of this template-id.
2679 unsigned getNumTemplateArgs() const {
2680 return getExplicitTemplateArgs().NumTemplateArgs;
2683 /// \brief Retrieve the location of the right angle bracket
2684 /// following the template arguments ('>').
2685 SourceLocation getRAngleLoc() const {
2686 return getExplicitTemplateArgs().RAngleLoc;
2689 SourceRange getSourceRange() const {
2690 SourceRange Range = getMemberNameInfo().getSourceRange();
2691 if (!isImplicitAccess())
2692 Range.setBegin(Base->getSourceRange().getBegin());
2693 else if (getQualifierLoc())
2694 Range.setBegin(getQualifierLoc().getBeginLoc());
2696 if (hasExplicitTemplateArgs())
2697 Range.setEnd(getRAngleLoc());
2701 static bool classof(const Stmt *T) {
2702 return T->getStmtClass() == UnresolvedMemberExprClass;
2704 static bool classof(const UnresolvedMemberExpr *) { return true; }
2707 child_range children() {
2708 if (isImplicitAccess()) return child_range();
2709 return child_range(&Base, &Base + 1);
2713 /// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
2715 /// The noexcept expression tests whether a given expression might throw. Its
2716 /// result is a boolean constant.
2717 class CXXNoexceptExpr : public Expr {
2722 friend class ASTStmtReader;
2725 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
2726 SourceLocation Keyword, SourceLocation RParen)
2727 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
2728 /*TypeDependent*/false,
2729 /*ValueDependent*/Val == CT_Dependent,
2730 Operand->containsUnexpandedParameterPack()),
2731 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
2734 CXXNoexceptExpr(EmptyShell Empty)
2735 : Expr(CXXNoexceptExprClass, Empty)
2738 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
2740 SourceRange getSourceRange() const { return Range; }
2742 bool getValue() const { return Value; }
2744 static bool classof(const Stmt *T) {
2745 return T->getStmtClass() == CXXNoexceptExprClass;
2747 static bool classof(const CXXNoexceptExpr *) { return true; }
2750 child_range children() { return child_range(&Operand, &Operand + 1); }
2753 /// \brief Represents a C++0x pack expansion that produces a sequence of
2756 /// A pack expansion expression contains a pattern (which itself is an
2757 /// expression) followed by an ellipsis. For example:
2760 /// template<typename F, typename ...Types>
2761 /// void forward(F f, Types &&...args) {
2762 /// f(static_cast<Types&&>(args)...);
2766 /// Here, the argument to the function object \c f is a pack expansion whose
2767 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
2768 /// template is instantiated, the pack expansion will instantiate to zero or
2769 /// or more function arguments to the function object \c f.
2770 class PackExpansionExpr : public Expr {
2771 SourceLocation EllipsisLoc;
2773 /// \brief The number of expansions that will be produced by this pack
2774 /// expansion expression, if known.
2776 /// When zero, the number of expansions is not known. Otherwise, this value
2777 /// is the number of expansions + 1.
2778 unsigned NumExpansions;
2782 friend class ASTStmtReader;
2783 friend class ASTStmtWriter;
2786 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
2787 llvm::Optional<unsigned> NumExpansions)
2788 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
2789 Pattern->getObjectKind(), /*TypeDependent=*/true,
2790 /*ValueDependent=*/true, /*ContainsUnexpandedParameterPack=*/false),
2791 EllipsisLoc(EllipsisLoc),
2792 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
2793 Pattern(Pattern) { }
2795 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
2797 /// \brief Retrieve the pattern of the pack expansion.
2798 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
2800 /// \brief Retrieve the pattern of the pack expansion.
2801 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
2803 /// \brief Retrieve the location of the ellipsis that describes this pack
2805 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2807 /// \brief Determine the number of expansions that will be produced when
2808 /// this pack expansion is instantiated, if already known.
2809 llvm::Optional<unsigned> getNumExpansions() const {
2811 return NumExpansions - 1;
2813 return llvm::Optional<unsigned>();
2816 SourceRange getSourceRange() const {
2817 return SourceRange(Pattern->getLocStart(), EllipsisLoc);
2820 static bool classof(const Stmt *T) {
2821 return T->getStmtClass() == PackExpansionExprClass;
2823 static bool classof(const PackExpansionExpr *) { return true; }
2826 child_range children() {
2827 return child_range(&Pattern, &Pattern + 1);
2831 inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2832 if (isa<UnresolvedLookupExpr>(this))
2833 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2835 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2838 /// \brief Represents an expression that computes the length of a parameter
2842 /// template<typename ...Types>
2844 /// static const unsigned value = sizeof...(Types);
2847 class SizeOfPackExpr : public Expr {
2848 /// \brief The location of the 'sizeof' keyword.
2849 SourceLocation OperatorLoc;
2851 /// \brief The location of the name of the parameter pack.
2852 SourceLocation PackLoc;
2854 /// \brief The location of the closing parenthesis.
2855 SourceLocation RParenLoc;
2857 /// \brief The length of the parameter pack, if known.
2859 /// When this expression is value-dependent, the length of the parameter pack
2860 /// is unknown. When this expression is not value-dependent, the length is
2864 /// \brief The parameter pack itself.
2867 friend class ASTStmtReader;
2868 friend class ASTStmtWriter;
2871 /// \brief Creates a value-dependent expression that computes the length of
2872 /// the given parameter pack.
2873 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2874 SourceLocation PackLoc, SourceLocation RParenLoc)
2875 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2876 /*TypeDependent=*/false, /*ValueDependent=*/true,
2877 /*ContainsUnexpandedParameterPack=*/false),
2878 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2879 Length(0), Pack(Pack) { }
2881 /// \brief Creates an expression that computes the length of
2882 /// the given parameter pack, which is already known.
2883 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2884 SourceLocation PackLoc, SourceLocation RParenLoc,
2886 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2887 /*TypeDependent=*/false, /*ValueDependent=*/false,
2888 /*ContainsUnexpandedParameterPack=*/false),
2889 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2890 Length(Length), Pack(Pack) { }
2892 /// \brief Create an empty expression.
2893 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
2895 /// \brief Determine the location of the 'sizeof' keyword.
2896 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2898 /// \brief Determine the location of the parameter pack.
2899 SourceLocation getPackLoc() const { return PackLoc; }
2901 /// \brief Determine the location of the right parenthesis.
2902 SourceLocation getRParenLoc() const { return RParenLoc; }
2904 /// \brief Retrieve the parameter pack.
2905 NamedDecl *getPack() const { return Pack; }
2907 /// \brief Retrieve the length of the parameter pack.
2909 /// This routine may only be invoked when the expression is not
2910 /// value-dependent.
2911 unsigned getPackLength() const {
2912 assert(!isValueDependent() &&
2913 "Cannot get the length of a value-dependent pack size expression");
2917 SourceRange getSourceRange() const {
2918 return SourceRange(OperatorLoc, RParenLoc);
2921 static bool classof(const Stmt *T) {
2922 return T->getStmtClass() == SizeOfPackExprClass;
2924 static bool classof(const SizeOfPackExpr *) { return true; }
2927 child_range children() { return child_range(); }
2930 /// \brief Represents a reference to a non-type template parameter pack that
2931 /// has been substituted with a non-template argument pack.
2933 /// When a pack expansion in the source code contains multiple parameter packs
2934 /// and those parameter packs correspond to different levels of template
2935 /// parameter lists, this node node is used to represent a non-type template
2936 /// parameter pack from an outer level, which has already had its argument pack
2937 /// substituted but that still lives within a pack expansion that itself
2938 /// could not be instantiated. When actually performing a substitution into
2939 /// that pack expansion (e.g., when all template parameters have corresponding
2940 /// arguments), this type will be replaced with the appropriate underlying
2941 /// expression at the current pack substitution index.
2942 class SubstNonTypeTemplateParmPackExpr : public Expr {
2943 /// \brief The non-type template parameter pack itself.
2944 NonTypeTemplateParmDecl *Param;
2946 /// \brief A pointer to the set of template arguments that this
2947 /// parameter pack is instantiated with.
2948 const TemplateArgument *Arguments;
2950 /// \brief The number of template arguments in \c Arguments.
2951 unsigned NumArguments;
2953 /// \brief The location of the non-type template parameter pack reference.
2954 SourceLocation NameLoc;
2956 friend class ASTStmtReader;
2957 friend class ASTStmtWriter;
2960 SubstNonTypeTemplateParmPackExpr(QualType T,
2961 NonTypeTemplateParmDecl *Param,
2962 SourceLocation NameLoc,
2963 const TemplateArgument &ArgPack);
2965 SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
2966 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
2968 /// \brief Retrieve the non-type template parameter pack being substituted.
2969 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
2971 /// \brief Retrieve the location of the parameter pack name.
2972 SourceLocation getParameterPackLocation() const { return NameLoc; }
2974 /// \brief Retrieve the template argument pack containing the substituted
2975 /// template arguments.
2976 TemplateArgument getArgumentPack() const;
2978 SourceRange getSourceRange() const { return NameLoc; }
2980 static bool classof(const Stmt *T) {
2981 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
2983 static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
2988 child_range children() { return child_range(); }
2991 } // end namespace clang