| 1 | 26 | ▶ | use TestML1::Runtime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package TestML1::Compiler; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 26 | ▶ | use TestML1::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 26 | has code => (); | |||||||||||||||||||||||||||
| 8 | 26 | has data => (); | |||||||||||||||||||||||||||
| 9 | 26 | has text => (); | |||||||||||||||||||||||||||
| 10 | 26 | has directives => (); | |||||||||||||||||||||||||||
| 11 | 26 | has function => (); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 25 | ▶ | sub compile { | ||||||||||||||||||||||||||
|
Subroutine
compile: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 25 | my ($self, $input) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 25 | $self->preprocess($input, 'top'); | |||||||||||||||||||||||||||
| 17 | 25 | $self->compile_code; | |||||||||||||||||||||||||||
| 18 | 25 | $self->compile_data; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 25 | ▶ | if ($self->directives->{DumpAST}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 0 | XXX($self->function); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 25 | $self->function->namespace->{TestML} = $self->directives->{TestML}; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 25 | $self->function->outer(TestML1::Function->new); | |||||||||||||||||||||||||||
| 27 | 25 | return $self->function; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 27 | ▶ | sub preprocess { | ||||||||||||||||||||||||||
|
Subroutine
preprocess: called CC=22 SCAR=33.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 27 | my ($self, $input, $top) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 27 | my @parts = split /^((?:\%\w+.*|\#.*|\ *)\n)/m, $input; | |||||||||||||||||||||||||||
| 34 | 27 | $input = ''; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | $self->{directives} = { | ||||||||||||||||||||||||||||
| 37 | 27 | TestML => '', | |||||||||||||||||||||||||||
| 38 | DataMarker => '', | ||||||||||||||||||||||||||||
| 39 | BlockMarker => '===', | ||||||||||||||||||||||||||||
| 40 | PointMarker => '---', | ||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 27 | my $order_error = 0; | |||||||||||||||||||||||||||
| 44 | 27 | for my $part (@parts) { | |||||||||||||||||||||||||||
| 45 | 437 | ▶ | next unless length($part); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 339 | ▶ | if ($part =~ /^(\#.*|\ *)\n/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 179 | $input .= "\n"; | |||||||||||||||||||||||||||
| 48 | 179 | next; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 160 | ▶ | if ($part =~ /^%(\w+)\s*(.*?)\s*\n/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 29 | my ($directive, $value) = ($1, $2); | |||||||||||||||||||||||||||
| 52 | 29 | $input .= "\n"; | |||||||||||||||||||||||||||
| 53 | 29 | ▶ | if ($directive eq 'TestML') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 25 | ▶ | die "Invalid TestML directive" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | unless $value =~ /^\d+\.\d+\.\d+$/; | ||||||||||||||||||||||||||||
| 56 | die "More than one TestML directive found" | ||||||||||||||||||||||||||||
| 57 | 25 | ▶ | if $self->directives->{TestML}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | $self->directives->{TestML} = | ||||||||||||||||||||||||||||
| 59 | 25 | TestML1::Str->new(value => $value); | |||||||||||||||||||||||||||
| 60 | 25 | next; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 4 | ▶ | $order_error = 1 unless $self->directives->{TestML}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 4 | ▶ | if ($directive eq 'Include') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | my $runtime = $TestML1::Runtime::Singleton | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | or die "Can't process Include. No runtime available"; | ||||||||||||||||||||||||||||
| 66 | 2 | my $include = ref($self)->new; | |||||||||||||||||||||||||||
| 67 | 2 | $include->preprocess($runtime->read_testml_file($value)); | |||||||||||||||||||||||||||
| 68 | 2 | $input .= $include->text; | |||||||||||||||||||||||||||
| 69 | $self->directives->{DataMarker} = | ||||||||||||||||||||||||||||
| 70 | 2 | $include->directives->{DataMarker}; | |||||||||||||||||||||||||||
| 71 | $self->directives->{BlockMarker} = | ||||||||||||||||||||||||||||
| 72 | 2 | $include->directives->{BlockMarker}; | |||||||||||||||||||||||||||
| 73 | $self->directives->{PointMarker} = | ||||||||||||||||||||||||||||
| 74 | 2 | $include->directives->{PointMarker}; | |||||||||||||||||||||||||||
| 75 | die "Can't define %TestML in an Included file" | ||||||||||||||||||||||||||||
| 76 | 2 | ▶ | if $include->directives->{TestML}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | elsif ($directive =~ /^(DataMarker|BlockMarker|PointMarker)$/) { | ||||||||||||||||||||||||||||
| 79 | 2 | $self->directives->{$directive} = $value; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | elsif ($directive =~ /^(DebugPegex|DumpAST)$/) { | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $value = 1 unless length($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | $self->directives->{$directive} = $value; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||||||||||
| 86 | 0 | die "Unknown TestML directive '$directive'"; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 131 | ▶ | $order_error = 1 if $input and not $self->directives->{TestML}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$input and not $self->directives->{"TestML"}
MC/DC0%0/2
$input and not $self->directives->{"TestML"}
$input
not $self->directives->{"TestML"}
Truth table66%2/3
A and not(B)
A= $inputB= not $self->directives->{"TestML"}
| |||||||||||||||||||||||||||||
| 91 | 131 | $input .= $part; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 27 | ▶ | if ($top) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | die "No TestML directive found" | ||||||||||||||||||||||||||||
| 97 | 25 | ▶ | unless $self->directives->{TestML}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 25 | ▶ | die "%TestML directive must be the first (non-comment) statement" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | if $order_error; | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | my $DataMarker = | ||||||||||||||||||||||||||||
| 102 | $self->directives->{DataMarker} ||= | ||||||||||||||||||||||||||||
| 103 | 25 | ▶ | $self->directives->{BlockMarker}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->directives->{"DataMarker"} ||= $self->directives->{"BlockMarker"}
MC/DC0%0/2
$self->directives->{"DataMarker"} ||= $self->directives->{"BlockMarker"}
$self->directives->{"DataMarker"}
$self->directives->{"BlockMarker"}
Truth table33%1/3
A ||= B
A= $self->directives->{"DataMarker"}B= $self->directives->{"BlockMarker"}
| |||||||||||||||||||||||||||||
| 104 | 25 | ▶ | if ((my $split = index($input, "\n$DataMarker")) >= 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 17 | $self->{code} = substr($input, 0, $split + 1); | |||||||||||||||||||||||||||
| 106 | 17 | $self->{data} = substr($input, $split + 1); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||
| 109 | 8 | $self->{code} = $input; | |||||||||||||||||||||||||||
| 110 | 8 | $self->{data} = ''; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||||||||||
| 114 | 2 | $self->{text} = $input; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 26 | 1; | |||||||||||||||||||||||||||