Source file funcDatatype.ml
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
open GoblintCil
let find_def name file =
Util.list_filter_map
(function
| GType (info, loc) ->
if String.compare name info.tname = 0 then Some ("", loc, name, -1)
else None
| GCompTag (info, loc) ->
if String.compare name info.cname = 0 then Some ("", loc, name, -1)
else None
| GEnumTag (info, loc) ->
if String.compare name info.ename = 0 then Some ("", loc, name, -1)
else None
| _ -> None)
file.globals
let find_def_all file =
Util.list_filter_map
(function
| GType (info, loc) -> Some ("", loc, info.tname, -1)
| GCompTag (info, loc) -> Some ("", loc, info.cname, -1)
| GEnumTag (info, loc) -> Some ("", loc, info.ename, -1)
| _ -> None)
file.globals
let find_in_globals list name =
Util.list_filter_map
(function
| GVar (info, _, _) ->
if
String.compare name
(String.trim (Pretty.sprint ~width:1 (d_type () info.vtype)))
= 0
then Some info.vid
else None
| _ -> None)
list
let find_in_varinfos list name =
Util.list_filter_map
(fun info ->
if
String.compare name
(String.trim (Pretty.sprint ~width:1 (d_type () info.vtype)))
= 0
then Some info.vid
else None)
list
let find_fundec globals name =
let gfun =
List.find_opt
(function
| GFun (fundec, _) -> String.compare fundec.svar.vname name = 0
| _ -> false)
globals
in
match gfun with Some (GFun (fundec, _)) -> Some fundec | _ -> None
let find_typevar_uses_in_fun list funname file =
List.flatten
@@ List.map (fun x -> FuncVar.find_uses_in_fun "" x funname file false) list
let find_uses_in_fun typename funname file =
match find_fundec file.globals funname with
| None -> []
| Some f ->
find_typevar_uses_in_fun
( find_in_globals file.globals typename
@ find_in_varinfos f.slocals typename
@ find_in_varinfos f.sformals typename )
f.svar.vname file
let find_uses typename file =
let list = FuncVar.find_uses_all file false in
List.filter (fun (_, _, typ, _) -> String.compare typ typename = 0) list
let find_uses_in_cond typename file =
let list = FuncVar.find_uses_in_cond_all file false in
List.filter (fun (_, _, typ, _) -> String.compare typ typename = 0) list
let find_uses_in_noncond typename file =
let list = FuncVar.find_uses_in_noncond_all file false in
List.filter (fun (_, _, typ, _) -> String.compare typ typename = 0) list