-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.jl
111 lines (89 loc) · 3.73 KB
/
data.jl
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#######################################################################
# Data types for the analysis of lower bounds
#######################################################################
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Analysis
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#--------------------------------------------------
# Simple search of text for `<:` and `>:`
#--------------------------------------------------
@enum ConstrKind subtc suptc
# Regex expressions corresponding to
# subtype and supertype constraints
const CONSTRAINT_PATTERN = Dict(
subtc => "<:",
suptc => ">:"
)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Gathering statistics
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#--------------------------------------------------
# Cumulative lower-bounds stat
#--------------------------------------------------
# Information about textual and parsing-based
# appearance of lower-bound constraints
struct TxtConstrStat
subConsr :: UInt # number of `<:` in text
supConsr :: UInt # number of `>:` in text
end
TxtConstrStat() = TxtConstrStat(0, 0)
# Frequencies of lower-bound values
LBValsFreq = Multiset
# Information about lower-bound constraints
struct LBStat
lbs :: UInt # number of lower bounds
lbsUnique :: UInt # number of unique lower-bound values
lbsFreq :: LBValsFreq # frequencies of lower-bound values
end
LBStat() = LBStat(0, 0, LBValsFreq())
LBStat(lbsFreq :: LBValsFreq) =
LBStat(length(lbsFreq), lengthUnique(lbsFreq), lbsFreq)
#--------------------------------------------------
# File stat
#--------------------------------------------------
# Information about lower bounds in a file:
# - `txtStat` textual bounds info
# - `err` possibly exception during processing
# - `lbStat` possibly proper lb-stat if `txtStat` is non-vacuous
struct FileLBInfo
txtStat :: TxtConstrStat
err :: Union{Exception, Nothing}
lbStat :: Union{LBStat, Nothing}
end
FileLBInfo(txtStat :: TxtConstrStat) =
FileLBInfo(txtStat, nothing, nothing)
FileLBInfo(txtStat :: TxtConstrStat, err :: Exception) =
FileLBInfo(txtStat, err, nothing)
FileLBInfo(txtStat :: TxtConstrStat, lbStat :: LBStat) =
FileLBInfo(txtStat, nothing, lbStat)
#--------------------------------------------------
# Package stat
#--------------------------------------------------
# Files statistics (fileName => statistics)
FilesLBInfo = Dict{String, FileLBInfo}
# Single package statistics
mutable struct PackageStat
name :: String
hasSrc :: Bool
totalFilesNum :: UInt # number of source Julia files
failedFilesNum :: UInt # number of files that failed to process
nonVacFilesNum :: UInt # number of files with lower bounds
filesInfo :: FilesLBInfo # fileName => FileLBInfo
lbStat :: LBStat # package cumulative statistics
end
PackageStat(name :: String, hasSrc :: Bool) =
PackageStat(name, hasSrc, 0, 0, 0, FilesLBInfo(), LBStat())
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Base functions
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#--------------------------------------------------
# Equality
#--------------------------------------------------
Base.:(==)(v1 :: TxtConstrStat, v2 :: TxtConstrStat) = structEqual(v1, v2)
Base.:(==)(v1 :: LBStat, v2 :: LBStat) = structEqual(v1, v2)
Base.:(==)(v1 :: FileLBInfo, v2 :: FileLBInfo) = structEqual(v1, v2)
Base.:(==)(v1 :: PackageStat, v2 :: PackageStat) = structEqual(v1, v2)
#--------------------------------------------------
# Show
#--------------------------------------------------
Base.show(io :: IO, un :: UInt) = print(io, string(un, base=10))