36 lines
2.6 KiB
Python
36 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Method-name comparison against active AVA2 Windows extension tables.
|
|
Presence is not behavioral parity. Macros use ONLY AVA2 Windows headers.
|
|
"""
|
|
from pathlib import Path
|
|
import re,json,subprocess,sys
|
|
root=Path(__file__).resolve().parents[1]
|
|
compiler=sys.argv[1] if len(sys.argv)>1 else 'clang++'
|
|
headers=''.join(f'#include "{root/p}"\n' for p in ('upstream/ava2-client/UserInterface/Locale_inc.h','upstream/ava2-client/EterBase/ServiceDefs.h'))
|
|
def modules(paths,preprocess=False):
|
|
result={}
|
|
for path in paths:
|
|
source=path.read_text(errors='replace')
|
|
if preprocess:
|
|
source=re.sub(r'^\s*#\s*include[^\n]*','',source,flags=re.M)
|
|
source=source.replace('#pragma once','')
|
|
source=subprocess.check_output([compiler,'-E','-P','-x','c++','-'],input=headers+source,text=True,stderr=subprocess.DEVNULL)
|
|
tables=list(re.finditer(r'PyMethodDef\s+(\w+)\s*\[\s*\]\s*=\s*\{(.*?)\};',source,re.S))
|
|
for call in re.finditer(r'Py_InitModule\s*\(\s*"([^"\n]+)"\s*,\s*(\w+)',source):
|
|
candidates=[t for t in tables if t[1]==call[2] and t.start()<call.start()]
|
|
if not candidates: continue
|
|
methods={name:handler for name,handler in re.findall(r'\{\s*"([^"\n]+)"\s*,\s*(\w+)\s*,',candidates[-1][2])}
|
|
result[call[1]]={'path':str(path.relative_to(root)),'methods':methods}
|
|
return result
|
|
windows=modules(sorted((root/'upstream/ava2-client').rglob('*Module.cpp')),True)
|
|
port=modules(sorted((root/'src').glob('python_*.cpp')))
|
|
rows=[]
|
|
for name,reference in sorted(windows.items()):
|
|
target=port.get(name,{'methods':{}});original=set(reference['methods']);current=set(target['methods'])
|
|
rows.append({'module':name,'windows_file':reference['path'],'port_file':target.get('path'),'windows_methods':len(original),'missing':sorted(original-current),'extra':sorted(current-original),'placeholder':sorted(method for method in original¤t if 'dummy' in target['methods'][method])})
|
|
report={'basis':'AVA2 Windows active method tables; module constants/signatures/behavior require further audit','modules':rows,'missing_method_count':sum(len(r['missing']) for r in rows),'placeholder_method_count':sum(len(r['placeholder']) for r in rows)}
|
|
(root/'docs/AVA2-PYTHON-INTERFACES.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print(f"{len(rows)} Windows modules compared; {report['missing_method_count']} missing methods; {report['placeholder_method_count']} overlapping placeholder methods")
|
|
for row in rows:
|
|
if row['missing']: print(row['module'],len(row['missing']),', '.join(row['missing'][:8]))
|