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;
811 bool ZeroInitialization : 1;
812 unsigned ConstructKind : 2;
817 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
819 CXXConstructorDecl *d, bool elidable,
820 Expr **args, unsigned numargs,
821 bool ZeroInitialization = false,
822 ConstructionKind ConstructKind = CK_Complete,
823 SourceRange ParenRange = SourceRange());
825 /// \brief Construct an empty C++ construction expression.
826 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
827 : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
828 ConstructKind(0), Args(0), NumArgs(0) { }
831 /// \brief Construct an empty C++ construction expression.
832 explicit CXXConstructExpr(EmptyShell Empty)
833 : Expr(CXXConstructExprClass, Empty), Constructor(0),
834 Elidable(0), ZeroInitialization(0),
835 ConstructKind(0), Args(0), NumArgs(0) { }
837 static CXXConstructExpr *Create(ASTContext &C, QualType T,
839 CXXConstructorDecl *D, bool Elidable,
840 Expr **Args, unsigned NumArgs,
841 bool ZeroInitialization = false,
842 ConstructionKind ConstructKind = CK_Complete,
843 SourceRange ParenRange = SourceRange());
846 CXXConstructorDecl* getConstructor() const { return Constructor; }
847 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
849 SourceLocation getLocation() const { return Loc; }
850 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
852 /// \brief Whether this construction is elidable.
853 bool isElidable() const { return Elidable; }
854 void setElidable(bool E) { Elidable = E; }
856 /// \brief Whether this construction first requires
857 /// zero-initialization before the initializer is called.
858 bool requiresZeroInitialization() const { return ZeroInitialization; }
859 void setRequiresZeroInitialization(bool ZeroInit) {
860 ZeroInitialization = ZeroInit;
863 /// \brief Determines whether this constructor is actually constructing
864 /// a base class (rather than a complete object).
865 ConstructionKind getConstructionKind() const {
866 return (ConstructionKind)ConstructKind;
868 void setConstructionKind(ConstructionKind CK) {
872 typedef ExprIterator arg_iterator;
873 typedef ConstExprIterator const_arg_iterator;
875 arg_iterator arg_begin() { return Args; }
876 arg_iterator arg_end() { return Args + NumArgs; }
877 const_arg_iterator arg_begin() const { return Args; }
878 const_arg_iterator arg_end() const { return Args + NumArgs; }
880 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
881 unsigned getNumArgs() const { return NumArgs; }
883 /// getArg - Return the specified argument.
884 Expr *getArg(unsigned Arg) {
885 assert(Arg < NumArgs && "Arg access out of range!");
886 return cast<Expr>(Args[Arg]);
888 const Expr *getArg(unsigned Arg) const {
889 assert(Arg < NumArgs && "Arg access out of range!");
890 return cast<Expr>(Args[Arg]);
893 /// setArg - Set the specified argument.
894 void setArg(unsigned Arg, Expr *ArgExpr) {
895 assert(Arg < NumArgs && "Arg access out of range!");
899 SourceRange getSourceRange() const;
900 SourceRange getParenRange() const { return ParenRange; }
902 static bool classof(const Stmt *T) {
903 return T->getStmtClass() == CXXConstructExprClass ||
904 T->getStmtClass() == CXXTemporaryObjectExprClass;
906 static bool classof(const CXXConstructExpr *) { return true; }
909 child_range children() {
910 return child_range(&Args[0], &Args[0]+NumArgs);
913 friend class ASTStmtReader;
916 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
917 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
919 class CXXFunctionalCastExpr : public ExplicitCastExpr {
920 SourceLocation TyBeginLoc;
921 SourceLocation RParenLoc;
923 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
924 TypeSourceInfo *writtenTy,
925 SourceLocation tyBeginLoc, CastKind kind,
926 Expr *castExpr, unsigned pathSize,
927 SourceLocation rParenLoc)
928 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
929 castExpr, pathSize, writtenTy),
930 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
932 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
933 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
936 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
938 TypeSourceInfo *Written,
939 SourceLocation TyBeginLoc,
940 CastKind Kind, Expr *Op,
941 const CXXCastPath *Path,
942 SourceLocation RPLoc);
943 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
946 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
947 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
948 SourceLocation getRParenLoc() const { return RParenLoc; }
949 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
951 SourceRange getSourceRange() const {
952 return SourceRange(TyBeginLoc, RParenLoc);
954 static bool classof(const Stmt *T) {
955 return T->getStmtClass() == CXXFunctionalCastExprClass;
957 static bool classof(const CXXFunctionalCastExpr *) { return true; }
960 /// @brief Represents a C++ functional cast expression that builds a
961 /// temporary object.
963 /// This expression type represents a C++ "functional" cast
964 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
965 /// constructor to build a temporary object. With N == 1 arguments the
966 /// functional cast expression will be represented by CXXFunctionalCastExpr.
969 /// struct X { X(int, float); }
972 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
975 class CXXTemporaryObjectExpr : public CXXConstructExpr {
976 TypeSourceInfo *Type;
979 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
980 TypeSourceInfo *Type,
981 Expr **Args,unsigned NumArgs,
982 SourceRange parenRange,
983 bool ZeroInitialization = false);
984 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
985 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
987 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
989 SourceRange getSourceRange() const;
991 static bool classof(const Stmt *T) {
992 return T->getStmtClass() == CXXTemporaryObjectExprClass;
994 static bool classof(const CXXTemporaryObjectExpr *) { return true; }
996 friend class ASTStmtReader;
999 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1000 /// Expression "T()" which creates a value-initialized rvalue of type
1001 /// T, which is a non-class type.
1003 class CXXScalarValueInitExpr : public Expr {
1004 SourceLocation RParenLoc;
1005 TypeSourceInfo *TypeInfo;
1007 friend class ASTStmtReader;
1010 /// \brief Create an explicitly-written scalar-value initialization
1012 CXXScalarValueInitExpr(QualType Type,
1013 TypeSourceInfo *TypeInfo,
1014 SourceLocation rParenLoc ) :
1015 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1016 false, false, Type->isInstantiationDependentType(), false),
1017 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1019 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1020 : Expr(CXXScalarValueInitExprClass, Shell) { }
1022 TypeSourceInfo *getTypeSourceInfo() const {
1026 SourceLocation getRParenLoc() const { return RParenLoc; }
1028 SourceRange getSourceRange() const;
1030 static bool classof(const Stmt *T) {
1031 return T->getStmtClass() == CXXScalarValueInitExprClass;
1033 static bool classof(const CXXScalarValueInitExpr *) { return true; }
1036 child_range children() { return child_range(); }
1039 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
1040 /// e.g: "new CXXNewExpr(foo)".
1041 class CXXNewExpr : public Expr {
1042 // Was the usage ::new, i.e. is the global new to be used?
1044 // Is there an initializer? If not, built-ins are uninitialized, else they're
1045 // value-initialized.
1046 bool Initializer : 1;
1047 // Do we allocate an array? If so, the first SubExpr is the size expression.
1049 // If this is an array allocation, does the usual deallocation
1050 // function for the allocated type want to know the allocated size?
1051 bool UsualArrayDeleteWantsSize : 1;
1052 // The number of placement new arguments.
1053 unsigned NumPlacementArgs : 14;
1054 // The number of constructor arguments. This may be 1 even for non-class
1055 // types; use the pseudo copy constructor.
1056 unsigned NumConstructorArgs : 14;
1057 // Contains an optional array size expression, any number of optional
1058 // placement arguments, and any number of optional constructor arguments,
1061 // Points to the allocation function used.
1062 FunctionDecl *OperatorNew;
1063 // Points to the deallocation function used in case of error. May be null.
1064 FunctionDecl *OperatorDelete;
1065 // Points to the constructor used. Cannot be null if AllocType is a record;
1066 // it would still point at the default constructor (even an implicit one).
1067 // Must be null for all other types.
1068 CXXConstructorDecl *Constructor;
1070 /// \brief The allocated type-source information, as written in the source.
1071 TypeSourceInfo *AllocatedTypeInfo;
1073 /// \brief If the allocated type was expressed as a parenthesized type-id,
1074 /// the source range covering the parenthesized type-id.
1075 SourceRange TypeIdParens;
1077 SourceLocation StartLoc;
1078 SourceLocation EndLoc;
1079 SourceLocation ConstructorLParen;
1080 SourceLocation ConstructorRParen;
1082 friend class ASTStmtReader;
1084 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1085 Expr **placementArgs, unsigned numPlaceArgs,
1086 SourceRange TypeIdParens,
1087 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
1088 Expr **constructorArgs, unsigned numConsArgs,
1089 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1090 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1091 SourceLocation startLoc, SourceLocation endLoc,
1092 SourceLocation constructorLParen,
1093 SourceLocation constructorRParen);
1094 explicit CXXNewExpr(EmptyShell Shell)
1095 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1097 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1098 unsigned numConsArgs);
1100 QualType getAllocatedType() const {
1101 assert(getType()->isPointerType());
1102 return getType()->getAs<PointerType>()->getPointeeType();
1105 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1106 return AllocatedTypeInfo;
1109 /// \brief True if the allocation result needs to be null-checked.
1110 /// C++0x [expr.new]p13:
1111 /// If the allocation function returns null, initialization shall
1112 /// not be done, the deallocation function shall not be called,
1113 /// and the value of the new-expression shall be null.
1114 /// An allocation function is not allowed to return null unless it
1115 /// has a non-throwing exception-specification. The '03 rule is
1116 /// identical except that the definition of a non-throwing
1117 /// exception specification is just "is it throw()?".
1118 bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1120 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1121 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1122 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1123 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1124 CXXConstructorDecl *getConstructor() const { return Constructor; }
1125 void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
1127 bool isArray() const { return Array; }
1128 Expr *getArraySize() {
1129 return Array ? cast<Expr>(SubExprs[0]) : 0;
1131 const Expr *getArraySize() const {
1132 return Array ? cast<Expr>(SubExprs[0]) : 0;
1135 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1136 Expr **getPlacementArgs() {
1137 return reinterpret_cast<Expr **>(SubExprs + Array);
1140 Expr *getPlacementArg(unsigned i) {
1141 assert(i < NumPlacementArgs && "Index out of range");
1142 return cast<Expr>(SubExprs[Array + i]);
1144 const Expr *getPlacementArg(unsigned i) const {
1145 assert(i < NumPlacementArgs && "Index out of range");
1146 return cast<Expr>(SubExprs[Array + i]);
1149 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1150 SourceRange getTypeIdParens() const { return TypeIdParens; }
1152 bool isGlobalNew() const { return GlobalNew; }
1153 bool hasInitializer() const { return Initializer; }
1155 /// Answers whether the usual array deallocation function for the
1156 /// allocated type expects the size of the allocation as a
1158 bool doesUsualArrayDeleteWantSize() const {
1159 return UsualArrayDeleteWantsSize;
1162 unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1164 Expr **getConstructorArgs() {
1165 return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs);
1168 Expr *getConstructorArg(unsigned i) {
1169 assert(i < NumConstructorArgs && "Index out of range");
1170 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1172 const Expr *getConstructorArg(unsigned i) const {
1173 assert(i < NumConstructorArgs && "Index out of range");
1174 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1177 typedef ExprIterator arg_iterator;
1178 typedef ConstExprIterator const_arg_iterator;
1180 arg_iterator placement_arg_begin() {
1181 return SubExprs + Array;
1183 arg_iterator placement_arg_end() {
1184 return SubExprs + Array + getNumPlacementArgs();
1186 const_arg_iterator placement_arg_begin() const {
1187 return SubExprs + Array;
1189 const_arg_iterator placement_arg_end() const {
1190 return SubExprs + Array + getNumPlacementArgs();
1193 arg_iterator constructor_arg_begin() {
1194 return SubExprs + Array + getNumPlacementArgs();
1196 arg_iterator constructor_arg_end() {
1197 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1199 const_arg_iterator constructor_arg_begin() const {
1200 return SubExprs + Array + getNumPlacementArgs();
1202 const_arg_iterator constructor_arg_end() const {
1203 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1206 typedef Stmt **raw_arg_iterator;
1207 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1208 raw_arg_iterator raw_arg_end() {
1209 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1211 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1212 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
1214 SourceLocation getStartLoc() const { return StartLoc; }
1215 SourceLocation getEndLoc() const { return EndLoc; }
1217 SourceLocation getConstructorLParen() const { return ConstructorLParen; }
1218 SourceLocation getConstructorRParen() const { return ConstructorRParen; }
1220 SourceRange getSourceRange() const {
1221 return SourceRange(StartLoc, EndLoc);
1224 static bool classof(const Stmt *T) {
1225 return T->getStmtClass() == CXXNewExprClass;
1227 static bool classof(const CXXNewExpr *) { return true; }
1230 child_range children() {
1231 return child_range(&SubExprs[0],
1232 &SubExprs[0] + Array + getNumPlacementArgs()
1233 + getNumConstructorArgs());
1237 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1238 /// calls, e.g. "delete[] pArray".
1239 class CXXDeleteExpr : public Expr {
1240 // Is this a forced global delete, i.e. "::delete"?
1241 bool GlobalDelete : 1;
1242 // Is this the array form of delete, i.e. "delete[]"?
1244 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1245 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1247 bool ArrayFormAsWritten : 1;
1248 // Does the usual deallocation function for the element type require
1249 // a size_t argument?
1250 bool UsualArrayDeleteWantsSize : 1;
1251 // Points to the operator delete overload that is used. Could be a member.
1252 FunctionDecl *OperatorDelete;
1253 // The pointer expression to be deleted.
1255 // Location of the expression.
1258 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1259 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1260 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1261 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1262 arg->isInstantiationDependent(),
1263 arg->containsUnexpandedParameterPack()),
1264 GlobalDelete(globalDelete),
1265 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1266 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
1267 OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
1268 explicit CXXDeleteExpr(EmptyShell Shell)
1269 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1271 bool isGlobalDelete() const { return GlobalDelete; }
1272 bool isArrayForm() const { return ArrayForm; }
1273 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1275 /// Answers whether the usual array deallocation function for the
1276 /// allocated type expects the size of the allocation as a
1277 /// parameter. This can be true even if the actual deallocation
1278 /// function that we're using doesn't want a size.
1279 bool doesUsualArrayDeleteWantSize() const {
1280 return UsualArrayDeleteWantsSize;
1283 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1285 Expr *getArgument() { return cast<Expr>(Argument); }
1286 const Expr *getArgument() const { return cast<Expr>(Argument); }
1288 /// \brief Retrieve the type being destroyed. If the type being
1289 /// destroyed is a dependent type which may or may not be a pointer,
1290 /// return an invalid type.
1291 QualType getDestroyedType() const;
1293 SourceRange getSourceRange() const {
1294 return SourceRange(Loc, Argument->getLocEnd());
1297 static bool classof(const Stmt *T) {
1298 return T->getStmtClass() == CXXDeleteExprClass;
1300 static bool classof(const CXXDeleteExpr *) { return true; }
1303 child_range children() { return child_range(&Argument, &Argument+1); }
1305 friend class ASTStmtReader;
1308 /// \brief Structure used to store the type being destroyed by a
1309 /// pseudo-destructor expression.
1310 class PseudoDestructorTypeStorage {
1311 /// \brief Either the type source information or the name of the type, if
1312 /// it couldn't be resolved due to type-dependence.
1313 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1315 /// \brief The starting source location of the pseudo-destructor type.
1316 SourceLocation Location;
1319 PseudoDestructorTypeStorage() { }
1321 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1322 : Type(II), Location(Loc) { }
1324 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1326 TypeSourceInfo *getTypeSourceInfo() const {
1327 return Type.dyn_cast<TypeSourceInfo *>();
1330 IdentifierInfo *getIdentifier() const {
1331 return Type.dyn_cast<IdentifierInfo *>();
1334 SourceLocation getLocation() const { return Location; }
1337 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1339 /// A pseudo-destructor is an expression that looks like a member access to a
1340 /// destructor of a scalar type, except that scalar types don't have
1341 /// destructors. For example:
1345 /// void f(int *p) {
1350 /// Pseudo-destructors typically occur when instantiating templates such as:
1353 /// template<typename T>
1354 /// void destroy(T* ptr) {
1359 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1360 /// beyond evaluating the base expression.
1361 class CXXPseudoDestructorExpr : public Expr {
1362 /// \brief The base expression (that is being destroyed).
1365 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1369 /// \brief The location of the '.' or '->' operator.
1370 SourceLocation OperatorLoc;
1372 /// \brief The nested-name-specifier that follows the operator, if present.
1373 NestedNameSpecifierLoc QualifierLoc;
1375 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1377 TypeSourceInfo *ScopeType;
1379 /// \brief The location of the '::' in a qualified pseudo-destructor
1381 SourceLocation ColonColonLoc;
1383 /// \brief The location of the '~'.
1384 SourceLocation TildeLoc;
1386 /// \brief The type being destroyed, or its name if we were unable to
1387 /// resolve the name.
1388 PseudoDestructorTypeStorage DestroyedType;
1390 friend class ASTStmtReader;
1393 CXXPseudoDestructorExpr(ASTContext &Context,
1394 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1395 NestedNameSpecifierLoc QualifierLoc,
1396 TypeSourceInfo *ScopeType,
1397 SourceLocation ColonColonLoc,
1398 SourceLocation TildeLoc,
1399 PseudoDestructorTypeStorage DestroyedType);
1401 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1402 : Expr(CXXPseudoDestructorExprClass, Shell),
1403 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1405 Expr *getBase() const { return cast<Expr>(Base); }
1407 /// \brief Determines whether this member expression actually had
1408 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1410 bool hasQualifier() const { return QualifierLoc; }
1412 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1413 /// with source-location information.
1414 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1416 /// \brief If the member name was qualified, retrieves the
1417 /// nested-name-specifier that precedes the member name. Otherwise, returns
1419 NestedNameSpecifier *getQualifier() const {
1420 return QualifierLoc.getNestedNameSpecifier();
1423 /// \brief Determine whether this pseudo-destructor expression was written
1424 /// using an '->' (otherwise, it used a '.').
1425 bool isArrow() const { return IsArrow; }
1427 /// \brief Retrieve the location of the '.' or '->' operator.
1428 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1430 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1433 /// Pseudo-destructor expressions can have extra qualification within them
1434 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1435 /// Here, if the object type of the expression is (or may be) a scalar type,
1436 /// \p T may also be a scalar type and, therefore, cannot be part of a
1437 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1438 /// destructor expression.
1439 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1441 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1443 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1445 /// \brief Retrieve the location of the '~'.
1446 SourceLocation getTildeLoc() const { return TildeLoc; }
1448 /// \brief Retrieve the source location information for the type
1449 /// being destroyed.
1451 /// This type-source information is available for non-dependent
1452 /// pseudo-destructor expressions and some dependent pseudo-destructor
1453 /// expressions. Returns NULL if we only have the identifier for a
1454 /// dependent pseudo-destructor expression.
1455 TypeSourceInfo *getDestroyedTypeInfo() const {
1456 return DestroyedType.getTypeSourceInfo();
1459 /// \brief In a dependent pseudo-destructor expression for which we do not
1460 /// have full type information on the destroyed type, provides the name
1461 /// of the destroyed type.
1462 IdentifierInfo *getDestroyedTypeIdentifier() const {
1463 return DestroyedType.getIdentifier();
1466 /// \brief Retrieve the type being destroyed.
1467 QualType getDestroyedType() const;
1469 /// \brief Retrieve the starting location of the type being destroyed.
1470 SourceLocation getDestroyedTypeLoc() const {
1471 return DestroyedType.getLocation();
1474 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1476 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1477 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1480 /// \brief Set the destroyed type.
1481 void setDestroyedType(TypeSourceInfo *Info) {
1482 DestroyedType = PseudoDestructorTypeStorage(Info);
1485 SourceRange getSourceRange() const;
1487 static bool classof(const Stmt *T) {
1488 return T->getStmtClass() == CXXPseudoDestructorExprClass;
1490 static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1493 child_range children() { return child_range(&Base, &Base + 1); }
1496 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1497 /// implementation of TR1/C++0x type trait templates.
1499 /// __is_pod(int) == true
1500 /// __is_enum(std::string) == false
1501 class UnaryTypeTraitExpr : public Expr {
1502 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
1504 /// The value of the type trait. Unspecified if dependent.
1507 /// Loc - The location of the type trait keyword.
1510 /// RParen - The location of the closing paren.
1511 SourceLocation RParen;
1513 /// The type being queried.
1514 TypeSourceInfo *QueriedType;
1517 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1518 TypeSourceInfo *queried, bool value,
1519 SourceLocation rparen, QualType ty)
1520 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1521 false, queried->getType()->isDependentType(),
1522 queried->getType()->isInstantiationDependentType(),
1523 queried->getType()->containsUnexpandedParameterPack()),
1524 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
1526 explicit UnaryTypeTraitExpr(EmptyShell Empty)
1527 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
1530 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1532 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
1534 QualType getQueriedType() const { return QueriedType->getType(); }
1536 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1538 bool getValue() const { return Value; }
1540 static bool classof(const Stmt *T) {
1541 return T->getStmtClass() == UnaryTypeTraitExprClass;
1543 static bool classof(const UnaryTypeTraitExpr *) { return true; }
1546 child_range children() { return child_range(); }
1548 friend class ASTStmtReader;
1551 /// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
1552 /// implementation of TR1/C++0x type trait templates.
1554 /// __is_base_of(Base, Derived) == true
1555 class BinaryTypeTraitExpr : public Expr {
1556 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
1559 /// The value of the type trait. Unspecified if dependent.
1562 /// Loc - The location of the type trait keyword.
1565 /// RParen - The location of the closing paren.
1566 SourceLocation RParen;
1568 /// The lhs type being queried.
1569 TypeSourceInfo *LhsType;
1571 /// The rhs type being queried.
1572 TypeSourceInfo *RhsType;
1575 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1576 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
1577 bool value, SourceLocation rparen, QualType ty)
1578 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
1579 lhsType->getType()->isDependentType() ||
1580 rhsType->getType()->isDependentType(),
1581 (lhsType->getType()->isInstantiationDependentType() ||
1582 rhsType->getType()->isInstantiationDependentType()),
1583 (lhsType->getType()->containsUnexpandedParameterPack() ||
1584 rhsType->getType()->containsUnexpandedParameterPack())),
1585 BTT(btt), Value(value), Loc(loc), RParen(rparen),
1586 LhsType(lhsType), RhsType(rhsType) { }
1589 explicit BinaryTypeTraitExpr(EmptyShell Empty)
1590 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1591 LhsType(), RhsType() { }
1593 SourceRange getSourceRange() const {
1594 return SourceRange(Loc, RParen);
1597 BinaryTypeTrait getTrait() const {
1598 return static_cast<BinaryTypeTrait>(BTT);
1601 QualType getLhsType() const { return LhsType->getType(); }
1602 QualType getRhsType() const { return RhsType->getType(); }
1604 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
1605 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
1607 bool getValue() const { assert(!isTypeDependent()); return Value; }
1609 static bool classof(const Stmt *T) {
1610 return T->getStmtClass() == BinaryTypeTraitExprClass;
1612 static bool classof(const BinaryTypeTraitExpr *) { return true; }
1615 child_range children() { return child_range(); }
1617 friend class ASTStmtReader;
1620 /// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the
1621 /// implementation of __array_rank and __array_extent.
1623 /// __array_rank(int[10][20]) == 2
1624 /// __array_extent(int, 1) == 20
1625 class ArrayTypeTraitExpr : public Expr {
1626 /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
1629 /// The value of the type trait. Unspecified if dependent.
1632 /// The array dimension being queried, or -1 if not used
1635 /// Loc - The location of the type trait keyword.
1638 /// RParen - The location of the closing paren.
1639 SourceLocation RParen;
1641 /// The type being queried.
1642 TypeSourceInfo *QueriedType;
1645 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
1646 TypeSourceInfo *queried, uint64_t value,
1647 Expr *dimension, SourceLocation rparen, QualType ty)
1648 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1649 false, queried->getType()->isDependentType(),
1650 (queried->getType()->isInstantiationDependentType() ||
1651 (dimension && dimension->isInstantiationDependent())),
1652 queried->getType()->containsUnexpandedParameterPack()),
1653 ATT(att), Value(value), Dimension(dimension),
1654 Loc(loc), RParen(rparen), QueriedType(queried) { }
1657 explicit ArrayTypeTraitExpr(EmptyShell Empty)
1658 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
1661 virtual ~ArrayTypeTraitExpr() { }
1663 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen); }
1665 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
1667 QualType getQueriedType() const { return QueriedType->getType(); }
1669 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1671 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
1673 Expr *getDimensionExpression() const { return Dimension; }
1675 static bool classof(const Stmt *T) {
1676 return T->getStmtClass() == ArrayTypeTraitExprClass;
1678 static bool classof(const ArrayTypeTraitExpr *) { return true; }
1681 child_range children() { return child_range(); }
1683 friend class ASTStmtReader;
1686 /// ExpressionTraitExpr - An expression trait intrinsic
1688 /// __is_lvalue_expr(std::cout) == true
1689 /// __is_lvalue_expr(1) == false
1690 class ExpressionTraitExpr : public Expr {
1691 /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned.
1693 /// The value of the type trait. Unspecified if dependent.
1696 /// Loc - The location of the type trait keyword.
1699 /// RParen - The location of the closing paren.
1700 SourceLocation RParen;
1702 Expr* QueriedExpression;
1704 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
1705 Expr *queried, bool value,
1706 SourceLocation rparen, QualType resultType)
1707 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1708 false, // Not type-dependent
1709 // Value-dependent if the argument is type-dependent.
1710 queried->isTypeDependent(),
1711 queried->isInstantiationDependent(),
1712 queried->containsUnexpandedParameterPack()),
1713 ET(et), Value(value), Loc(loc), RParen(rparen), QueriedExpression(queried) { }
1715 explicit ExpressionTraitExpr(EmptyShell Empty)
1716 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
1717 QueriedExpression() { }
1719 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1721 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
1723 Expr *getQueriedExpression() const { return QueriedExpression; }
1725 bool getValue() const { return Value; }
1727 static bool classof(const Stmt *T) {
1728 return T->getStmtClass() == ExpressionTraitExprClass;
1730 static bool classof(const ExpressionTraitExpr *) { return true; }
1733 child_range children() { return child_range(); }
1735 friend class ASTStmtReader;
1739 /// \brief A reference to an overloaded function set, either an
1740 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1741 class OverloadExpr : public Expr {
1742 /// The results. These are undesugared, which is to say, they may
1743 /// include UsingShadowDecls. Access is relative to the naming
1745 // FIXME: Allocate this data after the OverloadExpr subclass.
1746 DeclAccessPair *Results;
1747 unsigned NumResults;
1749 /// The common name of these declarations.
1750 DeclarationNameInfo NameInfo;
1752 /// \brief The nested-name-specifier that qualifies the name, if any.
1753 NestedNameSpecifierLoc QualifierLoc;
1756 /// True if the name was a template-id.
1757 bool HasExplicitTemplateArgs;
1759 OverloadExpr(StmtClass K, ASTContext &C,
1760 NestedNameSpecifierLoc QualifierLoc,
1761 const DeclarationNameInfo &NameInfo,
1762 const TemplateArgumentListInfo *TemplateArgs,
1763 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1764 bool KnownDependent,
1765 bool KnownInstantiationDependent,
1766 bool KnownContainsUnexpandedParameterPack);
1768 OverloadExpr(StmtClass K, EmptyShell Empty)
1769 : Expr(K, Empty), Results(0), NumResults(0),
1770 QualifierLoc(), HasExplicitTemplateArgs(false) { }
1772 void initializeResults(ASTContext &C,
1773 UnresolvedSetIterator Begin,
1774 UnresolvedSetIterator End);
1778 OverloadExpr *Expression;
1779 bool IsAddressOfOperand;
1780 bool HasFormOfMemberPointer;
1783 /// Finds the overloaded expression in the given expression of
1786 /// \return the expression (which must be there) and true if it has
1787 /// the particular form of a member pointer expression
1788 static FindResult find(Expr *E) {
1789 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1793 E = E->IgnoreParens();
1794 if (isa<UnaryOperator>(E)) {
1795 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
1796 E = cast<UnaryOperator>(E)->getSubExpr();
1797 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
1799 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
1800 Result.IsAddressOfOperand = true;
1801 Result.Expression = Ovl;
1803 Result.HasFormOfMemberPointer = false;
1804 Result.IsAddressOfOperand = false;
1805 Result.Expression = cast<OverloadExpr>(E);
1811 /// Gets the naming class of this lookup, if any.
1812 CXXRecordDecl *getNamingClass() const;
1814 typedef UnresolvedSetImpl::iterator decls_iterator;
1815 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1816 decls_iterator decls_end() const {
1817 return UnresolvedSetIterator(Results + NumResults);
1820 /// Gets the number of declarations in the unresolved set.
1821 unsigned getNumDecls() const { return NumResults; }
1823 /// Gets the full name info.
1824 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1826 /// Gets the name looked up.
1827 DeclarationName getName() const { return NameInfo.getName(); }
1829 /// Gets the location of the name.
1830 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
1832 /// Fetches the nested-name qualifier, if one was given.
1833 NestedNameSpecifier *getQualifier() const {
1834 return QualifierLoc.getNestedNameSpecifier();
1837 /// Fetches the nested-name qualifier with source-location information, if
1839 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1841 /// \brief Determines whether this expression had an explicit
1842 /// template argument list, e.g. f<int>.
1843 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1845 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1847 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1848 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1851 /// \brief Retrieves the optional explicit template arguments.
1852 /// This points to the same data as getExplicitTemplateArgs(), but
1853 /// returns null if there are no explicit template arguments.
1854 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1855 if (!hasExplicitTemplateArgs()) return 0;
1856 return &getExplicitTemplateArgs();
1859 static bool classof(const Stmt *T) {
1860 return T->getStmtClass() == UnresolvedLookupExprClass ||
1861 T->getStmtClass() == UnresolvedMemberExprClass;
1863 static bool classof(const OverloadExpr *) { return true; }
1865 friend class ASTStmtReader;
1866 friend class ASTStmtWriter;
1869 /// \brief A reference to a name which we were able to look up during
1870 /// parsing but could not resolve to a specific declaration. This
1871 /// arises in several ways:
1872 /// * we might be waiting for argument-dependent lookup
1873 /// * the name might resolve to an overloaded function
1875 /// * the lookup might have included a function template
1876 /// These never include UnresolvedUsingValueDecls, which are always
1877 /// class members and therefore appear only in
1878 /// UnresolvedMemberLookupExprs.
1879 class UnresolvedLookupExpr : public OverloadExpr {
1880 /// True if these lookup results should be extended by
1881 /// argument-dependent lookup if this is the operand of a function
1885 /// True if namespace ::std should be considered an associated namespace
1886 /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
1887 bool StdIsAssociatedNamespace;
1889 /// True if these lookup results are overloaded. This is pretty
1890 /// trivially rederivable if we urgently need to kill this field.
1893 /// The naming class (C++ [class.access.base]p5) of the lookup, if
1894 /// any. This can generally be recalculated from the context chain,
1895 /// but that can be fairly expensive for unqualified lookups. If we
1896 /// want to improve memory use here, this could go in a union
1897 /// against the qualified-lookup bits.
1898 CXXRecordDecl *NamingClass;
1900 UnresolvedLookupExpr(ASTContext &C,
1901 CXXRecordDecl *NamingClass,
1902 NestedNameSpecifierLoc QualifierLoc,
1903 const DeclarationNameInfo &NameInfo,
1904 bool RequiresADL, bool Overloaded,
1905 const TemplateArgumentListInfo *TemplateArgs,
1906 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1907 bool StdIsAssociatedNamespace)
1908 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, NameInfo,
1909 TemplateArgs, Begin, End, false, false, false),
1910 RequiresADL(RequiresADL),
1911 StdIsAssociatedNamespace(StdIsAssociatedNamespace),
1912 Overloaded(Overloaded), NamingClass(NamingClass)
1915 UnresolvedLookupExpr(EmptyShell Empty)
1916 : OverloadExpr(UnresolvedLookupExprClass, Empty),
1917 RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
1921 friend class ASTStmtReader;
1924 static UnresolvedLookupExpr *Create(ASTContext &C,
1925 CXXRecordDecl *NamingClass,
1926 NestedNameSpecifierLoc QualifierLoc,
1927 const DeclarationNameInfo &NameInfo,
1928 bool ADL, bool Overloaded,
1929 UnresolvedSetIterator Begin,
1930 UnresolvedSetIterator End,
1931 bool StdIsAssociatedNamespace = false) {
1932 assert((ADL || !StdIsAssociatedNamespace) &&
1933 "std considered associated namespace when not performing ADL");
1934 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
1935 ADL, Overloaded, 0, Begin, End,
1936 StdIsAssociatedNamespace);
1939 static UnresolvedLookupExpr *Create(ASTContext &C,
1940 CXXRecordDecl *NamingClass,
1941 NestedNameSpecifierLoc QualifierLoc,
1942 const DeclarationNameInfo &NameInfo,
1944 const TemplateArgumentListInfo &Args,
1945 UnresolvedSetIterator Begin,
1946 UnresolvedSetIterator End);
1948 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1949 bool HasExplicitTemplateArgs,
1950 unsigned NumTemplateArgs);
1952 /// True if this declaration should be extended by
1953 /// argument-dependent lookup.
1954 bool requiresADL() const { return RequiresADL; }
1956 /// True if namespace ::std should be artificially added to the set of
1957 /// associated namespaecs for argument-dependent lookup purposes.
1958 bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
1960 /// True if this lookup is overloaded.
1961 bool isOverloaded() const { return Overloaded; }
1963 /// Gets the 'naming class' (in the sense of C++0x
1964 /// [class.access.base]p5) of the lookup. This is the scope
1965 /// that was looked in to find these results.
1966 CXXRecordDecl *getNamingClass() const { return NamingClass; }
1968 // Note that, inconsistently with the explicit-template-argument AST
1969 // nodes, users are *forbidden* from calling these methods on objects
1970 // without explicit template arguments.
1972 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1973 assert(hasExplicitTemplateArgs());
1974 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1977 /// Gets a reference to the explicit template argument list.
1978 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1979 assert(hasExplicitTemplateArgs());
1980 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1983 /// \brief Retrieves the optional explicit template arguments.
1984 /// This points to the same data as getExplicitTemplateArgs(), but
1985 /// returns null if there are no explicit template arguments.
1986 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1987 if (!hasExplicitTemplateArgs()) return 0;
1988 return &getExplicitTemplateArgs();
1991 /// \brief Copies the template arguments (if present) into the given
1993 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1994 getExplicitTemplateArgs().copyInto(List);
1997 SourceLocation getLAngleLoc() const {
1998 return getExplicitTemplateArgs().LAngleLoc;
2001 SourceLocation getRAngleLoc() const {
2002 return getExplicitTemplateArgs().RAngleLoc;
2005 TemplateArgumentLoc const *getTemplateArgs() const {
2006 return getExplicitTemplateArgs().getTemplateArgs();
2009 unsigned getNumTemplateArgs() const {
2010 return getExplicitTemplateArgs().NumTemplateArgs;
2013 SourceRange getSourceRange() const {
2014 SourceRange Range(getNameInfo().getSourceRange());
2015 if (getQualifierLoc())
2016 Range.setBegin(getQualifierLoc().getBeginLoc());
2017 if (hasExplicitTemplateArgs())
2018 Range.setEnd(getRAngleLoc());
2022 child_range children() { return child_range(); }
2024 static bool classof(const Stmt *T) {
2025 return T->getStmtClass() == UnresolvedLookupExprClass;
2027 static bool classof(const UnresolvedLookupExpr *) { return true; }
2030 /// \brief A qualified reference to a name whose declaration cannot
2031 /// yet be resolved.
2033 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2034 /// it expresses a reference to a declaration such as
2035 /// X<T>::value. The difference, however, is that an
2036 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2037 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2038 /// this case, X<T>::value cannot resolve to a declaration because the
2039 /// declaration will differ from on instantiation of X<T> to the
2040 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2041 /// qualifier (X<T>::) and the name of the entity being referenced
2042 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2043 /// declaration can be found.
2044 class DependentScopeDeclRefExpr : public Expr {
2045 /// \brief The nested-name-specifier that qualifies this unresolved
2046 /// declaration name.
2047 NestedNameSpecifierLoc QualifierLoc;
2049 /// The name of the entity we will be referencing.
2050 DeclarationNameInfo NameInfo;
2052 /// \brief Whether the name includes explicit template arguments.
2053 bool HasExplicitTemplateArgs;
2055 DependentScopeDeclRefExpr(QualType T,
2056 NestedNameSpecifierLoc QualifierLoc,
2057 const DeclarationNameInfo &NameInfo,
2058 const TemplateArgumentListInfo *Args);
2061 static DependentScopeDeclRefExpr *Create(ASTContext &C,
2062 NestedNameSpecifierLoc QualifierLoc,
2063 const DeclarationNameInfo &NameInfo,
2064 const TemplateArgumentListInfo *TemplateArgs = 0);
2066 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2067 bool HasExplicitTemplateArgs,
2068 unsigned NumTemplateArgs);
2070 /// \brief Retrieve the name that this expression refers to.
2071 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2073 /// \brief Retrieve the name that this expression refers to.
2074 DeclarationName getDeclName() const { return NameInfo.getName(); }
2076 /// \brief Retrieve the location of the name within the expression.
2077 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2079 /// \brief Retrieve the nested-name-specifier that qualifies the
2080 /// name, with source location information.
2081 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2084 /// \brief Retrieve the nested-name-specifier that qualifies this
2086 NestedNameSpecifier *getQualifier() const {
2087 return QualifierLoc.getNestedNameSpecifier();
2090 /// Determines whether this lookup had explicit template arguments.
2091 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
2093 // Note that, inconsistently with the explicit-template-argument AST
2094 // nodes, users are *forbidden* from calling these methods on objects
2095 // without explicit template arguments.
2097 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2098 assert(hasExplicitTemplateArgs());
2099 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
2102 /// Gets a reference to the explicit template argument list.
2103 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2104 assert(hasExplicitTemplateArgs());
2105 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
2108 /// \brief Retrieves the optional explicit template arguments.
2109 /// This points to the same data as getExplicitTemplateArgs(), but
2110 /// returns null if there are no explicit template arguments.
2111 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2112 if (!hasExplicitTemplateArgs()) return 0;
2113 return &getExplicitTemplateArgs();
2116 /// \brief Copies the template arguments (if present) into the given
2118 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2119 getExplicitTemplateArgs().copyInto(List);
2122 SourceLocation getLAngleLoc() const {
2123 return getExplicitTemplateArgs().LAngleLoc;
2126 SourceLocation getRAngleLoc() const {
2127 return getExplicitTemplateArgs().RAngleLoc;
2130 TemplateArgumentLoc const *getTemplateArgs() const {
2131 return getExplicitTemplateArgs().getTemplateArgs();
2134 unsigned getNumTemplateArgs() const {
2135 return getExplicitTemplateArgs().NumTemplateArgs;
2138 SourceRange getSourceRange() const {
2139 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2140 if (hasExplicitTemplateArgs())
2141 Range.setEnd(getRAngleLoc());
2145 static bool classof(const Stmt *T) {
2146 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2148 static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2150 child_range children() { return child_range(); }
2152 friend class ASTStmtReader;
2153 friend class ASTStmtWriter;
2156 /// Represents an expression --- generally a full-expression --- which
2157 /// introduces cleanups to be run at the end of the sub-expression's
2158 /// evaluation. The most common source of expression-introduced
2159 /// cleanups is temporary objects in C++, but several other C++
2160 /// expressions can create cleanups.
2161 class ExprWithCleanups : public Expr {
2164 CXXTemporary **Temps;
2167 ExprWithCleanups(ASTContext &C, Expr *SubExpr,
2168 CXXTemporary **Temps, unsigned NumTemps);
2171 ExprWithCleanups(EmptyShell Empty)
2172 : Expr(ExprWithCleanupsClass, Empty),
2173 SubExpr(0), Temps(0), NumTemps(0) {}
2175 static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr,
2176 CXXTemporary **Temps,
2179 unsigned getNumTemporaries() const { return NumTemps; }
2180 void setNumTemporaries(ASTContext &C, unsigned N);
2182 CXXTemporary *getTemporary(unsigned i) {
2183 assert(i < NumTemps && "Index out of range");
2186 const CXXTemporary *getTemporary(unsigned i) const {
2187 return const_cast<ExprWithCleanups*>(this)->getTemporary(i);
2189 void setTemporary(unsigned i, CXXTemporary *T) {
2190 assert(i < NumTemps && "Index out of range");
2194 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2195 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2196 void setSubExpr(Expr *E) { SubExpr = E; }
2198 SourceRange getSourceRange() const {
2199 return SubExpr->getSourceRange();
2202 // Implement isa/cast/dyncast/etc.
2203 static bool classof(const Stmt *T) {
2204 return T->getStmtClass() == ExprWithCleanupsClass;
2206 static bool classof(const ExprWithCleanups *) { return true; }
2209 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2212 /// \brief Describes an explicit type conversion that uses functional
2213 /// notion but could not be resolved because one or more arguments are
2216 /// The explicit type conversions expressed by
2217 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2218 /// where \c T is some type and \c a1, a2, ..., aN are values, and
2219 /// either \C T is a dependent type or one or more of the \c a's is
2220 /// type-dependent. For example, this would occur in a template such
2224 /// template<typename T, typename A1>
2225 /// inline T make_a(const A1& a1) {
2230 /// When the returned expression is instantiated, it may resolve to a
2231 /// constructor call, conversion function call, or some kind of type
2233 class CXXUnresolvedConstructExpr : public Expr {
2234 /// \brief The type being constructed.
2235 TypeSourceInfo *Type;
2237 /// \brief The location of the left parentheses ('(').
2238 SourceLocation LParenLoc;
2240 /// \brief The location of the right parentheses (')').
2241 SourceLocation RParenLoc;
2243 /// \brief The number of arguments used to construct the type.
2246 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2247 SourceLocation LParenLoc,
2250 SourceLocation RParenLoc);
2252 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2253 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2255 friend class ASTStmtReader;
2258 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2259 TypeSourceInfo *Type,
2260 SourceLocation LParenLoc,
2263 SourceLocation RParenLoc);
2265 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2268 /// \brief Retrieve the type that is being constructed, as specified
2269 /// in the source code.
2270 QualType getTypeAsWritten() const { return Type->getType(); }
2272 /// \brief Retrieve the type source information for the type being
2274 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2276 /// \brief Retrieve the location of the left parentheses ('(') that
2277 /// precedes the argument list.
2278 SourceLocation getLParenLoc() const { return LParenLoc; }
2279 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2281 /// \brief Retrieve the location of the right parentheses (')') that
2282 /// follows the argument list.
2283 SourceLocation getRParenLoc() const { return RParenLoc; }
2284 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2286 /// \brief Retrieve the number of arguments.
2287 unsigned arg_size() const { return NumArgs; }
2289 typedef Expr** arg_iterator;
2290 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2291 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2293 typedef const Expr* const * const_arg_iterator;
2294 const_arg_iterator arg_begin() const {
2295 return reinterpret_cast<const Expr* const *>(this + 1);
2297 const_arg_iterator arg_end() const {
2298 return arg_begin() + NumArgs;
2301 Expr *getArg(unsigned I) {
2302 assert(I < NumArgs && "Argument index out-of-range");
2303 return *(arg_begin() + I);
2306 const Expr *getArg(unsigned I) const {
2307 assert(I < NumArgs && "Argument index out-of-range");
2308 return *(arg_begin() + I);
2311 void setArg(unsigned I, Expr *E) {
2312 assert(I < NumArgs && "Argument index out-of-range");
2313 *(arg_begin() + I) = E;
2316 SourceRange getSourceRange() const;
2318 static bool classof(const Stmt *T) {
2319 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2321 static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2324 child_range children() {
2325 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2326 return child_range(begin, begin + NumArgs);
2330 /// \brief Represents a C++ member access expression where the actual
2331 /// member referenced could not be resolved because the base
2332 /// expression or the member name was dependent.
2334 /// Like UnresolvedMemberExprs, these can be either implicit or
2335 /// explicit accesses. It is only possible to get one of these with
2336 /// an implicit access if a qualifier is provided.
2337 class CXXDependentScopeMemberExpr : public Expr {
2338 /// \brief The expression for the base pointer or class reference,
2339 /// e.g., the \c x in x.f. Can be null in implicit accesses.
2342 /// \brief The type of the base expression. Never null, even for
2343 /// implicit accesses.
2346 /// \brief Whether this member expression used the '->' operator or
2347 /// the '.' operator.
2350 /// \brief Whether this member expression has explicitly-specified template
2352 bool HasExplicitTemplateArgs : 1;
2354 /// \brief The location of the '->' or '.' operator.
2355 SourceLocation OperatorLoc;
2357 /// \brief The nested-name-specifier that precedes the member name, if any.
2358 NestedNameSpecifierLoc QualifierLoc;
2360 /// \brief In a qualified member access expression such as t->Base::f, this
2361 /// member stores the resolves of name lookup in the context of the member
2362 /// access expression, to be used at instantiation time.
2364 /// FIXME: This member, along with the QualifierLoc, could
2365 /// be stuck into a structure that is optionally allocated at the end of
2366 /// the CXXDependentScopeMemberExpr, to save space in the common case.
2367 NamedDecl *FirstQualifierFoundInScope;
2369 /// \brief The member to which this member expression refers, which
2370 /// can be name, overloaded operator, or destructor.
2371 /// FIXME: could also be a template-id
2372 DeclarationNameInfo MemberNameInfo;
2374 CXXDependentScopeMemberExpr(ASTContext &C,
2375 Expr *Base, QualType BaseType, bool IsArrow,
2376 SourceLocation OperatorLoc,
2377 NestedNameSpecifierLoc QualifierLoc,
2378 NamedDecl *FirstQualifierFoundInScope,
2379 DeclarationNameInfo MemberNameInfo,
2380 const TemplateArgumentListInfo *TemplateArgs);
2383 CXXDependentScopeMemberExpr(ASTContext &C,
2384 Expr *Base, QualType BaseType,
2386 SourceLocation OperatorLoc,
2387 NestedNameSpecifierLoc QualifierLoc,
2388 NamedDecl *FirstQualifierFoundInScope,
2389 DeclarationNameInfo MemberNameInfo);
2391 static CXXDependentScopeMemberExpr *
2392 Create(ASTContext &C,
2393 Expr *Base, QualType BaseType, bool IsArrow,
2394 SourceLocation OperatorLoc,
2395 NestedNameSpecifierLoc QualifierLoc,
2396 NamedDecl *FirstQualifierFoundInScope,
2397 DeclarationNameInfo MemberNameInfo,
2398 const TemplateArgumentListInfo *TemplateArgs);
2400 static CXXDependentScopeMemberExpr *
2401 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2402 unsigned NumTemplateArgs);
2404 /// \brief True if this is an implicit access, i.e. one in which the
2405 /// member being accessed was not written in the source. The source
2406 /// location of the operator is invalid in this case.
2407 bool isImplicitAccess() const;
2409 /// \brief Retrieve the base object of this member expressions,
2410 /// e.g., the \c x in \c x.m.
2411 Expr *getBase() const {
2412 assert(!isImplicitAccess());
2413 return cast<Expr>(Base);
2416 QualType getBaseType() const { return BaseType; }
2418 /// \brief Determine whether this member expression used the '->'
2419 /// operator; otherwise, it used the '.' operator.
2420 bool isArrow() const { return IsArrow; }
2422 /// \brief Retrieve the location of the '->' or '.' operator.
2423 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2425 /// \brief Retrieve the nested-name-specifier that qualifies the member
2427 NestedNameSpecifier *getQualifier() const {
2428 return QualifierLoc.getNestedNameSpecifier();
2431 /// \brief Retrieve the nested-name-specifier that qualifies the member
2432 /// name, with source location information.
2433 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2436 /// \brief Retrieve the first part of the nested-name-specifier that was
2437 /// found in the scope of the member access expression when the member access
2438 /// was initially parsed.
2440 /// This function only returns a useful result when member access expression
2441 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2442 /// returned by this function describes what was found by unqualified name
2443 /// lookup for the identifier "Base" within the scope of the member access
2444 /// expression itself. At template instantiation time, this information is
2445 /// combined with the results of name lookup into the type of the object
2446 /// expression itself (the class type of x).
2447 NamedDecl *getFirstQualifierFoundInScope() const {
2448 return FirstQualifierFoundInScope;
2451 /// \brief Retrieve the name of the member that this expression
2453 const DeclarationNameInfo &getMemberNameInfo() const {
2454 return MemberNameInfo;
2457 /// \brief Retrieve the name of the member that this expression
2459 DeclarationName getMember() const { return MemberNameInfo.getName(); }
2461 // \brief Retrieve the location of the name of the member that this
2462 // expression refers to.
2463 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2465 /// \brief Determines whether this member expression actually had a C++
2466 /// template argument list explicitly specified, e.g., x.f<int>.
2467 bool hasExplicitTemplateArgs() const {
2468 return HasExplicitTemplateArgs;
2471 /// \brief Retrieve the explicit template argument list that followed the
2472 /// member template name, if any.
2473 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2474 assert(HasExplicitTemplateArgs);
2475 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2478 /// \brief Retrieve the explicit template argument list that followed the
2479 /// member template name, if any.
2480 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2481 return const_cast<CXXDependentScopeMemberExpr *>(this)
2482 ->getExplicitTemplateArgs();
2485 /// \brief Retrieves the optional explicit template arguments.
2486 /// This points to the same data as getExplicitTemplateArgs(), but
2487 /// returns null if there are no explicit template arguments.
2488 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2489 if (!hasExplicitTemplateArgs()) return 0;
2490 return &getExplicitTemplateArgs();
2493 /// \brief Copies the template arguments (if present) into the given
2495 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2496 getExplicitTemplateArgs().copyInto(List);
2499 /// \brief Initializes the template arguments using the given structure.
2500 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2501 getExplicitTemplateArgs().initializeFrom(List);
2504 /// \brief Retrieve the location of the left angle bracket following the
2505 /// member name ('<'), if any.
2506 SourceLocation getLAngleLoc() const {
2507 return getExplicitTemplateArgs().LAngleLoc;
2510 /// \brief Retrieve the template arguments provided as part of this
2512 const TemplateArgumentLoc *getTemplateArgs() const {
2513 return getExplicitTemplateArgs().getTemplateArgs();
2516 /// \brief Retrieve the number of template arguments provided as part of this
2518 unsigned getNumTemplateArgs() const {
2519 return getExplicitTemplateArgs().NumTemplateArgs;
2522 /// \brief Retrieve the location of the right angle bracket following the
2523 /// template arguments ('>').
2524 SourceLocation getRAngleLoc() const {
2525 return getExplicitTemplateArgs().RAngleLoc;
2528 SourceRange getSourceRange() const {
2530 if (!isImplicitAccess())
2531 Range.setBegin(Base->getSourceRange().getBegin());
2532 else if (getQualifier())
2533 Range.setBegin(getQualifierLoc().getBeginLoc());
2535 Range.setBegin(MemberNameInfo.getBeginLoc());
2537 if (hasExplicitTemplateArgs())
2538 Range.setEnd(getRAngleLoc());
2540 Range.setEnd(MemberNameInfo.getEndLoc());
2544 static bool classof(const Stmt *T) {
2545 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2547 static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2550 child_range children() {
2551 if (isImplicitAccess()) return child_range();
2552 return child_range(&Base, &Base + 1);
2555 friend class ASTStmtReader;
2556 friend class ASTStmtWriter;
2559 /// \brief Represents a C++ member access expression for which lookup
2560 /// produced a set of overloaded functions.
2562 /// The member access may be explicit or implicit:
2565 /// int explicitAccess() { return this->a + this->A::b; }
2566 /// int implicitAccess() { return a + A::b; }
2569 /// In the final AST, an explicit access always becomes a MemberExpr.
2570 /// An implicit access may become either a MemberExpr or a
2571 /// DeclRefExpr, depending on whether the member is static.
2572 class UnresolvedMemberExpr : public OverloadExpr {
2573 /// \brief Whether this member expression used the '->' operator or
2574 /// the '.' operator.
2577 /// \brief Whether the lookup results contain an unresolved using
2579 bool HasUnresolvedUsing : 1;
2581 /// \brief The expression for the base pointer or class reference,
2582 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
2583 /// member expression
2586 /// \brief The type of the base expression; never null.
2589 /// \brief The location of the '->' or '.' operator.
2590 SourceLocation OperatorLoc;
2592 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
2593 Expr *Base, QualType BaseType, bool IsArrow,
2594 SourceLocation OperatorLoc,
2595 NestedNameSpecifierLoc QualifierLoc,
2596 const DeclarationNameInfo &MemberNameInfo,
2597 const TemplateArgumentListInfo *TemplateArgs,
2598 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2600 UnresolvedMemberExpr(EmptyShell Empty)
2601 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2602 HasUnresolvedUsing(false), Base(0) { }
2604 friend class ASTStmtReader;
2607 static UnresolvedMemberExpr *
2608 Create(ASTContext &C, bool HasUnresolvedUsing,
2609 Expr *Base, QualType BaseType, bool IsArrow,
2610 SourceLocation OperatorLoc,
2611 NestedNameSpecifierLoc QualifierLoc,
2612 const DeclarationNameInfo &MemberNameInfo,
2613 const TemplateArgumentListInfo *TemplateArgs,
2614 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2616 static UnresolvedMemberExpr *
2617 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2618 unsigned NumTemplateArgs);
2620 /// \brief True if this is an implicit access, i.e. one in which the
2621 /// member being accessed was not written in the source. The source
2622 /// location of the operator is invalid in this case.
2623 bool isImplicitAccess() const;
2625 /// \brief Retrieve the base object of this member expressions,
2626 /// e.g., the \c x in \c x.m.
2628 assert(!isImplicitAccess());
2629 return cast<Expr>(Base);
2631 const Expr *getBase() const {
2632 assert(!isImplicitAccess());
2633 return cast<Expr>(Base);
2636 QualType getBaseType() const { return BaseType; }
2638 /// \brief Determine whether the lookup results contain an unresolved using
2640 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2642 /// \brief Determine whether this member expression used the '->'
2643 /// operator; otherwise, it used the '.' operator.
2644 bool isArrow() const { return IsArrow; }
2646 /// \brief Retrieve the location of the '->' or '.' operator.
2647 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2649 /// \brief Retrieves the naming class of this lookup.
2650 CXXRecordDecl *getNamingClass() const;
2652 /// \brief Retrieve the full name info for the member that this expression
2654 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
2656 /// \brief Retrieve the name of the member that this expression
2658 DeclarationName getMemberName() const { return getName(); }
2660 // \brief Retrieve the location of the name of the member that this
2661 // expression refers to.
2662 SourceLocation getMemberLoc() const { return getNameLoc(); }
2664 /// \brief Retrieve the explicit template argument list that followed the
2665 /// member template name.
2666 ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2667 assert(hasExplicitTemplateArgs());
2668 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2671 /// \brief Retrieve the explicit template argument list that followed the
2672 /// member template name, if any.
2673 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2674 assert(hasExplicitTemplateArgs());
2675 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2678 /// \brief Retrieves the optional explicit template arguments.
2679 /// This points to the same data as getExplicitTemplateArgs(), but
2680 /// returns null if there are no explicit template arguments.
2681 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2682 if (!hasExplicitTemplateArgs()) return 0;
2683 return &getExplicitTemplateArgs();
2686 /// \brief Copies the template arguments into the given structure.
2687 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2688 getExplicitTemplateArgs().copyInto(List);
2691 /// \brief Retrieve the location of the left angle bracket following
2692 /// the member name ('<').
2693 SourceLocation getLAngleLoc() const {
2694 return getExplicitTemplateArgs().LAngleLoc;
2697 /// \brief Retrieve the template arguments provided as part of this
2699 const TemplateArgumentLoc *getTemplateArgs() const {
2700 return getExplicitTemplateArgs().getTemplateArgs();
2703 /// \brief Retrieve the number of template arguments provided as
2704 /// part of this template-id.
2705 unsigned getNumTemplateArgs() const {
2706 return getExplicitTemplateArgs().NumTemplateArgs;
2709 /// \brief Retrieve the location of the right angle bracket
2710 /// following the template arguments ('>').
2711 SourceLocation getRAngleLoc() const {
2712 return getExplicitTemplateArgs().RAngleLoc;
2715 SourceRange getSourceRange() const {
2716 SourceRange Range = getMemberNameInfo().getSourceRange();
2717 if (!isImplicitAccess())
2718 Range.setBegin(Base->getSourceRange().getBegin());
2719 else if (getQualifierLoc())
2720 Range.setBegin(getQualifierLoc().getBeginLoc());
2722 if (hasExplicitTemplateArgs())
2723 Range.setEnd(getRAngleLoc());
2727 static bool classof(const Stmt *T) {
2728 return T->getStmtClass() == UnresolvedMemberExprClass;
2730 static bool classof(const UnresolvedMemberExpr *) { return true; }
2733 child_range children() {
2734 if (isImplicitAccess()) return child_range();
2735 return child_range(&Base, &Base + 1);
2739 /// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
2741 /// The noexcept expression tests whether a given expression might throw. Its
2742 /// result is a boolean constant.
2743 class CXXNoexceptExpr : public Expr {
2748 friend class ASTStmtReader;
2751 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
2752 SourceLocation Keyword, SourceLocation RParen)
2753 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
2754 /*TypeDependent*/false,
2755 /*ValueDependent*/Val == CT_Dependent,
2756 Val == CT_Dependent || Operand->isInstantiationDependent(),
2757 Operand->containsUnexpandedParameterPack()),
2758 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
2761 CXXNoexceptExpr(EmptyShell Empty)
2762 : Expr(CXXNoexceptExprClass, Empty)
2765 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
2767 SourceRange getSourceRange() const { return Range; }
2769 bool getValue() const { return Value; }
2771 static bool classof(const Stmt *T) {
2772 return T->getStmtClass() == CXXNoexceptExprClass;
2774 static bool classof(const CXXNoexceptExpr *) { return true; }
2777 child_range children() { return child_range(&Operand, &Operand + 1); }
2780 /// \brief Represents a C++0x pack expansion that produces a sequence of
2783 /// A pack expansion expression contains a pattern (which itself is an
2784 /// expression) followed by an ellipsis. For example:
2787 /// template<typename F, typename ...Types>
2788 /// void forward(F f, Types &&...args) {
2789 /// f(static_cast<Types&&>(args)...);
2793 /// Here, the argument to the function object \c f is a pack expansion whose
2794 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
2795 /// template is instantiated, the pack expansion will instantiate to zero or
2796 /// or more function arguments to the function object \c f.
2797 class PackExpansionExpr : public Expr {
2798 SourceLocation EllipsisLoc;
2800 /// \brief The number of expansions that will be produced by this pack
2801 /// expansion expression, if known.
2803 /// When zero, the number of expansions is not known. Otherwise, this value
2804 /// is the number of expansions + 1.
2805 unsigned NumExpansions;
2809 friend class ASTStmtReader;
2810 friend class ASTStmtWriter;
2813 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
2814 llvm::Optional<unsigned> NumExpansions)
2815 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
2816 Pattern->getObjectKind(), /*TypeDependent=*/true,
2817 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
2818 /*ContainsUnexpandedParameterPack=*/false),
2819 EllipsisLoc(EllipsisLoc),
2820 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
2821 Pattern(Pattern) { }
2823 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
2825 /// \brief Retrieve the pattern of the pack expansion.
2826 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
2828 /// \brief Retrieve the pattern of the pack expansion.
2829 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
2831 /// \brief Retrieve the location of the ellipsis that describes this pack
2833 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2835 /// \brief Determine the number of expansions that will be produced when
2836 /// this pack expansion is instantiated, if already known.
2837 llvm::Optional<unsigned> getNumExpansions() const {
2839 return NumExpansions - 1;
2841 return llvm::Optional<unsigned>();
2844 SourceRange getSourceRange() const {
2845 return SourceRange(Pattern->getLocStart(), EllipsisLoc);
2848 static bool classof(const Stmt *T) {
2849 return T->getStmtClass() == PackExpansionExprClass;
2851 static bool classof(const PackExpansionExpr *) { return true; }
2854 child_range children() {
2855 return child_range(&Pattern, &Pattern + 1);
2859 inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2860 if (isa<UnresolvedLookupExpr>(this))
2861 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2863 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2866 /// \brief Represents an expression that computes the length of a parameter
2870 /// template<typename ...Types>
2872 /// static const unsigned value = sizeof...(Types);
2875 class SizeOfPackExpr : public Expr {
2876 /// \brief The location of the 'sizeof' keyword.
2877 SourceLocation OperatorLoc;
2879 /// \brief The location of the name of the parameter pack.
2880 SourceLocation PackLoc;
2882 /// \brief The location of the closing parenthesis.
2883 SourceLocation RParenLoc;
2885 /// \brief The length of the parameter pack, if known.
2887 /// When this expression is value-dependent, the length of the parameter pack
2888 /// is unknown. When this expression is not value-dependent, the length is
2892 /// \brief The parameter pack itself.
2895 friend class ASTStmtReader;
2896 friend class ASTStmtWriter;
2899 /// \brief Creates a value-dependent expression that computes the length of
2900 /// the given parameter pack.
2901 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2902 SourceLocation PackLoc, SourceLocation RParenLoc)
2903 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2904 /*TypeDependent=*/false, /*ValueDependent=*/true,
2905 /*InstantiationDependent=*/true,
2906 /*ContainsUnexpandedParameterPack=*/false),
2907 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2908 Length(0), Pack(Pack) { }
2910 /// \brief Creates an expression that computes the length of
2911 /// the given parameter pack, which is already known.
2912 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2913 SourceLocation PackLoc, SourceLocation RParenLoc,
2915 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2916 /*TypeDependent=*/false, /*ValueDependent=*/false,
2917 /*InstantiationDependent=*/false,
2918 /*ContainsUnexpandedParameterPack=*/false),
2919 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2920 Length(Length), Pack(Pack) { }
2922 /// \brief Create an empty expression.
2923 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
2925 /// \brief Determine the location of the 'sizeof' keyword.
2926 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2928 /// \brief Determine the location of the parameter pack.
2929 SourceLocation getPackLoc() const { return PackLoc; }
2931 /// \brief Determine the location of the right parenthesis.
2932 SourceLocation getRParenLoc() const { return RParenLoc; }
2934 /// \brief Retrieve the parameter pack.
2935 NamedDecl *getPack() const { return Pack; }
2937 /// \brief Retrieve the length of the parameter pack.
2939 /// This routine may only be invoked when the expression is not
2940 /// value-dependent.
2941 unsigned getPackLength() const {
2942 assert(!isValueDependent() &&
2943 "Cannot get the length of a value-dependent pack size expression");
2947 SourceRange getSourceRange() const {
2948 return SourceRange(OperatorLoc, RParenLoc);
2951 static bool classof(const Stmt *T) {
2952 return T->getStmtClass() == SizeOfPackExprClass;
2954 static bool classof(const SizeOfPackExpr *) { return true; }
2957 child_range children() { return child_range(); }
2960 /// \brief Represents a reference to a non-type template parameter
2961 /// that has been substituted with a template argument.
2962 class SubstNonTypeTemplateParmExpr : public Expr {
2963 /// \brief The replaced parameter.
2964 NonTypeTemplateParmDecl *Param;
2966 /// \brief The replacement expression.
2969 /// \brief The location of the non-type template parameter reference.
2970 SourceLocation NameLoc;
2972 friend class ASTReader;
2973 friend class ASTStmtReader;
2974 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
2975 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
2978 SubstNonTypeTemplateParmExpr(QualType type,
2979 ExprValueKind valueKind,
2981 NonTypeTemplateParmDecl *param,
2983 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
2984 replacement->isTypeDependent(), replacement->isValueDependent(),
2985 replacement->isInstantiationDependent(),
2986 replacement->containsUnexpandedParameterPack()),
2987 Param(param), Replacement(replacement), NameLoc(loc) {}
2989 SourceLocation getNameLoc() const { return NameLoc; }
2990 SourceRange getSourceRange() const { return NameLoc; }
2992 Expr *getReplacement() const { return cast<Expr>(Replacement); }
2994 NonTypeTemplateParmDecl *getParameter() const { return Param; }
2996 static bool classof(const Stmt *s) {
2997 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
2999 static bool classof(const SubstNonTypeTemplateParmExpr *) {
3004 child_range children() { return child_range(&Replacement, &Replacement+1); }
3007 /// \brief Represents a reference to a non-type template parameter pack that
3008 /// has been substituted with a non-template argument pack.
3010 /// When a pack expansion in the source code contains multiple parameter packs
3011 /// and those parameter packs correspond to different levels of template
3012 /// parameter lists, this node node is used to represent a non-type template
3013 /// parameter pack from an outer level, which has already had its argument pack
3014 /// substituted but that still lives within a pack expansion that itself
3015 /// could not be instantiated. When actually performing a substitution into
3016 /// that pack expansion (e.g., when all template parameters have corresponding
3017 /// arguments), this type will be replaced with the appropriate underlying
3018 /// expression at the current pack substitution index.
3019 class SubstNonTypeTemplateParmPackExpr : public Expr {
3020 /// \brief The non-type template parameter pack itself.
3021 NonTypeTemplateParmDecl *Param;
3023 /// \brief A pointer to the set of template arguments that this
3024 /// parameter pack is instantiated with.
3025 const TemplateArgument *Arguments;
3027 /// \brief The number of template arguments in \c Arguments.
3028 unsigned NumArguments;
3030 /// \brief The location of the non-type template parameter pack reference.
3031 SourceLocation NameLoc;
3033 friend class ASTReader;
3034 friend class ASTStmtReader;
3035 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3036 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3039 SubstNonTypeTemplateParmPackExpr(QualType T,
3040 NonTypeTemplateParmDecl *Param,
3041 SourceLocation NameLoc,
3042 const TemplateArgument &ArgPack);
3044 /// \brief Retrieve the non-type template parameter pack being substituted.
3045 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3047 /// \brief Retrieve the location of the parameter pack name.
3048 SourceLocation getParameterPackLocation() const { return NameLoc; }
3050 /// \brief Retrieve the template argument pack containing the substituted
3051 /// template arguments.
3052 TemplateArgument getArgumentPack() const;
3054 SourceRange getSourceRange() const { return NameLoc; }
3056 static bool classof(const Stmt *T) {
3057 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3059 static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
3064 child_range children() { return child_range(); }
3067 /// \brief Represents a prvalue temporary that written into memory so that
3068 /// a reference can bind to it.
3070 /// Prvalue expressions are materialized when they need to have an address
3071 /// in memory for a reference to bind to. This happens when binding a
3072 /// reference to the result of a conversion, e.g.,
3075 /// const int &r = 1.0;
3078 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3079 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3080 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3081 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3082 /// to it), maintaining the invariant that references always bind to glvalues.
3083 class MaterializeTemporaryExpr : public Expr {
3084 /// \brief The temporary-generating expression whose value will be
3088 friend class ASTStmtReader;
3089 friend class ASTStmtWriter;
3092 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3093 bool BoundToLvalueReference)
3094 : Expr(MaterializeTemporaryExprClass, T,
3095 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3096 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3097 Temporary->isInstantiationDependent(),
3098 Temporary->containsUnexpandedParameterPack()),
3099 Temporary(Temporary) { }
3101 MaterializeTemporaryExpr(EmptyShell Empty)
3102 : Expr(MaterializeTemporaryExprClass, Empty) { }
3104 /// \brief Retrieve the temporary-generating subexpression whose value will
3105 /// be materialized into a glvalue.
3106 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3108 /// \brief Determine whether this materialized temporary is bound to an
3109 /// lvalue reference; otherwise, it's bound to an rvalue reference.
3110 bool isBoundToLvalueReference() const {
3111 return getValueKind() == VK_LValue;
3114 SourceRange getSourceRange() const { return Temporary->getSourceRange(); }
3116 static bool classof(const Stmt *T) {
3117 return T->getStmtClass() == MaterializeTemporaryExprClass;
3119 static bool classof(const MaterializeTemporaryExpr *) {
3124 child_range children() { return child_range(&Temporary, &Temporary + 1); }
3127 } // end namespace clang