]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/AST/StmtObjC.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / AST / StmtObjC.cpp
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
21 ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
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
46 ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context,
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
58 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
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
67 SourceLocation ObjCAtTryStmt::getEndLoc() const {
68   if (HasFinally)
69     return getFinallyStmt()->getEndLoc();
70   if (NumCatchStmts)
71     return getCatchStmt(NumCatchStmts - 1)->getEndLoc();
72   return getTryBody()->getEndLoc();
73 }