1
0
mirror of https://github.com/ARMmbed/mbedtls.git synced 2025-05-12 01:42:21 +08:00

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

View File

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