367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
55 lines
4.5 KiB
Python
55 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Join the saved source catalogue with pinned native reference declarations.
|
|
No same-name, same-number or normalized-name candidate is auto-admitted.
|
|
"""
|
|
import argparse,json,re,time
|
|
from collections import defaultdict
|
|
from pathlib import Path
|
|
from rea_protocol_coverage import ENUM,number,save,strip_comments
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
def normalized(s):
|
|
for prefix in ('UNIT_FIELD_','PLAYER_FIELD_','OBJECT_FIELD_','ITEM_FIELD_','CONTAINER_FIELD_','GAMEOBJECT_FIELD_','DYNAMICOBJECT_FIELD_','CORPSE_FIELD_'):
|
|
if s.startswith(prefix):s=s[len(prefix):];break
|
|
return re.sub('[^a-z0-9]','',s.lower())
|
|
def main():
|
|
ap=argparse.ArgumentParser();ap.add_argument('--job-directory',type=Path,required=True);args=ap.parse_args();out=args.job_directory.resolve()/'protocol-correlation'
|
|
source=json.loads((out/'server-contract-catalogue.json').read_text());inputs=json.loads((out/'native-reference-inputs.json').read_text())
|
|
inputs += [str(ROOT/'include/gateway/forever_opcode_profile.hpp'),str(ROOT/'include/gateway/aura_state.hpp')]
|
|
records=[];known={};fielddecl=[]
|
|
for raw in inputs:
|
|
p=Path(raw)
|
|
if not p.is_absolute():p=ROOT/p
|
|
if not p.exists():continue
|
|
s=strip_comments(p.read_text(errors='replace'))
|
|
for m in ENUM.finditer(s):
|
|
last=-1
|
|
for part in m.group('body').split(','):
|
|
a=re.fullmatch(r'(\w+)\s*(?:=\s*(.*))?',re.sub(r'^\s*#.*$','',part,flags=re.M).strip(),re.S)
|
|
if not a:continue
|
|
name,expr=a.groups();v=number(expr,known) if expr else last+1 if last is not None else None
|
|
if v is not None:known[name]=v
|
|
last=v;records.append({'symbol':name,'value':v,'enum':m.group('name'),'file':str(p.resolve()),'authority':'reference declaration; requires original client contract'})
|
|
for m in re.finditer(r'\bconstexpr\s+(?:unsigned|u?int\d*_t|uint\d+)\s+(\w+)\s*=\s*([^;]+);',s):
|
|
records.append({'symbol':m.group(1),'value':number(m.group(2),known),'file':str(p.resolve()),'authority':'current profile declaration; handler acceptance separate'})
|
|
struct=None
|
|
for ln,line in enumerate(s.splitlines(),1):
|
|
m=re.search(r'\bstruct\s+(\w+)',line)
|
|
if m:struct=m.group(1)
|
|
m=re.search(r'(?:UF::)?((?:Update\w*|DynamicUpdateField|MapUpdateField|OptionalUpdateField|SetUpdateField|VariantUpdateField))<(.+)>\s+(\w+)\s*;',line)
|
|
if m:fielddecl.append({'structure':struct,'field':m.group(3),'declaration_type':m.group(1),'template_arguments':m.group(2),'file':str(p.resolve()),'line':ln,'authority':'typed reference declaration; template mask bits are not serialized field offsets'})
|
|
byname=defaultdict(list);byfold=defaultdict(list)
|
|
for r in records:byname[r['symbol']].append(r);byfold[normalized(r['symbol'])].append(r)
|
|
byfield=defaultdict(list)
|
|
for r in fielddecl:byfield[normalized(r['field'])].append(r)
|
|
rows=[];stats=defaultdict(int)
|
|
for r in source['records']:
|
|
exact=byname.get(r['symbol'],[]);folded=[] if exact else byfold.get(normalized(r['symbol']),[])
|
|
fields=byfield.get(normalized(r['symbol']),[]) if r['kind']=='update-field' else []
|
|
status='exact-name-contract-review' if exact else 'normalized-name-contract-review' if folded or fields else 'no-native-name-candidate'
|
|
stats[status]+=1
|
|
rows.append({'source_file':r['source_file'],'source_enum':r['source_enum'],'source_symbol':r['symbol'],'source_value':r['value'],'kind':r['kind'],'status':status,'native_declaration_candidates':exact or folded,'typed_native_field_candidates':fields,'gateway_reference_status':r['status'],'semantic_equivalence_verified':False,'auto_admitted':False})
|
|
save(out/'source-native-declaration-correlation.json',{'source_records_reused':True,'source_headers_rescanned':False,'native_inputs':inputs,'native_enum_profile_declarations':len(records),'native_typed_fields':len(fielddecl),'rows':rows,'limitations':['Reference source declarations do not replace pinned original native consumer REA.','Numeric equality and name similarity do not establish semantic equivalence or listener admission.','Template mask indices are not wire field offsets.']})
|
|
save(out/'native-contract-join-summary.json',{'phase':'source-native-reference-join-complete','finished':time.time(),'source_records':len(rows),'native_declarations':len(records),'native_typed_fields':len(fielddecl),'counts':dict(stats),'actual_listener_mapping_complete':False,'next':'Apply pinned original consumer and handler receipts to candidates, then fix whole affected relationships.'})
|
|
print('Saved source-to-native declaration candidates; prior source inventory reused without rescanning.',flush=True)
|
|
if __name__=='__main__':main()
|