-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
line number for files with no newline
The parser sets the line number used for error messages once reaching a newline. This fixes the logic for the case that the input file does not have a newline. This is only visible on .i files, as the preprocessor adds a newline when there isn't one on .c files.
- Loading branch information
Showing
6 changed files
with
32 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
file_with_no_newline.i | ||
|
||
^file file_with_no_newline\.i line 1 function syntax: .*$ | ||
^EXIT=6$ | ||
^SIGNAL=0$ | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
syntax error, no newline here -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <filesystem> | ||
#include <iosfwd> | ||
#include <limits> | ||
#include <string> | ||
#include <vector> | ||
|
||
|
@@ -33,7 +34,7 @@ class parsert | |
: in(nullptr), | ||
log(message_handler), | ||
line_no(0), | ||
previous_line_no(0), | ||
previous_line_no(std::numeric_limits<unsigned int>::max()), | ||
column(1) | ||
{ | ||
} | ||
|
@@ -82,14 +83,14 @@ class parsert | |
|
||
void set_file(const irep_idt &file) | ||
{ | ||
source_location.set_file(file); | ||
source_location.set_working_directory( | ||
_source_location.set_file(file); | ||
_source_location.set_working_directory( | ||
std::filesystem::current_path().string()); | ||
} | ||
|
||
irep_idt get_file() const | ||
{ | ||
return source_location.get_file(); | ||
return _source_location.get_file(); | ||
} | ||
|
||
unsigned get_line_no() const | ||
|
@@ -107,21 +108,31 @@ class parsert | |
column=_column; | ||
} | ||
|
||
void set_source_location(exprt &e) | ||
const source_locationt &source_location() | ||
{ | ||
// Only set line number when needed, as this destroys sharing. | ||
if(previous_line_no!=line_no) | ||
{ | ||
previous_line_no=line_no; | ||
source_location.set_line(line_no); | ||
|
||
// for the case of a file with no newlines | ||
if(line_no == 0) | ||
_source_location.set_line(1); | ||
else | ||
_source_location.set_line(line_no); | ||
} | ||
|
||
e.add_source_location()=source_location; | ||
return _source_location; | ||
} | ||
|
||
void set_source_location(exprt &e) | ||
{ | ||
e.add_source_location() = source_location(); | ||
} | ||
|
||
void set_function(const irep_idt &function) | ||
{ | ||
source_location.set_function(function); | ||
_source_location.set_function(function); | ||
} | ||
|
||
void advance_column(unsigned token_width) | ||
|
@@ -131,7 +142,7 @@ class parsert | |
|
||
protected: | ||
messaget log; | ||
source_locationt source_location; | ||
source_locationt _source_location; | ||
unsigned line_no, previous_line_no; | ||
unsigned column; | ||
}; | ||
|