Spurious "Unbalanced pre-processor directed" when no newline after final `endif
Status: Beta
Brought to you by:
mballance
The standard multiple inclusion guard gets marked with an "Unbalanced pre-preprocessor directive" error if there is no newline after the final '`endif'
`ifndef __MY_FILE_SV__ `define __MY_FILE_SV__ interface my_interface_if ; logic thingy ; endinterface `endif // <-- If there is NO newline here.... // last char is the 'f'
Diff:
Just tested this in 1.8.3. I don't see the issue. Can I close it as fixed?
6 days after stating that I can't replicate the issue, I replicate the issue. Looks like it stays open for now.
The trick is to have the code above as a file that is included in another file. Below I have 2 files, which replicate the issue. Looks like the "fileid" of the `endif is being added incorrectly (i.e. bleeds over into the next file).
top.sv:
sub.sv:
Last edit: StevenAZ 2016-04-13
Poking around a bit ... it appears that the following occurs in SVPreProcessor2.java:
SVPreProcessor2.java will call "AbstractTextScanner:readPreProcIdentifier" which calls "get_ch". If "get_ch" reaches an end of file, it calls "leave_file" before returning, which in turn will call the "cleanup_preproc_leftovers" which flags an error.
Once we return, "readPreProcIdentifier" will retun the "endif" which would normally pop the identifier stack, but too late.
There's probably a million ways of doing this ...
One crude way is to replace the "AbstractTextScanner.java::readPreProcIdentifier" with the following code. Down side is that we are doing a string compare every time we read a character in a `some_field which could slow the parsing down.
I dare say there is a more elegant, less expensive way of fixing this.
~~~~~~~
Last edit: StevenAZ 2016-04-14
Corrected in 1.8.8. Updated the preprocessor to ensure that every file appears to end with a newline.