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