@@ -50,9 +50,6 @@ void emit_struct_brace_initializer(block_t *parent,
50
50
basic_block_t * * bb ,
51
51
var_t * dest ,
52
52
type_t * struct_type );
53
-
54
-
55
-
56
53
label_t * find_label (char * name )
57
54
{
58
55
for (int i = 0 ; i < label_idx ; i ++ ) {
@@ -1118,17 +1115,14 @@ basic_block_t *handle_struct_variable_decl(block_t *parent,
1118
1115
gen_name_to (struct_addr -> var_name );
1119
1116
add_insn (parent , bb , OP_address_of , struct_addr , var , NULL , 0 ,
1120
1117
NULL );
1121
-
1122
1118
lex_expect (T_open_curly );
1123
-
1124
1119
parse_struct_field_init (parent , & bb , struct_type , struct_addr ,
1125
1120
true);
1126
1121
lex_expect (T_close_curly );
1127
1122
} else {
1128
1123
read_expr (parent , & bb );
1129
1124
read_ternary_operation (parent , & bb );
1130
1125
var_t * rs1 = resize_var (parent , & bb , opstack_pop (), var );
1131
-
1132
1126
add_insn (parent , bb , OP_assign , var , rs1 , NULL , 0 , NULL );
1133
1127
}
1134
1128
}
@@ -1855,7 +1849,6 @@ void handle_sizeof_operator(block_t *parent, basic_block_t **bb)
1855
1849
add_insn (parent , * bb , OP_load_constant , vd , NULL , NULL , 0 , NULL );
1856
1850
}
1857
1851
1858
-
1859
1852
void read_expr_operand (block_t * parent , basic_block_t * * bb )
1860
1853
{
1861
1854
var_t * vd , * rs1 ;
@@ -1873,7 +1866,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
1873
1866
read_literal_param (parent , * bb );
1874
1867
else if (lex_peek (T_char , NULL ))
1875
1868
read_char_param (parent , * bb );
1876
-
1877
1869
else if (lex_peek (T_numeric , NULL ))
1878
1870
read_numeric_param (parent , * bb , is_neg );
1879
1871
else if (lex_accept (T_log_not )) {
@@ -1932,8 +1924,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
1932
1924
type_t * cast_or_literal_type = NULL ;
1933
1925
int cast_ptr_level = 0 ;
1934
1926
1935
- /* Look ahead to see if we have a typename followed by ) */
1936
-
1937
1927
if (lex_peek (T_identifier , lookahead_token )) {
1938
1928
/* Check if it's a basic type or typedef */
1939
1929
type_t * type = find_type (lookahead_token , true);
@@ -1993,23 +1983,19 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
1993
1983
}
1994
1984
}
1995
1985
}
1996
-
1997
1986
/* add struct/union support */
1998
1987
else if (lex_peek (T_struct , NULL ) || lex_peek (T_union , NULL )) {
1999
1988
/* Check for (struct/union T){...} or (struct/union T)expr */
2000
1989
int saved_pos = SOURCE -> size ;
2001
1990
char saved_char = next_char ;
2002
1991
token_t saved_token = next_token ;
2003
-
2004
1992
int find_type_flag = lex_accept (T_struct ) ? 2 : 1 ;
2005
1993
if (find_type_flag == 1 && lex_accept (T_union )) {
2006
1994
find_type_flag = 2 ;
2007
1995
}
2008
-
2009
1996
char tag_name [MAX_TYPE_LEN ];
2010
1997
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) */
2013
1999
SOURCE -> size = saved_pos ;
2014
2000
next_char = saved_char ;
2015
2001
next_token = saved_token ;
@@ -2018,8 +2004,7 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2018
2004
lex_expect (T_identifier );
2019
2005
type_t * type = find_type (tag_name , find_type_flag );
2020
2006
if (!type ) {
2021
- /* Not a valid (struct/union identifier) - backtrack to
2022
- * (expr) */
2007
+ /* Not a valid (struct/union identifier) - backtrack to * (expr) */
2023
2008
SOURCE -> size = saved_pos ;
2024
2009
next_char = saved_char ;
2025
2010
next_token = saved_token ;
@@ -2028,7 +2013,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2028
2013
int ptr_level = 0 ;
2029
2014
while (lex_accept (T_asterisk ))
2030
2015
ptr_level ++ ;
2031
-
2032
2016
/* Handle (struct P[]){...} syntax: */
2033
2017
bool is_array = false;
2034
2018
if (lex_accept (T_open_square )) {
@@ -2041,7 +2025,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2041
2025
}
2042
2026
2043
2027
/* close brackets */
2044
-
2045
2028
if (lex_accept (T_close_bracket )) {
2046
2029
if (lex_peek (T_open_curly , NULL )) {
2047
2030
/* (struct P){...} → compound literal */
@@ -2065,7 +2048,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2065
2048
}
2066
2049
}
2067
2050
2068
-
2069
2051
if (is_cast ) {
2070
2052
/* Process cast: (type)expr */
2071
2053
/* Parse the expression to be cast */
@@ -2086,15 +2068,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2086
2068
/* Push the cast result */
2087
2069
opstack_push (cast_var );
2088
2070
} 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
-
2098
2071
/* Create variable for compound literal result */
2099
2072
var_t * compound_var =
2100
2073
require_typed_var (parent , cast_or_literal_type );
@@ -2106,8 +2079,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2106
2079
cast_ptr_level = 0 ; /* Reset for normal processing */
2107
2080
2108
2081
/* Check if this is a pointer compound literal */
2109
-
2110
-
2111
2082
if (cast_ptr_level > 0 ) {
2112
2083
/* Pointer compound literal: (int*){&x} */
2113
2084
compound_var -> ptr_level = cast_ptr_level ;
@@ -2147,8 +2118,6 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2147
2118
cast_or_literal_type -> base_type == TYPE_typedef ) {
2148
2119
/* Struct compound literal support (following proposed solution
2149
2120
* pattern) */
2150
-
2151
- /* Resolve typedef to actual struct type */
2152
2121
type_t * struct_type = cast_or_literal_type ;
2153
2122
if (struct_type -> base_type == TYPE_typedef &&
2154
2123
struct_type -> base_struct )
@@ -2157,18 +2126,14 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2157
2126
/* Create temporary variable for compound literal */
2158
2127
compound_var = require_typed_var (parent , struct_type );
2159
2128
gen_name_to (compound_var -> var_name );
2160
-
2161
2129
compound_var -> init_val = 0 ;
2162
2130
compound_var -> ptr_level = 0 ;
2163
-
2164
2131
/* Allocate storage for the compound literal */
2165
2132
add_insn (parent , * bb , OP_allocat , compound_var , NULL , NULL , 0 ,
2166
2133
NULL );
2167
-
2168
2134
/* Parse compound literal using the helper function */
2169
2135
emit_struct_brace_initializer (parent , bb , compound_var ,
2170
2136
struct_type );
2171
-
2172
2137
/* Push result onto operand stack */
2173
2138
opstack_push (compound_var );
2174
2139
return ;
@@ -2455,7 +2420,6 @@ void emit_struct_brace_initializer(block_t *parent,
2455
2420
if (struct_type -> base_type == TYPE_typedef && struct_type -> base_struct )
2456
2421
struct_type = struct_type -> base_struct ;
2457
2422
2458
-
2459
2423
lex_expect (T_open_curly );
2460
2424
2461
2425
int field_idx = 0 ;
@@ -2465,22 +2429,15 @@ void emit_struct_brace_initializer(block_t *parent,
2465
2429
read_expr (parent , bb );
2466
2430
read_ternary_operation (parent , bb );
2467
2431
var_t * val = opstack_pop ();
2468
-
2469
2432
if (field_idx < struct_type -> num_fields ) {
2470
2433
var_t * field = & struct_type -> fields [field_idx ];
2471
-
2472
-
2473
2434
/* Adjust val to field type */
2474
2435
var_t target = {0 };
2475
2436
target .type = field -> type ;
2476
2437
target .ptr_level = field -> ptr_level ;
2477
2438
var_t * field_val = resize_var (parent , bb , val , & target );
2478
-
2479
-
2480
2439
/* 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 );
2484
2441
/* Get field size */
2485
2442
int field_size = size_var (field );
2486
2443
add_insn (parent , * bb , OP_write , NULL , field_addr , field_val ,
@@ -2494,13 +2451,9 @@ void emit_struct_brace_initializer(block_t *parent,
2494
2451
break ;
2495
2452
}
2496
2453
}
2497
-
2498
-
2499
2454
lex_expect (T_close_curly );
2500
2455
}
2501
2456
2502
-
2503
-
2504
2457
/* Helper function to calculate element size for pointer operations */
2505
2458
int get_pointer_element_size (var_t * ptr_var )
2506
2459
{
@@ -3218,7 +3171,6 @@ void read_lvalue(lvalue_t *lvalue,
3218
3171
3219
3172
/* change type currently pointed to */
3220
3173
var = find_member (token , lvalue -> type );
3221
-
3222
3174
lvalue -> type = var -> type ;
3223
3175
lvalue -> ptr_level = var -> ptr_level ;
3224
3176
lvalue -> is_func = var -> is_func ;
@@ -3308,7 +3260,6 @@ void read_lvalue(lvalue_t *lvalue,
3308
3260
t = require_var (parent );
3309
3261
gen_name_to (t -> var_name );
3310
3262
opstack_push (t );
3311
-
3312
3263
add_insn (parent , * bb , OP_read , t , rs1 , NULL , lvalue -> size , NULL );
3313
3264
}
3314
3265
if (prefix_op != OP_generic ) {
@@ -4425,7 +4376,6 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
4425
4376
var = require_typed_var (parent , type );
4426
4377
var -> is_const_qualified = is_const ;
4427
4378
read_partial_var_decl (var , NULL );
4428
-
4429
4379
add_insn (parent , bb , OP_allocat , var , NULL , NULL , 0 , NULL );
4430
4380
add_symbol (bb , var );
4431
4381
if (lex_accept (T_assign )) {
@@ -4504,10 +4454,7 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
4504
4454
} else {
4505
4455
read_expr (parent , & bb );
4506
4456
read_ternary_operation (parent , & bb );
4507
-
4508
4457
var_t * expr_result = opstack_pop ();
4509
-
4510
-
4511
4458
/* Handle struct compound literal assignment */
4512
4459
if (expr_result && expr_result -> var_name [0 ] == '.' &&
4513
4460
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)
4567
4514
add_insn (parent , bb , OP_write , NULL , dst_word_addr ,
4568
4515
word_val , 4 , NULL );
4569
4516
}
4570
-
4571
-
4572
-
4573
4517
} else if (expr_result && expr_result -> array_size > 0 &&
4574
4518
!var -> ptr_level && var -> array_size == 0 &&
4575
4519
var -> type && var -> type -> base_type == TYPE_int &&
0 commit comments