srdatalog.dataset_const¶
Dataset-specific interned constants.
Mirrors the dataset_const NAME: "symbol" macro in src/srdatalog/lang.nim
(lines ~126-265). In Nim, SCREAMING_SNAKE identifiers declared in a rule
set are resolved at macro-expansion time by reading a JSON file that maps
lower-case symbol names to int64 IDs (produced by the domain’s
string-intern table — e.g., Java-symbol dictionary for doop):
dataset_const MAIN: "main" # NAME in rule body
dataset_const CLASS_INIT_METHOD: "class_init_method"
The resolver replaces each NAME with the corresponding int everywhere:
In atom args where the NAME appears as a bare identifier.
Inside
Filter.codeC++ bodies via word-boundary substitution.
The Python port does the same at rule-build time (when building the
Program) via resolve_dataset_consts(program, consts).
Typical usage:
from srdatalog.dataset_const import load_meta, resolve_program_consts
consts = load_meta("integration_tests/examples/doop/batik_meta.json", {
"ABSTRACT": "abstract",
"CLASS_INIT_METHOD": "class_init_method",
"JAVA_LANG_OBJECT": "java_lang_Object",
})
prog = resolve_program_consts(build_doop_program(consts), consts)
Module Contents¶
Functions¶
Read |
|
Apply dataset_const substitution across every rule in a Program.
|
|
Rewrite a single Rule: substitute dataset consts in head, body, and debug_code. Returns a new Rule (dataclass is frozen). |
Data¶
API¶
- srdatalog.dataset_const.__all__¶
[‘load_meta’, ‘resolve_program_consts’, ‘resolve_rule_consts’]
- srdatalog.dataset_const.load_meta(meta_path: str | pathlib.Path, declarations: dict[str, str]) dict[str, int][source]¶
Read
meta_path(JSON map: symbol-name → int) and return{const_name: int_value}for each declared entry.Args: meta_path: path to the JSON file (e.g. batik_meta.json). declarations: mapping from UPPER_CASE const name (as used in rules) to the lower-case JSON key. Mirrors the
dataset_const NAME: "key"pairs from Nim’s rules_def.Raises KeyError on any missing declaration — we fail fast rather than silently resolving to a garbage value (Nim aborts the compile with a similar error).
- srdatalog.dataset_const.resolve_program_consts(program: srdatalog.dsl.Program, consts: dict[str, int]) srdatalog.dsl.Program[source]¶
Apply dataset_const substitution across every rule in a Program.
Relationdecls don’t carry constant references, so they pass through unchanged.
- srdatalog.dataset_const.resolve_rule_consts(rule: srdatalog.dsl.Rule, consts: dict[str, int]) srdatalog.dsl.Rule[source]¶
Rewrite a single Rule: substitute dataset consts in head, body, and debug_code. Returns a new Rule (dataclass is frozen).