Preserve line breaks from continued line comments

The commit "Preserve line breaks in comments before test functions"
only handled block comments. This commit handles line comments.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2022-11-30 16:38:49 +01:00
parent d8c0803821
commit 18f7028a0e
2 changed files with 8 additions and 1 deletions

View file

@ -537,11 +537,15 @@ def skip_comments(line, stream):
break
if line[opening.start(0) + 1] == '/': # //...
continuation = line
# Count the number of line breaks, to keep line numbers aligned
# in the output.
line_count = 1
while continuation.endswith('\\\n'):
# This errors out if the file ends with an unfinished line
# comment. That's acceptable to not complicate the code further.
continuation = next(stream)
return line[:opening.start(0)].rstrip() + '\n'
line_count += 1
return line[:opening.start(0)].rstrip() + '\n' * line_count
# Parsing /*...*/, looking for the end
closing = line.find('*/', opening.end(0))
while closing == -1:

View file

@ -767,6 +767,8 @@ exit:
void test_func()
{
ba ba black sheep
@ -813,6 +815,7 @@ exit:
expected = '''#line 1 "test_suite_ut.function"
void test_func( int x,
int y )
{
ba ba black sheep