clang  10.0.0svn
StmtObjC.cpp
Go to the documentation of this file.
1 //===--- StmtObjC.cpp - Classes for representing ObjC statements ---------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the subclesses of Stmt class declared in StmtObjC.h
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/AST/StmtObjC.h"
14 
15 #include "clang/AST/Expr.h"
16 #include "clang/AST/ASTContext.h"
17 
18 using namespace clang;
19 
21  Stmt *Body, SourceLocation FCL,
22  SourceLocation RPL)
23  : Stmt(ObjCForCollectionStmtClass) {
24  SubExprs[ELEM] = Elem;
25  SubExprs[COLLECTION] = Collect;
26  SubExprs[BODY] = Body;
27  ForLoc = FCL;
28  RParenLoc = RPL;
29 }
30 
31 ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
32  Stmt **CatchStmts, unsigned NumCatchStmts,
33  Stmt *atFinallyStmt)
34  : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
35  NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) {
36  Stmt **Stmts = getStmts();
37  Stmts[0] = atTryStmt;
38  for (unsigned I = 0; I != NumCatchStmts; ++I)
39  Stmts[I + 1] = CatchStmts[I];
40 
41  if (HasFinally)
42  Stmts[NumCatchStmts + 1] = atFinallyStmt;
43 }
44 
46  SourceLocation atTryLoc, Stmt *atTryStmt,
47  Stmt **CatchStmts, unsigned NumCatchStmts,
48  Stmt *atFinallyStmt) {
49  unsigned Size =
50  sizeof(ObjCAtTryStmt) +
51  (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
52  void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
53  return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
54  atFinallyStmt);
55 }
56 
58  unsigned NumCatchStmts,
59  bool HasFinally) {
60  unsigned Size =
61  sizeof(ObjCAtTryStmt) + (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
62  void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
63  return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
64 }
65 
67  if (HasFinally)
68  return getFinallyStmt()->getEndLoc();
69  if (NumCatchStmts)
70  return getCatchStmt(NumCatchStmts - 1)->getEndLoc();
71  return getTryBody()->getEndLoc();
72 }
Defines the clang::ASTContext interface.
Stmt - This represents one statement.
Definition: Stmt.h:66
Defines the Objective-C statement AST node classes.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
SourceLocation getEndLoc() const LLVM_READONLY
Definition: StmtObjC.cpp:66
This represents one expression.
Definition: Expr.h:108
ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, Stmt *Body, SourceLocation FCL, SourceLocation RPL)
Definition: StmtObjC.cpp:20
Stmt()=delete
Encodes a location in the source.
static ObjCAtTryStmt * CreateEmpty(const ASTContext &Context, unsigned NumCatchStmts, bool HasFinally)
Definition: StmtObjC.cpp:57
A placeholder type used to construct an empty shell of a type, that will be filled in later (e...
Definition: Stmt.h:1044
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:685
Dataflow Directional Tag Classes.
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:165
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: StmtObjC.cpp:45