@@ -704,9 +704,9 @@ def error_out_at_index(_i, exc, msg):
704
704
site , val_expr , targets , error_out_at_index ,
705
705
f'deserialization of arguments to { self .method .name } ' )
706
706
if self .args_type :
707
- ctree .mkAssignStatement (site , out_expr ,
708
- ctree .ExpressionInitializer (
709
- tmp_out_ref )).toc ()
707
+ ctree .AssignStatement (site , out_expr ,
708
+ ctree .ExpressionInitializer (
709
+ tmp_out_ref )).toc ()
710
710
711
711
@property
712
712
def args_type (self ):
@@ -822,8 +822,8 @@ def error_out_at_index(_i, exc, msg):
822
822
'deserialization of arguments to a send_now' )
823
823
824
824
825
- ctree .mkAssignStatement (site , out_expr ,
826
- ctree .ExpressionInitializer (tmp_out_ref )).toc ()
825
+ ctree .AssignStatement (site , out_expr ,
826
+ ctree .ExpressionInitializer (tmp_out_ref )).toc ()
827
827
828
828
@property
829
829
def args_type (self ):
@@ -2132,8 +2132,8 @@ def make_static_var(site, location, static_sym_type, name, init=None,
2132
2132
with init_code :
2133
2133
if deep_const (static_sym_type ):
2134
2134
coverity_marker ('store_writes_const_field' , 'FALSE' )
2135
- init .assign_to (mkStaticVariable (site , static_sym ),
2136
- static_sym_type )
2135
+ out ( init .assign_to (mkStaticVariable (site , static_sym ). read ( ),
2136
+ static_sym_type ) + '; \n ' )
2137
2137
c_init = init_code .buf
2138
2138
else :
2139
2139
c_init = None
@@ -2355,7 +2355,6 @@ def stmt_assign(stmt, location, scope):
2355
2355
else :
2356
2356
method_tgts = tgts
2357
2357
2358
- # TODO support multiple assign sources. It should be generalized.
2359
2358
method_invocation = try_codegen_invocation (site , src_asts , method_tgts ,
2360
2359
location , scope )
2361
2360
if method_invocation :
@@ -2371,19 +2370,26 @@ def stmt_assign(stmt, location, scope):
2371
2370
+ f'initializer: Expected { src_asts } , got 1' ))
2372
2371
return []
2373
2372
2374
- stmts = []
2375
2373
lscope = Symtab (scope )
2374
+ init_typ = tgts [- 1 ].ctype ()
2376
2375
init = eval_initializer (
2377
- site , tgts [- 1 ].ctype (), src_asts [0 ], location , scope , False )
2378
-
2379
- for (i , tgt ) in enumerate (reversed (tgts [1 :])):
2380
- name = 'tmp%d' % (i ,)
2381
- sym = lscope .add_variable (
2382
- name , type = tgt .ctype (), site = tgt .site , init = init , stmt = True )
2383
- init = ExpressionInitializer (mkLocalVariable (tgt .site , sym ))
2384
- stmts .extend ([sym_declaration (sym ),
2385
- mkAssignStatement (tgt .site , tgt , init )])
2386
- return stmts + [mkAssignStatement (tgts [0 ].site , tgts [0 ], init )]
2376
+ tgts [- 1 ].site , init_typ , src_asts [0 ], location , scope , False )
2377
+
2378
+ if len (tgts ) == 1 :
2379
+ return [mkAssignStatement (tgts [0 ].site , tgts [0 ], init )]
2380
+
2381
+ sym = lscope .add_variable (
2382
+ 'tmp' , type = init_typ , site = init .site , init = init ,
2383
+ stmt = True )
2384
+ init_expr = mkLocalVariable (init .site , sym )
2385
+ stmts = [sym_declaration (sym )]
2386
+ for tgt in reversed (tgts [1 :]):
2387
+ stmts .append (mkCopyData (tgt .site , init_expr , tgt ))
2388
+ init_expr = (tgt if isinstance (tgt , NonValue )
2389
+ else source_for_assignment (tgt .site , tgt .ctype (),
2390
+ init_expr ))
2391
+ stmts .append (mkCopyData (tgts [0 ].site , init_expr , tgts [0 ]))
2392
+ return [mkCompound (site , stmts )]
2387
2393
else :
2388
2394
# Guaranteed by grammar
2389
2395
assert tgt_ast .kind == 'assign_target_tuple' and len (tgts ) > 1
@@ -2410,43 +2416,51 @@ def stmt_assign(stmt, location, scope):
2410
2416
stmt = True )
2411
2417
syms .append (sym )
2412
2418
2413
- stmts .extend (map ( sym_declaration , syms ) )
2419
+ stmts .extend (sym_declaration ( sym ) for sym in syms )
2414
2420
stmts .extend (
2415
- mkAssignStatement (
2416
- tgt .site , tgt , ExpressionInitializer ( mkLocalVariable ( tgt . site ,
2417
- sym )))
2421
+ AssignStatement (
2422
+ tgt .site , tgt ,
2423
+ ExpressionInitializer ( mkLocalVariable ( tgt . site , sym )))
2418
2424
for (tgt , sym ) in zip (tgts , syms ))
2419
- return stmts
2425
+ return [ mkCompound ( site , stmts )]
2420
2426
2421
2427
@statement_dispatcher
2422
2428
def stmt_assignop (stmt , location , scope ):
2423
- (kind , site , tgt_ast , op , src_ast ) = stmt
2429
+ (_ , site , tgt_ast , op , src_ast ) = stmt
2424
2430
2425
2431
tgt = codegen_expression (tgt_ast , location , scope )
2426
- if deep_const (tgt .ctype ()):
2432
+ if isinstance (tgt , ctree .InlinedParam ):
2433
+ raise EASSINL (tgt .site , tgt .name )
2434
+ if not tgt .writable :
2435
+ raise EASSIGN (site , tgt )
2436
+
2437
+ ttype = tgt .ctype ()
2438
+ if deep_const (ttype ):
2427
2439
raise ECONST (tgt .site )
2428
- if isinstance (tgt , ctree .BitSlice ):
2429
- # destructive hack
2430
- return stmt_assign (
2431
- ast .assign (site , ast .assign_target_chain (site , [tgt_ast ]),
2432
- [ast .initializer_scalar (
2433
- site ,
2434
- ast .binop (site , tgt_ast , op [:- 1 ], src_ast ))]),
2435
- location , scope )
2440
+
2436
2441
src = codegen_expression (src_ast , location , scope )
2437
- ttype = tgt .ctype ()
2438
- lscope = Symtab (scope )
2439
- sym = lscope .add_variable (
2440
- 'tmp' , type = TPtr (ttype ), site = tgt .site ,
2441
- init = ExpressionInitializer (mkAddressOf (tgt .site , tgt )), stmt = True )
2442
- # Side-Effect Free representation of the tgt lvalue
2443
- tgt_sef = mkDereference (site , mkLocalVariable (tgt .site , sym ))
2444
- return [
2445
- sym_declaration (sym ), mkExpressionStatement (
2446
- site ,
2447
- mkAssignOp (site , tgt_sef , arith_binops [op [:- 1 ]](
2448
- site , tgt_sef , src )))]
2449
2442
2443
+ if tgt .addressable :
2444
+ lscope = Symtab (scope )
2445
+ tmp_tgt_sym = lscope .add_variable (
2446
+ '_tmp_tgt' , type = TPtr (ttype ), site = tgt .site ,
2447
+ init = ExpressionInitializer (mkAddressOf (tgt .site , tgt )),
2448
+ stmt = True )
2449
+ # Side-Effect Free representation of the tgt lvalue
2450
+ tgt = mkDereference (site , mkLocalVariable (tgt .site , tmp_tgt_sym ))
2451
+ else :
2452
+ # TODO Not ideal. This path is needed to deal with writable
2453
+ # expressions that do not correspond to C lvalues; such as bit slices.
2454
+ # The incurred repeated evaluation is painful.
2455
+ tmp_tgt_sym = None
2456
+
2457
+ assign_src = source_for_assignment (site , ttype ,
2458
+ arith_binops [op [:- 1 ]](site , tgt , src ))
2459
+
2460
+ return [mkCompound (site ,
2461
+ ([sym_declaration (tmp_tgt_sym )] if tmp_tgt_sym else [])
2462
+ + [mkExpressionStatement (site ,
2463
+ ctree .AssignOp (site , tgt , assign_src ))])]
2450
2464
@statement_dispatcher
2451
2465
def stmt_expression (stmt , location , scope ):
2452
2466
[expr ] = stmt .args
@@ -3886,7 +3900,7 @@ def prelude():
3886
3900
param = mkDereference (site ,
3887
3901
mkLit (site , name , TPtr (typ )))
3888
3902
fnscope .add (ExpressionSymbol (name , param , site ))
3889
- code .append (mkAssignStatement (site , param , init ))
3903
+ code .append (AssignStatement (site , param , init ))
3890
3904
else :
3891
3905
code = []
3892
3906
0 commit comments