|
1 | 1 | (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
|
2 |
| - * |
| 2 | + * |
3 | 3 | * This program is free software: you can redistribute it and/or modify
|
4 | 4 | * it under the terms of the GNU Lesser General Public License as published by
|
5 | 5 | * the Free Software Foundation, either version 3 of the License, or
|
|
17 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 | 19 | * GNU Lesser General Public License for more details.
|
20 |
| - * |
| 20 | + * |
21 | 21 | * You should have received a copy of the GNU Lesser General Public License
|
22 | 22 | * along with this program; if not, write to the Free Software
|
23 | 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
|
|
27 | 27 |
|
28 | 28 |
|
29 | 29 |
|
30 |
| -let rec has_exit_code exits (lam : Lam.t) : bool = |
| 30 | +let rec has_exit_code exits (lam : Lam.t) : bool = |
31 | 31 | match lam with
|
32 | 32 | | Lvar _
|
33 |
| - | Lconst _ |
| 33 | + | Lconst _ |
34 | 34 | | Lfunction _ (* static exit can not across function boundary *)
|
35 | 35 | -> false
|
36 |
| - | Lapply {fn = l; args; _ } |
37 |
| - -> has_exit_code exits l || List.exists (fun x -> has_exit_code exits x ) args |
| 36 | + | Lapply {fn = l; args; _ } |
| 37 | + -> has_exit_code exits l || List.exists (fun x -> has_exit_code exits x ) args |
38 | 38 |
|
39 |
| - | Llet (_kind,_id,v,body) |
| 39 | + | Llet (_kind,_id,v,body) |
40 | 40 | -> has_exit_code exits v || has_exit_code exits body
|
41 | 41 | | Lletrec (binding,body) ->
|
42 | 42 | List.exists (fun (_, l) -> has_exit_code exits l ) binding ||
|
43 |
| - has_exit_code exits body |
| 43 | + has_exit_code exits body |
44 | 44 | | Lam.Lglobal_module _ -> false
|
45 |
| - | Lprim {args; _} |
| 45 | + | Lprim {args; _} |
46 | 46 | -> List.exists (fun x -> has_exit_code exits x) args
|
47 |
| - | Lswitch (l,lam_switch) |
| 47 | + | Lswitch (l,lam_switch) |
48 | 48 | -> has_exit_code exits l || has_exit_code_lam_switch exits lam_switch
|
49 | 49 |
|
50 |
| - | Lstringswitch (l,ls,opt) -> |
| 50 | + | Lstringswitch (l,ls,opt) -> |
51 | 51 | has_exit_code exits l ||
|
52 | 52 | List.exists (fun (_,l) -> has_exit_code exits l) ls ||
|
53 |
| - (match opt with |
| 53 | + (match opt with |
54 | 54 | | None -> false
|
55 | 55 | | Some x -> has_exit_code exits l )
|
56 | 56 | | Lstaticraise (v,ls) ->
|
57 |
| - exits v || |
| 57 | + exits v || |
58 | 58 | List.exists (has_exit_code exits) ls
|
59 |
| - | Lstaticcatch (l,_,handler) |
| 59 | + | Lstaticcatch (l,_,handler) |
60 | 60 | ->
|
61 | 61 | has_exit_code exits l || has_exit_code exits handler
|
62 |
| - | Ltrywith (l,_, handler) |
| 62 | + | Ltrywith (l,_, handler) |
63 | 63 | ->
|
64 | 64 | has_exit_code exits l || has_exit_code exits handler
|
65 |
| - | Lifthenelse (a,b,c) |
66 |
| - -> |
| 65 | + | Lifthenelse (a,b,c) |
| 66 | + -> |
67 | 67 | has_exit_code exits a || has_exit_code exits b || has_exit_code exits c
|
68 |
| - | Lsequence (a,b) |
| 68 | + | Lsequence (a,b) |
69 | 69 | ->
|
70 | 70 | has_exit_code exits a || has_exit_code exits b
|
71 |
| - | Lwhile (a,b) |
| 71 | + | Lwhile (a,b) |
72 | 72 | ->
|
73 | 73 | has_exit_code exits a || has_exit_code exits b
|
74 |
| - | Lfor (_,a,b,_dir,body) -> |
75 |
| - has_exit_code exits a |
| 74 | + | Lfor (_,a,b,_dir,body) -> |
| 75 | + has_exit_code exits a |
76 | 76 | || has_exit_code exits b
|
77 | 77 | || has_exit_code exits body
|
78 |
| - |
79 |
| - | Lassign (_,a) |
80 |
| - -> |
| 78 | + |
| 79 | + | Lassign (_,a) |
| 80 | + -> |
81 | 81 | has_exit_code exits a
|
82 |
| - | Lsend (_,obj,l,ls,_loc) |
83 |
| - -> |
| 82 | + | Lsend (_,obj,l,ls,_loc) |
| 83 | + -> |
84 | 84 | has_exit_code exits obj ||
|
85 | 85 | has_exit_code exits l ||
|
86 | 86 | List.exists (has_exit_code exits) ls
|
87 |
| - | Lifused (_,b) |
| 87 | + | Lifused (_,b) |
88 | 88 | -> has_exit_code exits b
|
89 | 89 |
|
90 |
| -and has_exit_code_lam_switch exits (lam_switch : Lam.switch) = |
| 90 | +and has_exit_code_lam_switch exits (lam_switch : Lam.switch) = |
91 | 91 | match lam_switch with
|
92 | 92 | | { sw_numconsts = _; sw_consts; sw_numblocks = _ ; sw_blocks; sw_failaction } ->
|
93 | 93 | List.exists (fun (_,l) -> has_exit_code exits l) sw_consts ||
|
94 | 94 | List.exists (fun (_,l) -> has_exit_code exits l) sw_blocks ||
|
95 |
| - (match sw_failaction with |
96 |
| - | None -> false |
| 95 | + (match sw_failaction with |
| 96 | + | None -> false |
97 | 97 | | Some x -> has_exit_code exits x)
|
| 98 | + |
| 99 | + |
| 100 | +let has_exit lam = |
| 101 | + has_exit_code (fun _ -> true) lam |
0 commit comments