SXXXXXXX_PyUCC/tools/debug_comments.py

75 lines
2.3 KiB
Python

"""Debug script to understand comment counting differences."""
from pathlib import Path
import re
test_file = Path(r"C:\__temp\Metrics\_25_10\REP\Projects\DSP\ChimeraMCK\dev\mck_c66\mck_c66_boot_multicore.c")
if not test_file.exists():
print("File not found")
exit(1)
with open(test_file, 'r', encoding='utf-8', errors='ignore') as f:
lines = f.readlines()
print("Analyzing comment patterns...")
print("=" * 80)
in_block = False
comment_whole = 0
comment_embedded = 0
blank = 0
for i, line in enumerate(lines, 1):
stripped = line.strip()
if not stripped:
blank += 1
continue
# Check for whole line comments
if stripped.startswith('//'):
comment_whole += 1
if i <= 50:
print(f"Line {i:3d} (WHOLE //): {line.rstrip()}")
elif stripped.startswith('/*'):
# Check if ends on same line
if '*/' in stripped:
if stripped == '/*' + stripped[2:stripped.index('*/')].strip() + '*/':
comment_whole += 1
if i <= 50:
print(f"Line {i:3d} (WHOLE /*): {line.rstrip()}")
else:
comment_embedded += 1
if i <= 50:
print(f"Line {i:3d} (EMBED /*): {line.rstrip()}")
else:
comment_whole += 1
in_block = True
if i <= 50:
print(f"Line {i:3d} (WHOLE /* START): {line.rstrip()}")
elif in_block:
if '*/' in line:
in_block = False
after = line[line.index('*/') + 2:].strip()
if after:
comment_embedded += 1
if i <= 50:
print(f"Line {i:3d} (EMBED */ END): {line.rstrip()}")
# Don't count this line - was already counted at block start
# else: don't count continuation lines
elif '//' in stripped or '/*' in stripped:
comment_embedded += 1
if i <= 50:
print(f"Line {i:3d} (EMBED INLINE): {line.rstrip()}")
print("\n" + "=" * 80)
print(f"Manual count:")
print(f" Blank: {blank}")
print(f" Comment Whole: {comment_whole}")
print(f" Comment Embedded: {comment_embedded}")
print(f"\nUCC Expected:")
print(f" Blank: 86")
print(f" Comment Whole: 45")
print(f" Comment Embedded: 13")