Open atyrberg opened 2 years ago
This looks like a bug to me. See #58.
Thanks, Dave, this seems to fix the default_nettype
case (and probably many other preprocessor directives).
The include case seems still to be wrong, but I guess that is a harder problem to solve since multiple files are involved.
@atyrberg Would you mind making a draft PR or branch with a testcase? Perhaps by adding some checks to test2: https://github.com/dalance/sv-parser/blob/master/sv-parser-pp/src/preprocess.rs#L919
Thanks for the help to try to solve this.
I have added a commit atyrberg/sv-parser@ed2eac6d583640da3af0fe11f7c639aabdc517ed with a test showing the line number issue for include files. The line numbers are incorrect both for statements in the include file and in the source file. Also, I have not found any way to see if a statement is from an include file or from the source file (see out-comment assert in test).
I didn't manage to add the test to preprocessor.rs
since I'm not sure if the problem is visible at this stage of the parsing. There are probably better ways to write this test, but I hope it shows the problem.
Thanks, I see what you mean now, but I'm not sure of an immediate fix.
@atyrberg Are your cases helped by #61? If not, would you consider adding some tests in sv-parser-pp/src/preprocess.rs
? I think that adding tests is a bit easier now.
@DaveMcEwan After some simple testing, #61 doesn't seem to fix the problem.
I have looked quickly in sv-parser-pp/src/preprocess.rs
but what I can see the problem is not there. In the preprocessor stage, it looks like the information is there (and probably correct, the origins
in PreprocessedText
have different PathBuf
for the source file and the include file). I think the information about the included files is lost in some later stage.
Some preprocessor directives seem to give wrong line numbers.
The
default_nettype
get the correct line number, but everything after have line number offset by 1.Using include seems to offset the line number with the number of lines in the included file.
inc.vh
:Is there some why to get the line number of the source-file (and in case of includes which source/include-file) and not (what I guess) the preprocessed file? Or is this a bug?