line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Token.pm,v 1.7 2015/04/18 18:02:05 Paulo Exp $
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Asm::Preproc::Token;
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Asm::Preproc::Token - One token retrieved from the input
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
1948
|
use strict;
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
77
|
|
16
|
3
|
|
|
3
|
|
9
|
use warnings;
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
97
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '1.01';
|
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
1903
|
use Data::Dump 'dump';
|
|
3
|
|
|
|
|
10119
|
|
|
3
|
|
|
|
|
158
|
|
21
|
3
|
|
|
3
|
|
388
|
use Asm::Preproc::Line;
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
83
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Asm::Preproc::Token;
|
28
|
|
|
|
|
|
|
my $token = Asm::Preproc::Token->new($type, $value, $line);
|
29
|
|
|
|
|
|
|
$token->type; $token->value;
|
30
|
|
|
|
|
|
|
$token->line; # isa Asm::Preproc::Line
|
31
|
|
|
|
|
|
|
my $token2 = $token->clone;
|
32
|
|
|
|
|
|
|
$token->error($message);
|
33
|
|
|
|
|
|
|
$token->warning($message);
|
34
|
|
|
|
|
|
|
Asm::Preproc::Token->error_at($token, $message);
|
35
|
|
|
|
|
|
|
Asm::Preproc::Token->warning_at($token, $message);
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This module defines the object to represent one token of input text as retrieved
|
40
|
|
|
|
|
|
|
from the preprocessed input text.
|
41
|
|
|
|
|
|
|
It contains the token type (a string), the token value (a string) and a
|
42
|
|
|
|
|
|
|
L object with the line where the token
|
43
|
|
|
|
|
|
|
was found.
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
There are also utility methods for error messages.
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 new
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Creates a new object with the given type, value and line.
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 type
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Get/set type.
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 value
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Get/set file value.
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 line
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Get/set line.
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 clone
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Creates an identical copy as a new object.
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
72
|
|
|
|
|
|
|
use Class::XSAccessor::Array {
|
73
|
3
|
|
|
|
|
19
|
accessors => {
|
74
|
|
|
|
|
|
|
type => 0,
|
75
|
|
|
|
|
|
|
value => 1,
|
76
|
|
|
|
|
|
|
_line => 2,
|
77
|
|
|
|
|
|
|
},
|
78
|
|
|
|
|
|
|
predicates => {
|
79
|
|
|
|
|
|
|
_has_line => 2,
|
80
|
|
|
|
|
|
|
},
|
81
|
3
|
|
|
3
|
|
10
|
};
|
|
3
|
|
|
|
|
3
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# create line on demand
|
84
|
|
|
|
|
|
|
sub line {
|
85
|
209
|
|
|
209
|
1
|
48336
|
my $self = shift;
|
86
|
209
|
100
|
|
|
|
736
|
$self->_has_line or $self->_line( Asm::Preproc::Line->new );
|
87
|
209
|
|
|
|
|
543
|
$self->_line(@_);
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub new {
|
91
|
|
|
|
|
|
|
#my($class, $type, $value, $line) = @_;
|
92
|
67
|
|
|
67
|
1
|
623
|
my $class = shift;
|
93
|
67
|
|
|
|
|
250
|
bless [@_], $class;
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub clone {
|
97
|
1
|
|
|
1
|
1
|
1
|
my $self = shift;
|
98
|
1
|
|
|
|
|
8
|
bless [$self->type, $self->value, $self->line->clone], ref($self);
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 error
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Dies with the given error message, indicating the place in the input source file
|
106
|
|
|
|
|
|
|
where the error occured as:
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
FILE(LINE) : error ... at TOKEN
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
113
|
|
|
|
|
|
|
sub error {
|
114
|
12
|
|
|
12
|
1
|
13
|
my($self, $message) = @_;
|
115
|
12
|
|
|
|
|
16
|
$self->line->error($self->_format_error_msg($message));
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 error_at
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Same as error(), but is a class method and can receive an undef $token.
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
126
|
|
|
|
|
|
|
sub error_at {
|
127
|
24
|
|
|
24
|
1
|
5598
|
my($class, $token, $message) = @_;
|
128
|
24
|
|
66
|
|
|
55
|
$token ||= $class->new();
|
129
|
24
|
|
|
|
|
29
|
$token->line->error($token->_format_error_msg($message));
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 warning
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Warns with the given error message, indicating the place in the input source file
|
136
|
|
|
|
|
|
|
where the error occured as:
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
FILE(LINE) : warning ... at TOKEN
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
143
|
|
|
|
|
|
|
sub warning {
|
144
|
12
|
|
|
12
|
1
|
2726
|
my($self, $message) = @_;
|
145
|
12
|
|
|
|
|
16
|
$self->line->warning($self->_format_error_msg($message));
|
146
|
|
|
|
|
|
|
}
|
147
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 warning_at
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Same as warning(), but is a class method and can receive an undef $token.
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
156
|
|
|
|
|
|
|
sub warning_at {
|
157
|
24
|
|
|
24
|
1
|
5647
|
my($class, $token, $message) = @_;
|
158
|
24
|
|
66
|
|
|
52
|
$token ||= $class->new();
|
159
|
24
|
|
|
|
|
31
|
$token->line->warning($token->_format_error_msg($message));
|
160
|
|
|
|
|
|
|
}
|
161
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
162
|
|
|
|
|
|
|
# error message for error() and warning()
|
163
|
|
|
|
|
|
|
sub _format_error_msg {
|
164
|
72
|
|
|
72
|
|
53
|
my($self, $message) = @_;
|
165
|
72
|
|
|
|
|
71
|
my $type = $self->type;
|
166
|
|
|
|
|
|
|
|
167
|
72
|
100
|
|
|
|
93
|
defined($message) or $message = "";
|
168
|
72
|
|
|
|
|
183
|
$message =~ s/\s+$//;
|
169
|
72
|
100
|
|
|
|
107
|
$message .= " " if $message ne "";
|
170
|
72
|
100
|
|
|
|
150
|
$message .= "at ".
|
|
|
100
|
|
|
|
|
|
171
|
|
|
|
|
|
|
(! defined($type) ?
|
172
|
|
|
|
|
|
|
"EOF" :
|
173
|
|
|
|
|
|
|
$type =~ /\W/ ?
|
174
|
|
|
|
|
|
|
dump($type) :
|
175
|
|
|
|
|
|
|
$type
|
176
|
|
|
|
|
|
|
);
|
177
|
72
|
|
|
|
|
817
|
return $message;
|
178
|
|
|
|
|
|
|
}
|
179
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR, BUGS, SUPPORT, LICENSE, COPYRIGHT
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
See L.
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1;
|