ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
parser.json_emitter Namespace Reference

Classes

class  ImportResolverLike
class  JsonEmitterDeps
class  EmitPipelineDeps

Functions

set[str] get_referenced_names (ast.AST node)
Iterable[str] _assign_target_names (ast.expr target)
set[str] _node_bound_names (ast.stmt node)
list[ast.stmt] _filter_nodes_for_import (ast.Module tree, elements_to_import)
str _compute_output_json_path (str python_filename, str output_dir, str|None module_qualname)
None _reject_unencodable_string_constants (ast.AST tree, str source_filename)
 generate_ast_json (ast.Module tree, str python_filename, elements_to_import, str output_dir, module_qualname=None, *, JsonEmitterDeps deps)
None emit_file_as_json (str filename, str output_dir, str|None module_qualname=None, elements_to_import=None, *, EmitPipelineDeps deps)
None emit_module_json (str module_qualname, str output_dir, elements_to_import=None, *, EmitPipelineDeps deps)

Detailed Description

AST JSON emission helpers for parser pipeline.

Function Documentation

◆ _assign_target_names()

Iterable[str] parser.json_emitter._assign_target_names ( ast.expr target)
protected

◆ _compute_output_json_path()

str parser.json_emitter._compute_output_json_path ( str python_filename,
str output_dir,
str | None module_qualname )
protected

◆ _filter_nodes_for_import()

list[ast.stmt] parser.json_emitter._filter_nodes_for_import ( ast.Module tree,
elements_to_import )
protected
Return the subset of ``tree.body`` selected by ``elements_to_import``.

Beyond the explicitly imported names, retain every top-level definition or
global *transitively* referenced by them, computed as a fixpoint over
``get_referenced_names``. An imported class whose method reads a module
global — or calls a sibling helper that itself reads one — keeps that
global in the emitted body, matching CPython's rule that the global resolves
against its defining module at call time (GitHub #4984). The closure only
ever adds nodes, so it cannot drop anything the previous one-hop scan kept.

◆ _node_bound_names()

set[str] parser.json_emitter._node_bound_names ( ast.stmt node)
protected
Top-level binding names introduced by ``node`` (empty for non-bindings).

◆ _reject_unencodable_string_constants()

None parser.json_emitter._reject_unencodable_string_constants ( ast.AST tree,
str source_filename )
protected
Refuse string literals that cannot cross the parser->converter JSON boundary.

A surrogate code point is representable in a CPython ``str`` but has no
UTF-8 encoding, and the C++ reader rejects both transportable spellings: an
escaped ``\\ud800`` is invalid JSON (nlohmann requires a low surrogate to
follow), and the WTF-8 byte form is ill-formed UTF-8. Python never combines
a surrogate pair, so ``"\\ud83d\\ude00"`` is two unencodable code points
rather than an emoji and is refused the same way. Emitting one aborts the
parser mid-``json.dump``, so refuse at parse time with a located diagnostic
rather than crash or emit a silently truncated string.

◆ emit_file_as_json()

None parser.json_emitter.emit_file_as_json ( str filename,
str output_dir,
str | None module_qualname = None,
elements_to_import = None,
* ,
EmitPipelineDeps deps )
Generate AST JSON for a source file.

◆ emit_module_json()

None parser.json_emitter.emit_module_json ( str module_qualname,
str output_dir,
elements_to_import = None,
* ,
EmitPipelineDeps deps )
Resolve module to file and emit AST JSON.

◆ generate_ast_json()

parser.json_emitter.generate_ast_json ( ast.Module tree,
str python_filename,
elements_to_import,
str output_dir,
module_qualname = None,
* ,
JsonEmitterDeps deps )
Generate AST JSON from the given Python AST tree.

◆ get_referenced_names()

set[str] parser.json_emitter.get_referenced_names ( ast.AST node)
Collect every name *read* inside a definition (``Load`` context).

This subsumes call targets (``C()``), type annotations (``-> Node``,
``x: Tile``), and — crucially — bare reads of module-level globals such as
a method that reads a module constant. Capturing the last case lets a
named import (``from mod import C``) carry along the globals ``C``'s methods
reference, instead of dropping them and failing name resolution at the use
site (GitHub #4984). Local stores and parameters are in ``Store``/``Param``
context and are intentionally excluded; only top-level definitions whose
names match are ever retained by ``_filter_nodes_for_import``, so any
incidental over-collection is sound (it can only keep a real sibling
global, never drop one).