@@ -50,9 +50,6 @@ void emit_struct_brace_initializer(block_t *parent,
5050                                   basic_block_t  * * bb ,
5151                                   var_t  * dest ,
5252                                   type_t  * struct_type );
53- 
54- 
55- 
5653label_t  * find_label (char  * name )
5754{
5855    for  (int  i  =  0 ; i  <  label_idx ; i ++ ) {
@@ -1118,17 +1115,14 @@ basic_block_t *handle_struct_variable_decl(block_t *parent,
11181115            gen_name_to (struct_addr -> var_name );
11191116            add_insn (parent , bb , OP_address_of , struct_addr , var , NULL , 0 ,
11201117                     NULL );
1121- 
11221118            lex_expect (T_open_curly );
1123- 
11241119            parse_struct_field_init (parent , & bb , struct_type , struct_addr ,
11251120                                    true);
11261121            lex_expect (T_close_curly );
11271122        } else  {
11281123            read_expr (parent , & bb );
11291124            read_ternary_operation (parent , & bb );
11301125            var_t  * rs1  =  resize_var (parent , & bb , opstack_pop (), var );
1131- 
11321126            add_insn (parent , bb , OP_assign , var , rs1 , NULL , 0 , NULL );
11331127        }
11341128    }
@@ -1855,7 +1849,6 @@ void handle_sizeof_operator(block_t *parent, basic_block_t **bb)
18551849    add_insn (parent , * bb , OP_load_constant , vd , NULL , NULL , 0 , NULL );
18561850}
18571851
1858- 
18591852void  read_expr_operand (block_t  * parent , basic_block_t  * * bb )
18601853{
18611854    var_t  * vd , * rs1 ;
@@ -1873,7 +1866,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
18731866        read_literal_param (parent , * bb );
18741867    else  if  (lex_peek (T_char , NULL ))
18751868        read_char_param (parent , * bb );
1876- 
18771869    else  if  (lex_peek (T_numeric , NULL ))
18781870        read_numeric_param (parent , * bb , is_neg );
18791871    else  if  (lex_accept (T_log_not )) {
@@ -1932,8 +1924,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
19321924        type_t  * cast_or_literal_type  =  NULL ;
19331925        int  cast_ptr_level  =  0 ;
19341926
1935-         /* Look ahead to see if we have a typename followed by ) */ 
1936- 
19371927        if  (lex_peek (T_identifier , lookahead_token )) {
19381928            /* Check if it's a basic type or typedef */ 
19391929            type_t  * type  =  find_type (lookahead_token , true);
@@ -1993,23 +1983,19 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
19931983                }
19941984            }
19951985        }
1996- 
19971986        /* add struct/union support */ 
19981987        else  if  (lex_peek (T_struct , NULL ) ||  lex_peek (T_union , NULL )) {
19991988            /* Check for (struct/union T){...} or (struct/union T)expr */ 
20001989            int  saved_pos  =  SOURCE -> size ;
20011990            char  saved_char  =  next_char ;
20021991            token_t  saved_token  =  next_token ;
2003- 
20041992            int  find_type_flag  =  lex_accept (T_struct ) ? 2  : 1 ;
20051993            if  (find_type_flag  ==  1  &&  lex_accept (T_union )) {
20061994                find_type_flag  =  2 ;
20071995            }
2008- 
20091996            char  tag_name [MAX_TYPE_LEN ];
20101997            if  (!lex_peek (T_identifier , tag_name )) {
2011-                 /* Not a valid (struct/union identifier) - backtrack to (expr) 
2012-                  */ 
1998+                 /* Not a valid (struct/union identifier) - backtrack to (expr) */ 
20131999                SOURCE -> size  =  saved_pos ;
20142000                next_char  =  saved_char ;
20152001                next_token  =  saved_token ;
@@ -2018,8 +2004,7 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
20182004                lex_expect (T_identifier );
20192005                type_t  * type  =  find_type (tag_name , find_type_flag );
20202006                if  (!type ) {
2021-                     /* Not a valid (struct/union identifier) - backtrack to 
2022-                      * (expr) */ 
2007+                     /* Not a valid (struct/union identifier) - backtrack to * (expr) */ 
20232008                    SOURCE -> size  =  saved_pos ;
20242009                    next_char  =  saved_char ;
20252010                    next_token  =  saved_token ;
@@ -2028,7 +2013,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
20282013                    int  ptr_level  =  0 ;
20292014                    while  (lex_accept (T_asterisk ))
20302015                        ptr_level ++ ;
2031- 
20322016                    /* Handle (struct P[]){...} syntax: */ 
20332017                    bool  is_array  =  false;
20342018                    if  (lex_accept (T_open_square )) {
@@ -2041,7 +2025,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
20412025                    }
20422026
20432027                    /* close brackets */ 
2044- 
20452028                    if  (lex_accept (T_close_bracket )) {
20462029                        if  (lex_peek (T_open_curly , NULL )) {
20472030                            /* (struct P){...} → compound literal */ 
@@ -2065,7 +2048,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
20652048            }
20662049        }
20672050
2068- 
20692051        if  (is_cast ) {
20702052            /* Process cast: (type)expr */ 
20712053            /* Parse the expression to be cast */ 
@@ -2086,15 +2068,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
20862068            /* Push the cast result */ 
20872069            opstack_push (cast_var );
20882070        } else  if  (is_compound_literal ) {
2089-             /* Process compound literal */ 
2090-             /* 
2091-              * Warning: Assume function emit_struct_brace_initializer will 
2092-              * handle the '{' and '}' 
2093-              */ 
2094- 
2095-             /* lex_expect(T_open_curly); */ 
2096- 
2097- 
20982071            /* Create variable for compound literal result */ 
20992072            var_t  * compound_var  = 
21002073                require_typed_var (parent , cast_or_literal_type );
@@ -2106,8 +2079,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
21062079                cast_ptr_level  =  0 ; /* Reset for normal processing */ 
21072080
21082081            /* Check if this is a pointer compound literal */ 
2109- 
2110- 
21112082            if  (cast_ptr_level  >  0 ) {
21122083                /* Pointer compound literal: (int*){&x} */ 
21132084                compound_var -> ptr_level  =  cast_ptr_level ;
@@ -2147,8 +2118,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
21472118                       cast_or_literal_type -> base_type  ==  TYPE_typedef ) {
21482119                /* Struct compound literal support (following proposed solution 
21492120                 * pattern) */ 
2150- 
2151-                 /* Resolve typedef to actual struct type */ 
21522121                type_t  * struct_type  =  cast_or_literal_type ;
21532122                if  (struct_type -> base_type  ==  TYPE_typedef  && 
21542123                    struct_type -> base_struct )
@@ -2157,18 +2126,14 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
21572126                /* Create temporary variable for compound literal */ 
21582127                compound_var  =  require_typed_var (parent , struct_type );
21592128                gen_name_to (compound_var -> var_name );
2160- 
21612129                compound_var -> init_val  =  0 ;
21622130                compound_var -> ptr_level  =  0 ;
2163- 
21642131                /* Allocate storage for the compound literal */ 
21652132                add_insn (parent , * bb , OP_allocat , compound_var , NULL , NULL , 0 ,
21662133                         NULL );
2167- 
21682134                /* Parse compound literal using the helper function */ 
21692135                emit_struct_brace_initializer (parent , bb , compound_var ,
21702136                                              struct_type );
2171- 
21722137                /* Push result onto operand stack */ 
21732138                opstack_push (compound_var );
21742139                return ;
@@ -2455,7 +2420,6 @@ void emit_struct_brace_initializer(block_t *parent,
24552420    if  (struct_type -> base_type  ==  TYPE_typedef  &&  struct_type -> base_struct )
24562421        struct_type  =  struct_type -> base_struct ;
24572422
2458- 
24592423    lex_expect (T_open_curly );
24602424
24612425    int  field_idx  =  0 ;
@@ -2465,22 +2429,15 @@ void emit_struct_brace_initializer(block_t *parent,
24652429            read_expr (parent , bb );
24662430            read_ternary_operation (parent , bb );
24672431            var_t  * val  =  opstack_pop ();
2468- 
24692432            if  (field_idx  <  struct_type -> num_fields ) {
24702433                var_t  * field  =  & struct_type -> fields [field_idx ];
2471- 
2472- 
24732434                /* Adjust val to field type */ 
24742435                var_t  target  =  {0 };
24752436                target .type  =  field -> type ;
24762437                target .ptr_level  =  field -> ptr_level ;
24772438                var_t  * field_val  =  resize_var (parent , bb , val , & target );
2478- 
2479- 
24802439                /* Compute field address */ 
2481-                 var_t  * field_addr  = 
2482-                     compute_field_address (parent , bb , dest , field );
2483- 
2440+                 var_t  * field_addr  =  compute_field_address (parent , bb , dest , field );
24842441                /* Get field size */ 
24852442                int  field_size  =  size_var (field );
24862443                add_insn (parent , * bb , OP_write , NULL , field_addr , field_val ,
@@ -2494,13 +2451,9 @@ void emit_struct_brace_initializer(block_t *parent,
24942451                break ;
24952452        }
24962453    }
2497- 
2498- 
24992454    lex_expect (T_close_curly );
25002455}
25012456
2502- 
2503- 
25042457/* Helper function to calculate element size for pointer operations */ 
25052458int  get_pointer_element_size (var_t  * ptr_var )
25062459{
@@ -3218,7 +3171,6 @@ void read_lvalue(lvalue_t *lvalue,
32183171
32193172            /* change type currently pointed to */ 
32203173            var  =  find_member (token , lvalue -> type );
3221- 
32223174            lvalue -> type  =  var -> type ;
32233175            lvalue -> ptr_level  =  var -> ptr_level ;
32243176            lvalue -> is_func  =  var -> is_func ;
@@ -3308,7 +3260,6 @@ void read_lvalue(lvalue_t *lvalue,
33083260            t  =  require_var (parent );
33093261            gen_name_to (t -> var_name );
33103262            opstack_push (t );
3311- 
33123263            add_insn (parent , * bb , OP_read , t , rs1 , NULL , lvalue -> size , NULL );
33133264        }
33143265        if  (prefix_op  !=  OP_generic ) {
@@ -4425,7 +4376,6 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
44254376            var  =  require_typed_var (parent , type );
44264377            var -> is_const_qualified  =  is_const ;
44274378            read_partial_var_decl (var , NULL );
4428- 
44294379            add_insn (parent , bb , OP_allocat , var , NULL , NULL , 0 , NULL );
44304380            add_symbol (bb , var );
44314381            if  (lex_accept (T_assign )) {
@@ -4504,10 +4454,7 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
45044454                } else  {
45054455                    read_expr (parent , & bb );
45064456                    read_ternary_operation (parent , & bb );
4507- 
45084457                    var_t  * expr_result  =  opstack_pop ();
4509- 
4510- 
45114458                    /* Handle struct compound literal assignment */ 
45124459                    if  (expr_result  &&  expr_result -> var_name [0 ] ==  '.'  && 
45134460                        var -> type  &&  var -> type -> base_type  ==  TYPE_struct  && 
@@ -4567,9 +4514,6 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
45674514                            add_insn (parent , bb , OP_write , NULL , dst_word_addr ,
45684515                                     word_val , 4 , NULL );
45694516                        }
4570- 
4571- 
4572- 
45734517                    } else  if  (expr_result  &&  expr_result -> array_size  >  0  && 
45744518                               !var -> ptr_level  &&  var -> array_size  ==  0  && 
45754519                               var -> type  &&  var -> type -> base_type  ==  TYPE_int  && 
0 commit comments