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()->isInstantiationDependentType(),
399 Operand->getType()->containsUnexpandedParameterPack()),
400 Operand(Operand), Range(R) { }
402 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
403 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
404 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
406 // typeid is value-dependent if the type or expression are dependent
407 Operand->isTypeDependent() || Operand->isValueDependent(),
408 Operand->isInstantiationDependent(),
409 Operand->containsUnexpandedParameterPack()),
410 Operand(Operand), Range(R) { }
412 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
413 : Expr(CXXTypeidExprClass, Empty) {
417 Operand = (TypeSourceInfo*)0;
420 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
422 /// \brief Retrieves the type operand of this typeid() expression after
423 /// various required adjustments (removing reference types, cv-qualifiers).
424 QualType getTypeOperand() const;
426 /// \brief Retrieve source information for the type operand.
427 TypeSourceInfo *getTypeOperandSourceInfo() const {
428 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
429 return Operand.get<TypeSourceInfo *>();
432 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
433 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
437 Expr *getExprOperand() const {
438 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
439 return static_cast<Expr*>(Operand.get<Stmt *>());
442 void setExprOperand(Expr *E) {
443 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
447 SourceRange getSourceRange() const { return Range; }
448 void setSourceRange(SourceRange R) { Range = R; }
450 static bool classof(const Stmt *T) {
451 return T->getStmtClass() == CXXTypeidExprClass;
453 static bool classof(const CXXTypeidExpr *) { return true; }
456 child_range children() {
457 if (isTypeOperand()) return child_range();
458 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
459 return child_range(begin, begin + 1);
463 /// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
464 /// the _GUID that corresponds to the supplied type or expression.
466 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
467 class CXXUuidofExpr : public Expr {
469 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
473 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
474 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
475 false, Operand->getType()->isDependentType(),
476 Operand->getType()->isInstantiationDependentType(),
477 Operand->getType()->containsUnexpandedParameterPack()),
478 Operand(Operand), Range(R) { }
480 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
481 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
482 false, Operand->isTypeDependent(),
483 Operand->isInstantiationDependent(),
484 Operand->containsUnexpandedParameterPack()),
485 Operand(Operand), Range(R) { }
487 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
488 : Expr(CXXUuidofExprClass, Empty) {
492 Operand = (TypeSourceInfo*)0;
495 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
497 /// \brief Retrieves the type operand of this __uuidof() expression after
498 /// various required adjustments (removing reference types, cv-qualifiers).
499 QualType getTypeOperand() const;
501 /// \brief Retrieve source information for the type operand.
502 TypeSourceInfo *getTypeOperandSourceInfo() const {
503 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
504 return Operand.get<TypeSourceInfo *>();
507 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
508 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
512 Expr *getExprOperand() const {
513 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
514 return static_cast<Expr*>(Operand.get<Stmt *>());
517 void setExprOperand(Expr *E) {
518 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
522 SourceRange getSourceRange() const { return Range; }
523 void setSourceRange(SourceRange R) { Range = R; }
525 static bool classof(const Stmt *T) {
526 return T->getStmtClass() == CXXUuidofExprClass;
528 static bool classof(const CXXUuidofExpr *) { return true; }
531 child_range children() {
532 if (isTypeOperand()) return child_range();
533 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
534 return child_range(begin, begin + 1);
538 /// CXXThisExpr - Represents the "this" expression in C++, which is a
539 /// pointer to the object on which the current member function is
540 /// executing (C++ [expr.prim]p3). Example:
546 /// void test() { this->bar(); }
549 class CXXThisExpr : public Expr {
554 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
555 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
556 // 'this' is type-dependent if the class type of the enclosing
557 // member function is dependent (C++ [temp.dep.expr]p2)
558 Type->isDependentType(), Type->isDependentType(),
559 Type->isInstantiationDependentType(),
560 /*ContainsUnexpandedParameterPack=*/false),
561 Loc(L), Implicit(isImplicit) { }
563 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
565 SourceLocation getLocation() const { return Loc; }
566 void setLocation(SourceLocation L) { Loc = L; }
568 SourceRange getSourceRange() const { return SourceRange(Loc); }
570 bool isImplicit() const { return Implicit; }
571 void setImplicit(bool I) { Implicit = I; }
573 static bool classof(const Stmt *T) {
574 return T->getStmtClass() == CXXThisExprClass;
576 static bool classof(const CXXThisExpr *) { return true; }
579 child_range children() { return child_range(); }
582 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
583 /// 'throw' and 'throw' assignment-expression. When
584 /// assignment-expression isn't present, Op will be null.
586 class CXXThrowExpr : public Expr {
588 SourceLocation ThrowLoc;
589 /// \brief Whether the thrown variable (if any) is in scope.
590 unsigned IsThrownVariableInScope : 1;
592 friend class ASTStmtReader;
595 // Ty is the void type which is used as the result type of the
596 // exepression. The l is the location of the throw keyword. expr
597 // can by null, if the optional expression to throw isn't present.
598 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
599 bool IsThrownVariableInScope) :
600 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
601 expr && expr->isInstantiationDependent(),
602 expr && expr->containsUnexpandedParameterPack()),
603 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
604 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
606 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
607 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
609 SourceLocation getThrowLoc() const { return ThrowLoc; }
611 /// \brief Determines whether the variable thrown by this expression (if any!)
612 /// is within the innermost try block.
614 /// This information is required to determine whether the NRVO can apply to
616 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
618 SourceRange getSourceRange() const {
619 if (getSubExpr() == 0)
620 return SourceRange(ThrowLoc, ThrowLoc);
621 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
624 static bool classof(const Stmt *T) {
625 return T->getStmtClass() == CXXThrowExprClass;
627 static bool classof(const CXXThrowExpr *) { return true; }
630 child_range children() {
631 return child_range(&Op, Op ? &Op+1 : &Op);
635 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
636 /// function call argument that was created from the corresponding
637 /// parameter's default argument, when the call did not explicitly
638 /// supply arguments for all of the parameters.
639 class CXXDefaultArgExpr : public Expr {
640 /// \brief The parameter whose default is being used.
642 /// When the bit is set, the subexpression is stored after the
643 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
644 /// actual default expression is the subexpression.
645 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
647 /// \brief The location where the default argument expression was used.
650 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
652 param->hasUnparsedDefaultArg()
653 ? param->getType().getNonReferenceType()
654 : param->getDefaultArg()->getType(),
655 param->getDefaultArg()->getValueKind(),
656 param->getDefaultArg()->getObjectKind(), false, false, false, false),
657 Param(param, false), Loc(Loc) { }
659 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
661 : Expr(SC, SubExpr->getType(),
662 SubExpr->getValueKind(), SubExpr->getObjectKind(),
663 false, false, false, false),
664 Param(param, true), Loc(Loc) {
665 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
669 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
672 // Param is the parameter whose default argument is used by this
674 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
675 ParmVarDecl *Param) {
676 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
679 // Param is the parameter whose default argument is used by this
680 // expression, and SubExpr is the expression that will actually be used.
681 static CXXDefaultArgExpr *Create(ASTContext &C,
686 // Retrieve the parameter that the argument was created from.
687 const ParmVarDecl *getParam() const { return Param.getPointer(); }
688 ParmVarDecl *getParam() { return Param.getPointer(); }
690 // Retrieve the actual argument to the function call.
691 const Expr *getExpr() const {
693 return *reinterpret_cast<Expr const * const*> (this + 1);
694 return getParam()->getDefaultArg();
698 return *reinterpret_cast<Expr **> (this + 1);
699 return getParam()->getDefaultArg();
702 /// \brief Retrieve the location where this default argument was actually
704 SourceLocation getUsedLocation() const { return Loc; }
706 SourceRange getSourceRange() const {
707 // Default argument expressions have no representation in the
708 // source, so they have an empty source range.
709 return SourceRange();
712 static bool classof(const Stmt *T) {
713 return T->getStmtClass() == CXXDefaultArgExprClass;
715 static bool classof(const CXXDefaultArgExpr *) { return true; }
718 child_range children() { return child_range(); }
720 friend class ASTStmtReader;
721 friend class ASTStmtWriter;
724 /// CXXTemporary - Represents a C++ temporary.
726 /// Destructor - The destructor that needs to be called.
727 const CXXDestructorDecl *Destructor;
729 CXXTemporary(const CXXDestructorDecl *destructor)
730 : Destructor(destructor) { }
733 static CXXTemporary *Create(ASTContext &C,
734 const CXXDestructorDecl *Destructor);
736 const CXXDestructorDecl *getDestructor() const { return Destructor; }
739 /// \brief Represents binding an expression to a temporary.
741 /// This ensures the destructor is called for the temporary. It should only be
742 /// needed for non-POD, non-trivially destructable class types. For example:
746 /// S() { } // User defined constructor makes S non-POD.
747 /// ~S() { } // User defined destructor makes it non-trivial.
750 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
753 class CXXBindTemporaryExpr : public Expr {
758 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
759 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
760 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
761 SubExpr->isValueDependent(),
762 SubExpr->isInstantiationDependent(),
763 SubExpr->containsUnexpandedParameterPack()),
764 Temp(temp), SubExpr(SubExpr) { }
767 CXXBindTemporaryExpr(EmptyShell Empty)
768 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
770 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
773 CXXTemporary *getTemporary() { return Temp; }
774 const CXXTemporary *getTemporary() const { return Temp; }
775 void setTemporary(CXXTemporary *T) { Temp = T; }
777 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
778 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
779 void setSubExpr(Expr *E) { SubExpr = E; }
781 SourceRange getSourceRange() const {
782 return SubExpr->getSourceRange();
785 // Implement isa/cast/dyncast/etc.
786 static bool classof(const Stmt *T) {
787 return T->getStmtClass() == CXXBindTemporaryExprClass;
789 static bool classof(const CXXBindTemporaryExpr *) { return true; }
792 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
795 /// CXXConstructExpr - Represents a call to a C++ constructor.
796 class CXXConstructExpr : public Expr {
798 enum ConstructionKind {
806 CXXConstructorDecl *Constructor;
809 SourceRange ParenRange;
810 unsigned NumArgs : 16;
812 bool HadMultipleCandidates : 1;
813 bool ZeroInitialization : 1;
814 unsigned ConstructKind : 2;
818 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
820 CXXConstructorDecl *d, bool elidable,
821 Expr **args, unsigned numargs,
822 bool HadMultipleCandidates,
823 bool ZeroInitialization = false,
824 ConstructionKind ConstructKind = CK_Complete,
825 SourceRange ParenRange = SourceRange());
827 /// \brief Construct an empty C++ construction expression.
828 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
829 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(0),
830 HadMultipleCandidates(false), ZeroInitialization(0),
831 ConstructKind(0), Args(0) { }
834 /// \brief Construct an empty C++ construction expression.
835 explicit CXXConstructExpr(EmptyShell Empty)
836 : Expr(CXXConstructExprClass, Empty), Constructor(0),
837 NumArgs(0), Elidable(0), HadMultipleCandidates(false),
838 ZeroInitialization(0), ConstructKind(0), Args(0) { }
840 static CXXConstructExpr *Create(ASTContext &C, QualType T,
842 CXXConstructorDecl *D, bool Elidable,
843 Expr **Args, unsigned NumArgs,
844 bool HadMultipleCandidates,
845 bool ZeroInitialization = false,
846 ConstructionKind ConstructKind = CK_Complete,
847 SourceRange ParenRange = SourceRange());
850 CXXConstructorDecl* getConstructor() const { return Constructor; }
851 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
853 SourceLocation getLocation() const { return Loc; }
854 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
856 /// \brief Whether this construction is elidable.
857 bool isElidable() const { return Elidable; }
858 void setElidable(bool E) { Elidable = E; }
860 /// \brief Whether the referred constructor was resolved from
861 /// an overloaded set having size greater than 1.
862 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
863 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
865 /// \brief Whether this construction first requires
866 /// zero-initialization before the initializer is called.
867 bool requiresZeroInitialization() const { return ZeroInitialization; }
868 void setRequiresZeroInitialization(bool ZeroInit) {
869 ZeroInitialization = ZeroInit;
872 /// \brief Determines whether this constructor is actually constructing
873 /// a base class (rather than a complete object).
874 ConstructionKind getConstructionKind() const {
875 return (ConstructionKind)ConstructKind;
877 void setConstructionKind(ConstructionKind CK) {
881 typedef ExprIterator arg_iterator;
882 typedef ConstExprIterator const_arg_iterator;
884 arg_iterator arg_begin() { return Args; }
885 arg_iterator arg_end() { return Args + NumArgs; }
886 const_arg_iterator arg_begin() const { return Args; }
887 const_arg_iterator arg_end() const { return Args + NumArgs; }
889 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
890 unsigned getNumArgs() const { return NumArgs; }
892 /// getArg - Return the specified argument.
893 Expr *getArg(unsigned Arg) {
894 assert(Arg < NumArgs && "Arg access out of range!");
895 return cast<Expr>(Args[Arg]);
897 const Expr *getArg(unsigned Arg) const {
898 assert(Arg < NumArgs && "Arg access out of range!");
899 return cast<Expr>(Args[Arg]);
902 /// setArg - Set the specified argument.
903 void setArg(unsigned Arg, Expr *ArgExpr) {
904 assert(Arg < NumArgs && "Arg access out of range!");
908 SourceRange getSourceRange() const;
909 SourceRange getParenRange() const { return ParenRange; }
911 static bool classof(const Stmt *T) {
912 return T->getStmtClass() == CXXConstructExprClass ||
913 T->getStmtClass() == CXXTemporaryObjectExprClass;
915 static bool classof(const CXXConstructExpr *) { return true; }
918 child_range children() {
919 return child_range(&Args[0], &Args[0]+NumArgs);
922 friend class ASTStmtReader;
925 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
926 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
928 class CXXFunctionalCastExpr : public ExplicitCastExpr {
929 SourceLocation TyBeginLoc;
930 SourceLocation RParenLoc;
932 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
933 TypeSourceInfo *writtenTy,
934 SourceLocation tyBeginLoc, CastKind kind,
935 Expr *castExpr, unsigned pathSize,
936 SourceLocation rParenLoc)
937 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
938 castExpr, pathSize, writtenTy),
939 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
941 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
942 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
945 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
947 TypeSourceInfo *Written,
948 SourceLocation TyBeginLoc,
949 CastKind Kind, Expr *Op,
950 const CXXCastPath *Path,
951 SourceLocation RPLoc);
952 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
955 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
956 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
957 SourceLocation getRParenLoc() const { return RParenLoc; }
958 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
960 SourceRange getSourceRange() const {
961 return SourceRange(TyBeginLoc, RParenLoc);
963 static bool classof(const Stmt *T) {
964 return T->getStmtClass() == CXXFunctionalCastExprClass;
966 static bool classof(const CXXFunctionalCastExpr *) { return true; }
969 /// @brief Represents a C++ functional cast expression that builds a
970 /// temporary object.
972 /// This expression type represents a C++ "functional" cast
973 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
974 /// constructor to build a temporary object. With N == 1 arguments the
975 /// functional cast expression will be represented by CXXFunctionalCastExpr.
978 /// struct X { X(int, float); }
981 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
984 class CXXTemporaryObjectExpr : public CXXConstructExpr {
985 TypeSourceInfo *Type;
988 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
989 TypeSourceInfo *Type,
990 Expr **Args,unsigned NumArgs,
991 SourceRange parenRange,
992 bool HadMultipleCandidates,
993 bool ZeroInitialization = false);
994 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
995 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
997 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
999 SourceRange getSourceRange() const;
1001 static bool classof(const Stmt *T) {
1002 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1004 static bool classof(const CXXTemporaryObjectExpr *) { return true; }
1006 friend class ASTStmtReader;
1009 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1010 /// Expression "T()" which creates a value-initialized rvalue of type
1011 /// T, which is a non-class type.
1013 class CXXScalarValueInitExpr : public Expr {
1014 SourceLocation RParenLoc;
1015 TypeSourceInfo *TypeInfo;
1017 friend class ASTStmtReader;
1020 /// \brief Create an explicitly-written scalar-value initialization
1022 CXXScalarValueInitExpr(QualType Type,
1023 TypeSourceInfo *TypeInfo,
1024 SourceLocation rParenLoc ) :
1025 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1026 false, false, Type->isInstantiationDependentType(), false),
1027 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1029 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1030 : Expr(CXXScalarValueInitExprClass, Shell) { }
1032 TypeSourceInfo *getTypeSourceInfo() const {
1036 SourceLocation getRParenLoc() const { return RParenLoc; }
1038 SourceRange getSourceRange() const;
1040 static bool classof(const Stmt *T) {
1041 return T->getStmtClass() == CXXScalarValueInitExprClass;
1043 static bool classof(const CXXScalarValueInitExpr *) { return true; }
1046 child_range children() { return child_range(); }
1049 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
1050 /// e.g: "new CXXNewExpr(foo)".
1051 class CXXNewExpr : public Expr {
1052 // Was the usage ::new, i.e. is the global new to be used?
1054 // Is there an initializer? If not, built-ins are uninitialized, else they're
1055 // value-initialized.
1056 bool Initializer : 1;
1057 // Do we allocate an array? If so, the first SubExpr is the size expression.
1059 // If this is an array allocation, does the usual deallocation
1060 // function for the allocated type want to know the allocated size?
1061 bool UsualArrayDeleteWantsSize : 1;
1062 // Whether the referred constructor (if any) was resolved from an
1063 // overload set having size greater than 1.
1064 bool HadMultipleCandidates : 1;
1065 // The number of placement new arguments.
1066 unsigned NumPlacementArgs : 13;
1067 // The number of constructor arguments. This may be 1 even for non-class
1068 // types; use the pseudo copy constructor.
1069 unsigned NumConstructorArgs : 14;
1070 // Contains an optional array size expression, any number of optional
1071 // placement arguments, and any number of optional constructor arguments,
1074 // Points to the allocation function used.
1075 FunctionDecl *OperatorNew;
1076 // Points to the deallocation function used in case of error. May be null.
1077 FunctionDecl *OperatorDelete;
1078 // Points to the constructor used. Cannot be null if AllocType is a record;
1079 // it would still point at the default constructor (even an implicit one).
1080 // Must be null for all other types.
1081 CXXConstructorDecl *Constructor;
1083 /// \brief The allocated type-source information, as written in the source.
1084 TypeSourceInfo *AllocatedTypeInfo;
1086 /// \brief If the allocated type was expressed as a parenthesized type-id,
1087 /// the source range covering the parenthesized type-id.
1088 SourceRange TypeIdParens;
1090 SourceLocation StartLoc;
1091 SourceLocation EndLoc;
1092 SourceLocation ConstructorLParen;
1093 SourceLocation ConstructorRParen;
1095 friend class ASTStmtReader;
1097 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1098 Expr **placementArgs, unsigned numPlaceArgs,
1099 SourceRange TypeIdParens,
1100 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
1101 Expr **constructorArgs, unsigned numConsArgs,
1102 bool HadMultipleCandidates,
1103 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1104 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1105 SourceLocation startLoc, SourceLocation endLoc,
1106 SourceLocation constructorLParen,
1107 SourceLocation constructorRParen);
1108 explicit CXXNewExpr(EmptyShell Shell)
1109 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1111 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1112 unsigned numConsArgs);
1114 QualType getAllocatedType() const {
1115 assert(getType()->isPointerType());
1116 return getType()->getAs<PointerType>()->getPointeeType();
1119 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1120 return AllocatedTypeInfo;
1123 /// \brief True if the allocation result needs to be null-checked.
1124 /// C++0x [expr.new]p13:
1125 /// If the allocation function returns null, initialization shall
1126 /// not be done, the deallocation function shall not be called,
1127 /// and the value of the new-expression shall be null.
1128 /// An allocation function is not allowed to return null unless it
1129 /// has a non-throwing exception-specification. The '03 rule is
1130 /// identical except that the definition of a non-throwing
1131 /// exception specification is just "is it throw()?".
1132 bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1134 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1135 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1136 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1137 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1138 CXXConstructorDecl *getConstructor() const { return Constructor; }
1139 void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
1141 bool isArray() const { return Array; }
1142 Expr *getArraySize() {
1143 return Array ? cast<Expr>(SubExprs[0]) : 0;
1145 const Expr *getArraySize() const {
1146 return Array ? cast<Expr>(SubExprs[0]) : 0;
1149 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1150 Expr **getPlacementArgs() {
1151 return reinterpret_cast<Expr **>(SubExprs + Array);
1154 Expr *getPlacementArg(unsigned i) {
1155 assert(i < NumPlacementArgs && "Index out of range");
1156 return cast<Expr>(SubExprs[Array + i]);
1158 const Expr *getPlacementArg(unsigned i) const {
1159 assert(i < NumPlacementArgs && "Index out of range");
1160 return cast<Expr>(SubExprs[Array + i]);
1163 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1164 SourceRange getTypeIdParens() const { return TypeIdParens; }
1166 bool isGlobalNew() const { return GlobalNew; }
1167 bool hasInitializer() const { return Initializer; }
1169 /// Answers whether the usual array deallocation function for the
1170 /// allocated type expects the size of the allocation as a
1172 bool doesUsualArrayDeleteWantSize() const {
1173 return UsualArrayDeleteWantsSize;
1176 unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1178 Expr **getConstructorArgs() {
1179 return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs);
1182 Expr *getConstructorArg(unsigned i) {
1183 assert(i < NumConstructorArgs && "Index out of range");
1184 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1186 const Expr *getConstructorArg(unsigned i) const {
1187 assert(i < NumConstructorArgs && "Index out of range");
1188 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1191 /// \brief Whether the new expression refers a constructor that was
1192 /// resolved from an overloaded set having size greater than 1.
1193 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
1194 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1196 typedef ExprIterator arg_iterator;
1197 typedef ConstExprIterator const_arg_iterator;
1199 arg_iterator placement_arg_begin() {
1200 return SubExprs + Array;
1202 arg_iterator placement_arg_end() {
1203 return SubExprs + Array + getNumPlacementArgs();
1205 const_arg_iterator placement_arg_begin() const {
1206 return SubExprs + Array;
1208 const_arg_iterator placement_arg_end() const {
1209 return SubExprs + Array + getNumPlacementArgs();
1212 arg_iterator constructor_arg_begin() {
1213 return SubExprs + Array + getNumPlacementArgs();
1215 arg_iterator constructor_arg_end() {
1216 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1218 const_arg_iterator constructor_arg_begin() const {
1219 return SubExprs + Array + getNumPlacementArgs();
1221 const_arg_iterator constructor_arg_end() const {
1222 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1225 typedef Stmt **raw_arg_iterator;
1226 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1227 raw_arg_iterator raw_arg_end() {
1228 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1230 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1231 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
1233 SourceLocation getStartLoc() const { return StartLoc; }
1234 SourceLocation getEndLoc() const { return EndLoc; }
1236 SourceLocation getConstructorLParen() const { return ConstructorLParen; }
1237 SourceLocation getConstructorRParen() const { return ConstructorRParen; }
1239 SourceRange getSourceRange() const {
1240 return SourceRange(StartLoc, EndLoc);
1243 static bool classof(const Stmt *T) {
1244 return T->getStmtClass() == CXXNewExprClass;
1246 static bool classof(const CXXNewExpr *) { return true; }
1249 child_range children() {
1250 return child_range(&SubExprs[0],
1251 &SubExprs[0] + Array + getNumPlacementArgs()
1252 + getNumConstructorArgs());
1256 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1257 /// calls, e.g. "delete[] pArray".
1258 class CXXDeleteExpr : public Expr {
1259 // Is this a forced global delete, i.e. "::delete"?
1260 bool GlobalDelete : 1;
1261 // Is this the array form of delete, i.e. "delete[]"?
1263 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1264 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1266 bool ArrayFormAsWritten : 1;
1267 // Does the usual deallocation function for the element type require
1268 // a size_t argument?
1269 bool UsualArrayDeleteWantsSize : 1;
1270 // Points to the operator delete overload that is used. Could be a member.
1271 FunctionDecl *OperatorDelete;
1272 // The pointer expression to be deleted.
1274 // Location of the expression.
1277 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1278 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1279 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1280 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1281 arg->isInstantiationDependent(),
1282 arg->containsUnexpandedParameterPack()),
1283 GlobalDelete(globalDelete),
1284 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1285 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
1286 OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
1287 explicit CXXDeleteExpr(EmptyShell Shell)
1288 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1290 bool isGlobalDelete() const { return GlobalDelete; }
1291 bool isArrayForm() const { return ArrayForm; }
1292 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1294 /// Answers whether the usual array deallocation function for the
1295 /// allocated type expects the size of the allocation as a
1296 /// parameter. This can be true even if the actual deallocation
1297 /// function that we're using doesn't want a size.
1298 bool doesUsualArrayDeleteWantSize() const {
1299 return UsualArrayDeleteWantsSize;
1302 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1304 Expr *getArgument() { return cast<Expr>(Argument); }
1305 const Expr *getArgument() const { return cast<Expr>(Argument); }
1307 /// \brief Retrieve the type being destroyed. If the type being
1308 /// destroyed is a dependent type which may or may not be a pointer,
1309 /// return an invalid type.
1310 QualType getDestroyedType() const;
1312 SourceRange getSourceRange() const {
1313 return SourceRange(Loc, Argument->getLocEnd());
1316 static bool classof(const Stmt *T) {
1317 return T->getStmtClass() == CXXDeleteExprClass;
1319 static bool classof(const CXXDeleteExpr *) { return true; }
1322 child_range children() { return child_range(&Argument, &Argument+1); }
1324 friend class ASTStmtReader;
1327 /// \brief Structure used to store the type being destroyed by a
1328 /// pseudo-destructor expression.
1329 class PseudoDestructorTypeStorage {
1330 /// \brief Either the type source information or the name of the type, if
1331 /// it couldn't be resolved due to type-dependence.
1332 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1334 /// \brief The starting source location of the pseudo-destructor type.
1335 SourceLocation Location;
1338 PseudoDestructorTypeStorage() { }
1340 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1341 : Type(II), Location(Loc) { }
1343 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1345 TypeSourceInfo *getTypeSourceInfo() const {
1346 return Type.dyn_cast<TypeSourceInfo *>();
1349 IdentifierInfo *getIdentifier() const {
1350 return Type.dyn_cast<IdentifierInfo *>();
1353 SourceLocation getLocation() const { return Location; }
1356 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1358 /// A pseudo-destructor is an expression that looks like a member access to a
1359 /// destructor of a scalar type, except that scalar types don't have
1360 /// destructors. For example:
1364 /// void f(int *p) {
1369 /// Pseudo-destructors typically occur when instantiating templates such as:
1372 /// template<typename T>
1373 /// void destroy(T* ptr) {
1378 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1379 /// beyond evaluating the base expression.
1380 class CXXPseudoDestructorExpr : public Expr {
1381 /// \brief The base expression (that is being destroyed).
1384 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1388 /// \brief The location of the '.' or '->' operator.
1389 SourceLocation OperatorLoc;
1391 /// \brief The nested-name-specifier that follows the operator, if present.
1392 NestedNameSpecifierLoc QualifierLoc;
1394 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1396 TypeSourceInfo *ScopeType;
1398 /// \brief The location of the '::' in a qualified pseudo-destructor
1400 SourceLocation ColonColonLoc;
1402 /// \brief The location of the '~'.
1403 SourceLocation TildeLoc;
1405 /// \brief The type being destroyed, or its name if we were unable to
1406 /// resolve the name.
1407 PseudoDestructorTypeStorage DestroyedType;
1409 friend class ASTStmtReader;
1412 CXXPseudoDestructorExpr(ASTContext &Context,
1413 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1414 NestedNameSpecifierLoc QualifierLoc,
1415 TypeSourceInfo *ScopeType,
1416 SourceLocation ColonColonLoc,
1417 SourceLocation TildeLoc,
1418 PseudoDestructorTypeStorage DestroyedType);
1420 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1421 : Expr(CXXPseudoDestructorExprClass, Shell),
1422 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1424 Expr *getBase() const { return cast<Expr>(Base); }
1426 /// \brief Determines whether this member expression actually had
1427 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1429 bool hasQualifier() const { return QualifierLoc; }
1431 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1432 /// with source-location information.
1433 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1435 /// \brief If the member name was qualified, retrieves the
1436 /// nested-name-specifier that precedes the member name. Otherwise, returns
1438 NestedNameSpecifier *getQualifier() const {
1439 return QualifierLoc.getNestedNameSpecifier();
1442 /// \brief Determine whether this pseudo-destructor expression was written
1443 /// using an '->' (otherwise, it used a '.').
1444 bool isArrow() const { return IsArrow; }
1446 /// \brief Retrieve the location of the '.' or '->' operator.
1447 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1449 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1452 /// Pseudo-destructor expressions can have extra qualification within them
1453 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1454 /// Here, if the object type of the expression is (or may be) a scalar type,
1455 /// \p T may also be a scalar type and, therefore, cannot be part of a
1456 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1457 /// destructor expression.
1458 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1460 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1462 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1464 /// \brief Retrieve the location of the '~'.
1465 SourceLocation getTildeLoc() const { return TildeLoc; }
1467 /// \brief Retrieve the source location information for the type
1468 /// being destroyed.
1470 /// This type-source information is available for non-dependent
1471 /// pseudo-destructor expressions and some dependent pseudo-destructor
1472 /// expressions. Returns NULL if we only have the identifier for a
1473 /// dependent pseudo-destructor expression.
1474 TypeSourceInfo *getDestroyedTypeInfo() const {
1475 return DestroyedType.getTypeSourceInfo();
1478 /// \brief In a dependent pseudo-destructor expression for which we do not
1479 /// have full type information on the destroyed type, provides the name
1480 /// of the destroyed type.
1481 IdentifierInfo *getDestroyedTypeIdentifier() const {
1482 return DestroyedType.getIdentifier();
1485 /// \brief Retrieve the type being destroyed.
1486 QualType getDestroyedType() const;
1488 /// \brief Retrieve the starting location of the type being destroyed.
1489 SourceLocation getDestroyedTypeLoc() const {
1490 return DestroyedType.getLocation();
1493 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1495 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1496 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1499 /// \brief Set the destroyed type.
1500 void setDestroyedType(TypeSourceInfo *Info) {
1501 DestroyedType = PseudoDestructorTypeStorage(Info);
1504 SourceRange getSourceRange() const;
1506 static bool classof(const Stmt *T) {
1507 return T->getStmtClass() == CXXPseudoDestructorExprClass;
1509 static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1512 child_range children() { return child_range(&Base, &Base + 1); }
1515 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1516 /// implementation of TR1/C++0x type trait templates.
1518 /// __is_pod(int) == true
1519 /// __is_enum(std::string) == false
1520 class UnaryTypeTraitExpr : public Expr {
1521 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
1523 /// The value of the type trait. Unspecified if dependent.
1526 /// Loc - The location of the type trait keyword.
1529 /// RParen - The location of the closing paren.
1530 SourceLocation RParen;
1532 /// The type being queried.
1533 TypeSourceInfo *QueriedType;
1536 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1537 TypeSourceInfo *queried, bool value,
1538 SourceLocation rparen, QualType ty)
1539 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1540 false, queried->getType()->isDependentType(),
1541 queried->getType()->isInstantiationDependentType(),
1542 queried->getType()->containsUnexpandedParameterPack()),
1543 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
1545 explicit UnaryTypeTraitExpr(EmptyShell Empty)
1546 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
1549 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1551 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
1553 QualType getQueriedType() const { return QueriedType->getType(); }
1555 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1557 bool getValue() const { return Value; }
1559 static bool classof(const Stmt *T) {
1560 return T->getStmtClass() == UnaryTypeTraitExprClass;
1562 static bool classof(const UnaryTypeTraitExpr *) { return true; }
1565 child_range children() { return child_range(); }
1567 friend class ASTStmtReader;
1570 /// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
1571 /// implementation of TR1/C++0x type trait templates.
1573 /// __is_base_of(Base, Derived) == true
1574 class BinaryTypeTraitExpr : public Expr {
1575 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
1578 /// The value of the type trait. Unspecified if dependent.
1581 /// Loc - The location of the type trait keyword.
1584 /// RParen - The location of the closing paren.
1585 SourceLocation RParen;
1587 /// The lhs type being queried.
1588 TypeSourceInfo *LhsType;
1590 /// The rhs type being queried.
1591 TypeSourceInfo *RhsType;
1594 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1595 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
1596 bool value, SourceLocation rparen, QualType ty)
1597 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
1598 lhsType->getType()->isDependentType() ||
1599 rhsType->getType()->isDependentType(),
1600 (lhsType->getType()->isInstantiationDependentType() ||
1601 rhsType->getType()->isInstantiationDependentType()),
1602 (lhsType->getType()->containsUnexpandedParameterPack() ||
1603 rhsType->getType()->containsUnexpandedParameterPack())),
1604 BTT(btt), Value(value), Loc(loc), RParen(rparen),
1605 LhsType(lhsType), RhsType(rhsType) { }
1608 explicit BinaryTypeTraitExpr(EmptyShell Empty)
1609 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1610 LhsType(), RhsType() { }
1612 SourceRange getSourceRange() const {
1613 return SourceRange(Loc, RParen);
1616 BinaryTypeTrait getTrait() const {
1617 return static_cast<BinaryTypeTrait>(BTT);
1620 QualType getLhsType() const { return LhsType->getType(); }
1621 QualType getRhsType() const { return RhsType->getType(); }
1623 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
1624 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
1626 bool getValue() const { assert(!isTypeDependent()); return Value; }
1628 static bool classof(const Stmt *T) {
1629 return T->getStmtClass() == BinaryTypeTraitExprClass;
1631 static bool classof(const BinaryTypeTraitExpr *) { return true; }
1634 child_range children() { return child_range(); }
1636 friend class ASTStmtReader;
1639 /// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the
1640 /// implementation of __array_rank and __array_extent.
1642 /// __array_rank(int[10][20]) == 2
1643 /// __array_extent(int, 1) == 20
1644 class ArrayTypeTraitExpr : public Expr {
1645 /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
1648 /// The value of the type trait. Unspecified if dependent.
1651 /// The array dimension being queried, or -1 if not used
1654 /// Loc - The location of the type trait keyword.
1657 /// RParen - The location of the closing paren.
1658 SourceLocation RParen;
1660 /// The type being queried.
1661 TypeSourceInfo *QueriedType;
1664 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
1665 TypeSourceInfo *queried, uint64_t value,
1666 Expr *dimension, SourceLocation rparen, QualType ty)
1667 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1668 false, queried->getType()->isDependentType(),
1669 (queried->getType()->isInstantiationDependentType() ||
1670 (dimension && dimension->isInstantiationDependent())),
1671 queried->getType()->containsUnexpandedParameterPack()),
1672 ATT(att), Value(value), Dimension(dimension),
1673 Loc(loc), RParen(rparen), QueriedType(queried) { }
1676 explicit ArrayTypeTraitExpr(EmptyShell Empty)
1677 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
1680 virtual ~ArrayTypeTraitExpr() { }
1682 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen); }
1684 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
1686 QualType getQueriedType() const { return QueriedType->getType(); }
1688 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1690 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
1692 Expr *getDimensionExpression() const { return Dimension; }
1694 static bool classof(const Stmt *T) {
1695 return T->getStmtClass() == ArrayTypeTraitExprClass;
1697 static bool classof(const ArrayTypeTraitExpr *) { return true; }
1700 child_range children() { return child_range(); }
1702 friend class ASTStmtReader;
1705 /// ExpressionTraitExpr - An expression trait intrinsic
1707 /// __is_lvalue_expr(std::cout) == true
1708 /// __is_lvalue_expr(1) == false
1709 class ExpressionTraitExpr : public Expr {
1710 /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned.
1712 /// The value of the type trait. Unspecified if dependent.
1715 /// Loc - The location of the type trait keyword.
1718 /// RParen - The location of the closing paren.
1719 SourceLocation RParen;
1721 Expr* QueriedExpression;
1723 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
1724 Expr *queried, bool value,
1725 SourceLocation rparen, QualType resultType)
1726 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1727 false, // Not type-dependent
1728 // Value-dependent if the argument is type-dependent.
1729 queried->isTypeDependent(),
1730 queried->isInstantiationDependent(),
1731 queried->containsUnexpandedParameterPack()),
1732 ET(et), Value(value), Loc(loc), RParen(rparen), QueriedExpression(queried) { }
1734 explicit ExpressionTraitExpr(EmptyShell Empty)
1735 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
1736 QueriedExpression() { }
1738 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1740 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
1742 Expr *getQueriedExpression() const { return QueriedExpression; }
1744 bool getValue() const { return Value; }
1746 static bool classof(const Stmt *T) {
1747 return T->getStmtClass() == ExpressionTraitExprClass;
1749 static bool classof(const ExpressionTraitExpr *) { return true; }
1752 child_range children() { return child_range(); }
1754 friend class ASTStmtReader;
1758 /// \brief A reference to an overloaded function set, either an
1759 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1760 class OverloadExpr : public Expr {
1761 /// The results. These are undesugared, which is to say, they may
1762 /// include UsingShadowDecls. Access is relative to the naming
1764 // FIXME: Allocate this data after the OverloadExpr subclass.
1765 DeclAccessPair *Results;
1766 unsigned NumResults;
1768 /// The common name of these declarations.
1769 DeclarationNameInfo NameInfo;
1771 /// \brief The nested-name-specifier that qualifies the name, if any.
1772 NestedNameSpecifierLoc QualifierLoc;
1775 /// True if the name was a template-id.
1776 bool HasExplicitTemplateArgs;
1778 OverloadExpr(StmtClass K, ASTContext &C,
1779 NestedNameSpecifierLoc QualifierLoc,
1780 const DeclarationNameInfo &NameInfo,
1781 const TemplateArgumentListInfo *TemplateArgs,
1782 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1783 bool KnownDependent,
1784 bool KnownInstantiationDependent,
1785 bool KnownContainsUnexpandedParameterPack);
1787 OverloadExpr(StmtClass K, EmptyShell Empty)
1788 : Expr(K, Empty), Results(0), NumResults(0),
1789 QualifierLoc(), HasExplicitTemplateArgs(false) { }
1791 void initializeResults(ASTContext &C,
1792 UnresolvedSetIterator Begin,
1793 UnresolvedSetIterator End);
1797 OverloadExpr *Expression;
1798 bool IsAddressOfOperand;
1799 bool HasFormOfMemberPointer;
1802 /// Finds the overloaded expression in the given expression of
1805 /// \return the expression (which must be there) and true if it has
1806 /// the particular form of a member pointer expression
1807 static FindResult find(Expr *E) {
1808 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1812 E = E->IgnoreParens();
1813 if (isa<UnaryOperator>(E)) {
1814 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
1815 E = cast<UnaryOperator>(E)->getSubExpr();
1816 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
1818 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
1819 Result.IsAddressOfOperand = true;
1820 Result.Expression = Ovl;
1822 Result.HasFormOfMemberPointer = false;
1823 Result.IsAddressOfOperand = false;
1824 Result.Expression = cast<OverloadExpr>(E);
1830 /// Gets the naming class of this lookup, if any.
1831 CXXRecordDecl *getNamingClass() const;
1833 typedef UnresolvedSetImpl::iterator decls_iterator;
1834 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1835 decls_iterator decls_end() const {
1836 return UnresolvedSetIterator(Results + NumResults);
1839 /// Gets the number of declarations in the unresolved set.
1840 unsigned getNumDecls() const { return NumResults; }
1842 /// Gets the full name info.
1843 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1845 /// Gets the name looked up.
1846 DeclarationName getName() const { return NameInfo.getName(); }
1848 /// Gets the location of the name.
1849 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
1851 /// Fetches the nested-name qualifier, if one was given.
1852 NestedNameSpecifier *getQualifier() const {
1853 return QualifierLoc.getNestedNameSpecifier();
1856 /// Fetches the nested-name qualifier with source-location information, if
1858 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1860 /// \brief Determines whether this expression had an explicit
1861 /// template argument list, e.g. f<int>.
1862 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1864 ASTTemplateArgumentListInfo &getExplicitTemplateArgs(); // defined far below
1866 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
1867 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1870 /// \brief Retrieves the optional explicit template arguments.
1871 /// This points to the same data as getExplicitTemplateArgs(), but
1872 /// returns null if there are no explicit template arguments.
1873 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
1874 if (!hasExplicitTemplateArgs()) return 0;
1875 return &getExplicitTemplateArgs();
1878 static bool classof(const Stmt *T) {
1879 return T->getStmtClass() == UnresolvedLookupExprClass ||
1880 T->getStmtClass() == UnresolvedMemberExprClass;
1882 static bool classof(const OverloadExpr *) { return true; }
1884 friend class ASTStmtReader;
1885 friend class ASTStmtWriter;
1888 /// \brief A reference to a name which we were able to look up during
1889 /// parsing but could not resolve to a specific declaration. This
1890 /// arises in several ways:
1891 /// * we might be waiting for argument-dependent lookup
1892 /// * the name might resolve to an overloaded function
1894 /// * the lookup might have included a function template
1895 /// These never include UnresolvedUsingValueDecls, which are always
1896 /// class members and therefore appear only in
1897 /// UnresolvedMemberLookupExprs.
1898 class UnresolvedLookupExpr : public OverloadExpr {
1899 /// True if these lookup results should be extended by
1900 /// argument-dependent lookup if this is the operand of a function
1904 /// True if namespace ::std should be considered an associated namespace
1905 /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
1906 bool StdIsAssociatedNamespace;
1908 /// True if these lookup results are overloaded. This is pretty
1909 /// trivially rederivable if we urgently need to kill this field.
1912 /// The naming class (C++ [class.access.base]p5) of the lookup, if
1913 /// any. This can generally be recalculated from the context chain,
1914 /// but that can be fairly expensive for unqualified lookups. If we
1915 /// want to improve memory use here, this could go in a union
1916 /// against the qualified-lookup bits.
1917 CXXRecordDecl *NamingClass;
1919 UnresolvedLookupExpr(ASTContext &C,
1920 CXXRecordDecl *NamingClass,
1921 NestedNameSpecifierLoc QualifierLoc,
1922 const DeclarationNameInfo &NameInfo,
1923 bool RequiresADL, bool Overloaded,
1924 const TemplateArgumentListInfo *TemplateArgs,
1925 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1926 bool StdIsAssociatedNamespace)
1927 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, NameInfo,
1928 TemplateArgs, Begin, End, false, false, false),
1929 RequiresADL(RequiresADL),
1930 StdIsAssociatedNamespace(StdIsAssociatedNamespace),
1931 Overloaded(Overloaded), NamingClass(NamingClass)
1934 UnresolvedLookupExpr(EmptyShell Empty)
1935 : OverloadExpr(UnresolvedLookupExprClass, Empty),
1936 RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
1940 friend class ASTStmtReader;
1943 static UnresolvedLookupExpr *Create(ASTContext &C,
1944 CXXRecordDecl *NamingClass,
1945 NestedNameSpecifierLoc QualifierLoc,
1946 const DeclarationNameInfo &NameInfo,
1947 bool ADL, bool Overloaded,
1948 UnresolvedSetIterator Begin,
1949 UnresolvedSetIterator End,
1950 bool StdIsAssociatedNamespace = false) {
1951 assert((ADL || !StdIsAssociatedNamespace) &&
1952 "std considered associated namespace when not performing ADL");
1953 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
1954 ADL, Overloaded, 0, Begin, End,
1955 StdIsAssociatedNamespace);
1958 static UnresolvedLookupExpr *Create(ASTContext &C,
1959 CXXRecordDecl *NamingClass,
1960 NestedNameSpecifierLoc QualifierLoc,
1961 const DeclarationNameInfo &NameInfo,
1963 const TemplateArgumentListInfo &Args,
1964 UnresolvedSetIterator Begin,
1965 UnresolvedSetIterator End);
1967 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1968 bool HasExplicitTemplateArgs,
1969 unsigned NumTemplateArgs);
1971 /// True if this declaration should be extended by
1972 /// argument-dependent lookup.
1973 bool requiresADL() const { return RequiresADL; }
1975 /// True if namespace ::std should be artificially added to the set of
1976 /// associated namespaecs for argument-dependent lookup purposes.
1977 bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
1979 /// True if this lookup is overloaded.
1980 bool isOverloaded() const { return Overloaded; }
1982 /// Gets the 'naming class' (in the sense of C++0x
1983 /// [class.access.base]p5) of the lookup. This is the scope
1984 /// that was looked in to find these results.
1985 CXXRecordDecl *getNamingClass() const { return NamingClass; }
1987 // Note that, inconsistently with the explicit-template-argument AST
1988 // nodes, users are *forbidden* from calling these methods on objects
1989 // without explicit template arguments.
1991 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
1992 assert(hasExplicitTemplateArgs());
1993 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
1996 /// Gets a reference to the explicit template argument list.
1997 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
1998 assert(hasExplicitTemplateArgs());
1999 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2002 /// \brief Retrieves the optional explicit template arguments.
2003 /// This points to the same data as getExplicitTemplateArgs(), but
2004 /// returns null if there are no explicit template arguments.
2005 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2006 if (!hasExplicitTemplateArgs()) return 0;
2007 return &getExplicitTemplateArgs();
2010 /// \brief Copies the template arguments (if present) into the given
2012 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2013 getExplicitTemplateArgs().copyInto(List);
2016 SourceLocation getLAngleLoc() const {
2017 return getExplicitTemplateArgs().LAngleLoc;
2020 SourceLocation getRAngleLoc() const {
2021 return getExplicitTemplateArgs().RAngleLoc;
2024 TemplateArgumentLoc const *getTemplateArgs() const {
2025 return getExplicitTemplateArgs().getTemplateArgs();
2028 unsigned getNumTemplateArgs() const {
2029 return getExplicitTemplateArgs().NumTemplateArgs;
2032 SourceRange getSourceRange() const {
2033 SourceRange Range(getNameInfo().getSourceRange());
2034 if (getQualifierLoc())
2035 Range.setBegin(getQualifierLoc().getBeginLoc());
2036 if (hasExplicitTemplateArgs())
2037 Range.setEnd(getRAngleLoc());
2041 child_range children() { return child_range(); }
2043 static bool classof(const Stmt *T) {
2044 return T->getStmtClass() == UnresolvedLookupExprClass;
2046 static bool classof(const UnresolvedLookupExpr *) { return true; }
2049 /// \brief A qualified reference to a name whose declaration cannot
2050 /// yet be resolved.
2052 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2053 /// it expresses a reference to a declaration such as
2054 /// X<T>::value. The difference, however, is that an
2055 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2056 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2057 /// this case, X<T>::value cannot resolve to a declaration because the
2058 /// declaration will differ from on instantiation of X<T> to the
2059 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2060 /// qualifier (X<T>::) and the name of the entity being referenced
2061 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2062 /// declaration can be found.
2063 class DependentScopeDeclRefExpr : public Expr {
2064 /// \brief The nested-name-specifier that qualifies this unresolved
2065 /// declaration name.
2066 NestedNameSpecifierLoc QualifierLoc;
2068 /// The name of the entity we will be referencing.
2069 DeclarationNameInfo NameInfo;
2071 /// \brief Whether the name includes explicit template arguments.
2072 bool HasExplicitTemplateArgs;
2074 DependentScopeDeclRefExpr(QualType T,
2075 NestedNameSpecifierLoc QualifierLoc,
2076 const DeclarationNameInfo &NameInfo,
2077 const TemplateArgumentListInfo *Args);
2080 static DependentScopeDeclRefExpr *Create(ASTContext &C,
2081 NestedNameSpecifierLoc QualifierLoc,
2082 const DeclarationNameInfo &NameInfo,
2083 const TemplateArgumentListInfo *TemplateArgs = 0);
2085 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2086 bool HasExplicitTemplateArgs,
2087 unsigned NumTemplateArgs);
2089 /// \brief Retrieve the name that this expression refers to.
2090 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2092 /// \brief Retrieve the name that this expression refers to.
2093 DeclarationName getDeclName() const { return NameInfo.getName(); }
2095 /// \brief Retrieve the location of the name within the expression.
2096 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2098 /// \brief Retrieve the nested-name-specifier that qualifies the
2099 /// name, with source location information.
2100 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2103 /// \brief Retrieve the nested-name-specifier that qualifies this
2105 NestedNameSpecifier *getQualifier() const {
2106 return QualifierLoc.getNestedNameSpecifier();
2109 /// Determines whether this lookup had explicit template arguments.
2110 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
2112 // Note that, inconsistently with the explicit-template-argument AST
2113 // nodes, users are *forbidden* from calling these methods on objects
2114 // without explicit template arguments.
2116 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2117 assert(hasExplicitTemplateArgs());
2118 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
2121 /// Gets a reference to the explicit template argument list.
2122 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2123 assert(hasExplicitTemplateArgs());
2124 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2127 /// \brief Retrieves the optional explicit template arguments.
2128 /// This points to the same data as getExplicitTemplateArgs(), but
2129 /// returns null if there are no explicit template arguments.
2130 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2131 if (!hasExplicitTemplateArgs()) return 0;
2132 return &getExplicitTemplateArgs();
2135 /// \brief Copies the template arguments (if present) into the given
2137 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2138 getExplicitTemplateArgs().copyInto(List);
2141 SourceLocation getLAngleLoc() const {
2142 return getExplicitTemplateArgs().LAngleLoc;
2145 SourceLocation getRAngleLoc() const {
2146 return getExplicitTemplateArgs().RAngleLoc;
2149 TemplateArgumentLoc const *getTemplateArgs() const {
2150 return getExplicitTemplateArgs().getTemplateArgs();
2153 unsigned getNumTemplateArgs() const {
2154 return getExplicitTemplateArgs().NumTemplateArgs;
2157 SourceRange getSourceRange() const {
2158 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2159 if (hasExplicitTemplateArgs())
2160 Range.setEnd(getRAngleLoc());
2164 static bool classof(const Stmt *T) {
2165 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2167 static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2169 child_range children() { return child_range(); }
2171 friend class ASTStmtReader;
2172 friend class ASTStmtWriter;
2175 /// Represents an expression --- generally a full-expression --- which
2176 /// introduces cleanups to be run at the end of the sub-expression's
2177 /// evaluation. The most common source of expression-introduced
2178 /// cleanups is temporary objects in C++, but several other C++
2179 /// expressions can create cleanups.
2180 class ExprWithCleanups : public Expr {
2183 CXXTemporary **Temps;
2186 ExprWithCleanups(ASTContext &C, Expr *SubExpr,
2187 CXXTemporary **Temps, unsigned NumTemps);
2190 ExprWithCleanups(EmptyShell Empty)
2191 : Expr(ExprWithCleanupsClass, Empty),
2192 SubExpr(0), Temps(0), NumTemps(0) {}
2194 static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr,
2195 CXXTemporary **Temps,
2198 unsigned getNumTemporaries() const { return NumTemps; }
2199 void setNumTemporaries(ASTContext &C, unsigned N);
2201 CXXTemporary *getTemporary(unsigned i) {
2202 assert(i < NumTemps && "Index out of range");
2205 const CXXTemporary *getTemporary(unsigned i) const {
2206 return const_cast<ExprWithCleanups*>(this)->getTemporary(i);
2208 void setTemporary(unsigned i, CXXTemporary *T) {
2209 assert(i < NumTemps && "Index out of range");
2213 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2214 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2215 void setSubExpr(Expr *E) { SubExpr = E; }
2217 SourceRange getSourceRange() const {
2218 return SubExpr->getSourceRange();
2221 // Implement isa/cast/dyncast/etc.
2222 static bool classof(const Stmt *T) {
2223 return T->getStmtClass() == ExprWithCleanupsClass;
2225 static bool classof(const ExprWithCleanups *) { return true; }
2228 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2231 /// \brief Describes an explicit type conversion that uses functional
2232 /// notion but could not be resolved because one or more arguments are
2235 /// The explicit type conversions expressed by
2236 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2237 /// where \c T is some type and \c a1, a2, ..., aN are values, and
2238 /// either \C T is a dependent type or one or more of the \c a's is
2239 /// type-dependent. For example, this would occur in a template such
2243 /// template<typename T, typename A1>
2244 /// inline T make_a(const A1& a1) {
2249 /// When the returned expression is instantiated, it may resolve to a
2250 /// constructor call, conversion function call, or some kind of type
2252 class CXXUnresolvedConstructExpr : public Expr {
2253 /// \brief The type being constructed.
2254 TypeSourceInfo *Type;
2256 /// \brief The location of the left parentheses ('(').
2257 SourceLocation LParenLoc;
2259 /// \brief The location of the right parentheses (')').
2260 SourceLocation RParenLoc;
2262 /// \brief The number of arguments used to construct the type.
2265 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2266 SourceLocation LParenLoc,
2269 SourceLocation RParenLoc);
2271 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2272 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2274 friend class ASTStmtReader;
2277 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2278 TypeSourceInfo *Type,
2279 SourceLocation LParenLoc,
2282 SourceLocation RParenLoc);
2284 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2287 /// \brief Retrieve the type that is being constructed, as specified
2288 /// in the source code.
2289 QualType getTypeAsWritten() const { return Type->getType(); }
2291 /// \brief Retrieve the type source information for the type being
2293 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2295 /// \brief Retrieve the location of the left parentheses ('(') that
2296 /// precedes the argument list.
2297 SourceLocation getLParenLoc() const { return LParenLoc; }
2298 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2300 /// \brief Retrieve the location of the right parentheses (')') that
2301 /// follows the argument list.
2302 SourceLocation getRParenLoc() const { return RParenLoc; }
2303 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2305 /// \brief Retrieve the number of arguments.
2306 unsigned arg_size() const { return NumArgs; }
2308 typedef Expr** arg_iterator;
2309 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2310 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2312 typedef const Expr* const * const_arg_iterator;
2313 const_arg_iterator arg_begin() const {
2314 return reinterpret_cast<const Expr* const *>(this + 1);
2316 const_arg_iterator arg_end() const {
2317 return arg_begin() + NumArgs;
2320 Expr *getArg(unsigned I) {
2321 assert(I < NumArgs && "Argument index out-of-range");
2322 return *(arg_begin() + I);
2325 const Expr *getArg(unsigned I) const {
2326 assert(I < NumArgs && "Argument index out-of-range");
2327 return *(arg_begin() + I);
2330 void setArg(unsigned I, Expr *E) {
2331 assert(I < NumArgs && "Argument index out-of-range");
2332 *(arg_begin() + I) = E;
2335 SourceRange getSourceRange() const;
2337 static bool classof(const Stmt *T) {
2338 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2340 static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2343 child_range children() {
2344 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2345 return child_range(begin, begin + NumArgs);
2349 /// \brief Represents a C++ member access expression where the actual
2350 /// member referenced could not be resolved because the base
2351 /// expression or the member name was dependent.
2353 /// Like UnresolvedMemberExprs, these can be either implicit or
2354 /// explicit accesses. It is only possible to get one of these with
2355 /// an implicit access if a qualifier is provided.
2356 class CXXDependentScopeMemberExpr : public Expr {
2357 /// \brief The expression for the base pointer or class reference,
2358 /// e.g., the \c x in x.f. Can be null in implicit accesses.
2361 /// \brief The type of the base expression. Never null, even for
2362 /// implicit accesses.
2365 /// \brief Whether this member expression used the '->' operator or
2366 /// the '.' operator.
2369 /// \brief Whether this member expression has explicitly-specified template
2371 bool HasExplicitTemplateArgs : 1;
2373 /// \brief The location of the '->' or '.' operator.
2374 SourceLocation OperatorLoc;
2376 /// \brief The nested-name-specifier that precedes the member name, if any.
2377 NestedNameSpecifierLoc QualifierLoc;
2379 /// \brief In a qualified member access expression such as t->Base::f, this
2380 /// member stores the resolves of name lookup in the context of the member
2381 /// access expression, to be used at instantiation time.
2383 /// FIXME: This member, along with the QualifierLoc, could
2384 /// be stuck into a structure that is optionally allocated at the end of
2385 /// the CXXDependentScopeMemberExpr, to save space in the common case.
2386 NamedDecl *FirstQualifierFoundInScope;
2388 /// \brief The member to which this member expression refers, which
2389 /// can be name, overloaded operator, or destructor.
2390 /// FIXME: could also be a template-id
2391 DeclarationNameInfo MemberNameInfo;
2393 CXXDependentScopeMemberExpr(ASTContext &C,
2394 Expr *Base, QualType BaseType, bool IsArrow,
2395 SourceLocation OperatorLoc,
2396 NestedNameSpecifierLoc QualifierLoc,
2397 NamedDecl *FirstQualifierFoundInScope,
2398 DeclarationNameInfo MemberNameInfo,
2399 const TemplateArgumentListInfo *TemplateArgs);
2402 CXXDependentScopeMemberExpr(ASTContext &C,
2403 Expr *Base, QualType BaseType,
2405 SourceLocation OperatorLoc,
2406 NestedNameSpecifierLoc QualifierLoc,
2407 NamedDecl *FirstQualifierFoundInScope,
2408 DeclarationNameInfo MemberNameInfo);
2410 static CXXDependentScopeMemberExpr *
2411 Create(ASTContext &C,
2412 Expr *Base, QualType BaseType, bool IsArrow,
2413 SourceLocation OperatorLoc,
2414 NestedNameSpecifierLoc QualifierLoc,
2415 NamedDecl *FirstQualifierFoundInScope,
2416 DeclarationNameInfo MemberNameInfo,
2417 const TemplateArgumentListInfo *TemplateArgs);
2419 static CXXDependentScopeMemberExpr *
2420 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2421 unsigned NumTemplateArgs);
2423 /// \brief True if this is an implicit access, i.e. one in which the
2424 /// member being accessed was not written in the source. The source
2425 /// location of the operator is invalid in this case.
2426 bool isImplicitAccess() const;
2428 /// \brief Retrieve the base object of this member expressions,
2429 /// e.g., the \c x in \c x.m.
2430 Expr *getBase() const {
2431 assert(!isImplicitAccess());
2432 return cast<Expr>(Base);
2435 QualType getBaseType() const { return BaseType; }
2437 /// \brief Determine whether this member expression used the '->'
2438 /// operator; otherwise, it used the '.' operator.
2439 bool isArrow() const { return IsArrow; }
2441 /// \brief Retrieve the location of the '->' or '.' operator.
2442 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2444 /// \brief Retrieve the nested-name-specifier that qualifies the member
2446 NestedNameSpecifier *getQualifier() const {
2447 return QualifierLoc.getNestedNameSpecifier();
2450 /// \brief Retrieve the nested-name-specifier that qualifies the member
2451 /// name, with source location information.
2452 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2455 /// \brief Retrieve the first part of the nested-name-specifier that was
2456 /// found in the scope of the member access expression when the member access
2457 /// was initially parsed.
2459 /// This function only returns a useful result when member access expression
2460 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2461 /// returned by this function describes what was found by unqualified name
2462 /// lookup for the identifier "Base" within the scope of the member access
2463 /// expression itself. At template instantiation time, this information is
2464 /// combined with the results of name lookup into the type of the object
2465 /// expression itself (the class type of x).
2466 NamedDecl *getFirstQualifierFoundInScope() const {
2467 return FirstQualifierFoundInScope;
2470 /// \brief Retrieve the name of the member that this expression
2472 const DeclarationNameInfo &getMemberNameInfo() const {
2473 return MemberNameInfo;
2476 /// \brief Retrieve the name of the member that this expression
2478 DeclarationName getMember() const { return MemberNameInfo.getName(); }
2480 // \brief Retrieve the location of the name of the member that this
2481 // expression refers to.
2482 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2484 /// \brief Determines whether this member expression actually had a C++
2485 /// template argument list explicitly specified, e.g., x.f<int>.
2486 bool hasExplicitTemplateArgs() const {
2487 return HasExplicitTemplateArgs;
2490 /// \brief Retrieve the explicit template argument list that followed the
2491 /// member template name, if any.
2492 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2493 assert(HasExplicitTemplateArgs);
2494 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
2497 /// \brief Retrieve the explicit template argument list that followed the
2498 /// member template name, if any.
2499 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2500 return const_cast<CXXDependentScopeMemberExpr *>(this)
2501 ->getExplicitTemplateArgs();
2504 /// \brief Retrieves the optional explicit template arguments.
2505 /// This points to the same data as getExplicitTemplateArgs(), but
2506 /// returns null if there are no explicit template arguments.
2507 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2508 if (!hasExplicitTemplateArgs()) return 0;
2509 return &getExplicitTemplateArgs();
2512 /// \brief Copies the template arguments (if present) into the given
2514 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2515 getExplicitTemplateArgs().copyInto(List);
2518 /// \brief Initializes the template arguments using the given structure.
2519 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2520 getExplicitTemplateArgs().initializeFrom(List);
2523 /// \brief Retrieve the location of the left angle bracket following the
2524 /// member name ('<'), if any.
2525 SourceLocation getLAngleLoc() const {
2526 return getExplicitTemplateArgs().LAngleLoc;
2529 /// \brief Retrieve the template arguments provided as part of this
2531 const TemplateArgumentLoc *getTemplateArgs() const {
2532 return getExplicitTemplateArgs().getTemplateArgs();
2535 /// \brief Retrieve the number of template arguments provided as part of this
2537 unsigned getNumTemplateArgs() const {
2538 return getExplicitTemplateArgs().NumTemplateArgs;
2541 /// \brief Retrieve the location of the right angle bracket following the
2542 /// template arguments ('>').
2543 SourceLocation getRAngleLoc() const {
2544 return getExplicitTemplateArgs().RAngleLoc;
2547 SourceRange getSourceRange() const {
2549 if (!isImplicitAccess())
2550 Range.setBegin(Base->getSourceRange().getBegin());
2551 else if (getQualifier())
2552 Range.setBegin(getQualifierLoc().getBeginLoc());
2554 Range.setBegin(MemberNameInfo.getBeginLoc());
2556 if (hasExplicitTemplateArgs())
2557 Range.setEnd(getRAngleLoc());
2559 Range.setEnd(MemberNameInfo.getEndLoc());
2563 static bool classof(const Stmt *T) {
2564 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2566 static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2569 child_range children() {
2570 if (isImplicitAccess()) return child_range();
2571 return child_range(&Base, &Base + 1);
2574 friend class ASTStmtReader;
2575 friend class ASTStmtWriter;
2578 /// \brief Represents a C++ member access expression for which lookup
2579 /// produced a set of overloaded functions.
2581 /// The member access may be explicit or implicit:
2584 /// int explicitAccess() { return this->a + this->A::b; }
2585 /// int implicitAccess() { return a + A::b; }
2588 /// In the final AST, an explicit access always becomes a MemberExpr.
2589 /// An implicit access may become either a MemberExpr or a
2590 /// DeclRefExpr, depending on whether the member is static.
2591 class UnresolvedMemberExpr : public OverloadExpr {
2592 /// \brief Whether this member expression used the '->' operator or
2593 /// the '.' operator.
2596 /// \brief Whether the lookup results contain an unresolved using
2598 bool HasUnresolvedUsing : 1;
2600 /// \brief The expression for the base pointer or class reference,
2601 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
2602 /// member expression
2605 /// \brief The type of the base expression; never null.
2608 /// \brief The location of the '->' or '.' operator.
2609 SourceLocation OperatorLoc;
2611 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
2612 Expr *Base, QualType BaseType, bool IsArrow,
2613 SourceLocation OperatorLoc,
2614 NestedNameSpecifierLoc QualifierLoc,
2615 const DeclarationNameInfo &MemberNameInfo,
2616 const TemplateArgumentListInfo *TemplateArgs,
2617 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2619 UnresolvedMemberExpr(EmptyShell Empty)
2620 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2621 HasUnresolvedUsing(false), Base(0) { }
2623 friend class ASTStmtReader;
2626 static UnresolvedMemberExpr *
2627 Create(ASTContext &C, bool HasUnresolvedUsing,
2628 Expr *Base, QualType BaseType, bool IsArrow,
2629 SourceLocation OperatorLoc,
2630 NestedNameSpecifierLoc QualifierLoc,
2631 const DeclarationNameInfo &MemberNameInfo,
2632 const TemplateArgumentListInfo *TemplateArgs,
2633 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2635 static UnresolvedMemberExpr *
2636 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2637 unsigned NumTemplateArgs);
2639 /// \brief True if this is an implicit access, i.e. one in which the
2640 /// member being accessed was not written in the source. The source
2641 /// location of the operator is invalid in this case.
2642 bool isImplicitAccess() const;
2644 /// \brief Retrieve the base object of this member expressions,
2645 /// e.g., the \c x in \c x.m.
2647 assert(!isImplicitAccess());
2648 return cast<Expr>(Base);
2650 const Expr *getBase() const {
2651 assert(!isImplicitAccess());
2652 return cast<Expr>(Base);
2655 QualType getBaseType() const { return BaseType; }
2657 /// \brief Determine whether the lookup results contain an unresolved using
2659 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2661 /// \brief Determine whether this member expression used the '->'
2662 /// operator; otherwise, it used the '.' operator.
2663 bool isArrow() const { return IsArrow; }
2665 /// \brief Retrieve the location of the '->' or '.' operator.
2666 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2668 /// \brief Retrieves the naming class of this lookup.
2669 CXXRecordDecl *getNamingClass() const;
2671 /// \brief Retrieve the full name info for the member that this expression
2673 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
2675 /// \brief Retrieve the name of the member that this expression
2677 DeclarationName getMemberName() const { return getName(); }
2679 // \brief Retrieve the location of the name of the member that this
2680 // expression refers to.
2681 SourceLocation getMemberLoc() const { return getNameLoc(); }
2683 /// \brief Retrieve the explicit template argument list that followed the
2684 /// member template name.
2685 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2686 assert(hasExplicitTemplateArgs());
2687 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
2690 /// \brief Retrieve the explicit template argument list that followed the
2691 /// member template name, if any.
2692 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2693 assert(hasExplicitTemplateArgs());
2694 return *reinterpret_cast<const ASTTemplateArgumentListInfo *>(this + 1);
2697 /// \brief Retrieves the optional explicit template arguments.
2698 /// This points to the same data as getExplicitTemplateArgs(), but
2699 /// returns null if there are no explicit template arguments.
2700 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2701 if (!hasExplicitTemplateArgs()) return 0;
2702 return &getExplicitTemplateArgs();
2705 /// \brief Copies the template arguments into the given structure.
2706 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2707 getExplicitTemplateArgs().copyInto(List);
2710 /// \brief Retrieve the location of the left angle bracket following
2711 /// the member name ('<').
2712 SourceLocation getLAngleLoc() const {
2713 return getExplicitTemplateArgs().LAngleLoc;
2716 /// \brief Retrieve the template arguments provided as part of this
2718 const TemplateArgumentLoc *getTemplateArgs() const {
2719 return getExplicitTemplateArgs().getTemplateArgs();
2722 /// \brief Retrieve the number of template arguments provided as
2723 /// part of this template-id.
2724 unsigned getNumTemplateArgs() const {
2725 return getExplicitTemplateArgs().NumTemplateArgs;
2728 /// \brief Retrieve the location of the right angle bracket
2729 /// following the template arguments ('>').
2730 SourceLocation getRAngleLoc() const {
2731 return getExplicitTemplateArgs().RAngleLoc;
2734 SourceRange getSourceRange() const {
2735 SourceRange Range = getMemberNameInfo().getSourceRange();
2736 if (!isImplicitAccess())
2737 Range.setBegin(Base->getSourceRange().getBegin());
2738 else if (getQualifierLoc())
2739 Range.setBegin(getQualifierLoc().getBeginLoc());
2741 if (hasExplicitTemplateArgs())
2742 Range.setEnd(getRAngleLoc());
2746 static bool classof(const Stmt *T) {
2747 return T->getStmtClass() == UnresolvedMemberExprClass;
2749 static bool classof(const UnresolvedMemberExpr *) { return true; }
2752 child_range children() {
2753 if (isImplicitAccess()) return child_range();
2754 return child_range(&Base, &Base + 1);
2758 /// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
2760 /// The noexcept expression tests whether a given expression might throw. Its
2761 /// result is a boolean constant.
2762 class CXXNoexceptExpr : public Expr {
2767 friend class ASTStmtReader;
2770 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
2771 SourceLocation Keyword, SourceLocation RParen)
2772 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
2773 /*TypeDependent*/false,
2774 /*ValueDependent*/Val == CT_Dependent,
2775 Val == CT_Dependent || Operand->isInstantiationDependent(),
2776 Operand->containsUnexpandedParameterPack()),
2777 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
2780 CXXNoexceptExpr(EmptyShell Empty)
2781 : Expr(CXXNoexceptExprClass, Empty)
2784 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
2786 SourceRange getSourceRange() const { return Range; }
2788 bool getValue() const { return Value; }
2790 static bool classof(const Stmt *T) {
2791 return T->getStmtClass() == CXXNoexceptExprClass;
2793 static bool classof(const CXXNoexceptExpr *) { return true; }
2796 child_range children() { return child_range(&Operand, &Operand + 1); }
2799 /// \brief Represents a C++0x pack expansion that produces a sequence of
2802 /// A pack expansion expression contains a pattern (which itself is an
2803 /// expression) followed by an ellipsis. For example:
2806 /// template<typename F, typename ...Types>
2807 /// void forward(F f, Types &&...args) {
2808 /// f(static_cast<Types&&>(args)...);
2812 /// Here, the argument to the function object \c f is a pack expansion whose
2813 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
2814 /// template is instantiated, the pack expansion will instantiate to zero or
2815 /// or more function arguments to the function object \c f.
2816 class PackExpansionExpr : public Expr {
2817 SourceLocation EllipsisLoc;
2819 /// \brief The number of expansions that will be produced by this pack
2820 /// expansion expression, if known.
2822 /// When zero, the number of expansions is not known. Otherwise, this value
2823 /// is the number of expansions + 1.
2824 unsigned NumExpansions;
2828 friend class ASTStmtReader;
2829 friend class ASTStmtWriter;
2832 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
2833 llvm::Optional<unsigned> NumExpansions)
2834 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
2835 Pattern->getObjectKind(), /*TypeDependent=*/true,
2836 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
2837 /*ContainsUnexpandedParameterPack=*/false),
2838 EllipsisLoc(EllipsisLoc),
2839 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
2840 Pattern(Pattern) { }
2842 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
2844 /// \brief Retrieve the pattern of the pack expansion.
2845 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
2847 /// \brief Retrieve the pattern of the pack expansion.
2848 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
2850 /// \brief Retrieve the location of the ellipsis that describes this pack
2852 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2854 /// \brief Determine the number of expansions that will be produced when
2855 /// this pack expansion is instantiated, if already known.
2856 llvm::Optional<unsigned> getNumExpansions() const {
2858 return NumExpansions - 1;
2860 return llvm::Optional<unsigned>();
2863 SourceRange getSourceRange() const {
2864 return SourceRange(Pattern->getLocStart(), EllipsisLoc);
2867 static bool classof(const Stmt *T) {
2868 return T->getStmtClass() == PackExpansionExprClass;
2870 static bool classof(const PackExpansionExpr *) { return true; }
2873 child_range children() {
2874 return child_range(&Pattern, &Pattern + 1);
2878 inline ASTTemplateArgumentListInfo &OverloadExpr::getExplicitTemplateArgs() {
2879 if (isa<UnresolvedLookupExpr>(this))
2880 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2882 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2885 /// \brief Represents an expression that computes the length of a parameter
2889 /// template<typename ...Types>
2891 /// static const unsigned value = sizeof...(Types);
2894 class SizeOfPackExpr : public Expr {
2895 /// \brief The location of the 'sizeof' keyword.
2896 SourceLocation OperatorLoc;
2898 /// \brief The location of the name of the parameter pack.
2899 SourceLocation PackLoc;
2901 /// \brief The location of the closing parenthesis.
2902 SourceLocation RParenLoc;
2904 /// \brief The length of the parameter pack, if known.
2906 /// When this expression is value-dependent, the length of the parameter pack
2907 /// is unknown. When this expression is not value-dependent, the length is
2911 /// \brief The parameter pack itself.
2914 friend class ASTStmtReader;
2915 friend class ASTStmtWriter;
2918 /// \brief Creates a value-dependent expression that computes the length of
2919 /// the given parameter pack.
2920 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2921 SourceLocation PackLoc, SourceLocation RParenLoc)
2922 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2923 /*TypeDependent=*/false, /*ValueDependent=*/true,
2924 /*InstantiationDependent=*/true,
2925 /*ContainsUnexpandedParameterPack=*/false),
2926 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2927 Length(0), Pack(Pack) { }
2929 /// \brief Creates an expression that computes the length of
2930 /// the given parameter pack, which is already known.
2931 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2932 SourceLocation PackLoc, SourceLocation RParenLoc,
2934 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2935 /*TypeDependent=*/false, /*ValueDependent=*/false,
2936 /*InstantiationDependent=*/false,
2937 /*ContainsUnexpandedParameterPack=*/false),
2938 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2939 Length(Length), Pack(Pack) { }
2941 /// \brief Create an empty expression.
2942 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
2944 /// \brief Determine the location of the 'sizeof' keyword.
2945 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2947 /// \brief Determine the location of the parameter pack.
2948 SourceLocation getPackLoc() const { return PackLoc; }
2950 /// \brief Determine the location of the right parenthesis.
2951 SourceLocation getRParenLoc() const { return RParenLoc; }
2953 /// \brief Retrieve the parameter pack.
2954 NamedDecl *getPack() const { return Pack; }
2956 /// \brief Retrieve the length of the parameter pack.
2958 /// This routine may only be invoked when the expression is not
2959 /// value-dependent.
2960 unsigned getPackLength() const {
2961 assert(!isValueDependent() &&
2962 "Cannot get the length of a value-dependent pack size expression");
2966 SourceRange getSourceRange() const {
2967 return SourceRange(OperatorLoc, RParenLoc);
2970 static bool classof(const Stmt *T) {
2971 return T->getStmtClass() == SizeOfPackExprClass;
2973 static bool classof(const SizeOfPackExpr *) { return true; }
2976 child_range children() { return child_range(); }
2979 /// \brief Represents a reference to a non-type template parameter
2980 /// that has been substituted with a template argument.
2981 class SubstNonTypeTemplateParmExpr : public Expr {
2982 /// \brief The replaced parameter.
2983 NonTypeTemplateParmDecl *Param;
2985 /// \brief The replacement expression.
2988 /// \brief The location of the non-type template parameter reference.
2989 SourceLocation NameLoc;
2991 friend class ASTReader;
2992 friend class ASTStmtReader;
2993 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
2994 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
2997 SubstNonTypeTemplateParmExpr(QualType type,
2998 ExprValueKind valueKind,
3000 NonTypeTemplateParmDecl *param,
3002 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3003 replacement->isTypeDependent(), replacement->isValueDependent(),
3004 replacement->isInstantiationDependent(),
3005 replacement->containsUnexpandedParameterPack()),
3006 Param(param), Replacement(replacement), NameLoc(loc) {}
3008 SourceLocation getNameLoc() const { return NameLoc; }
3009 SourceRange getSourceRange() const { return NameLoc; }
3011 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3013 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3015 static bool classof(const Stmt *s) {
3016 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3018 static bool classof(const SubstNonTypeTemplateParmExpr *) {
3023 child_range children() { return child_range(&Replacement, &Replacement+1); }
3026 /// \brief Represents a reference to a non-type template parameter pack that
3027 /// has been substituted with a non-template argument pack.
3029 /// When a pack expansion in the source code contains multiple parameter packs
3030 /// and those parameter packs correspond to different levels of template
3031 /// parameter lists, this node node is used to represent a non-type template
3032 /// parameter pack from an outer level, which has already had its argument pack
3033 /// substituted but that still lives within a pack expansion that itself
3034 /// could not be instantiated. When actually performing a substitution into
3035 /// that pack expansion (e.g., when all template parameters have corresponding
3036 /// arguments), this type will be replaced with the appropriate underlying
3037 /// expression at the current pack substitution index.
3038 class SubstNonTypeTemplateParmPackExpr : public Expr {
3039 /// \brief The non-type template parameter pack itself.
3040 NonTypeTemplateParmDecl *Param;
3042 /// \brief A pointer to the set of template arguments that this
3043 /// parameter pack is instantiated with.
3044 const TemplateArgument *Arguments;
3046 /// \brief The number of template arguments in \c Arguments.
3047 unsigned NumArguments;
3049 /// \brief The location of the non-type template parameter pack reference.
3050 SourceLocation NameLoc;
3052 friend class ASTReader;
3053 friend class ASTStmtReader;
3054 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3055 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3058 SubstNonTypeTemplateParmPackExpr(QualType T,
3059 NonTypeTemplateParmDecl *Param,
3060 SourceLocation NameLoc,
3061 const TemplateArgument &ArgPack);
3063 /// \brief Retrieve the non-type template parameter pack being substituted.
3064 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3066 /// \brief Retrieve the location of the parameter pack name.
3067 SourceLocation getParameterPackLocation() const { return NameLoc; }
3069 /// \brief Retrieve the template argument pack containing the substituted
3070 /// template arguments.
3071 TemplateArgument getArgumentPack() const;
3073 SourceRange getSourceRange() const { return NameLoc; }
3075 static bool classof(const Stmt *T) {
3076 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3078 static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
3083 child_range children() { return child_range(); }
3086 /// \brief Represents a prvalue temporary that written into memory so that
3087 /// a reference can bind to it.
3089 /// Prvalue expressions are materialized when they need to have an address
3090 /// in memory for a reference to bind to. This happens when binding a
3091 /// reference to the result of a conversion, e.g.,
3094 /// const int &r = 1.0;
3097 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3098 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3099 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3100 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3101 /// to it), maintaining the invariant that references always bind to glvalues.
3102 class MaterializeTemporaryExpr : public Expr {
3103 /// \brief The temporary-generating expression whose value will be
3107 friend class ASTStmtReader;
3108 friend class ASTStmtWriter;
3111 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3112 bool BoundToLvalueReference)
3113 : Expr(MaterializeTemporaryExprClass, T,
3114 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3115 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3116 Temporary->isInstantiationDependent(),
3117 Temporary->containsUnexpandedParameterPack()),
3118 Temporary(Temporary) { }
3120 MaterializeTemporaryExpr(EmptyShell Empty)
3121 : Expr(MaterializeTemporaryExprClass, Empty) { }
3123 /// \brief Retrieve the temporary-generating subexpression whose value will
3124 /// be materialized into a glvalue.
3125 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3127 /// \brief Determine whether this materialized temporary is bound to an
3128 /// lvalue reference; otherwise, it's bound to an rvalue reference.
3129 bool isBoundToLvalueReference() const {
3130 return getValueKind() == VK_LValue;
3133 SourceRange getSourceRange() const { return Temporary->getSourceRange(); }
3135 static bool classof(const Stmt *T) {
3136 return T->getStmtClass() == MaterializeTemporaryExprClass;
3138 static bool classof(const MaterializeTemporaryExpr *) {
3143 child_range children() { return child_range(&Temporary, &Temporary + 1); }
3146 } // end namespace clang