feat: type_fields in diff and tracker, joined with emulator property reads

The tracker lists each scope's original properties (constructor chain,
or class fields up the chain for Piklib 6.1 and singletons such as
SCENE) and where the emulator reads them: a CNVParser.createVariable
case arm, an attribute read in the type's class or Variable.java, or
other code. The switch-arm parser is shared with the @ statements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Patryk Gensch
2026-10-24 20:30:36 +02:00
co-authored by Claude Opus 5.5
parent 9d5a600d6b
commit aee8f17417
9 changed files with 198 additions and 25 deletions
+2 -2
View File
@@ -113,7 +113,7 @@ bywają aliasami (ICF skleja identyczne ciała), więc liczy się adres i każda
| Typy | `CMC_ObjectsContainer::resolve` (8.x/BlooMoo) lub `CMC_Scene::resolve` (Piklib 6.1/7.1): `operator==("NAME")` → `operator_new(SIZE)` → ctor | ✅ (8.x inline; 6.1 tag-based = nazwy bez ctora) | | Typy | `CMC_ObjectsContainer::resolve` (8.x/BlooMoo) lub `CMC_Scene::resolve` (Piklib 6.1/7.1): `operator==("NAME")` → `operator_new(SIZE)` → ctor | ✅ (8.x inline; 6.1 tag-based = nazwy bez ctora) |
| Metody | `CMC_*_Runner::prepareMthHashSet`: `CInteger(id)` + `CStringHashCode("NAME")` + `CHashtable::put` | ✅ (+ `method_inheritance`) | | Metody | `CMC_*_Runner::prepareMthHashSet`: `CInteger(id)` + `CStringHashCode("NAME")` + `CHashtable::put` | ✅ (+ `method_inheritance`) |
| Eventy | `CMC_*::getBehavioursList`: lista literałów `CXString` | ✅ per klasa (`events`) i per typ (`type_events`: slot `getBehavioursList` z vtable typu, także klasy bez symboli) | | Eventy | `CMC_*::getBehavioursList`: lista literałów `CXString` | ✅ per klasa (`events`) i per typ (`type_events`: slot `getBehavioursList` z vtable typu, także klasy bez symboli) |
| Pola (skryptowe) | ctory `CMC_*`: literały czytane przez `CMElement::getProperty<T>Value` → nazwa + typ pola (FPS, PRELOAD, VISIBLE…) | ✅ (+ `field_inheritance`) | | Pola (skryptowe) | ctory `CMC_*`: literały czytane przez `CMElement::getProperty<T>Value` → nazwa + typ pola (FPS, PRELOAD, VISIBLE…) | ✅ per klasa (`fields` + `field_inheritance`) i per typ (`type_fields`: łańcuch konstruktorów od konstruktora z fabryki, także klasy bez symboli) |
| Layout C++ (bonus) | ctory `CMC_*`: store'y `this+offset` przez P-code (rozmyte, `is_vtable`) | ✅ pod `struct_layout` | | Layout C++ (bonus) | ctory `CMC_*`: store'y `this+offset` przez P-code (rozmyte, `is_vtable`) | ✅ pod `struct_layout` |
| Ciała metod | `CMC_*_Runner::run`: `switch(id)` → per case kotwice CALL (`Klasa::metoda` / `vtbl+0xNN`), rozwinięcie wrapperów | ✅ pod `method_dispatch` (id→`impl_addr`+`calls`) | | Ciała metod | `CMC_*_Runner::run`: `switch(id)` → per case kotwice CALL (`Klasa::metoda` / `vtbl+0xNN`), rozwinięcie wrapperów | ✅ pod `method_dispatch` (id→`impl_addr`+`calls`) |
| Typ → runner | 7.1+/BlooMoo: emulacja `CMC_RunnerFactory::getRunner(typeId)`, `typeId` z konstruktora typu, vtable runnerów z `RunnerFactory::initialize` (także runnery bez symboli: VECTOR, FILTER, PATH, FIFO/LIFO, MOVIE, instrukcje `@`). 6.1: konstruktor klasy tworzący runner | ✅ pod `runner_map` | | Typ → runner | 7.1+/BlooMoo: emulacja `CMC_RunnerFactory::getRunner(typeId)`, `typeId` z konstruktora typu, vtable runnerów z `RunnerFactory::initialize` (także runnery bez symboli: VECTOR, FILTER, PATH, FIFO/LIFO, MOVIE, instrukcje `@`). 6.1: konstruktor klasy tworzący runner | ✅ pod `runner_map` |
@@ -277,4 +277,4 @@ A/B i odpalający porównanie).
`schema_version`, `binary{name,sha256,engine,compiler,factory_addr}`, oraz listy `schema_version`, `binary{name,sha256,engine,compiler,factory_addr}`, oraz listy
`types` / `methods` / `events` / `fields`. Diff = operacje na zbiorach dwóch snapshotów. `types` / `methods` / `events` / `fields`. Diff = operacje na zbiorach dwóch snapshotów.
Od wersji 5: `runner_map` (`by_type_id` / `by_class`, sloty `CMC_Runner`), `types[].type_id` Od wersji 5: `runner_map` (`by_type_id` / `by_class`, sloty `CMC_Runner`), `types[].type_id`
i `vftable`, a w `method_dispatch` fakty z ciała metody. Od wersji 6: `type_events`. i `vftable`, a w `method_dispatch` fakty z ciała metody. Od wersji 6: `type_events`, od 7: `type_fields`.
+2 -1
View File
@@ -1,5 +1,6 @@
'use strict'; '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 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 FIELD_STATUS={read:'czytane w obsłudze typu',read_base:'czytane w Variable',engine_literal:'literał w innym kodzie',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 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 $ = 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'}; 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'};
@@ -24,7 +25,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')); $('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(); $('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);} 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?.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(); 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?.fields?.length?['Pola w oryginale: '+chosen.fields.map(f=>`${f.name}:${f.value_types.join('/')} (${FIELD_STATUS[f.status]||f.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);} 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.'; $('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.';
} }
+3 -1
View File
@@ -121,6 +121,8 @@ def compute_diff(old: Snapshot, new: Snapshot) -> dict[str, Any]:
"type_events": keyed_diff(old.type_events, new.type_events, "type_events": keyed_diff(old.type_events, new.type_events,
lambda x: (x["type"], x["name"]), ["order"]), lambda x: (x["type"], x["name"]), ["order"]),
"fields": keyed_diff(old.fields, new.fields, _owner_name_key, ["type"]), "fields": keyed_diff(old.fields, new.fields, _owner_name_key, ["type"]),
"type_fields": keyed_diff(old.type_fields, new.type_fields,
lambda x: (x["type"], x["name"]), ["value_types"]),
"struct_layout": keyed_diff(old.struct_layout, new.struct_layout, _layout_key, "struct_layout": keyed_diff(old.struct_layout, new.struct_layout, _layout_key,
["size", "is_vtable"]), ["size", "is_vtable"]),
"method_dispatch": _dispatch_diff(old, new), "method_dispatch": _dispatch_diff(old, new),
@@ -138,7 +140,7 @@ def _item_owner(axis: str, item: Item) -> str | None:
return item.get("cpp_class") return item.get("cpp_class")
if axis in ("methods", "events", "fields", "struct_layout", "method_dispatch"): if axis in ("methods", "events", "fields", "struct_layout", "method_dispatch"):
return item.get("owner") return item.get("owner")
if axis == "type_events": if axis in ("type_events", "type_fields"):
return item.get("type") # script type name, e.g. --owner ANIMO return item.get("type") # script type name, e.g. --owner ANIMO
if axis == "method_inheritance": if axis == "method_inheritance":
return item.get("runner") return item.get("runner")
+4
View File
@@ -157,6 +157,10 @@ def render_text(diff: dict[str, Any], only: set[str] | None = None) -> str:
if want("fields") and not _is_empty(diff["fields"]): if want("fields") and not _is_empty(diff["fields"]):
_section_owned(out, "FIELDS", diff["fields"], _fmt_field, _section_owned(out, "FIELDS", diff["fields"], _fmt_field,
lambda f: f["owner"], lambda f: f["name"]) lambda f: f["owner"], lambda f: f["name"])
if want("fields") and not _is_empty(diff.get("type_fields", _EMPTY)):
_section_owned(out, "TYPE FIELDS", diff["type_fields"],
lambda f: "{0}: {1}".format(f["name"], "/".join(f.get("value_types", []))),
lambda f: f["type"], lambda f: f["name"])
if want("layout") and not _is_empty(diff["struct_layout"]): if want("layout") and not _is_empty(diff["struct_layout"]):
_section_owned(out, "STRUCT LAYOUT", diff["struct_layout"], _fmt_layout, _section_owned(out, "STRUCT LAYOUT", diff["struct_layout"], _fmt_layout,
lambda x: x["owner"], lambda x: "@{0:#x}".format(x["offset"])) lambda x: x["owner"], lambda x: "@{0:#x}".format(x["offset"]))
+5
View File
@@ -40,6 +40,11 @@ class Snapshot:
"""Events per script type, read through each type's own vftable (schema 6).""" """Events per script type, read through each type's own vftable (schema 6)."""
return self.raw.get("type_events", []) return self.raw.get("type_events", [])
@property
def type_fields(self) -> list[dict]:
"""Properties per script type, read along its constructor chain (schema 7)."""
return self.raw.get("type_fields", [])
@property @property
def fields(self) -> list[dict]: def fields(self) -> list[dict]:
return self.raw.get("fields", []) return self.raw.get("fields", [])
+128 -21
View File
@@ -89,6 +89,63 @@ def scan_signals(root: Path, source_root: Path, variable_root: Path) -> dict:
return scopes return scopes
def switch_arms(text: str, code: str, head: re.Pattern) -> list[tuple[list[str], int, int]]:
"""[(case labels, start, end)] of the first `switch` inside the method `head` matches.
Positions index `text`; `code` is its literal/comment mask. Default arms are skipped."""
found = head.search(code)
if found is None:
return []
switch = code.index("switch", found.end())
body_start = code.index("{", switch)
body_end = closing(code, body_start, "{}")
arms = list(CASE_ARM.finditer(code, body_start, body_end))
out = []
for arm, following in zip(arms, arms[1:] + [None]):
if arm.group(1) is not None:
labels = re.findall(r'"([A-Za-z_]+)"', text[arm.start(1):arm.end(1)])
out.append((labels, arm.start(), following.start() if following else body_end))
return out
CNV_SOURCE = "pl/genschu/bloomooemulator/loader/CNVParser.java"
CNV_CREATE = re.compile(r"\bcreateVariable\s*\([^)]*\)\s*\{")
PROPERTY_KEY = re.compile(r'":([A-Z][A-Z0-9_]*)"')
ATTRIBUTE_NAME = re.compile(r'"([A-Z][A-Z0-9_]*)"')
# context.getAttribute(name, "X"), getAttributeInHierarchy(name(), "X"), attributes().get(name, "X")
ATTRIBUTE_CALL = re.compile(r"(?:\bgetAttribute\w*|\battributes\(\)\s*\.\s*get\w*)\s*\([^;]*$")
def scan_properties(root: Path, source_root: Path, variable_root: Path) -> dict:
"""Where the emulator reads each CNV property: {scope: {property: [source]}}. A `":NAME"`
key inside a `case "TYPE"` arm of CNVParser.createVariable belongs to those types, and
an attribute read (`getAttribute`, `getAttributeInHierarchy`, `attributes().get`) in
`<Type>Variable.java` to that type, in Variable.java to `*`; anything else is `engine`.
Like signals, absence means only that no literal was found."""
scopes = {}
for path in sorted(source_root.rglob("*.java")):
text = path.read_text(encoding="utf-8")
code = code_mask(text)
scope = "engine"
if path.parent == variable_root and path.name == "Variable.java":
scope = "*"
elif path.parent == variable_root and path.name.endswith("Variable.java"):
match = re.search(r"return\s+VariableType\.([A-Z_]+)\s*;", code)
scope = canonical(match[1]) if match else "engine"
arms = switch_arms(text, code, CNV_CREATE) if path == source_root / CNV_SOURCE else []
for token in JAVA_TOKENS.finditer(text):
literal = PROPERTY_KEY.fullmatch(token.group())
if literal is None:
literal = ATTRIBUTE_NAME.fullmatch(token.group())
if literal is None or not ATTRIBUTE_CALL.search(code[max(0, token.start() - 160):token.start()]):
continue
owners = [canonical(label) for labels, start, end in arms if start <= token.start() < end
for label in labels] or [scope]
source = {"path": str(path.relative_to(root)), "line": text.count("\n", 0, token.start()) + 1}
for owner in owners:
scopes.setdefault(owner, {}).setdefault(literal[1], []).append(source)
return scopes
def scan_builtins(root: Path, source_root: Path) -> dict | None: def scan_builtins(root: Path, source_root: Path) -> dict | None:
"""`@IF`, `@LOOP`, ... are parsed by CodeParser.dispatchSpecialCall, not registered as """`@IF`, `@LOOP`, ... are parsed by CodeParser.dispatchSpecialCall, not registered as
MethodSpec: each `case "NAME", ... ->` arm of its switch is one built-in statement.""" MethodSpec: each `case "NAME", ... ->` arm of its switch is one built-in statement."""
@@ -97,27 +154,19 @@ def scan_builtins(root: Path, source_root: Path) -> dict | None:
return None return None
text = path.read_text(encoding="utf-8") text = path.read_text(encoding="utf-8")
code = code_mask(text) code = code_mask(text)
head = BUILTINS_DISPATCH.search(code) if BUILTINS_DISPATCH.search(code) is None:
if head is None:
return None return None
switch = code.index("switch", head.end())
body_start = code.index("{", switch)
body_end = closing(code, body_start, "{}")
arms = list(CASE_ARM.finditer(code, body_start, body_end))
methods = {} methods = {}
for arm, following in zip(arms, arms[1:] + [None]): for labels, start, end in switch_arms(text, code, BUILTINS_DISPATCH):
if arm.group(1) is None: body = text[start:end]
continue # default arm: unknown statements are a parse error
end = following.start() if following else body_end
body = text[arm.start():end]
status = "registered" status = "registered"
notes = [] notes = []
if re.search(r"not (?:yet )?implemented", body, re.I) or "UnsupportedOperationException" in body: if re.search(r"not (?:yet )?implemented", body, re.I) or "UnsupportedOperationException" in body:
status = "stub_candidate" status = "stub_candidate"
notes.append("Heurystyka: wyjątek lub komunikat o braku implementacji; wymaga przeglądu.") notes.append("Heurystyka: wyjątek lub komunikat o braku implementacji; wymaga przeglądu.")
for name in re.findall(r'"([A-Za-z_]+)"', text[arm.start(1):arm.end(1)]): for name in labels:
methods[name.upper()] = {"status": status, "notes": list(notes), "source": { methods[name.upper()] = {"status": status, "notes": list(notes), "source": {
"path": str(path.relative_to(root)), "line": text.count("\n", 0, arm.start()) + 1, "path": str(path.relative_to(root)), "line": text.count("\n", 0, start) + 1,
"owner": "@", "body_sha256": digest(body.encode()), "file_sha256": digest(text.encode())}} "owner": "@", "body_sha256": digest(body.encode()), "file_sha256": digest(text.encode())}}
return {"methods": methods, "mapping_notes": [ return {"methods": methods, "mapping_notes": [
"Instrukcje @ są rozpoznawane w CodeParser.dispatchSpecialCall, nie przez MethodSpec."]} "Instrukcje @ są rozpoznawane w CodeParser.dispatchSpecialCall, nie przez MethodSpec."]}
@@ -178,7 +227,8 @@ def scan_emulator(root: Path) -> dict:
builtins = scan_builtins(root, source_root) builtins = scan_builtins(root, source_root)
if builtins is not None: if builtins is not None:
types["@"] = builtins types["@"] = builtins
return {"root": str(root), "signals": scan_signals(root, source_root, variable_root), "commit": _git(root, "rev-parse", "HEAD"), return {"root": str(root), "signals": scan_signals(root, source_root, variable_root),
"properties": scan_properties(root, source_root, variable_root), "commit": _git(root, "rev-parse", "HEAD"),
"dirty": bool(_git(root, "status", "--porcelain")), "dirty": bool(_git(root, "status", "--porcelain")),
"source_tree_sha256": tree.hexdigest(), "types": types, "warnings": warnings} "source_tree_sha256": tree.hexdigest(), "types": types, "warnings": warnings}
@@ -225,10 +275,11 @@ def _constructor_runner(name, cpp_class, class_runner, bases, known_classes):
return None return None
def script_events(snap: Snapshot) -> dict[str, list[str]]: def script_events(snap: Snapshot, scopes: dict | None = None) -> dict[str, list[str]]:
"""Script type -> ordered event names for one binary. `type_events` (each type's own """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 vftable, schema 6) wins; otherwise the class list of the nearest class up this snapshot's
constructor chain that has one (INTEGER -> CMC_Variable).""" constructor chain that has one (INTEGER -> CMC_Variable). `scopes` (script_owners) adds
singletons such as SCENE, whose class is their runner's owner."""
out = {} out = {}
for e in sorted(snap.type_events, key=lambda e: e["order"]): for e in sorted(snap.type_events, key=lambda e: e["order"]):
out.setdefault(canonical(e["type"]), []).append(e["name"].upper()) out.setdefault(canonical(e["type"]), []).append(e["name"].upper())
@@ -251,6 +302,43 @@ def script_events(snap: Snapshot) -> dict[str, list[str]]:
cls = bases.get(cls) cls = bases.get(cls)
if cls in by_class: if cls in by_class:
out[name] = by_class[cls] out[name] = by_class[cls]
for name, (owner, _) in (scopes or {}).items():
if name not in out and owner in by_class:
out[name] = by_class[owner]
return out
def script_fields(snap: Snapshot, scopes: dict | None = None) -> dict[str, list[tuple[str, list[str]]]]:
"""Script type -> [(property, value types)] for one binary. `type_fields` (constructor
chain, schema 7) wins; otherwise the class fields of the type's class and every base up
this snapshot's constructor chain, base first - properties accumulate, unlike events.
`scopes` (script_owners) adds singletons such as SCENE."""
out = {}
for f in sorted(snap.type_fields, key=lambda f: f["order"]):
out.setdefault(canonical(f["type"]), []).append((f["name"].upper(), f.get("value_types", [])))
by_class = {}
for f in sorted(snap.fields, key=lambda f: f.get("order") or 0):
by_class.setdefault(f["owner"], []).append((f["name"].upper(), [f.get("type")]))
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
chain = []
while cls and cls not in chain:
chain.append(cls)
cls = bases.get(cls)
fields = [f for c in reversed(chain) for f in by_class.get(c, [])]
if fields:
out[name] = fields
for name, (owner, _) in (scopes or {}).items():
if name not in out and owner in by_class:
out[name] = by_class[owner]
return out return out
@@ -346,12 +434,20 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict]
parents = defaultdict(list) parents = defaultdict(list)
for edge in snap.method_inheritance: for edge in snap.method_inheritance:
parents[edge["runner"].removesuffix("_Runner")].append(edge["base_runner"].removesuffix("_Runner")) parents[edge["runner"].removesuffix("_Runner")].append(edge["base_runner"].removesuffix("_Runner"))
for name, names in script_events(snap).items(): mappings = script_owners(snap, owners)
for name, names in script_events(snap, mappings).items():
events = type_row(name).setdefault("events", {}) events = type_row(name).setdefault("events", {})
for order, event in enumerate(names): for order, event in enumerate(names):
events.setdefault(event, {"name": event, "order": order, "original": [], "emulator": [], events.setdefault(event, {"name": event, "order": order, "original": [], "emulator": [],
"status": "not_found"})["original"].append(bid) "status": "not_found"})["original"].append(bid)
mappings = script_owners(snap, owners) for name, props in script_fields(snap, mappings).items():
fields = type_row(name).setdefault("fields", {})
for order, (prop, value_types) in enumerate(props):
row = fields.setdefault(prop, {"name": prop, "order": order, "value_types": [],
"original": [], "emulator": [], "status": "not_found"})
if bid not in row["original"]:
row["original"].append(bid)
row["value_types"] = sorted(set(row["value_types"]) | {v for v in value_types if v})
for t in snap.types: for t in snap.types:
row = type_row(canonical(t["script_name"])) row = type_row(canonical(t["script_name"]))
if t.get("cpp_class_provenance"): if t.get("cpp_class_provenance"):
@@ -436,6 +532,13 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict]
row["emulator"] = own + base + engine row["emulator"] = own + base + engine
row["status"] = ("emitted" if own else "emitted_base" if base row["status"] = ("emitted" if own else "emitted_base" if base
else "engine_literal" if engine else "not_found") else "engine_literal" if engine else "not_found")
properties = emulator.get("properties", {})
for name, t in rows.items():
for prop, row in t.get("fields", {}).items():
own, base, engine = (properties.get(scope, {}).get(prop, []) for scope in (name, "*", "engine"))
row["emulator"] = own + base + engine
row["status"] = ("read" if own else "read_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"]} base_verbs = {m for m, row in rows.get(BASE_SCOPE, {}).get("methods", {}).items() if row["original"]}
for name, t in rows.items(): for name, t in rows.items():
for method, row in t["methods"].items(): for method, row in t["methods"].items():
@@ -475,20 +578,24 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict]
if "inherits" in t: if "inherits" in t:
t["inherits"] = sorted(set(t["inherits"])) t["inherits"] = sorted(set(t["inherits"]))
t["events"] = sorted(t.get("events", {}).values(), key=lambda e: (e["order"], e["name"])) t["events"] = sorted(t.get("events", {}).values(), key=lambda e: (e["order"], e["name"]))
t["fields"] = sorted(t.get("fields", {}).values(), key=lambda f: (f["order"], f["name"]))
all_rows = [m for t in rows.values() for m in t["methods"]] all_rows = [m for t in rows.values() for m in t["methods"]]
all_events = [e for t in rows.values() for e in t["events"]] 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")}, all_fields = [f for t in rows.values() for f in t["fields"]]
return {"schema": "tracker/1", "emulator": {k: v for k, v in emulator.items() if k not in ("types", "warnings", "signals", "properties")},
"binaries": sorted(binaries, key=lambda b: (b["name"].lower(), b["id"])), "binaries": sorted(binaries, key=lambda b: (b["name"].lower(), b["id"])),
"types": sorted(rows.values(), key=lambda t: t["name"]), "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)), "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))}, "events": len(all_events), "event_status": dict(Counter(e["status"] for e in all_events)),
"fields": len(all_fields), "field_status": dict(Counter(f["status"] for f in all_fields))},
"warnings": warnings + ["Brak obserwacji w wariancie oznacza nieustalone, nie brak metody.", "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.", "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).", "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 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."]} "Eventy: status emulatora to literał nazwy w kodzie (klasa typu / Variable / silnik); nazwy budowane dynamicznie nie są widoczne.",
"Pola: status emulatora to literał klucza (`:NAME` w gałęzi typu w CNVParser, odczyt atrybutu w klasie typu lub w Variable.java, albo w innym kodzie)."]}
def validate_review(review: dict) -> None: def validate_review(review: dict) -> None:
+1
View File
@@ -40,6 +40,7 @@ Atlas odczytuje snapshoty z dysku przy każdym pobraniu katalogu. Command Center
Licznik to pary typ/metoda. Nie jest liczbą unikalnych ciał Java ani procentem zgodności całego silnika. Metody bazowe `CMC_Runner` (SEND, CLONE, …) są w zakresie `*` raz; typy wskazują go polem `inherits`. Zakres `@` to instrukcje `@IF`/`@LOOP`/… (runner typu 0), porównywane z `CodeParser.dispatchSpecialCall`. Typy bez rozpoznanych metod pozostają widoczne. Licznik to pary typ/metoda. Nie jest liczbą unikalnych ciał Java ani procentem zgodności całego silnika. Metody bazowe `CMC_Runner` (SEND, CLONE, …) są w zakresie `*` raz; typy wskazują go polem `inherits`. Zakres `@` to instrukcje `@IF`/`@LOOP`/… (runner typu 0), porównywane z `CodeParser.dispatchSpecialCall`. Typy bez rozpoznanych metod pozostają widoczne.
Typ → runner pochodzi z `runner_map` snapshotu (fabryka w 7.1+, konstruktory klas w 6.1); bez niego z nazwy klasy, oznaczone jako wnioskowane. Metoda wspólnego runnera, którą oryginał pomija dla danego typu warunkiem `obj.getType()`, nie jest temu typowi przypisana; pusta implementacja wirtualna jest oznaczona jako brak efektu. Sygnatury (typy argumentów i wyniku) są odczytane z ciała metody i mogą być sumą wariantów (`int/string`). Typ → runner pochodzi z `runner_map` snapshotu (fabryka w 7.1+, konstruktory klas w 6.1); bez niego z nazwy klasy, oznaczone jako wnioskowane. Metoda wspólnego runnera, którą oryginał pomija dla danego typu warunkiem `obj.getType()`, nie jest temu typowi przypisana; pusta implementacja wirtualna jest oznaczona jako brak efektu. Sygnatury (typy argumentów i wyniku) są odczytane z ciała metody i mogą być sumą wariantów (`int/string`).
Eventy typu pochodzą z jego vtable (`type_events`) albo z listy najbliższej klasy w łańcuchu konstruktorów. Po stronie emulatora liczy się literał nazwy: w klasie typu (`emitted`), w `Variable.java` (`emitted_base`), w innym kodzie bez przypisania do typu (`engine_literal`); `not_found` znaczy tylko, że literału nie ma. Eventy typu pochodzą z jego vtable (`type_events`) albo z listy najbliższej klasy w łańcuchu konstruktorów. Po stronie emulatora liczy się literał nazwy: w klasie typu (`emitted`), w `Variable.java` (`emitted_base`), w innym kodzie bez przypisania do typu (`engine_literal`); `not_found` znaczy tylko, że literału nie ma.
Pola typu pochodzą z jego łańcucha konstruktorów (`type_fields`) albo z pól jego klasy i jej baz. Po stronie emulatora: klucz `":NAME"` w gałęzi typu w `CNVParser.createVariable` lub odczyt atrybutu (`getAttribute`, `getAttributeInHierarchy`, `attributes().get`) w klasie typu (`read`), w `Variable.java` (`read_base`), gdzie indziej (`engine_literal`).
Alias `BOOL` jest łączony z `BOOLEAN`, `INT` z `INTEGER`; nazwy metod są normalizowane do uppercase. ID metody pozostaje lokalne dla konkretnej klasy i binarki. Relacje dziedziczenia pochodzą wyłącznie ze snapshotu, nie są zgadywane z innej wersji. Alias `BOOL` jest łączony z `BOOLEAN`, `INT` z `INTEGER`; nazwy metod są normalizowane do uppercase. ID metody pozostaje lokalne dla konkretnej klasy i binarki. Relacje dziedziczenia pochodzą wyłącznie ze snapshotu, nie są zgadywane z innej wersji.
Adapter rozpoznaje bieżący wzorzec rejestracji Java; nie jest ogólnym parserem języka Java. Komentarze i literały nie tworzą fałszywych wpisów, nawiasy są dopasowywane leksykalnie. Własne dispatchery `GROUP` / `INSTANCE` są oznaczone do przeglądu. Celowe no-op nie są automatycznie stubami. Adapter rozpoznaje bieżący wzorzec rejestracji Java; nie jest ogólnym parserem języka Java. Komentarze i literały nie tworzą fałszywych wpisów, nawiasy są dopasowywane leksykalnie. Własne dispatchery `GROUP` / `INSTANCE` są oznaczone do przeglądu. Celowe no-op nie są automatycznie stubami.
+12
View File
@@ -139,3 +139,15 @@ def test_type_events_diff_by_script_type():
block = compute_diff(old, new)["type_events"] block = compute_diff(old, new)["type_events"]
assert [e["name"] for e in block["added"]] == ["ONFRAMEUPDATED"] and not block["removed"] assert [e["name"] for e in block["added"]] == ["ONFRAMEUPDATED"] and not block["removed"]
assert filter_by_owner(compute_diff(old, new), "MOVIE")["type_events"]["added"] assert filter_by_owner(compute_diff(old, new), "MOVIE")["type_events"]["added"]
def test_type_fields_diff_tracks_value_types():
from ams.diff import compute_diff
from ams.snapshot import Snapshot
old = Snapshot({"type_fields": [{"type": "VECTOR", "name": "VALUE", "value_types": ["list"], "order": 0}]})
new = Snapshot({"type_fields": [{"type": "VECTOR", "name": "VALUE", "value_types": ["list", "string"], "order": 0},
{"type": "VECTOR", "name": "SIZE", "value_types": ["int"], "order": 1}]})
block = compute_diff(old, new)["type_fields"]
assert [f["name"] for f in block["added"]] == ["SIZE"]
assert block["changed"][0]["changes"]["value_types"] == [["list"], ["list", "string"]]
+41
View File
@@ -313,3 +313,44 @@ def test_events_per_type_and_emulator_signal_literals(tmp_path):
"ONCHANGED": "emitted"} "ONCHANGED": "emitted"}
assert [e["name"] for e in typ(result, "STRING")["events"]] == ["ONCHANGED"] # via CMC_Variable assert [e["name"] for e in typ(result, "STRING")["events"]] == ["ONCHANGED"] # via CMC_Variable
assert result["summary"]["event_status"]["not_found"] >= 1 assert result["summary"]["event_status"]["not_found"] >= 1
def test_fields_per_type_and_emulator_property_literals(tmp_path):
root = tmp_path
variables = root / "core/src/pl/genschu/bloomooemulator/interpreter/variable"
variables.mkdir(parents=True)
(variables / "Variable.java").write_text(
'interface Variable { void r(Context c) { c.getAttributeInHierarchy(name(), "TOINI"); } }')
(variables / "TextVariable.java").write_text('''record TextVariable() {
VariableType type() { return VariableType.TEXT; }
void load(Context context) { context.attributes().get(name, "RECT"); log("FONT"); }
}''')
loader = root / "core/src/pl/genschu/bloomooemulator/loader"
loader.mkdir(parents=True)
(loader / "CNVParser.java").write_text('''class CNVParser {
private Variable createVariable(String type, String objectName, Map<String, String> properties) {
return switch (type) {
case "TIMER" -> new TimerVariable(properties.get(objectName + ":ELAPSE"));
case "INTEGER", "INT" -> make(properties.get(objectName + ":VALUE"));
default -> null;
};
}
void other(String n, Map<String, String> p) { p.get(n + ":PRIORITY"); }
}''')
emu = scan_emulator(root)
props = {scope: sorted(v) for scope, v in emu["properties"].items()}
assert props == {"*": ["TOINI"], "TEXT": ["RECT"], "TIMER": ["ELAPSE"], "INTEGER": ["VALUE"],
"engine": ["PRIORITY"]}
snap = Snapshot({"binary": {"name": "p8.dll", "sha256": SHA},
"types": [{"script_name": "TEXT", "cpp_class": "CMC_Text"}, {"script_name": "INTEGER", "cpp_class": None}],
"type_fields": [{"type": "TEXT", "name": n, "value_types": ["string"], "order": i}
for i, n in enumerate(["RECT", "FONT", "PRIORITY"])],
"fields": [{"owner": "CMC_Variable", "name": "TOINI", "type": "bool", "order": 0},
{"owner": "CMC_Integer", "name": "VALUE", "type": "int", "order": 0}],
"field_inheritance": [{"class": "CMC_Integer", "base_class": "CMC_Variable"}]})
result = build_tracker([snap], emu)
assert {f["name"]: f["status"] for f in typ(result, "TEXT")["fields"]} == {
"RECT": "read", "FONT": "not_found", "PRIORITY": "engine_literal"}
integer = {f["name"]: f for f in typ(result, "INTEGER")["fields"]} # class chain, base first
assert [f["name"] for f in typ(result, "INTEGER")["fields"]] == ["TOINI", "VALUE"]
assert integer["TOINI"]["status"] == "read_base" and integer["VALUE"]["value_types"] == ["int"]