|
UniSet 2.45.1
|
Открытые члены | |
| __init__ (self, IRProgram program, SensorMapping mapping, bool debug=False) | |
| str | generate (self) |
Открытые атрибуты | |
| program = program | |
| mapping = mapping | |
Защищенные члены | |
| list[str] | _emit_sensor_arrays (self) |
| list[SensorEntry] | _collect_input_entries (self) |
| list[SensorEntry] | _collect_output_entries (self) |
| list[str] | _emit_global_vars (self) |
| list[str] | _emit_local_vars (self) |
| None | _prescan_stub_types (self) |
| list[str] | _emit_auto_stubs (self) |
| list[str] | _emit_fb_instances (self) |
| list[str] | _emit_program_function (self, IRProgram prog) |
| list[str] | _emit_function_block_class (self, IRFunctionBlock fb) |
| str | _format_initial_value (self, IRVariable var) |
| str | _format_struct_literal (self, list[IRStructField] fields) |
| str | _format_array_init (self, IRVariable var) |
| str | _format_python_value (self, Any value, IECType iec_type) |
| list[str] | _emit_statement (self, IRStatement stmt, int indent, IRFunctionBlock|None fb_context=None) |
| list[str] | _emit_fb_call (self, IRFBCall call, int indent, IRFunctionBlock|None fb_context=None) |
| str | _get_fb_type (self, str instance_name) |
| list[str] | _emit_if_else (self, IRIfElse stmt, int indent, IRFunctionBlock|None fb_context=None) |
| list[str] | _emit_case (self, IRCase stmt, int indent) |
| list[str] | _emit_for_loop (self, IRForLoop stmt, int indent) |
| list[str] | _emit_while_loop (self, IRWhileLoop stmt, int indent) |
| list[str] | _emit_repeat_loop (self, IRRepeatLoop stmt, int indent) |
| str | _emit_expression (self, IRExpression expr, IRFunctionBlock|None fb_context=None) |
| str | _emit_function_call_expr (self, IRFunctionCall expr, IRFunctionBlock|None fb_context=None) |
| str | _emit_array_access (self, IRArrayAccess expr, IRFunctionBlock|None fb_context=None) |
| IRVariable|None | _find_variable (self, str name) |
| str | _emit_literal (self, IRLiteral lit) |
| str | _emit_var_ref (self, IRVarRef ref, IRFunctionBlock|None fb_context=None) |
| str | _prefixed_sensor (self, str sensor_name) |
| str | _prefixed_func (self, str func_name) |
| list[str] | _emit_debug_stubs (self) |
| dict[str, tuple[list[str], list[str]]] | _collect_fb_type_ports (self) |
| list[str] | _emit_program_meta (self) |
| list[dict] | _extract_connections (self, list stmts, list operator_nodes=None) |
| dict|None | _classify_connection (self, str instance, str param, expr, list operator_nodes=None, list connections=None) |
| str|None | _build_operator_subgraph (self, expr, list operator_nodes, list connections) |
| str | _emit_type_coercion (self, IRTypeCoercion coercion) |
Защищенные статические члены | |
| str | _format_array_literal (int size, str default_str) |
| str | _format_scale (float scale) |
Защищенные данные | |
| _debug = debug | |
| _has_mapping = bool(mapping.inputs or mapping.outputs) | |
| set[str] | _unsupported_fbs = set() |
| set[str] | _stub_fb_types = set() |
| dict | _user_fb_types = {fb.name for fb in program.function_blocks} |
| _var_prefix = mapping.options.var_prefix | |
| _func_prefix = mapping.options.func_prefix | |
| dict | _input_map |
| dict | _output_map |
| dict | _input_names = {v.name for v in program.inputs} |
| dict | _output_names = {v.name for v in program.outputs} |
| dict | _global_names = {v.name for v in program.globals} |
| dict | _scaled_inputs |
| dict | _scaled_outputs |
| _struct_flatten = mapping.options.struct_flatten | |
| dict | _flat_input_structs = {} |
| dict | _flat_output_structs = {} |
| int | _op_counter = 0 |
| _extracted_operator_nodes = operator_nodes | |
Статические защищенные данные | |
| dict | _FLOAT_TYPES = {IECType.REAL, IECType.LREAL} |
| dict | _ALL_INTEGER_TYPES |
Walks IR and emits JavaScript source code. Builds lookup tables for input/output variable-to-sensor mapping, then emits the JS file sections in order.
|
protected |
Recursively build operator nodes for a complex expression. Returns the output node ID of the subgraph, or None for literals.
|
protected |
Classify an FB call argument as a connection. For complex expressions, creates operator nodes with inner connections. Returns the final connection linking to the target FB.param.
|
protected |
Build fb_type -> (input_names, output_names) lookup. Covers user-defined FBs from the ST source (IRFunctionBlock), including nested FBs declared inside other FBs, and standard/library FBs from the fb_registry (IEC 61131-3 primitives + YAML lib types).
|
protected |
Collect sensor entries for all input variables. When struct_flatten is enabled, struct variables expand into their individual field entries (from dotted mapping names).
|
protected |
Collect sensor entries for all output variables. When struct_flatten is enabled, struct variables expand into their individual field entries (from dotted mapping names).
|
protected |
Emit an array access with 1-based to 0-based index conversion. Looks up the array variable to determine the lower bound, then emits arr[index - lower_bound].
|
protected |
Emit auto-generated stub classes for unknown external FB types.
|
protected |
Emit a switch/case statement.
|
protected |
Emit debug initialization: load uniset2-debug.js and start debug server.
|
protected |
Emit an expression as a JavaScript string.
Args:
expr: The IR expression to emit.
fb_context: If set, variable references within a FUNCTION_BLOCK
body should use this.name prefix for the FB's own variables.
|
protected |
Emit an FB call as instance.update(arg1, arg2, ...). Arguments are ordered according to the fb_registry update_params order. When inside a FUNCTION_BLOCK body (fb_context), uses this. prefix.
|
protected |
Emit function block instance declarations as const statements. Timers (TON/TOF/TP): constructor takes PT value -> new TON(ptValue) Counters (CTU/CTD/CTUD): constructor takes PV value -> new CTU(pvValue) Bistable/Edge (RS/SR/R_TRIG/F_TRIG): no constructor args -> new RS()
|
protected |
Emit a for loop statement.
|
protected |
Emit a FUNCTION_BLOCK as a JavaScript class with constructor and execute().
|
protected |
Emit a FUNCTION call expression as ``funcName(arg1, arg2, ...)``.
|
protected |
Emit global variable declarations (from VAR_GLOBAL) as let statements. Skips globals that are shadowed by local/input/output variables.
|
protected |
Emit an if/else if/else statement.
|
protected |
Emit a literal value.
|
protected |
Emit local variable declarations as let statements. Deduplicates by name (actions copy parent locals, causing repeats).
|
protected |
Emit a secondary PROGRAM as a JS class with execute() method. Same pattern as FUNCTION_BLOCK: local variables and FB instances stored as properties (this.xxx), body in execute(). This ensures state persists between calls. Called from main: `ProgramName.execute();`
|
protected |
Emit globalThis._program_meta with program structure info.
|
protected |
Emit a do..while loop statement (REPEAT..UNTIL).
|
protected |
Emit uniset_inputs and uniset_outputs array declarations.
|
protected |
Emit a single statement as a list of indented lines.
Args:
stmt: The IR statement to emit.
indent: Current indentation level.
fb_context: If set, we are inside a FUNCTION_BLOCK body and
variable references should use this.name prefix.
|
protected |
Emit a type coercion expression.
|
protected |
Emit a variable reference with input/output prefix substitution. When fb_context is set, variables belonging to the FUNCTION_BLOCK are prefixed with 'this.' instead of using sensor mapping.
|
protected |
Emit a while loop statement.
|
protected |
Extract FB connections from IR statements for the schema graph.
Extracts:
1. FB call inputs: fb(PARAM := source) → {from: source, to: fb, toParam: PARAM}
2. Output assignments: var := fb.field → {from: fb, fromField: field, to: var, toParam: "="}
3. Operator nodes: complex expressions (A AND B, NOT C) → virtual nodes with connections
Args:
stmts: IR statement list
operator_nodes: accumulator for generated operator nodes
|
protected |
Find a variable by name across all program variable sections.
|
protected |
Format an ARRAY as a JS array literal.
|
staticprotected |
Format an array as a JS literal [val, val, ...] for QuickJS compatibility.
|
protected |
Format the initial value for a local variable declaration.
|
protected |
Format a Python value as a JS literal string.
|
staticprotected |
Format a scale factor value, omitting .0 for integer values.
|
protected |
Format a STRUCT as a JS object literal with default values per field.
|
protected |
Look up the FB type for an instance name from all programs and FBs.
|
protected |
Apply func_prefix to a function/program/FB name.
|
protected |
Apply var_prefix to a sensor name.
|
protected |
Pre-scan all FB instances and GVL struct fields to find types needing auto-stubs.
| str st2js.codegen.CodeGenerator.generate | ( | self | ) |
Generate the complete JavaScript source string.
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |