| 1 | # /=====================================================================\ # | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | LaTeXML::Core::Definition | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | Representation of definitions of Control Sequences | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # |=====================================================================| # | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | Part of LaTeXML: | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | Public domain software, produced as part of work done by the | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | United States Government & not subject to copyright in the US. | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # |---------------------------------------------------------------------| # | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | Bruce Miller <bruce.miller@nist.gov> #_# | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | http://dlmf.nist.gov/LaTeXML/ (o o) | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # \=========================================================ooo==U==ooo=/ # | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | package LaTeXML::Core::Definition; | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use LaTeXML::Global; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use LaTeXML::Common::Object; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use LaTeXML::Core::Token; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use LaTeXML::Core::Parameters; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use base qw(LaTeXML::Common::Object); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Make these present, but do not import. | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | require LaTeXML::Core::Definition::Expandable; | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | require LaTeXML::Core::Definition::Conditional; | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | require LaTeXML::Core::Definition::Primitive; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | require LaTeXML::Core::Definition::Register; | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | require LaTeXML::Core::Definition::CharDef; | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | require LaTeXML::Core::Definition::Constructor; | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #********************************************************************** | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | sub isaDefinition { | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return 1; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isaDefinition: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sub getCS { | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getCS: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $$self{cs}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | sub getCSName { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getCSName: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return (defined $$self{alias} ? $$self{alias} : $$self{cs}->getCSName); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # NOTE: Need to clean up alias; really should already be Token (or Tokens?) | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # and is not always a CS! | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | sub getCSorAlias { | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getCSorAlias: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return (defined $$self{alias} ? T_CS($$self{alias}) : $$self{cs}); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub isExpandable { | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return 0; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isExpandable: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | sub isRegister { | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return ''; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isRegister: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sub isPrefix { | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return 0; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isPrefix: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # The following come from flags, but probably(?) only make sense for Expandable (macros) | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # and furthermore, only isProtected is used for anything significant. | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | sub isProtected { | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isProtected: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return $$self{isProtected}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | sub setIsProtected { | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setIsProtected: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $$self{isProtected} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | sub isOuter { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isOuter: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return $$self{isOuter}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | sub setIsOuter { | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setIsOuter: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $$self{isOuter} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | sub isLong { | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isLong: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return $$self{isLong}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | sub setIsLong { | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setIsLong: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $$self{isLong} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | sub getLocator { | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getLocator: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return $$self{locator}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | sub readArguments { | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my ($self, $gullet) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readArguments: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return ($$self{parameters} ? $$self{parameters}->readArguments($gullet, $self) : ()); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | sub getParameters { | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getParameters: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return $$self{parameters}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Overriding methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $type = ref $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $type =~ s/^LaTeXML:://; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $name = ($$self{alias} || $$self{cs}->getCSName); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'alias'} || $self->{'cs'}->getCSName
MC/DC0%0/2
$self->{'alias'} || $self->{'cs'}->getCSName
$self->{'alias'}
$self->{'cs'}->getCSName
Truth table0%0/3
A || B
A= $self->{'alias'}B= $self->{'cs'}->getCSName
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | return $type . '[' . ($$self{parameters} | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | ? $name . ' ' . Stringify($$self{parameters}) : $name) . ']'; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | sub toString { | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toString: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | return ($$self{parameters} | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | ? ToString($$self{cs}) . ' ' . ToString($$self{parameters}) : ToString($$self{cs})); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # Tracing support | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | sub tracingCSName { | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tracingCSName: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $parameters = $$self{parameters}; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | return ToString($self->getCSName) | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Show parameter string too | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | . ($parameters ? ' ' . ToString($parameters) : '') | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # And if this was \let to something show the name it was called by | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | . ($LaTeXML::CURRENT_TOKEN && !$$self{cs}->equals($LaTeXML::CURRENT_TOKEN) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$LaTeXML::CURRENT_TOKEN and not $self->{"cs"}->equals($LaTeXML::CURRENT_TOKEN)
MC/DC0%0/2
$LaTeXML::CURRENT_TOKEN and not $self->{"cs"}->equals($LaTeXML::CURRENT_TOKEN)
$LaTeXML::CURRENT_TOKEN
not $self->{"cs"}->equals($LaTeXML::CURRENT_TOKEN)
Truth table0%0/3
A and not(B)
A= $LaTeXML::CURRENT_TOKENB= not $self->{"cs"}->equals($LaTeXML::CURRENT_TOKEN)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ? ' [for ' . ToString($LaTeXML::CURRENT_TOKEN) . ']' : ''); } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | sub tracingArgs { | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my ($self, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tracingArgs: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return join("\n", map { '#' . $i++ . '<-' . tracingArgToString($_) } @args); } | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Annoying special handing of registers | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | sub tracingArgToString { | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | my ($arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tracingArgToString: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | return (ref $arg eq 'ARRAY' ? '[' . join(',', map { ToString($_) } @$arg) . ']' : ToString($arg)); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Profiling support | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # If the value PROFILING is true, we'll collect some primitive profiling info. | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Start profiling $CS (typically $LaTeXML::CURRENT_TOKEN) | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Call from within ->invoke. | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # $mode = expand | digest | absorb | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | sub startProfiling { | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my ($cs, $mode) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startProfiling: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $name = $cs->getCSName; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $entry = $STATE->lookupMapping('runtime_profile', $name); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | # [#calls, max_depth, inclusive_time, exclusive_time, #pending | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # starts of pending calls...] | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (!defined $entry) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $entry = [0, 0, 0, 0, 0]; $STATE->assignMapping('runtime_profile', $name, $entry); } | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $$entry[0]++ unless $mode eq 'absorb'; # One more call. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $$entry[4]++; # One more pending... | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | #Debug("START PROFILE $mode of ".ToString($cs)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $STATE->pushValue('runtime_stack', [$name, $mode, [Time::HiRes::gettimeofday], $entry]); | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Stop profiling $CS. | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # Complication w/Macros: If the expansion of a macro contains CS's that read tokens, | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # the end MARKER of macros may get read before the macro's effects have really been processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # So we need to ignore a stop on a macro that isn't at the top of the stack, | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # and conversely, automatically stop a macro that is at the top above a CS that is being stopped. | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | sub stopProfiling { | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my ($cs, $mode) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stopProfiling: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $cs = $cs->getString if $cs->getCatcode == CC_MARKER; # Special case for macros!! | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return unless ref $cs; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $name = $cs->getCSName; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $stack = $STATE->lookupValue('runtime_stack'); | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $currdepth = scalar(@$stack); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $prevdepth = $STATE->lookupValue('runtime_maxdepth') || '0'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$LaTeXML::Core::Definition::STATE->lookupValue('runtime_maxdepth') || '0'
MC/DC0%0/1
$LaTeXML::Core::Definition::STATE->lookupValue('runtime_maxdepth') || '0'
$LaTeXML::Core::Definition::STATE->lookupValue('runtime_maxdepth')
Truth table0%0/2
A
A= $LaTeXML::Core::Definition::STATE->lookupValue('runtime_maxdepth')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | $STATE->assignValue('runtime_maxdepth' => $currdepth, 'global') if $currdepth > $prevdepth; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | while (@{$stack}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my ($top, $topmode, $t0, $entry) = @{ $$stack[-1] }; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ((($top ne $name) || ($topmode ne $mode)) && ($topmode ne 'expand')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$top ne $name || $topmode ne $mode and $topmode ne "expand"
$top ne $name or $topmode ne $mode
MC/DC0%0/3
$top ne $name || $topmode ne $mode and $topmode ne "expand"
$top ne $name
$topmode ne $mode
$topmode ne "expand"
Truth table0%0/5
A or B and C
A= $top ne $nameB= $topmode ne $modeC= $topmode ne "expand"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | return if $mode eq 'expand'; # No error (yet) if this is a macro end marker. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | Debug("PROFILE Error: ending $mode of $name but stack holds " | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | . join(',', map { $$_[0] . '(' . $$_[1] . ')' } @$stack) . ", $top ($topmode)"); | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | pop(@$stack); | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $duration = Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday]); | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $depth = $$entry[4]; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ($depth > $$entry[1]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $$entry[1] = $depth; } | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | $$entry[2] += $duration if $depth == 1; # add to inclusive time only in uppermost call | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $$entry[3] += $duration; # add to exclusive time (see below) | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $$entry[4]--; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if (my $caller = $$stack[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my ($callername, $callermode, $callerstart, $callerentry) = @$caller; | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $$callerentry[3] -= $duration; } # Remove our cost from caller's exclusive time. | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return if $top eq $name; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | Debug("PROFILE Error: ending $mode of $name but stack is empty") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | unless $mode eq 'expand'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | our $MAX_PROFILE_ENTRIES = 30; # [CONSTANT] | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # Print out profiling information, if any was collected | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | sub showProfile { | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if (my $profile = $STATE->lookupValue('runtime_profile')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
showProfile: not called CC=3 SCAR=24.8
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my @cs = keys %$profile; | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $calls = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | map { $calls += $$profile{$_}[0] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $depth = $STATE->lookupValue('runtime_maxdepth'); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my @frequent = sort { $$profile{$b}[0] <=> $$profile{$a}[0] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | @frequent = @frequent[0 .. $MAX_PROFILE_ENTRIES]; | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my @deepest = sort { $$profile{$b}[1] <=> $$profile{$a}[1] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | @deepest = @deepest[0 .. $MAX_PROFILE_ENTRIES]; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my @inclusive = sort { $$profile{$b}[2] <=> $$profile{$a}[2] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | @inclusive = @inclusive[0 .. $MAX_PROFILE_ENTRIES]; | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my @exclusive = sort { $$profile{$b}[3] <=> $$profile{$a}[3] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | @exclusive = @exclusive[0 .. $MAX_PROFILE_ENTRIES]; | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | Debug("Profiling results:"); | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | Debug("Total calls: $calls; Maximum depth: $depth"); | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | Debug("Most frequent:\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | . join(', ', map { $_ . ':' . $$profile{$_}[0] } @frequent)); | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | Debug("Deepest :\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | . join(', ', map { $_ . ':' . $$profile{$_}[1] } @deepest)); | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | Debug("Most expensive inclusive:\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | . join(', ', map { $_ . ':' . sprintf("%.2fs", $$profile{$_}[2]) } @inclusive)); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | Debug("Most expensive exclusive:\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | . join(', ', map { $_ . ':' . sprintf("%.2fs", $$profile{$_}[3]) } @exclusive)); | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $stack = $STATE->lookupValue('runtime_stack'); | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if (@$stack) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | Debug("The following were never marked as done:\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | . join(', ', map { $$_[0] . '(' . $$_[1] . ')' } @$stack)); } } | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | #=============================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||