feat: type_events in diff and tracker, joined with emulator signal literals

Diff gains a type_events axis keyed by (script type, event). The tracker
lists each type's original events (vftable list, or the nearest class
list up the constructor chain for Piklib 6.1) and where the emulator names
them: the type's class, Variable.java or other engine code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Patryk Gensch
2026-10-24 19:49:26 +02:00
co-authored by Claude Opus 5.5
parent cb03de47ac
commit 597733d8d7
9 changed files with 135 additions and 7 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
'use strict';
const EVENT_STATUS={emitted:'emitowany w klasie typu',emitted_base:'emitowany w Variable',engine_literal:'literał w kodzie silnika',not_found:'brak literału w emulatorze'};
const MAPPING={explicit:'Jawne (klasa C++ z fabryki)',runner_factory:'CMC_RunnerFactory (typ → runner)',class_constructor:'Runner tworzony w konstruktorze klasy',inferred:'Wywnioskowane z nazwy'};
const $ = id => document.getElementById(id);
const labels = {missing:'Brak rejestracji',registered:'Zarejestrowana',stub_candidate:'Podejrzenie stubu',partial:'Częściowa',implemented:'Zaimplementowana',unverified:'Niezweryfikowana',asm_reviewed:'Przegląd ASM',runtime_tested:'Test zachowania',stale:'Dowód wymaga aktualizacji'};
@@ -23,7 +24,7 @@ function render(){
$('stats').replaceChildren(stat(methods.length,'par typ / metoda (także dziedziczone)'),stat(methods.filter(registered).length,'zarejestrowanych w emulatorze'),stat(methods.filter(m=>m.status==='implemented').length,'oznaczonych jako zaimplementowane'),stat(methods.filter(reviewed).length,'z aktualnym dowodem ASM / testu'));
$('types').replaceChildren();
for(const t of groups){const b=el('button',undefined,'type');b.type='button';b.setAttribute('aria-pressed',String(selected===t.name));const n=t.methods.length,r=t.methods.filter(registered).length,v=t.methods.filter(reviewed).length;b.append(el('strong',typeName(t.name)),el('small',n ? `${n} metod · ${r} rejestracji · ${v} dowodów` : 'Metody nierozpoznane — typ wykryty'));for(const [amount,cls,title] of [[r,'','Rejestracja'],[v,'review','Weryfikacja']]){const bar=el('div',undefined,'bar '+cls);bar.title=`${title}: ${amount} / ${n}`;const fill=el('i');fill.style.width=`${n ? 100*amount/n : 0}%`;bar.append(fill);b.append(bar);}b.onclick=()=>{selected=selected===t.name?null:t.name;render();};$('types').append(b);}
const chosen=data.types.find(t=>t.name===selected);const typeNotes=[...(chosen?.inherits||[]).map(base=>`Dziedziczy metody bazowe zakresu ${base}.`),...(chosen?.mapping_notes||[])];$('type-notes').hidden=!typeNotes.length;$('type-notes').textContent=typeNotes.map(note=>typeof note==='string'?note:JSON.stringify(note)).join('\n');$('methods-heading').textContent=selected?typeName(selected):'Wszystkie metody';$('count').textContent=`${methods.length} pozycji`;$('rows').replaceChildren();
const chosen=data.types.find(t=>t.name===selected);const typeNotes=[...(chosen?.inherits||[]).map(base=>`Dziedziczy metody bazowe zakresu ${base}.`),...(chosen?.events?.length?['Eventy w oryginale: '+chosen.events.map(e=>`${e.name} (${EVENT_STATUS[e.status]||e.status})`).join(', ')]:[]),...(chosen?.mapping_notes||[])];$('type-notes').hidden=!typeNotes.length;$('type-notes').textContent=typeNotes.map(note=>typeof note==='string'?note:JSON.stringify(note)).join('\n');$('methods-heading').textContent=selected?typeName(selected):'Wszystkie metody';$('count').textContent=`${methods.length} pozycji`;$('rows').replaceChildren();
for(const t of active)for(const m of t.methods){const tr=el('tr'),name=el('td');name.append(el('small',typeName(t.name)),el('strong',m.name));const s=el('td'),v=el('td');s.append(badge(m.status));v.append(badge(m.verification));const found=original(m);const availability=el('td',found.length?`Wykryta · ${new Set(found.map(o=>o.binary_id)).size} wariantów`:'Nieustalone');const action=el('td'),b=el('button','Dowody ↗','quiet');b.setAttribute('aria-label',`Dowody ${t.name}.${m.name}`);b.onclick=()=>detail(t,m);action.append(b);tr.append(name,s,v,availability,action);$('rows').append(tr);}
$('empty').hidden=methods.length>0;$('empty').textContent=chosen && !chosen.methods.length ? 'Typ został wykryty, ale metody nie zostały jeszcze rozpoznane. Brak wpisów nie oznacza braku API.' : 'Brak metod dla wybranych filtrów.';
}
+4
View File
@@ -118,6 +118,8 @@ def compute_diff(old: Snapshot, new: Snapshot) -> dict[str, Any]:
"types": keyed_diff(old.types, new.types, _type_key, ["cpp_class", "object_size"]),
"methods": keyed_diff(old.methods, new.methods, _owner_name_key, ["id"]),
"events": keyed_diff(old.events, new.events, _owner_name_key, ["order"]),
"type_events": keyed_diff(old.type_events, new.type_events,
lambda x: (x["type"], x["name"]), ["order"]),
"fields": keyed_diff(old.fields, new.fields, _owner_name_key, ["type"]),
"struct_layout": keyed_diff(old.struct_layout, new.struct_layout, _layout_key,
["size", "is_vtable"]),
@@ -136,6 +138,8 @@ def _item_owner(axis: str, item: Item) -> str | None:
return item.get("cpp_class")
if axis in ("methods", "events", "fields", "struct_layout", "method_dispatch"):
return item.get("owner")
if axis == "type_events":
return item.get("type") # script type name, e.g. --owner ANIMO
if axis == "method_inheritance":
return item.get("runner")
if axis == "field_inheritance":
+3
View File
@@ -151,6 +151,9 @@ def render_text(diff: dict[str, Any], only: set[str] | None = None) -> str:
if want("events") and not _is_empty(diff["events"]):
_section_owned(out, "EVENTS", diff["events"], _fmt_event,
lambda e: e["owner"], lambda e: e["name"])
if want("events") and not _is_empty(diff.get("type_events", _EMPTY)):
_section_owned(out, "TYPE EVENTS", diff["type_events"], _fmt_event,
lambda e: e["type"], lambda e: e["name"])
if want("fields") and not _is_empty(diff["fields"]):
_section_owned(out, "FIELDS", diff["fields"], _fmt_field,
lambda f: f["owner"], lambda f: f["name"])
+5
View File
@@ -35,6 +35,11 @@ class Snapshot:
def events(self) -> list[dict]:
return self.raw.get("events", [])
@property
def type_events(self) -> list[dict]:
"""Events per script type, read through each type's own vftable (schema 6)."""
return self.raw.get("type_events", [])
@property
def fields(self) -> list[dict]:
return self.raw.get("fields", [])
+75 -4
View File
@@ -63,6 +63,32 @@ BUILTINS_DISPATCH = re.compile(r"\bdispatchSpecialCall\s*\([^)]*\)\s*\{")
CASE_ARM = re.compile(r"\bcase\b([^;{}]*?)->|\bdefault\b\s*->")
SIGNAL_LITERAL = re.compile(r'"(ON[A-Z][A-Z_]*)"')
NOT_SIGNALS = {"ONEBREAK"} # the @ONEBREAK statement, not an event
def scan_signals(root: Path, source_root: Path, variable_root: Path) -> dict:
"""Where the emulator names each event: {scope: {event: [source]}}. A `<Type>Variable.java`
file is that type's scope, Variable.java is `*`, any other file is `engine`. Only string
literals count (comments ignored); names built at runtime are invisible, so absence is
"no literal found", never proof that an event is missing."""
scopes = {}
for path, text in sorted((p, p.read_text(encoding="utf-8")) for p in source_root.rglob("*.java")):
scope = "engine"
if path.parent == variable_root and path.name.endswith("Variable.java"):
if path.name == "Variable.java":
scope = "*"
else:
match = re.search(r"return\s+VariableType\.([A-Z_]+)\s*;", code_mask(text))
scope = canonical(match[1]) if match else "engine"
for token in JAVA_TOKENS.finditer(text):
literal = SIGNAL_LITERAL.fullmatch(token.group())
if literal and literal[1] not in NOT_SIGNALS:
scopes.setdefault(scope, {}).setdefault(literal[1], []).append(
{"path": str(path.relative_to(root)), "line": text.count("\n", 0, token.start()) + 1})
return scopes
def scan_builtins(root: Path, source_root: Path) -> dict | None:
"""`@IF`, `@LOOP`, ... are parsed by CodeParser.dispatchSpecialCall, not registered as
MethodSpec: each `case "NAME", ... ->` arm of its switch is one built-in statement."""
@@ -152,7 +178,7 @@ def scan_emulator(root: Path) -> dict:
builtins = scan_builtins(root, source_root)
if builtins is not None:
types["@"] = builtins
return {"root": str(root), "commit": _git(root, "rev-parse", "HEAD"),
return {"root": str(root), "signals": scan_signals(root, source_root, variable_root), "commit": _git(root, "rev-parse", "HEAD"),
"dirty": bool(_git(root, "status", "--porcelain")),
"source_tree_sha256": tree.hexdigest(), "types": types, "warnings": warnings}
@@ -199,6 +225,35 @@ def _constructor_runner(name, cpp_class, class_runner, bases, known_classes):
return None
def script_events(snap: Snapshot) -> dict[str, list[str]]:
"""Script type -> ordered event names for one binary. `type_events` (each type's own
vftable, schema 6) wins; otherwise the class list of the nearest class up this snapshot's
constructor chain that has one (INTEGER -> CMC_Variable)."""
out = {}
for e in sorted(snap.type_events, key=lambda e: e["order"]):
out.setdefault(canonical(e["type"]), []).append(e["name"].upper())
by_class = {}
for e in sorted(snap.events, key=lambda e: e.get("order") or 0):
by_class.setdefault(e["owner"], []).append(e["name"].upper())
bases = {e["class"]: e["base_class"] for e in snap.field_inheritance}
known = set(by_class) | set(bases) | set(bases.values())
for t in snap.types:
name = canonical(t["script_name"])
if name in out:
continue
cls = t.get("cpp_class") if t.get("cpp_class") != "CMC_Behaviour" or name == "BEHAVIOUR" else None
if not cls:
candidates = [c for c in known if owner_name(c) == name]
cls = candidates[0] if len(candidates) == 1 else None
seen = set()
while cls and cls not in seen and cls not in by_class:
seen.add(cls)
cls = bases.get(cls)
if cls in by_class:
out[name] = by_class[cls]
return out
def script_owners(snap: Snapshot, owners) -> dict[str, tuple[str, str]]:
"""Script scope -> (method owner, provenance) for one binary.
@@ -291,6 +346,11 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict]
parents = defaultdict(list)
for edge in snap.method_inheritance:
parents[edge["runner"].removesuffix("_Runner")].append(edge["base_runner"].removesuffix("_Runner"))
for name, names in script_events(snap).items():
events = type_row(name).setdefault("events", {})
for order, event in enumerate(names):
events.setdefault(event, {"name": event, "order": order, "original": [], "emulator": [],
"status": "not_found"})["original"].append(bid)
mappings = script_owners(snap, owners)
for t in snap.types:
row = type_row(canonical(t["script_name"]))
@@ -369,6 +429,13 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict]
if row is not None:
row["notes"].append(f"Oryginał ({len(binaries_)} binarek) pomija tę metodę dla tego typu: "
"warunek obj.getType() we wspólnym runnerze.")
signals = emulator.get("signals", {})
for name, t in rows.items():
for event, row in t.get("events", {}).items():
own, base, engine = (signals.get(scope, {}).get(event, []) for scope in (name, "*", "engine"))
row["emulator"] = own + base + engine
row["status"] = ("emitted" if own else "emitted_base" if base
else "engine_literal" if engine else "not_found")
base_verbs = {m for m, row in rows.get(BASE_SCOPE, {}).get("methods", {}).items() if row["original"]}
for name, t in rows.items():
for method, row in t["methods"].items():
@@ -407,17 +474,21 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict]
t["mapping_notes"] = sorted(set(t["mapping_notes"]))
if "inherits" in t:
t["inherits"] = sorted(set(t["inherits"]))
t["events"] = sorted(t.get("events", {}).values(), key=lambda e: (e["order"], e["name"]))
all_rows = [m for t in rows.values() for m in t["methods"]]
return {"schema": "tracker/1", "emulator": {k: v for k, v in emulator.items() if k not in ("types", "warnings")},
all_events = [e for t in rows.values() for e in t["events"]]
return {"schema": "tracker/1", "emulator": {k: v for k, v in emulator.items() if k not in ("types", "warnings", "signals")},
"binaries": sorted(binaries, key=lambda b: (b["name"].lower(), b["id"])),
"types": sorted(rows.values(), key=lambda t: t["name"]),
"summary": {"types": len(rows), "methods": len(all_rows), "status": dict(Counter(m["status"] for m in all_rows)),
"verification": dict(Counter(m["verification"] for m in all_rows))},
"verification": dict(Counter(m["verification"] for m in all_rows)),
"events": len(all_events), "event_status": dict(Counter(e["status"] for e in all_events))},
"warnings": warnings + ["Brak obserwacji w wariancie oznacza nieustalone, nie brak metody.",
"Rejestracja Java nie dowodzi poprawności. Liczniki obejmują pary typ/metoda, także odziedziczone.",
"Typ → runner pochodzi z CMC_RunnerFactory, gdy snapshot ma runner_map; inaczej z nazwy klasy (wnioskowane).",
"Zakres * to metody bazowe CMC_Runner, wspólne dla każdego typu (pole inherits); nie są powielane przy typach.",
"Zakres @ to wbudowane instrukcje @IF/@LOOP/... (runner typu 0)."]}
"Zakres @ to wbudowane instrukcje @IF/@LOOP/... (runner typu 0).",
"Eventy: status emulatora to literał nazwy w kodzie (klasa typu / Variable / silnik); nazwy budowane dynamicznie nie są widoczne."]}
def validate_review(review: dict) -> None: