line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
10
|
|
|
10
|
|
2308
|
use strict;
|
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
292
|
|
16
|
10
|
|
|
10
|
|
50
|
use warnings;
|
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
470
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
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
|
10
|
|
|
10
|
|
56
|
use base 'Class::Accessor';
|
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
5124
|
|
70
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(
|
71
|
|
|
|
|
|
|
'text',
|
72
|
|
|
|
|
|
|
'file',
|
73
|
|
|
|
|
|
|
'line_nr',
|
74
|
|
|
|
|
|
|
);
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new {
|
77
|
205
|
|
|
205
|
1
|
36390
|
my($class, $text, $file, $line_nr) = @_;
|
78
|
205
|
|
|
|
|
1029
|
bless {text => $text, file => $file, line_nr => $line_nr}, $class;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub clone {
|
82
|
2
|
|
|
2
|
1
|
1702
|
my $self = shift;
|
83
|
2
|
|
|
|
|
19
|
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
|
|
|
20
|
1
|
37
|
sub is_equal { my($self, $other) = @_;
|
98
|
10
|
|
|
10
|
|
19206
|
no warnings 'uninitialized';
|
|
10
|
|
|
|
|
32
|
|
|
10
|
|
|
|
|
987
|
|
99
|
20
|
|
100
|
|
|
44
|
return $self->text eq $other->text &&
|
100
|
|
|
|
|
|
|
$self->line_nr == $other->line_nr &&
|
101
|
|
|
|
|
|
|
$self->file eq $other->file;
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
10
|
|
|
10
|
|
1216
|
use overload '==' => \&is_equal, fallback => 1;
|
|
10
|
|
|
|
|
952
|
|
|
10
|
|
|
|
|
96
|
|
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
|
|
|
10
|
1
|
1397
|
sub is_different { my($self, $other) = @_;
|
117
|
10
|
|
|
|
|
24
|
return ! $self->is_equal($other);
|
118
|
|
|
|
|
|
|
}
|
119
|
|
|
|
|
|
|
|
120
|
10
|
|
|
10
|
|
1282
|
use overload '!=' => \&is_different, fallback => 1;
|
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
50
|
|
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
|
|
|
|
|
|
|
sub error {
|
134
|
52
|
|
|
52
|
1
|
107
|
my($self, $message) = @_;
|
135
|
52
|
|
|
|
|
129
|
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
|
|
|
45
|
1
|
4900
|
sub warning { my($self, $message) = @_;
|
150
|
45
|
|
|
|
|
91
|
warn $self->_error_msg("warning", $message);
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
153
|
|
|
|
|
|
|
# error message for error() and warning()
|
154
|
|
|
|
|
|
|
sub _error_msg {
|
155
|
97
|
|
|
97
|
|
185
|
my($self, $type, $message) = @_;
|
156
|
|
|
|
|
|
|
|
157
|
10
|
|
|
10
|
|
1551
|
no warnings 'uninitialized';
|
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
1456
|
|
158
|
|
|
|
|
|
|
|
159
|
97
|
|
|
|
|
195
|
my $file = $self->file;
|
160
|
97
|
100
|
|
|
|
993
|
my $line_nr = $self->line_nr ? '('.$self->line_nr.')' : '';
|
161
|
97
|
100
|
|
|
|
1323
|
my $pos = "$file$line_nr"; $pos .= " : " if $pos;
|
|
97
|
|
|
|
|
214
|
|
162
|
|
|
|
|
|
|
|
163
|
97
|
|
|
|
|
345
|
$message =~ s/\s+$//; # in case message comes from die, has a "\n"
|
164
|
|
|
|
|
|
|
|
165
|
97
|
|
|
|
|
694
|
return "$pos$type: $message\n";
|
166
|
|
|
|
|
|
|
}
|
167
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 AUTHOR, BUGS, SUPPORT, LICENSE, COPYRIGHT
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
See L.
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1;
|