blib/lib/Hardware/Vhdl/Tidy.pm

filter: Statementstmt 72.2% 146 / 202 Branchbran 73.3% 91 / 124 Conditioncond 51.9% 53 / 102 MC/DCmcdc 31.5% 18 / 57 Subroutinesub 92.3% 12 / 13 Podpod 100% 3 / 3 totaltotal 64.4% 323 / 501 CC 100 SCAR 59.3
CC
100
Cov
68%
tidy_vhdl
460.7
tidy_vhdl_file
8.4
parse_commandline
4.0
CRAP 375.1
↑ Summary
1 package Hardware::Vhdl::Tidy;
2
3 # TO DO:
4 # Tidier directives in source code to set stack
5 # setting to control whether we include whitespace at start of empty lines
6 # check whether there are any other 'loop' forms
7 # put underscore at start of names of internal routines
8 # implement PBP generally
9
10 5 ▶use Hardware::Vhdl::Lexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17
18 sub parse_commandline;
19 sub tidy_vhdl_file;
20 sub tidy_vhdl;
21
22 5 our $VERSION = 0.80;
23
24 #our @EXPORT=();
25 5 our @EXPORT_OK=qw/ tidy_vhdl_file tidy_vhdl /;
26
27 5 our $debug = 0;
28
29 5 our %default_args = (
30 indent_spaces => 4, # integer value, >= 0
31 cont_spaces => 2, # integer value, >= 0
32 tab_spaces => 0, # integer value, >= 0
33 starting_indentation => 0, # integer value, >= 0
34 preprocessor_prefix => '#', # string
35 indent_preprocessor => 0, # boolean
36 );
37
38 17 ▶sub parse_commandline {
Subroutine parse_commandline: called CC=4 SCAR=13.9
Pod documented
39 # parse command-line args
40 # for example, for an in-place tidy of a vhd file:
41 # perl -MHardware::Vhdl::Tidy -e "Hardware::Vhdl::Tidy::parse_commandline" -- -b <$file>
42 17 my $inplace = 0;
43 17 my $bext = '.bak';
44 17 my %args = %default_args;
45 my $result = GetOptions(
46 "b" => \$inplace,
47 "bext=s" => \$bext,
48 "i|indentation=i" => \$args{indent_spaces},
49 "ci|continuation-indentation=i" => \$args{cont_spaces},
50 "t|tab_spaces=i" => \$args{tab_spaces},
51 "sil|starting-indentation-level=i" => \$args{starting_indentation},
52 "ppp|preprocessor-prefix=s" => \$args{preprocessor_prefix},
53 "ipp|indent-preprocessor" => \$args{indent_preprocessor},
54 17 );
55
56 # any args not matched are taken to be input filenames
57 17 for my $afile (@ARGV) {
58 17 ▶ if ($inplace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inplace) { } 2 15 17
59 # change in-place: rename the original file and then make the old filename the destination
60 2 ▶ rename $afile, $afile . $bext || die "Could not rename $afile: $!\n";
Condition50%1/2
$afile . $bext || die("Could not rename ${afile}: $!\n")
l!l
20
MC/DC0%0/1
$afile . $bext || die("Could not rename ${afile}: $!\n")
$afile . $bext
Truth table50%1/2
A
A= $afile . $bext
Aresult
11
00
61 2 tidy_vhdl_file( source => $afile . $bext, destination => $afile, %args );
62 } else {
63 # not in-place: output to STDOUT
64 15 tidy_vhdl_file( source => $afile, %args );
65 }
66 }
67
68 17 return;
69 }
70
71 17 ▶sub tidy_vhdl_file {
Subroutine tidy_vhdl_file: called CC=7 SCAR=21.2
Pod documented
72 # reads from STDIN if source filename not specified
73 # writes to STDOUT if destination filename not specified
74 0 ▶ my %args = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 17 17
75
76 17 my $fhi;
77 17 ▶ if ( defined $args{source} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'source'}) { } 17 0 17
78 17 ▶ open $fhi, '<', $args{source} || die "Could not read $args{source}: $!\n";
Condition50%1/2
$args{'source'} || die("Could not read $args{'source'}: $!\n")
l!l
170
MC/DC0%0/1
$args{'source'} || die("Could not read $args{'source'}: $!\n")
$args{'source'}
Truth table50%1/2
A
A= $args{'source'}
Aresult
11
00
79 } else {
80 0 open $fhi, '-' || die "Could not read from STDIN: $!\n";
81 }
82 17 binmode $fhi;
83 17 $args{source} = $fhi;
84
85 17 my $fho;
86 17 ▶ if ( defined $args{destination} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'destination'}) { } 2 15 17
87 2 ▶ open $fho, '>', $args{destination} || die "Could not write $args{destination}: $!\n";
Condition50%1/2
$args{'destination'} || die("Could not write $args{'destination'}: $!\n")
l!l
20
MC/DC0%0/1
$args{'destination'} || die("Could not write $args{'destination'}: $!\n")
$args{'destination'}
Truth table50%1/2
A
A= $args{'destination'}
Aresult
11
00
88 } else {
89 15 open $fho, '>-' || die "Could not write to STDOUT: $!\n";
90 }
91 17 binmode $fho;
92 17 $args{destination} = $fho;
93
94 17 eval {
95 17 tidy_vhdl(\%args);
96 };
97 17 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 17 17
98 0 my $err=$@;
99 0 $err =~ s/ tidy_vhdl /tidy_vhdl_file/xmsg;
100 0 croak $err;
101 }
102 17 return;
103 }
104
105 # label is name end_t end_name/label
106 # entity n y y o o
107 # architecture n y y o o
108 # configuration n y y o o
109 # package [body] n y y o o
110 # function n y y o o
111 # procedure n y y o o
112
113 # component n o y y o
114 # for (in config) n n u y n
115
116 # case o y n y o
117 # process o o n y o
118 # if (...then) o n n y o
119 # for (...loop) o n n y o
120 # loop o n n y o
121
122 # block y o n y o
123 # if (...generate) y n n y o
124 # for (...generate) y n n y o
125
126 # NB: functions can be marked as pure or impure
127 # processes can be marked as postponed
128
129 29 ▶sub tidy_vhdl {
Subroutine tidy_vhdl: called CC=91 SCAR=61.3
Pod documented
130 # parse and check arguments
131 29 ▶ my %args = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 29 0 29
132 29 ▶ croak "tidy_vhdl requires a 'source' parameter" unless defined $args{source};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"source"} 1 28 29
133 28 ▶ croak "tidy_vhdl requires a 'destination' parameter" unless defined $args{destination};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"destination"} 1 27 28
134 27 for my $opt (keys %default_args) {
135 162 ▶ if ( !defined $args{$opt} ) { $args{$opt} = $default_args{$opt} }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{$opt}) 60 102 162
136 }
137
138 27 my $output_func;
139 {
140 27 my $outobj = $args{destination};
141 27 my $outtype = ref $outobj;
142 27 ▶ if ( $outtype eq q{} ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($outtype eq '') { } 0 27 27
elsif ($outtype eq 'GLOB') { } 18 9 27
elsif ($outtype eq 'SCALAR') { } 1 8 9
elsif ($outtype eq 'ARRAY') { } 7 1 8
elsif ($outtype eq 'CODE') { } 1 0 1
elsif (eval { do { $outobj->can('addtokens') } } and not $@) { } 0 0 0
143 0 croak "tidy_vhdl 'destination' parameter is not of a valid type (it is not a reference)";
144 } elsif ( $outtype eq 'GLOB' ) {
145 241 ▶ $output_func = sub { print $outobj shift }
Subroutine __ANON__: called CC=1 SCAR=0.0
146 18 } elsif ( $outtype eq 'SCALAR' ) {
147 11 ▶ $output_func = sub { $$outobj .= shift }
Subroutine __ANON__: called CC=1 SCAR=0.0
148 1 } elsif ( $outtype eq 'ARRAY' ) {
149 15 ▶ $output_func = sub { push @$outobj, shift }
Subroutine __ANON__: called CC=1 SCAR=0.0
150 7 } elsif ( $outtype eq 'CODE' ) {
151 1 $output_func = $outobj;
152 0 ▶ } elsif (eval {$outobj->can('addtokens')} && !$@) {
Condition0%0/3
eval { do { $outobj->can("addtokens") } } and not $@
!ll&&!rl&&r
000
MC/DC0%0/2
eval { do { $outobj->can("addtokens") } } and not $@
eval { do { $outobj->can("addtokens") } } not $@
Truth table0%0/3
A and not(B)
A= eval { do { $outobj->can("addtokens") } }B= not $@
ABresult
0X0
100
111
153 0 ▶ $output_func = sub { $outobj->addtokens(shift) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
154 0 } else {
155 0 croak "tidy_vhdl 'destination' parameter is not of a valid type (type is '$outtype')";
156 }
157 }
158
159 27 my $lexer;
160 27 eval {
161 27 $lexer = Hardware::Vhdl::Lexer->new({ linesource => $args{source} });
162 };
163 27 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 4 23 27
164 4 my $err=$@;
165 4 $err =~ s/ Hardware::Vhdl::Lexer->new /tidy_vhdl/xmsg;
166 4 $err =~ s/ linesource /source/xmsg;
167 4 croak $err;
168 }
169
170 23 my $indent = $args{starting_indentation}; # current indentation level
171 23 my $bracks = 0; # how many () brackets deep are we?
172 23 my $line = ''; # current line of code tokens (a syntax line, nothing to do with newlines)
173 23 my @stack; # a list of the indented things we are inside
174 23 my $ln = 1; # source line num
175 23 my @outline; # list of tokens to go on the output line
176 23 my ( $token, $type );
177 23 ▶ while ( ( ( $token, $type ) = $lexer->get_next_token ) && defined $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $lexer->get_next_token and defined $type) 1483 22 1505
Condition66%2/3
() = $lexer->get_next_token and defined $type
!ll&&!rl&&r
2201483
MC/DC50%1/2
() = $lexer->get_next_token and defined $type
() = $lexer->get_next_token defined $type
Truth table66%2/3
A and B
A= () = $lexer->get_next_tokenB= defined $type
ABresult
0X0
100
111
178 #print "\n# input token type $type, '".&escape($token)."'\n";
179 1483 my $indnext = 0;
180 1483 my $bracknext = 0;
181 1483 my $linestart = $line eq ''; # is this the first token of a syntax line?
182 1483 ▶ my $toplevel = @stack ? $stack[0][0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@stack ? : 1178 305 1483
183 1483 ▶ my $botlevel = @stack ? $stack[-1][0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@stack ? : 1178 305 1483
184 1483 ▶ if ( substr( $type, 0, 1 ) eq 'c' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($type, 0, 1) eq "c") 683 800 1483
185 683 ▶ if ( @outline == 0 && $args{preprocessor_prefix} ne '' && substr($token,0,length $args{preprocessor_prefix}) eq $args{preprocessor_prefix}) {
Branch: 4 branches
BranchTrueFalseTotal
if (@outline == 0 and $args{'preprocessor_prefix'} ne '' and substr($token, 0, length $args{'preprocessor_prefix'}) eq $args{'preprocessor_prefix'}) { } 21 662 683
elsif ($token eq '(') { } 0 662 662
elsif ($token eq ')') { } 0 662 662
elsif ($bracks == 0) { } 662 0 662
Condition83%5/6
@outline == 0 and $args{"preprocessor_prefix"} ne "" and substr($token, 0, length $args{"preprocessor_prefix"}) eq $args{"preprocessor_prefix"}
!ll&&!rl&&r
44721521
@outline == 0 and $args{"preprocessor_prefix"} ne ""
!ll&&!rl&&r
4470236
MC/DC66%2/3
@outline == 0 and $args{"preprocessor_prefix"} ne "" and substr($token, 0, length $args{"preprocessor_prefix"}) eq $args{"preprocessor_prefix"}
@outline == 0 $args{"preprocessor_prefix"} ne "" substr($token, 0, length $args{"preprocessor_prefix"}) eq $args{"preprocessor_prefix"}
Truth table75%3/4
A and B and C
A= @outline == 0B= $args{"preprocessor_prefix"} ne ""C= substr($token, 0, length $args{"preprocessor_prefix"}) eq $args{"preprocessor_prefix"}
ABCresult
0XX0
10X0
1100
1111
186 # this is a preprocessor line: don't attempt to understand it, just emit the whole line unchanged
187 21 my $t;
188 21 ▶ while ( ( ( $t, $type ) = $lexer->get_next_token ) && defined $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (($t, $type) = $lexer->get_next_token and defined $type) 77 0 77
Condition33%1/3
($t, $type) = $lexer->get_next_token and defined $type
!ll&&!rl&&r
0077
MC/DC0%0/2
($t, $type) = $lexer->get_next_token and defined $type
($t, $type) = $lexer->get_next_token defined $type
Truth table33%1/3
A and B
A= ($t, $type) = $lexer->get_next_tokenB= defined $type
ABresult
0X0
100
111
189 77 my $lastchar = substr($token, -1, 1);
190 77 $token .= $t;
191 77 ▶ if ($type eq 'wn') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "wn") 21 56 77
192 21 ▶ if ($lastchar eq "\\") {
Branch: 1 branch
BranchTrueFalseTotal
if ($lastchar eq '\\') { } 0 21 21
193 0 $ln++;
194 }
195 else {
196 21 last;
197 }
198 }
199 }
200 21 $type = 'pp';
201 }
202 0 elsif ( $token eq '(' ) { push @stack, [ '(', $ln ]; $indnext = 1; $bracknext = 1 }
203 0 elsif ( $token eq ')' ) { pop @stack; $indent--; $bracks-- }
204 elsif ( $bracks == 0 ) {
205 662 my $lctoken = lc $token;
206 662 ▶ $line .= ( $lctoken =~ m!^\\.*\\$! ) ? 'xid ' : $lctoken . ' ';
Branch: 1 branch
BranchTrueFalseTotal
$lctoken =~ /^\\.*\\$/ ? : 0 662 662
207
208 662 ▶ if ( $lctoken eq ';' ) {
Branch: 19 branches
BranchTrueFalseTotal
if ($lctoken eq ';') { } 102 560 662
elsif ($lctoken eq 'end' and $linestart) { } 27 533 560
elsif ($lctoken =~ /^(begin|elsif)$/) { } 21 512 533
elsif ($lctoken eq 'else' and @stack and $botlevel eq 'if') { } 0 512 512
elsif ($lctoken eq 'is' and $line =~ /^ (entity|architecture|configuration|package|((im)?pure \s )?function|procedure) \s /msx) { } 1 511 512
elsif ($lctoken eq 'is' and $line =~ /^(\S+ : )?case /) { } 0 511 511
elsif ($lctoken ne 'is' and $line =~ /^ (\S+ \s : \s )?(component|block|(postponed \s )?process) \s (is \s )?\S+ \s $/msx) { } 1 510 511
elsif ($lctoken eq 'loop' and $line =~ /^(\S+ : )?(for|while) /) { } 6 504 510
elsif ($lctoken eq 'use') { } 0 504 504
elsif ($lctoken =~ /^ (then|generate) $/msx) { } 0 504 504
elsif ($lctoken eq 'for' and $toplevel eq 'configuration' and not $line =~ /^end for $/ and not $line =~ / end for $/) { } 0 504 504
elsif ($lctoken =~ /^(case|if|for|while|loop)$/ and $line =~ /^((\S+) : )?\S+ $/) { } 6 498 504
elsif ($lctoken eq 'process' and $line =~ /^((\S+) : )?(postponed )?process $/) { } 21 477 498
elsif ($lctoken eq '=>' and $botlevel eq 'case' and $line =~ /^when /) { } 0 477 477
elsif ($lctoken eq 'when' and $linestart and $botlevel eq 'case=>') { } 0 477 477
elsif ($line =~ /^(im)?pure function $/) { } 0 477 477
elsif ($lctoken =~ /^(entity|architecture|configuration|package|function|procedure|component|units)$/ and $linestart) { } 2 475 477
elsif ($lctoken =~ /^(block)$/ and $line =~ /^(\S+) : \S+ $/) { } 0 475 475
elsif ($line =~ /^type / and $lctoken =~ /^(access|units|record)$/) { } 0 950 950
209 102 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($toplevel eq "architecture" and $line =~ /^for .* : / or $line =~ /^(pure |impure |)function \S+ return .* ; $/ and not $line =~ / is / or $line =~ /^procedure \S+ ; $/ or $botlevel eq "type-access") 0 102 102
Condition33%5/15
$toplevel eq "architecture" and $line =~ /^for .* : / or $line =~ /^(pure |impure |)function \S+ return .* ; $/ and not $line =~ / is / or $line =~ /^procedure \S+ ; $/ or $botlevel eq "type-access"
l!l&&r!l&&!r
00102
$toplevel eq "architecture" and $line =~ /^for .* : / or $line =~ /^(pure |impure |)function \S+ return .* ; $/ and not $line =~ / is / or $line =~ /^procedure \S+ ; $/
l!l&&r!l&&!r
00102
$toplevel eq "architecture" and $line =~ /^for .* : / or $line =~ /^(pure |impure |)function \S+ return .* ; $/ and not $line =~ / is /
l!l&&r!l&&!r
00102
$toplevel eq "architecture" and $line =~ /^for .* : /
!ll&&!rl&&r
10200
$line =~ /^(pure |impure |)function \S+ return .* ; $/ and not $line =~ / is /
!ll&&!rl&&r
10200
MC/DC0%0/6
$toplevel eq "architecture" and $line =~ /^for .* : / or $line =~ /^(pure |impure |)function \S+ return .* ; $/ and not $line =~ / is / or $line =~ /^procedure \S+ ; $/ or $botlevel eq "type-access"
$toplevel eq "architecture" $line =~ /^for .* : / $line =~ /^(pure |impure |)function \S+ return .* ; $/ not $line =~ / is / $line =~ /^procedure \S+ ; $/ $botlevel eq "type-access"
Truth table6%1/15
A and B or C and not(D) or E or F
A= $toplevel eq "architecture"B= $line =~ /^for .* : /C= $line =~ /^(pure |impure |)function \S+ return .* ; $/D= not $line =~ / is /E= $line =~ /^procedure \S+ ; $/F= $botlevel eq "type-access"
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X1X1
0X101X1
100X1X1
10101X1
0X0X011
0X10011
100X011
1010011
0X0X000
0X10000
100X000
1010000
210 # configuration spec: 'for' closed by a ';' rather than an 'end'
211 ( $toplevel eq 'architecture' && $line =~ /^for .* : / )
212 # a function declaration is completed by "return <typename>;"
213 || ( $line =~ /^(pure |impure |)function \S+ return .* ; $/ && $line !~ / is / )
214 # a procedure declaration is completed by a ";" after the procedure name and optional parameter list
215 || ( $line =~ /^procedure \S+ ; $/ )
216 # an access type declaration is closed by a ';'
217 || ( $botlevel eq 'type-access')
218 ) {
219 0 pop @stack;
220 0 $indnext--;
221 }
222 # semicolon always finishes a syntax line
223 102 $line = '';
224 }
225
226 # standard 'end' completes an indented section
227 ▶ elsif ( $lctoken eq 'end' && $linestart ) {
Condition100%3/3
$lctoken eq "end" and $linestart
!ll&&!rl&&r
532127
MC/DC100%2/2
$lctoken eq "end" and $linestart
$lctoken eq "end" $linestart
Truth table100%3/3
A and B
A= $lctoken eq "end"B= $linestart
ABresult
0X0
100
111
228 0 ▶ if ( $botlevel eq 'case=>' ) { pop @stack; $indent--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($botlevel eq "case=>") 0 27 27
229 27 pop @stack;
230 27 $indent--;
231 }
232
233 # 'begin' and 'elsif' give a temporary outdent, and finish a syntax line
234 21 elsif ( $lctoken =~ /^(begin|elsif)$/ ) { $indent--; $indnext = 1; $line = ''; $linestart = 1; }
235 # 'else' gives a temporary outdent, but check we are in an if/then rather than a "x<=y when..."
236 ▶ elsif ( $lctoken eq 'else' && @stack && $botlevel eq 'if' ) {
Condition33%2/6
$lctoken eq "else" and @stack and $botlevel eq "if"
!ll&&!rl&&r
51200
$lctoken eq "else" and @stack
!ll&&!rl&&r
51200
MC/DC0%0/3
$lctoken eq "else" and @stack and $botlevel eq "if"
$lctoken eq "else" @stack $botlevel eq "if"
Truth table25%1/4
A and B and C
A= $lctoken eq "else"B= @stackC= $botlevel eq "if"
ABCresult
0XX0
10X0
1100
1111
237 0 $indent--;
238 0 $indnext = 1;
239 0 $line = '';
240 }
241
242 # 'is' finishes a syntax line if associated with an indenting token that takes an 'is'
243 ▶ elsif ( $lctoken eq 'is'
Condition66%2/3
$lctoken eq "is" and $line =~ /^ (entity|architecture|configuration|package|((im)?pure \s )?function|procedure) \s /msx
!ll&&!rl&&r
51101
MC/DC50%1/2
$lctoken eq "is" and $line =~ /^ (entity|architecture|configuration|package|((im)?pure \s )?function|procedure) \s /msx
$lctoken eq "is" $line =~ /^ (entity|architecture|configuration|package|((im)?pure \s )?function|procedure) \s /msx
Truth table66%2/3
A and B
A= $lctoken eq "is"B= $line =~ /^ (entity|architecture|configuration|package|((im)?pure \s )?function|procedure) \s /msx
ABresult
0X0
100
111
244 && $line =~
245 /^ (entity|architecture|configuration|package|((im)?pure \s )?function|procedure) \s /xms ) {
246 1 $line = '';
247 ▶ } elsif ( $lctoken eq 'is' && $line =~ /^(\S+ : )?case / ) {
Condition33%1/3
$lctoken eq "is" and $line =~ /^(\S+ : )?case /
!ll&&!rl&&r
51100
MC/DC0%0/2
$lctoken eq "is" and $line =~ /^(\S+ : )?case /
$lctoken eq "is" $line =~ /^(\S+ : )?case /
Truth table33%1/3
A and B
A= $lctoken eq "is"B= $line =~ /^(\S+ : )?case /
ABresult
0X0
100
111
248 0 $line = '';
249 ▶ } elsif ( $lctoken ne 'is'
Condition66%2/3
$lctoken ne "is" and $line =~ /^ (\S+ \s : \s )?(component|block|(postponed \s )?process) \s (is \s )?\S+ \s $/msx
!ll&&!rl&&r
05101
MC/DC50%1/2
$lctoken ne "is" and $line =~ /^ (\S+ \s : \s )?(component|block|(postponed \s )?process) \s (is \s )?\S+ \s $/msx
$lctoken ne "is" $line =~ /^ (\S+ \s : \s )?(component|block|(postponed \s )?process) \s (is \s )?\S+ \s $/msx
Truth table66%2/3
A and B
A= $lctoken ne "is"B= $line =~ /^ (\S+ \s : \s )?(component|block|(postponed \s )?process) \s (is \s )?\S+ \s $/msx
ABresult
0X0
100
111
250 && $line =~ /^ (\S+ \s : \s )?(component|block|(postponed \s )?process) \s (is \s )?\S+ \s $/xms ) {
251 # this is meant to deal with the case where an optional 'is' is missing -
252 # but it also messes up recognition of component instantiations with the 'component' keyword included
253 1 $linestart = 1;
254 1 $line = $lctoken . ' ';
255 }
256 # 'loop' finishes a syntax line if associated with an indenting 'for' or 'while'
257 ▶ elsif ( $lctoken eq 'loop' && $line =~ /^(\S+ : )?(for|while) / ) {
Condition100%3/3
$lctoken eq "loop" and $line =~ /^(\S+ : )?(for|while) /
!ll&&!rl&&r
49866
MC/DC100%2/2
$lctoken eq "loop" and $line =~ /^(\S+ : )?(for|while) /
$lctoken eq "loop" $line =~ /^(\S+ : )?(for|while) /
Truth table100%3/3
A and B
A= $lctoken eq "loop"B= $line =~ /^(\S+ : )?(for|while) /
ABresult
0X0
100
111
258 6 $line = '';
259 }
260 # in a configuration declaration or specification, a 'use' starts a new syntax line
261 0 elsif ( $lctoken eq 'use' ) { $linestart = 1 }
262 # 'then' or 'generate' finishes a syntax line
263 0 elsif ( $lctoken =~ /^ (then|generate) $/xms ) { $line = '' }
264
265 # in a configuration declaration, a 'for' always starts a new syntax line and indents,
266 # unless it's an 'end for';
267 ▶ elsif ( $lctoken eq 'for'
Condition44%4/9
$lctoken eq "for" and $toplevel eq "configuration" and not $line =~ /^end for $/ and not $line =~ / end for $/
!ll&&!rl&&r
50400
$lctoken eq "for" and $toplevel eq "configuration" and not $line =~ /^end for $/
!ll&&!rl&&r
50400
$lctoken eq "for" and $toplevel eq "configuration"
!ll&&!rl&&r
49860
MC/DC0%0/4
$lctoken eq "for" and $toplevel eq "configuration" and not $line =~ /^end for $/ and not $line =~ / end for $/
$lctoken eq "for" $toplevel eq "configuration" not $line =~ /^end for $/ not $line =~ / end for $/
Truth table40%2/5
A and B and not(C) and not(D)
A= $lctoken eq "for"B= $toplevel eq "configuration"C= not $line =~ /^end for $/D= not $line =~ / end for $/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
268 && $toplevel eq 'configuration'
269 && $line !~ /^end for $/
270 && $line !~ / end for $/ ) {
271 0 push @stack, [ $lctoken, $ln, $2 ];
272 0 $indnext = 1;
273 0 $linestart = 1;
274 0 $line = 'for ';
275 }
276 # endable, indenting keywords which start a syntax line (optional label allowed)
277 ▶ elsif ( $lctoken =~ /^(case|if|for|while|loop)$/ && $line =~ /^((\S+) : )?\S+ $/ ) {
Condition100%3/3
$lctoken =~ /^(case|if|for|while|loop)$/ and $line =~ /^((\S+) : )?\S+ $/
!ll&&!rl&&r
49266
MC/DC100%2/2
$lctoken =~ /^(case|if|for|while|loop)$/ and $line =~ /^((\S+) : )?\S+ $/
$lctoken =~ /^(case|if|for|while|loop)$/ $line =~ /^((\S+) : )?\S+ $/
Truth table100%3/3
A and B
A= $lctoken =~ /^(case|if|for|while|loop)$/B= $line =~ /^((\S+) : )?\S+ $/
ABresult
0X0
100
111
278 6 push @stack, [ $lctoken, $ln, $2 ];
279 6 $indnext = 1;
280 0 ▶ if ($lctoken eq 'loop') { $line = '' }
Branch: 1 branch
BranchTrueFalseTotal
if ($lctoken eq "loop") 0 6 6
281 ▶ } elsif ( $lctoken eq 'process' && $line =~ /^((\S+) : )?(postponed )?process $/ ) {
Condition100%3/3
$lctoken eq "process" and $line =~ /^((\S+) : )?(postponed )?process $/
!ll&&!rl&&r
4562121
MC/DC100%2/2
$lctoken eq "process" and $line =~ /^((\S+) : )?(postponed )?process $/
$lctoken eq "process" $line =~ /^((\S+) : )?(postponed )?process $/
Truth table100%3/3
A and B
A= $lctoken eq "process"B= $line =~ /^((\S+) : )?(postponed )?process $/
ABresult
0X0
100
111
282 21 push @stack, [ $lctoken, $ln, $2 ];
283 21 $indnext = 1;
284 }
285
286 # code to be executed when a case option is matched
287 ▶ elsif ( $lctoken eq '=>' && $botlevel eq 'case' && $line =~ /^when / ) {
Condition33%2/6
$lctoken eq "=>" and $botlevel eq "case" and $line =~ /^when /
!ll&&!rl&&r
47700
$lctoken eq "=>" and $botlevel eq "case"
!ll&&!rl&&r
47700
MC/DC0%0/3
$lctoken eq "=>" and $botlevel eq "case" and $line =~ /^when /
$lctoken eq "=>" $botlevel eq "case" $line =~ /^when /
Truth table25%1/4
A and B and C
A= $lctoken eq "=>"B= $botlevel eq "case"C= $line =~ /^when /
ABCresult
0XX0
10X0
1100
1111
288 0 push @stack, [ 'case=>', $ln ];
289 0 $indnext = 1;
290 0 $line = '';
291 }
292 # the end of the code to be executed when a case option is matched, start of another option
293 ▶ elsif ( $lctoken eq 'when' && $linestart && $botlevel eq 'case=>' ) {
Condition33%2/6
$lctoken eq "when" and $linestart and $botlevel eq "case=>"
!ll&&!rl&&r
47700
$lctoken eq "when" and $linestart
!ll&&!rl&&r
47700
MC/DC0%0/3
$lctoken eq "when" and $linestart and $botlevel eq "case=>"
$lctoken eq "when" $linestart $botlevel eq "case=>"
Truth table25%1/4
A and B and C
A= $lctoken eq "when"B= $linestartC= $botlevel eq "case=>"
ABCresult
0XX0
10X0
1100
1111
294 0 pop @stack;
295 0 $indent--;
296 }
297
298 # endable, indenting keywords which start a syntax line (no label allowed)
299 0 elsif ( $line =~ /^(im)?pure function $/ ) { push @stack, [ $lctoken, $ln ]; $indnext = 1; }
300 ▶ elsif ( $lctoken =~
Condition100%3/3
$lctoken =~ /^(entity|architecture|configuration|package|function|procedure|component|units)$/ and $linestart
!ll&&!rl&&r
47412
MC/DC100%2/2
$lctoken =~ /^(entity|architecture|configuration|package|function|procedure|component|units)$/ and $linestart
$lctoken =~ /^(entity|architecture|configuration|package|function|procedure|component|units)$/ $linestart
Truth table100%3/3
A and B
A= $lctoken =~ /^(entity|architecture|configuration|package|function|procedure|component|units)$/B= $linestart
ABresult
0X0
100
111
301 /^(entity|architecture|configuration|package|function|procedure|component|units)$/
302 && $linestart ) {
303 2 push @stack, [ $lctoken, $ln ];
304 2 $indnext = 1;
305 }
306 # endable, indenting keywords which start a syntax line (label required)
307 ▶ elsif ( $lctoken =~ /^(block)$/ && $line =~ /^(\S+) : \S+ $/ ) {
Condition33%1/3
$lctoken =~ /^(block)$/ and $line =~ /^(\S+) : \S+ $/
!ll&&!rl&&r
47500
MC/DC0%0/2
$lctoken =~ /^(block)$/ and $line =~ /^(\S+) : \S+ $/
$lctoken =~ /^(block)$/ $line =~ /^(\S+) : \S+ $/
Truth table33%1/3
A and B
A= $lctoken =~ /^(block)$/B= $line =~ /^(\S+) : \S+ $/
ABresult
0X0
100
111
308 0 push @stack, [ $lctoken, $ln, $1 ];
309 0 $indnext = 1;
310 }
311
312 ▶ elsif ( $line =~ /^type / && $lctoken =~ /^(access|units|record)$/) {
Condition33%1/3
$line =~ /^type / and $lctoken =~ /^(access|units|record)$/
!ll&&!rl&&r
47500
MC/DC0%0/2
$line =~ /^type / and $lctoken =~ /^(access|units|record)$/
$line =~ /^type / $lctoken =~ /^(access|units|record)$/
Truth table33%1/3
A and B
A= $line =~ /^type /B= $lctoken =~ /^(access|units|record)$/
ABresult
0X0
100
111
313 0 push @stack, [ 'type-'.$lctoken, $ln, $1 ];
314 0 $indnext = 1;
315 0 $line = '';
316 }
317
318 }
319
320 0 ▶ if ( $indent < 0 ) { $indent = 0; warn "negative indent, source line $ln" }
Branch: 1 branch
BranchTrueFalseTotal
if ($indent < 0) 0 683 683
321 0 ▶ if ( $bracks < 0 ) { $bracks = 0; warn "negative bracket count, source line $ln" }
Branch: 1 branch
BranchTrueFalseTotal
if ($bracks < 0) 0 683 683
322
323 683 ▶ if ( $debug & 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug & 1) 0 683 683
324 # debug dump
325 0 print "# ";
326 0 print " " x $indent;
327 0 ▶ print " " if $bracks == 0 && !$linestart;
Branch: 1 branch
BranchTrueFalseTotal
if $bracks == 0 and not $linestart 0 0 0
Condition0%0/3
$bracks == 0 and not $linestart
!ll&&!rl&&r
000
MC/DC0%0/2
$bracks == 0 and not $linestart
$bracks == 0 not $linestart
Truth table0%0/3
A and not(B)
A= $bracks == 0B= not $linestart
ABresult
0X0
100
111
328 0 print $token;
329 0 print " \t\t\tstart=$linestart stack=" . join( ', ', map { $_->[0] . '@' . $_->[1] } @stack );
330 0 print " line='$line'";
331 0 print "\n";
332 }
333 }
334
335 1483 ▶ if ( @outline == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@outline == 0) { } 512 971 1483
336 512 ▶ if ( $type ne 'ws' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "ws") 278 234 512
337 #print "# emitting indent and token '".&escape($token)."'\n";
338 278 ▶ if ($type eq 'pp' && !$args{indent_preprocessor}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'pp' and not $args{'indent_preprocessor'}) { } 15 263 278
Condition100%3/3
$type eq "pp" and not $args{"indent_preprocessor"}
!ll&&!rl&&r
257615
MC/DC100%2/2
$type eq "pp" and not $args{"indent_preprocessor"}
$type eq "pp" not $args{"indent_preprocessor"}
Truth table100%3/3
A and not(B)
A= $type eq "pp"B= not $args{"indent_preprocessor"}
ABresult
0X0
100
111
339 # preprocessor command: left-align
340 15 @outline = ( $token );
341 } else {
342 # work out the number of spaces to indent by
343 263 my $nsp = $indent * $args{indent_spaces};
344 263 ▶ $nsp += $args{cont_spaces} if $bracks == 0 && !$linestart;
Branch: 1 branch
BranchTrueFalseTotal
if $bracks == 0 and not $linestart 63 200 263
Condition66%2/3
$bracks == 0 and not $linestart
!ll&&!rl&&r
020063
MC/DC50%1/2
$bracks == 0 and not $linestart
$bracks == 0 not $linestart
Truth table66%2/3
A and not(B)
A= $bracks == 0B= not $linestart
ABresult
0X0
100
111
345 # create a tab+space sequence to give the correct indent
346 263 my $ws;
347 263 ▶ if ( $args{tab_spaces} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'tab_spaces'} > 0) { } 60 203 263
348 60 $ws = ( "\t" x int( $nsp / $args{tab_spaces} ) ) . ( ' ' x ( $nsp % $args{tab_spaces} ) );
349 } else {
350 203 $ws = ' ' x $nsp;
351 }
352 263 @outline = ( $ws, $token );
353 }
354 }
355 } else {
356 #print "# emitting token '".&escape($token)."'\n";
357 971 push @outline, $token;
358 }
359 1483 ▶ if ( $type =~ /^(wn|pp)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^(wn|pp)$/) 277 1206 1483
360 277 &$output_func( join( '', @outline ) );
361 277 $ln++;
362 277 @outline = ();
363 }
364
365 1483 $indent += $indnext;
366 1483 $bracks += $bracknext;
367 }
368 22 ▶ &$output_func( join( '', @outline ) ) if @outline;
Branch: 1 branch
BranchTrueFalseTotal
if @outline 1 21 22
369 22 ▶ print "\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 22 22
370 22 return;
371 }
372
373 5 1;
374
375 __END__
↑ Summary