1 //===--- StmtObjC.cpp - Classes for representing ObjC statements ---------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the subclesses of Stmt class declared in StmtObjC.h
11 //===----------------------------------------------------------------------===//
13 #include "clang/AST/StmtObjC.h"
15 #include "clang/AST/Expr.h"
16 #include "clang/AST/ASTContext.h"
18 using namespace clang
;
20 ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt
*Elem
, Expr
*Collect
,
21 Stmt
*Body
, SourceLocation FCL
,
23 : Stmt(ObjCForCollectionStmtClass
) {
24 SubExprs
[ELEM
] = Elem
;
25 SubExprs
[COLLECTION
] = Collect
;
26 SubExprs
[BODY
] = Body
;
31 ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc
, Stmt
*atTryStmt
,
32 Stmt
**CatchStmts
, unsigned NumCatchStmts
,
34 : Stmt(ObjCAtTryStmtClass
), AtTryLoc(atTryLoc
),
35 NumCatchStmts(NumCatchStmts
), HasFinally(atFinallyStmt
!= nullptr) {
36 Stmt
**Stmts
= getStmts();
38 for (unsigned I
= 0; I
!= NumCatchStmts
; ++I
)
39 Stmts
[I
+ 1] = CatchStmts
[I
];
42 Stmts
[NumCatchStmts
+ 1] = atFinallyStmt
;
45 ObjCAtTryStmt
*ObjCAtTryStmt::Create(const ASTContext
&Context
,
46 SourceLocation atTryLoc
, Stmt
*atTryStmt
,
47 Stmt
**CatchStmts
, unsigned NumCatchStmts
,
48 Stmt
*atFinallyStmt
) {
50 totalSizeToAlloc
<Stmt
*>(1 + NumCatchStmts
+ (atFinallyStmt
!= nullptr));
51 void *Mem
= Context
.Allocate(Size
, alignof(ObjCAtTryStmt
));
52 return new (Mem
) ObjCAtTryStmt(atTryLoc
, atTryStmt
, CatchStmts
, NumCatchStmts
,
56 ObjCAtTryStmt
*ObjCAtTryStmt::CreateEmpty(const ASTContext
&Context
,
57 unsigned NumCatchStmts
,
59 size_t Size
= totalSizeToAlloc
<Stmt
*>(1 + NumCatchStmts
+ HasFinally
);
60 void *Mem
= Context
.Allocate(Size
, alignof(ObjCAtTryStmt
));
61 return new (Mem
) ObjCAtTryStmt(EmptyShell(), NumCatchStmts
, HasFinally
);
64 SourceLocation
ObjCAtTryStmt::getEndLoc() const {
66 return getFinallyStmt()->getEndLoc();
68 return getCatchStmt(NumCatchStmts
- 1)->getEndLoc();
69 return getTryBody()->getEndLoc();