| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Devel::TypeCheck::Type::Var; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
41
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
74
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Devel::TypeCheck::Type; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Devel::TypeCheck::Util; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
494
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Devel::TypeCheck::Type::Var - Type variable. |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Devel::TypeCheck::Type::Var; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Var represents type variables. When instantiated, a Var is unbound in |
|
20
|
|
|
|
|
|
|
the type environment. After unification, a Var might be bound to a |
|
21
|
|
|
|
|
|
|
complete and fully qualified type, or to another type variable. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Inherits from Devel::TypeCheck::Type::Type. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=over 4 |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
|
28
|
|
|
|
|
|
|
our @ISA = qw(Devel::TypeCheck::Type); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# **** INSTANCE **** |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
|
33
|
0
|
|
|
0
|
1
|
|
my ($name, $index) = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $this = {}; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$this->{'index'} = $index; |
|
38
|
0
|
|
|
|
|
|
$this->{'rank'} = 0; |
|
39
|
0
|
|
|
|
|
|
$this->{'parent'} = undef; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return bless($this, $name); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub type { |
|
45
|
0
|
|
|
0
|
1
|
|
return Devel::TypeCheck::Type::VAR(); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub subtype { |
|
49
|
0
|
|
|
0
|
1
|
|
abstract("subtype", "Devel::TypeCheck::Type::Var"); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub unify { |
|
53
|
0
|
|
|
0
|
0
|
|
my ($this, $that, $env) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$this = $env->find($this); |
|
56
|
0
|
|
|
|
|
|
$that = $env->find($that); |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $env->unify($this, $that); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub occurs { |
|
62
|
0
|
|
|
0
|
0
|
|
my ($this, $that, $env) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ($that->type != Devel::TypeCheck::Type::VAR()) { |
|
65
|
0
|
|
|
|
|
|
die("Invalid type ", $that->str, " for occurs check"); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $f = $env->find($this); |
|
69
|
0
|
|
|
|
|
|
my $g = $env->find($that); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ($f->type != Devel::TypeCheck::Type::VAR()) { |
|
72
|
0
|
|
|
|
|
|
return ($f->occurs($g, $env)); |
|
73
|
|
|
|
|
|
|
} else { |
|
74
|
0
|
|
|
|
|
|
return ($f == $g); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub letters { |
|
79
|
1
|
|
|
1
|
|
1073
|
use integer; |
|
|
1
|
|
|
|
|
13
|
|
|
|
1
|
|
|
|
|
7
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
0
|
0
|
|
my ($int) = @_; |
|
82
|
0
|
|
|
|
|
|
my $d = $int / 26; |
|
83
|
0
|
|
|
|
|
|
my $r = $int % 26; |
|
84
|
0
|
|
|
|
|
|
my $l = ""; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if ($d != 0) { |
|
87
|
0
|
|
|
|
|
|
$l = letters($d); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $l . chr(ord('a') + $r); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub str { |
|
94
|
0
|
|
|
0
|
1
|
|
my ($this, $env) = @_; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $that = $this; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if (defined($env)) { |
|
99
|
0
|
|
|
|
|
|
$that = $env->find($this); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if ($this == $that) { |
|
103
|
0
|
|
|
|
|
|
return letters($this->{'index'}); |
|
104
|
|
|
|
|
|
|
} else { |
|
105
|
0
|
|
|
|
|
|
return $that->str($env); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub pretty { |
|
110
|
0
|
|
|
0
|
1
|
|
my ($this, $env) = @_; |
|
111
|
0
|
|
|
|
|
|
my $that = $this; |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
if (defined($env)) { |
|
114
|
0
|
|
|
|
|
|
$that = $env->find($this); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if ($this == $that) { |
|
118
|
0
|
|
|
|
|
|
return "TYPE VARIABLE " . letters($this->{'index'}); |
|
119
|
|
|
|
|
|
|
} else { |
|
120
|
0
|
|
|
|
|
|
return $that->pretty($env); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item B |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Return the immediate parent of this type in the union-find data structure. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
sub getParent { |
|
130
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
131
|
0
|
|
|
|
|
|
return $this->{'parent'}; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item B($parent) |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Set the parent for this instance in the union-find data structure. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
|
139
|
|
|
|
|
|
|
sub setParent { |
|
140
|
0
|
|
|
0
|
1
|
|
my ($this, $parent) = @_; |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
die ("Devel::TypeCheck::Type::Var cannot be it's own parent") if ($this == $parent); |
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
$this->{'parent'} = $parent; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub is { |
|
148
|
0
|
|
|
0
|
1
|
|
my ($this, $type) = @_; |
|
149
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
150
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
151
|
0
|
|
|
|
|
|
return $parent->is($type); |
|
152
|
|
|
|
|
|
|
} else { |
|
153
|
0
|
0
|
|
|
|
|
return TRUE if ($type == $this->type); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
return FALSE; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub complete { |
|
160
|
0
|
|
|
0
|
1
|
|
return FALSE; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Garbage to support dereferencing and stuff through vars: |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub derefKappa { |
|
166
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
167
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
168
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
169
|
0
|
|
|
|
|
|
return $parent->derefKappa(); |
|
170
|
|
|
|
|
|
|
} else { |
|
171
|
0
|
|
|
|
|
|
return undef; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub derefOmicron { |
|
176
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
177
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
178
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
179
|
0
|
|
|
|
|
|
return $parent->derefOmicron(); |
|
180
|
|
|
|
|
|
|
} else { |
|
181
|
0
|
|
|
|
|
|
return undef; |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub derefChi { |
|
186
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
187
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
188
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
189
|
0
|
|
|
|
|
|
return $parent->derefChi(); |
|
190
|
|
|
|
|
|
|
} else { |
|
191
|
0
|
|
|
|
|
|
return undef; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub derefIndex { |
|
196
|
0
|
|
|
0
|
1
|
|
my ($this, $index, $env) = @_; |
|
197
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
198
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
199
|
0
|
|
|
|
|
|
return $parent->derefIndex($index, $env); |
|
200
|
|
|
|
|
|
|
} else { |
|
201
|
0
|
|
|
|
|
|
return undef; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub derefHomogeneous { |
|
206
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
207
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
208
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
209
|
0
|
|
|
|
|
|
return $parent->derefHomogeneous(); |
|
210
|
|
|
|
|
|
|
} else { |
|
211
|
0
|
|
|
|
|
|
return undef; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub homogeneous { |
|
216
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
217
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
218
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
219
|
0
|
|
|
|
|
|
return $parent->homogeneous(); |
|
220
|
|
|
|
|
|
|
} else { |
|
221
|
0
|
|
|
|
|
|
return undef; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub referize { |
|
226
|
0
|
|
|
0
|
1
|
|
my ($this, $env) = @_; |
|
227
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
228
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
229
|
0
|
|
|
|
|
|
return $parent->referize($env); |
|
230
|
|
|
|
|
|
|
} else { |
|
231
|
0
|
|
|
|
|
|
return undef; |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub append { |
|
236
|
0
|
|
|
0
|
1
|
|
my ($this, $that, $env) = @_; |
|
237
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
238
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
239
|
0
|
|
|
|
|
|
return $parent->append($that, $env, $this); |
|
240
|
|
|
|
|
|
|
} else { |
|
241
|
0
|
|
|
|
|
|
return undef; |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub ary { |
|
246
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
247
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
248
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
249
|
0
|
|
|
|
|
|
return $parent->ary(); |
|
250
|
|
|
|
|
|
|
} else { |
|
251
|
0
|
|
|
|
|
|
return undef; |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub listCoerce { |
|
256
|
0
|
|
|
0
|
1
|
|
my ($this, $env) = @_; |
|
257
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
258
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
259
|
0
|
|
|
|
|
|
return $parent->listCoerce($env); |
|
260
|
|
|
|
|
|
|
} else { |
|
261
|
0
|
|
|
|
|
|
return undef; |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub bindUp { |
|
266
|
0
|
|
|
0
|
0
|
|
my ($this, $env) = @_; |
|
267
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
268
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
269
|
0
|
|
|
|
|
|
return $parent->bindUp($env); |
|
270
|
|
|
|
|
|
|
} else { |
|
271
|
0
|
|
|
|
|
|
return undef; |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
} |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub deref { |
|
276
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
277
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
278
|
0
|
0
|
|
|
|
|
if ($this->getParent) { |
|
279
|
0
|
|
|
|
|
|
return $parent->deref(); |
|
280
|
|
|
|
|
|
|
} else { |
|
281
|
0
|
|
|
|
|
|
return undef; |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
sub arity { |
|
286
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
|
287
|
0
|
|
|
|
|
|
my $parent = $this->getParent; |
|
288
|
0
|
0
|
|
|
|
|
if ($parent) { |
|
289
|
0
|
|
|
|
|
|
return $parent->arity(); |
|
290
|
|
|
|
|
|
|
} else { |
|
291
|
0
|
|
|
|
|
|
return undef; |
|
292
|
|
|
|
|
|
|
} |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
TRUE; |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=back |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head1 AUTHOR |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Gary Jackson, C<< >> |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head1 BUGS |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
This version is specific to Perl 5.8.1. It may work with other |
|
306
|
|
|
|
|
|
|
versions that have the same opcode list and structure, but this is |
|
307
|
|
|
|
|
|
|
entirely untested. It definitely will not work if those parameters |
|
308
|
|
|
|
|
|
|
change. |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
311
|
|
|
|
|
|
|
C, or through the web interface at |
|
312
|
|
|
|
|
|
|
L. |
|
313
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
314
|
|
|
|
|
|
|
your bug as I make changes. |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
Copyright 2005 Gary Jackson, all rights reserved. |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
321
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=cut |