@@ -26,9 +26,7 @@ def create_targets_and_rvals(stmt):
2626 return stmt .targets , [stmt .value ]
2727
2828
29- def handle_assign_allocation (
30- builder , stmt , local_sym_tab , map_sym_tab , structs_sym_tab
31- ):
29+ def handle_assign_allocation (compilation_context , builder , stmt , local_sym_tab ):
3230 """Handle memory allocation for assignment statements."""
3331
3432 logger .info (f"Handling assignment for allocation: { ast .dump (stmt )} " )
@@ -59,7 +57,7 @@ def handle_assign_allocation(
5957 # Determine type and allocate based on rval
6058 if isinstance (rval , ast .Call ):
6159 _allocate_for_call (
62- builder , var_name , rval , local_sym_tab , map_sym_tab , structs_sym_tab
60+ builder , var_name , rval , local_sym_tab , compilation_context
6361 )
6462 elif isinstance (rval , ast .Constant ):
6563 _allocate_for_constant (builder , var_name , rval , local_sym_tab )
@@ -71,18 +69,17 @@ def handle_assign_allocation(
7169 elif isinstance (rval , ast .Attribute ):
7270 # Struct field-to-variable assignment (a = dat.fld)
7371 _allocate_for_attribute (
74- builder , var_name , rval , local_sym_tab , structs_sym_tab
72+ builder , var_name , rval , local_sym_tab , compilation_context
7573 )
7674 else :
7775 logger .warning (
7876 f"Unsupported assignment value type for { var_name } : { type (rval ).__name__ } "
7977 )
8078
8179
82- def _allocate_for_call (
83- builder , var_name , rval , local_sym_tab , map_sym_tab , structs_sym_tab
84- ):
80+ def _allocate_for_call (builder , var_name , rval , local_sym_tab , compilation_context ):
8581 """Allocate memory for variable assigned from a call."""
82+ structs_sym_tab = compilation_context .structs_sym_tab
8683
8784 if isinstance (rval .func , ast .Name ):
8885 call_type = rval .func .id
@@ -149,17 +146,19 @@ def _allocate_for_call(
149146 elif isinstance (rval .func , ast .Attribute ):
150147 # Map method calls - need double allocation for ptr handling
151148 _allocate_for_map_method (
152- builder , var_name , rval , local_sym_tab , map_sym_tab , structs_sym_tab
149+ builder , var_name , rval , local_sym_tab , compilation_context
153150 )
154151
155152 else :
156153 logger .warning (f"Unsupported call function type for { var_name } " )
157154
158155
159156def _allocate_for_map_method (
160- builder , var_name , rval , local_sym_tab , map_sym_tab , structs_sym_tab
157+ builder , var_name , rval , local_sym_tab , compilation_context
161158):
162159 """Allocate memory for variable assigned from map method (double alloc)."""
160+ map_sym_tab = compilation_context .map_sym_tab
161+ structs_sym_tab = compilation_context .structs_sym_tab
163162
164163 map_name = rval .func .value .id
165164 method_name = rval .func .attr
@@ -321,8 +320,12 @@ def _allocate_for_name(builder, var_name, rval, local_sym_tab):
321320 )
322321
323322
324- def _allocate_for_attribute (builder , var_name , rval , local_sym_tab , structs_sym_tab ):
323+ def _allocate_for_attribute (
324+ builder , var_name , rval , local_sym_tab , compilation_context
325+ ):
325326 """Allocate memory for struct field-to-variable assignment (a = dat.fld)."""
327+ structs_sym_tab = compilation_context .structs_sym_tab
328+
326329 if not isinstance (rval .value , ast .Name ):
327330 logger .warning (f"Complex attribute access not supported for { var_name } " )
328331 return
0 commit comments