|
UniSet 2.45.1
|
Функции | |
| IECType | resolve_type (IRExpression expr, dict[str, IRVariable] variables, list[IRFBInstance]|None fb_instances=None) |
| IECType | _resolve_field_access_type (IRFieldAccess expr, list[IRFBInstance]|None fb_instances=None, dict[str, IRVariable]|None variables=None) |
| IECType | _resolve_arithmetic_type (IECType left, IECType right, str op) |
| IRProgram | check_types (IRProgram program, *, bool ignore_undefined=False) |
| dict[str, IRVariable] | _build_variable_dict (IRProgram program) |
| IRStatement | _check_statement (IRStatement stmt, dict[str, IRVariable] variables, list[IRFBInstance]|None fb_instances=None) |
| IRAssignment | _check_assignment (IRAssignment assign, dict[str, IRVariable] variables, list[IRFBInstance]|None fb_instances=None) |
| IECType|None | _resolve_target_type (IRExpression target, dict[str, IRVariable] variables) |
| IRExpression | _coerce_assignment (IRExpression value, IECType value_type, IECType target_type) |
| IRExpression | _check_expression (IRExpression expr, dict[str, IRVariable] variables, list[IRFBInstance]|None fb_instances=None) |
| IRBinaryOp | _check_binary_op (IRBinaryOp expr, dict[str, IRVariable] variables, list[IRFBInstance]|None fb_instances=None) |
| IRIfElse | _check_if_else (IRIfElse stmt, dict[str, IRVariable] variables, list[IRFBInstance]|None fb_instances=None) |
| IRCase | _check_case (IRCase stmt, dict[str, IRVariable] variables, list[IRFBInstance]|None fb_instances=None) |
| IRForLoop | _check_for_loop (IRForLoop stmt, dict[str, IRVariable] variables, list[IRFBInstance]|None fb_instances=None) |
Переменные | |
| bool | _ignore_undefined = False |
| dict | _ARITHMETIC_OPS = {"+", "-", "*", "/", "MOD"} |
| dict | _COMPARISON_OPS = {"<", ">", "<=", ">=", "=", "<>"} |
| dict | _LOGICAL_OPS = {"AND", "OR", "XOR"} |
| dict | _NUMERIC_TYPES |
| dict | _INTEGER_TYPES |
| dict | _FB_TYPE_MAP |
Type system for the st2js converter. Provides type resolution and type checking for IEC 61131-3 types. Walks the IR tree and inserts IRTypeCoercion nodes where implicit type conversions are needed for correct JavaScript code generation. Supported coercions: - BOOL in arithmetic context -> IRTypeCoercion(BOOL, INT) - REAL assigned to INT/DINT variable -> IRTypeCoercion(REAL, INT/DINT) - INT assigned to REAL -> no coercion (JS handles automatically) Type errors are raised for incompatible types (e.g., STRING in arithmetic).
|
protected |
Build a name->IRVariable dict from all program variable sections. Also adds flat aliases for GVL fields so unqualified access (e.g., DI_GRU_QG1_IsOn instead of IO.DI_GRU_QG1_IsOn) resolves correctly.
|
protected |
Type-check an assignment, inserting coercions on the value if needed.
|
protected |
Type-check a binary operation, inserting BOOL->INT coercions for arithmetic.
|
protected |
Type-check a CASE statement.
|
protected |
Type-check an expression, inserting BOOL->INT coercions in arithmetic.
|
protected |
Type-check a FOR loop.
|
protected |
Type-check an IF/ELSIF/ELSE statement.
|
protected |
Type-check a single statement, returning a potentially modified copy.
|
protected |
Insert coercion node if value type doesn't match target type. Rules: - REAL -> INT/DINT: insert coercion (Math.trunc in codegen) - INT -> REAL: no coercion (JS handles) - STRING -> numeric: type error - Same type: no coercion
|
protected |
Resolve the result type of an arithmetic operation.
Rules:
- Any operand REAL -> result is REAL
- DINT + INT -> DINT
- INT + INT -> INT
- BOOL is treated as INT in arithmetic (coercion handled separately)
Raises:
STTypeError: If a non-numeric type is used in arithmetic.
|
protected |
Resolve the type of a field access expression. For FB instances, looks up the output type from the fb_registry. For STRUCT variables, looks up the field type from struct_fields. Returns VOID if the instance/variable or field is not found.
|
protected |
Resolve the type of an assignment target.
Walk the IR tree, inserting type coercion nodes where needed.
Modifies a copy of the program; the original is not mutated.
Args:
program: The IRProgram to type-check.
ignore_undefined: If True, undefined variables produce warnings
instead of errors (assumes INT type).
Returns:
A new IRProgram with IRTypeCoercion nodes inserted.
Raises:
STTypeError: If incompatible types are detected.
| IECType st2js.type_system.resolve_type | ( | IRExpression | expr, |
| dict[str, IRVariable] | variables, | ||
| list[IRFBInstance] | None | fb_instances = None ) |
Determine the IEC type of an expression.
Args:
expr: The IR expression node to resolve.
variables: A name->IRVariable dict for variable type lookup.
fb_instances: Optional list of FB instances for field access resolution.
Returns:
The resolved IECType for the expression.
Raises:
STTypeError: If the expression contains incompatible types.
|
protected |
|
protected |
|
protected |