Files
qt6-migration-pipeline/fix_telegrams_smart.py
T
torstenandCopilot d6500157f1 Fix RTI detection: only call FIND_PACKAGE if manual config failed
- Wrap FIND_PACKAGE(RTI) in IF(NOT TARGET RTI::nddsc) condition
- Prevents placeholder targets from overwriting manually configured RTI:: targets
- Manual configuration creates RTI:: targets when BUILD_RTI=ON and RTI found
- FIND_PACKAGE only called as fallback when manual config doesn't create targets

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Entire-Checkpoint: 01M1CT3XSQXCX9RQR6WM9DG3GH
2026-08-31 23:03:01 +02:00

88 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""
Smart fix for training_area_telegrams.cpp
- Parse each struct individually
- Only fix fromJson within that struct's context
- Handle both m_ prefix and public member patterns
"""
import re
from pathlib import Path
filepath = Path("/home/torsten/swy/sandbox/qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/training_area_telegrams.cpp")
header_path = Path("/home/torsten/swy/sandbox/qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/training_area_telegrams.h")
content = filepath.read_text()
header_content = header_path.read_text()
# Parse header to find struct member patterns
struct_members = {}
# Find all struct definitions and their members
struct_pattern = r'^struct\s+(\w+)\s*[:{]'
for match in re.finditer(struct_pattern, header_content, re.MULTILINE):
struct_name = match.group(1)
start = match.end()
# Find the struct body (up to the matching closing brace)
brace_count = 1
pos = start
while brace_count > 0 and pos < len(header_content):
if header_content[pos] == '{':
brace_count += 1
elif header_content[pos] == '}':
brace_count -= 1
pos += 1
struct_body = header_content[start:pos]
# Check if struct has m_ prefix members or public members
has_m_prefix = bool(re.search(r'\bm_(\w+);', struct_body))
# Extract member names
if has_m_prefix:
# Find m_* members
m_members = re.findall(r'\bm_(\w+);', struct_body)
struct_members[struct_name] = {'prefix': 'm_', 'members': m_members}
else:
# Find public members (no m_ prefix)
public_members = re.findall(r'^\s*(?:Header|int|double|float|QString|bool|QList|QVector|QMap|auto)\s+(\w+);', struct_body, re.MULTILINE)
struct_members[struct_name] = {'prefix': '', 'members': public_members}
print(f"Found {len(struct_members)} structs")
for name, info in list(struct_members.items())[:5]:
print(f" {name}: prefix={info['prefix']}, members={info['members'][:3]}...")
# Now fix fromJson functions
def fix_fromJson(match):
struct_name = match.group(1)
func_body = match.group(2)
if struct_name not in struct_members:
return match.group(0)
members = struct_members[struct_name]['members']
prefix = struct_members[struct_name]['prefix']
# For each member, fix ret.member -> ret.m_member (if m_ prefix exists)
fixed_body = func_body
for member in members:
# Only fix if this is a getter-style access (member without m_ prefix)
if prefix == 'm_':
# Replace ret.member with ret.m_member
pattern = r'\bret\.' + re.escape(member) + r'\b'
replacement = f'ret.m_{member}'
fixed_body = re.sub(pattern, replacement, fixed_body)
return f"{struct_name}::{struct_name}() {{\n{fixed_body}\n}}"
# Fix fromJson functions
content = re.sub(
r'(\w+)::\1\(\)\s*\{([^}]+)\}',
fix_fromJson,
content,
flags=re.DOTALL
)
filepath.write_text(content)
print("fromJson fixes applied")