| 1 | # $Id: Line.pm,v 1.10 2013/07/26 01:57:26 Paulo Exp $ | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | package Asm::Preproc::Line; | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | Asm::Preproc::Line - One line of text retrieved from the input | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | =cut | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 11 | our $VERSION = '1.03'; | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | use Asm::Preproc::Line; | ||||||||||||||||||||||||||||||||||
| 25 | my $line = Asm::Preproc::Line->new($text, $file, $line_nr); | ||||||||||||||||||||||||||||||||||
| 26 | $line->text; $line->rtext; $line->file; $line->line_nr; | ||||||||||||||||||||||||||||||||||
| 27 | my $line2 = $line->clone; | ||||||||||||||||||||||||||||||||||
| 28 | if ($line == $line2) {...} | ||||||||||||||||||||||||||||||||||
| 29 | if ($line != $line2) {...} | ||||||||||||||||||||||||||||||||||
| 30 | $line->error($message); | ||||||||||||||||||||||||||||||||||
| 31 | $line->warning($message); | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | This module defines the object to represent one line of input text | ||||||||||||||||||||||||||||||||||
| 36 | to preprocess. It contains the actual text from the line, and the file name | ||||||||||||||||||||||||||||||||||
| 37 | and line number where the text was retrieved. It contains also utility methods | ||||||||||||||||||||||||||||||||||
| 38 | for error messages. | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | =head2 new | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | Creates a new object with the given text, file name and line number. | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | =head2 text | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | Get/set line text. | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | =head2 rtext | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | Return reference to the text value. | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | =head2 file | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | Get/set file name. | ||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | =head2 line_nr | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | Get/set line number. | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | =head2 clone | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | Creates an identical copy as a new object. | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 69 | 11 | ▶ | use base 'Class::Accessor'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 70 | 11 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||||||||
| 71 | 'text', | ||||||||||||||||||||||||||||||||||
| 72 | 'file', | ||||||||||||||||||||||||||||||||||
| 73 | 'line_nr', | ||||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 205 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 77 | 205 | my($class, $text, $file, $line_nr) = @_; | |||||||||||||||||||||||||||||||||
| 78 | 205 | bless {text => $text, file => $file, line_nr => $line_nr}, $class; | |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 82 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 83 | 2 | bless {%$self}, ref($self); | |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | =head2 is_equal | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | if ($self == $other) { ... } | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | Compares two line objects. Overloads the '==' operator. | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 97 | 20 | ▶ | sub is_equal { my($self, $other) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
is_equal: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 98 | 11 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 99 | 20 | ▶ | return $self->text eq $other->text && | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
$self->text eq $other->text && $self->line_nr == $other->line_nr && $self->file eq $other->file
$self->text eq $other->text and $self->line_nr == $other->line_nr
MC/DC100%3/3
$self->text eq $other->text && $self->line_nr == $other->line_nr && $self->file eq $other->file
$self->text eq $other->text
$self->line_nr == $other->line_nr
$self->file eq $other->file
Truth table100%4/4
A and B && C
A= $self->text eq $other->textB= $self->line_nr == $other->line_nrC= $self->file eq $other->file
| |||||||||||||||||||||||||||||||||||
| 100 | $self->line_nr == $other->line_nr && | ||||||||||||||||||||||||||||||||||
| 101 | $self->file eq $other->file; | ||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 11 | ▶ | use overload '==' => \&is_equal, fallback => 1; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 105 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | =head2 is_different | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | if ($self != $other) { ... } | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | Compares two line objects. Overloads the '!=' operator. | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 116 | 10 | ▶ | sub is_different { my($self, $other) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
is_different: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 117 | 10 | return ! $self->is_equal($other); | |||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | 11 | ▶ | use overload '!=' => \&is_different, fallback => 1; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 121 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | =head2 error | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | Dies with the given error message, indicating the place in the input source file | ||||||||||||||||||||||||||||||||||
| 126 | where the error occured as: | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | FILE(LINE) : error: MESSAGE | ||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 133 | 52 | ▶ | sub error { | ||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 134 | 52 | my($self, $message) = @_; | |||||||||||||||||||||||||||||||||
| 135 | 52 | die $self->_error_msg("error", $message); | |||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | =head2 warning | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | Warns with the given error message, indicating the place in the input source file | ||||||||||||||||||||||||||||||||||
| 142 | where the error occured as: | ||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | FILE(LINE) : warning: MESSAGE | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 149 | 45 | ▶ | sub warning { my($self, $message) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
warning: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 150 | 45 | warn $self->_error_msg("warning", $message); | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 153 | # error message for error() and warning() | ||||||||||||||||||||||||||||||||||
| 154 | 97 | ▶ | sub _error_msg { | ||||||||||||||||||||||||||||||||
|
Subroutine
_error_msg: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 155 | 97 | my($self, $type, $message) = @_; | |||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | 11 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 97 | my $file = $self->file; | |||||||||||||||||||||||||||||||||
| 160 | 97 | ▶ | my $line_nr = $self->line_nr ? '('.$self->line_nr.')' : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 161 | 97 | ▶ | my $pos = "$file$line_nr"; $pos .= " : " if $pos; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | 97 | $message =~ s/\s+$//; # in case message comes from die, has a "\n" | |||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 97 | return "$pos$type: $message\n"; | |||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||
| 167 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | =head1 AUTHOR, BUGS, SUPPORT, LICENSE, COPYRIGHT | ||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | See L<Asm::Preproc|Asm::Preproc>. | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||
| 177 | 11 | 1; | |||||||||||||||||||||||||||||||||