@@ -17,6 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com
17
17
18
18
#include < filesystem>
19
19
#include < iosfwd>
20
+ #include < limits>
20
21
#include < string>
21
22
#include < vector>
22
23
@@ -33,7 +34,7 @@ class parsert
33
34
: in(nullptr ),
34
35
log(message_handler),
35
36
line_no(0 ),
36
- previous_line_no(0 ),
37
+ previous_line_no(std::numeric_limits< unsigned int >::max() ),
37
38
column(1 )
38
39
{
39
40
}
@@ -82,14 +83,14 @@ class parsert
82
83
83
84
void set_file (const irep_idt &file)
84
85
{
85
- source_location .set_file (file);
86
- source_location .set_working_directory (
86
+ _source_location .set_file (file);
87
+ _source_location .set_working_directory (
87
88
std::filesystem::current_path ().string ());
88
89
}
89
90
90
91
irep_idt get_file () const
91
92
{
92
- return source_location .get_file ();
93
+ return _source_location .get_file ();
93
94
}
94
95
95
96
unsigned get_line_no () const
@@ -107,21 +108,31 @@ class parsert
107
108
column=_column;
108
109
}
109
110
110
- void set_source_location (exprt &e )
111
+ const source_locationt & source_location ( )
111
112
{
112
113
// Only set line number when needed, as this destroys sharing.
113
114
if (previous_line_no!=line_no)
114
115
{
115
116
previous_line_no=line_no;
116
- source_location.set_line (line_no);
117
+
118
+ // for the case of a file with no newlines
119
+ if (line_no == 0 )
120
+ _source_location.set_line (1 );
121
+ else
122
+ _source_location.set_line (line_no);
117
123
}
118
124
119
- e.add_source_location ()=source_location;
125
+ return _source_location;
126
+ }
127
+
128
+ void set_source_location (exprt &e)
129
+ {
130
+ e.add_source_location () = source_location ();
120
131
}
121
132
122
133
void set_function (const irep_idt &function)
123
134
{
124
- source_location .set_function (function);
135
+ _source_location .set_function (function);
125
136
}
126
137
127
138
void advance_column (unsigned token_width)
@@ -131,7 +142,7 @@ class parsert
131
142
132
143
protected:
133
144
messaget log;
134
- source_locationt source_location ;
145
+ source_locationt _source_location ;
135
146
unsigned line_no, previous_line_no;
136
147
unsigned column;
137
148
};
0 commit comments