@@ -17,6 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com
1717
1818#include < filesystem>
1919#include < iosfwd>
20+ #include < limits>
2021#include < string>
2122#include < vector>
2223
@@ -33,7 +34,7 @@ class parsert
3334 : in(nullptr ),
3435 log(message_handler),
3536 line_no(0 ),
36- previous_line_no(0 ),
37+ previous_line_no(std::numeric_limits< unsigned int >::max() ),
3738 column(1 )
3839 {
3940 }
@@ -82,14 +83,14 @@ class parsert
8283
8384 void set_file (const irep_idt &file)
8485 {
85- source_location .set_file (file);
86- source_location .set_working_directory (
86+ _source_location .set_file (file);
87+ _source_location .set_working_directory (
8788 std::filesystem::current_path ().string ());
8889 }
8990
9091 irep_idt get_file () const
9192 {
92- return source_location .get_file ();
93+ return _source_location .get_file ();
9394 }
9495
9596 unsigned get_line_no () const
@@ -107,21 +108,31 @@ class parsert
107108 column=_column;
108109 }
109110
110- void set_source_location (exprt &e )
111+ const source_locationt & source_location ( )
111112 {
112113 // Only set line number when needed, as this destroys sharing.
113114 if (previous_line_no!=line_no)
114115 {
115116 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);
117123 }
118124
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 ();
120131 }
121132
122133 void set_function (const irep_idt &function)
123134 {
124- source_location .set_function (function);
135+ _source_location .set_function (function);
125136 }
126137
127138 void advance_column (unsigned token_width)
@@ -131,7 +142,7 @@ class parsert
131142
132143protected:
133144 messaget log;
134- source_locationt source_location ;
145+ source_locationt _source_location ;
135146 unsigned line_no, previous_line_no;
136147 unsigned column;
137148};
0 commit comments