-
Notifications
You must be signed in to change notification settings - Fork 482
Expand file tree
/
Copy pathDecl.ml
More file actions
93 lines (84 loc) · 2.56 KB
/
Decl.ml
File metadata and controls
93 lines (84 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(** Declaration types for dead code analysis. *)
module Kind = struct
type t =
| Exception
| RecordLabel
| VariantCase
| Value of {
isToplevel: bool;
mutable ownsOptionalArgs: bool;
mutable optionalArgs: OptionalArgs.t;
sideEffects: bool;
}
let isType dk =
match dk with
| RecordLabel | VariantCase -> true
| Exception | Value _ -> false
let toString dk =
match dk with
| Exception -> "Exception"
| RecordLabel -> "RecordLabel"
| VariantCase -> "VariantCase"
| Value _ -> "Value"
end
type posAdjustment = FirstVariant | OtherVariant | Nothing
type t = {
declKind: Kind.t;
moduleLoc: Location.t;
posAdjustment: posAdjustment;
path: DcePath.t;
(** For type re-exports (e.g. [type y = x = {...}]), record/variant label
declarations belonging to the re-exporting type can carry the manifest
type path so [DeadType.process_type_label_dependencies] can link fields
without needing the typed tree. *)
manifestTypePath: DcePath.t option;
pos: Lexing.position;
posEnd: Lexing.position;
posStart: Lexing.position;
mutable resolvedDead: bool option;
mutable report: bool;
}
let isValue decl =
match decl.declKind with
| Value _ (* | Exception *) -> true
| _ -> false
(** Check if a declaration is live (or unknown). Returns false only if resolved as dead. *)
let isLive decl =
match decl.resolvedDead with
| Some true -> false
| Some false | None -> true
let compareUsingDependencies ~orderedFiles
{
declKind = kind1;
path = _path1;
pos =
{pos_fname = fname1; pos_lnum = lnum1; pos_bol = bol1; pos_cnum = cnum1};
}
{
declKind = kind2;
path = _path2;
pos =
{pos_fname = fname2; pos_lnum = lnum2; pos_bol = bol2; pos_cnum = cnum2};
} =
let findPosition fn = Hashtbl.find orderedFiles fn [@@raises Not_found] in
(* From the root of the file dependency DAG to the leaves.
From the bottom of the file to the top. *)
let position1, position2 =
try (fname1 |> findPosition, fname2 |> findPosition)
with Not_found -> (0, 0)
in
compare
(position1, lnum2, bol2, cnum2, kind1)
(position2, lnum1, bol1, cnum1, kind2)
let compareForReporting
{
declKind = kind1;
pos =
{pos_fname = fname1; pos_lnum = lnum1; pos_bol = bol1; pos_cnum = cnum1};
}
{
declKind = kind2;
pos =
{pos_fname = fname2; pos_lnum = lnum2; pos_bol = bol2; pos_cnum = cnum2};
} =
compare (fname1, lnum1, bol1, cnum1, kind1) (fname2, lnum2, bol2, cnum2, kind2)