-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictcheck
executable file
·81 lines (66 loc) · 2.51 KB
/
dictcheck
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
#!/usr/bin/env perl
use warnings;
use strict;
my $ROOT = '__ROOT';
my $TOP = 'var_LATEST';
my @symbols = ( { name => 'ROOT', cname => $ROOT, 'link' => undef, type => undef } );
my $errors = 0;
while (<>) {
my ($name, $cname, $link, $type) = ();
# Parse definitions
if (m/^\s*PRIMITIVE\s*\(\"([^"]+?)\",\s*([^,]+),\s*([^,]+),\s*([^,]+)\s*\)\s*\{/) {
($name, undef, $cname, $link) = ($1, $2, $3, $4);
$type = 'primitive';
}
elsif (m/^\s*VARIABLE\s*\(([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+)\s*\)\s*;/) {
($name, undef, undef, $link) = ($1, $2, $3, $4);
$cname = "var_$name";
$type = 'variable';
}
elsif (m/^\s*CONSTANT\s*\(([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+)\s*\)\s*;/) {
($name, undef, undef, $link) = ($1, $2, $3, $4);
$cname = "const_$name";
$type = 'constant';
}
elsif (m/^\s*READONLY\s*\(([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+)\s*\)\s*;/) {
($name, undef, undef, $link) = ($1, $2, $3, $4);
$cname = "readonly_$name";
$type = 'readonly';
}
else {
next;
}
# Check coherence
if ($link ne $symbols[0]->{cname}) {
printf STDERR "%s:%d: warning: %s \"%s\" expected link to %s, got %s\n",
$ARGV, $., $type, $name, $symbols[0]->{cname}, $link;
if (scalar @symbols > 1) { # There's always at least one, for the ROOT node
print STDERR "$ARGV: note: The following previously-defined symbols ",
"may not be accessible:\n";
foreach my $s (@symbols) {
last if $s->{cname} eq $link or $s->{cname} eq $ROOT;
print STDERR "$ARGV: note: $s->{name} ($s->{type})\n";
}
}
$errors ++;
}
# Add it to the list
unshift @symbols, { name => $name, cname => $cname, 'link' => $link, type => $type };
} continue {
close ARGV if eof; # Reset line number $. for each file
}
# Make sure LATEST is at the top of the list
if ($symbols[0]->{cname} ne $TOP) {
printf STDERR "%s: warning: Incorrect top of dictionary, expected %s, got %s\n",
$ARGV, $TOP, $symbols[0]->{cname};
if (scalar @symbols > 1) {
print STDERR "$ARGV: note: The following previously-defined symbols ",
"may not be accessible:\n";
foreach my $s (@symbols) {
last if $s->{cname} eq $TOP or $s->{cname} eq $ROOT;
print STDERR "$ARGV: note: $s->{name} ($s->{type})\n";
}
}
$errors ++;
}
exit $errors;