UniSet 2.45.1
Класс st2js.transformer.ASTTransformer

Открытые члены

 __init__ (self, str filename="<stdin>", set[str]|None program_names=None)
None register_user_fb_type (self, str name)
None register_enum_type (self, str name)
None register_struct_type (self, StructureTypeDeclaration decl)
tuple[list[IRVariable], list[IRFBInstance]] transform_gvl_block (self, GVLBlock gvl)
IRProgram transform_program (self, Program node)
IRFunctionBlock transform_function_block (self, FunctionBlock node)

Открытые атрибуты

 filename = filename

Защищенные члены

 _parse_init_str (self, str init_str, IECType iec_type)
tuple[list[IRVariable], list[IRFBInstance]] _transform_var_items_with_fb (self, list items, bool is_local=False)
list[IRVariable_transform_var_items (self, list items, bool is_input=False, bool is_output=False, bool is_local=False)
list[IRVariable_transform_array_var (self, item, ArrayTypeInitialization init, bool is_input=False, bool is_output=False, bool is_local=False)
object|None _extract_initial_value (self, value)
list[IRStatement] _transform_statement_list (self, StatementList stmt_list)
IRStatement _transform_statement (self, stmt)
IRFBCall _transform_fb_call (self, FunctionCallStatement stmt)
None _extract_constructor_args (self, list[IRFBInstance] fb_instances, list[IRStatement] body)
IRAssignment _transform_assignment (self, AssignmentStatement stmt)
IRIfElse _transform_if (self, IfStatement stmt)
IRCase _transform_case (self, CaseStatement stmt)
IRForLoop _transform_for (self, ForStatement stmt)
IRWhileLoop _transform_while (self, WhileStatement stmt)
IRRepeatLoop _transform_repeat (self, RepeatStatement stmt)
IRExpression _transform_expression (self, expr)
IRFunctionCall _transform_function_call_expr (self, FunctionCall expr)
IRExpression _transform_multi_element_variable (self, MultiElementVariable expr)
IRLiteral _transform_duration (self, Duration expr)

Защищенные данные

dict _struct_types = {}
set[str] _program_names = program_names or set()
set[str] _user_fb_types = set()
set[str] _enum_types = set()

Подробное описание

Walks blark AST nodes and produces IR dataclasses.

Handles PROGRAM and FUNCTION_BLOCK declarations, VAR sections
(INPUT/OUTPUT/local), FB instance detection, FB call statements,
field access (obj.field), assignment, IF/ELSIF/ELSE,
CASE, FOR, WHILE, REPEAT, binary/unary expressions,
variable references, literals, and Duration (TIME) literals.

Методы

◆ _extract_constructor_args()

None st2js.transformer.ASTTransformer._extract_constructor_args ( self,
list[IRFBInstance] fb_instances,
list[IRStatement] body )
protected
Extract constructor arguments from FB calls and store in FB instances.

For standard FBs, constructor args (PT for timers, PV for counters) are
specified as named parameters in the first FB call. These are extracted
from the IRFBCall arguments and stored in the IRFBInstance constructor_args.
The constructor args are also removed from the IRFBCall arguments so that
only update() params remain.

◆ _extract_initial_value()

object | None st2js.transformer.ASTTransformer._extract_initial_value ( self,
value )
protected
Extract a Python value from a blark initial value node.

◆ _parse_init_str()

st2js.transformer.ASTTransformer._parse_init_str ( self,
str init_str,
IECType iec_type )
protected
Parse an initial value string into a Python value.

◆ _transform_array_var()

list[IRVariable] st2js.transformer.ASTTransformer._transform_array_var ( self,
item,
ArrayTypeInitialization init,
bool is_input = False,
bool is_output = False,
bool is_local = False )
protected
Transform an ARRAY variable declaration.

◆ _transform_assignment()

IRAssignment st2js.transformer.ASTTransformer._transform_assignment ( self,
AssignmentStatement stmt )
protected
Transform a blark AssignmentStatement into an IRAssignment.

◆ _transform_case()

IRCase st2js.transformer.ASTTransformer._transform_case ( self,
CaseStatement stmt )
protected
Transform a blark CaseStatement into an IRCase.

◆ _transform_duration()

IRLiteral st2js.transformer.ASTTransformer._transform_duration ( self,
Duration expr )
protected
Transform a blark Duration literal into an IRLiteral with millisecond value.

◆ _transform_expression()

IRExpression st2js.transformer.ASTTransformer._transform_expression ( self,
expr )
protected
Transform a blark expression node into an IR expression.

◆ _transform_fb_call()

IRFBCall st2js.transformer.ASTTransformer._transform_fb_call ( self,
FunctionCallStatement stmt )
protected
Transform a blark FunctionCallStatement into an IRFBCall.

Extracts the instance name and named parameters from the call.

◆ _transform_for()

IRForLoop st2js.transformer.ASTTransformer._transform_for ( self,
ForStatement stmt )
protected
Transform a blark ForStatement into an IRForLoop.

◆ _transform_function_call_expr()

IRFunctionCall st2js.transformer.ASTTransformer._transform_function_call_expr ( self,
FunctionCall expr )
protected
Transform a blark FunctionCall (expression) into an IRFunctionCall.

◆ _transform_if()

IRIfElse st2js.transformer.ASTTransformer._transform_if ( self,
IfStatement stmt )
protected
Transform a blark IfStatement into an IRIfElse.

◆ _transform_multi_element_variable()

IRExpression st2js.transformer.ASTTransformer._transform_multi_element_variable ( self,
MultiElementVariable expr )
protected
Transform a multi-element variable (e.g. myTimer.Q, arr[i]) into field/array access.

◆ _transform_repeat()

IRRepeatLoop st2js.transformer.ASTTransformer._transform_repeat ( self,
RepeatStatement stmt )
protected
Transform a blark RepeatStatement into an IRRepeatLoop.

◆ _transform_statement()

IRStatement st2js.transformer.ASTTransformer._transform_statement ( self,
stmt )
protected
Transform a single blark statement into an IR statement.

◆ _transform_statement_list()

list[IRStatement] st2js.transformer.ASTTransformer._transform_statement_list ( self,
StatementList stmt_list )
protected
Transform a blark StatementList into a list of IR statements.

◆ _transform_var_items()

list[IRVariable] st2js.transformer.ASTTransformer._transform_var_items ( self,
list items,
bool is_input = False,
bool is_output = False,
bool is_local = False )
protected
Transform a list of VariableOneInitDeclaration into IRVariables.

◆ _transform_var_items_with_fb()

tuple[list[IRVariable], list[IRFBInstance]] st2js.transformer.ASTTransformer._transform_var_items_with_fb ( self,
list items,
bool is_local = False )
protected
Transform VAR items, separating regular variables from FB instances.

Returns:
    A tuple of (regular_variables, fb_instances).

◆ _transform_while()

IRWhileLoop st2js.transformer.ASTTransformer._transform_while ( self,
WhileStatement stmt )
protected
Transform a blark WhileStatement into an IRWhileLoop.

◆ register_enum_type()

None st2js.transformer.ASTTransformer.register_enum_type ( self,
str name )
Register a user-defined ENUM type name.

◆ register_struct_type()

None st2js.transformer.ASTTransformer.register_struct_type ( self,
StructureTypeDeclaration decl )
Register a STRUCT type declaration for later use in variable resolution.

◆ register_user_fb_type()

None st2js.transformer.ASTTransformer.register_user_fb_type ( self,
str name )
Register a user-defined FUNCTION_BLOCK type name.

◆ transform_function_block()

IRFunctionBlock st2js.transformer.ASTTransformer.transform_function_block ( self,
FunctionBlock node )
Transform a blark FunctionBlock node into an IRFunctionBlock.

◆ transform_gvl_block()

tuple[list[IRVariable], list[IRFBInstance]] st2js.transformer.ASTTransformer.transform_gvl_block ( self,
GVLBlock gvl )
Transform a named GVL block into a single STRUCT-like IRVariable.

Each named GVL becomes one variable: `let GVL_Name = { field1: val, ... };`
FB-typed variables within the GVL are emitted as separate FB instances.

◆ transform_program()

IRProgram st2js.transformer.ASTTransformer.transform_program ( self,
Program node )
Transform a blark Program node into an IRProgram.