@@ -3267,11 +3267,42 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
3267
3267
}
3268
3268
3269
3269
/* is it a variable declaration? */
3270
- int find_type_flag = lex_accept (T_struct ) ? 2 : 1 ;
3271
- if (find_type_flag == 1 && lex_accept (T_union )) {
3272
- find_type_flag = 2 ;
3270
+ /* Special handling when statement starts with asterisk */
3271
+ if (has_asterisk ) {
3272
+ /* For "*identifier", check if identifier is a type.
3273
+ * If not, it's a dereference, not a declaration. */
3274
+ int saved_size = SOURCE -> size ;
3275
+ char saved_char = next_char ;
3276
+ int saved_token = next_token ;
3277
+
3278
+ /* Skip the asterisk to peek at the identifier */
3279
+ lex_accept (T_asterisk );
3280
+ char next_ident [MAX_TOKEN_LEN ];
3281
+ bool could_be_type = false;
3282
+
3283
+ if (lex_peek (T_identifier , next_ident )) {
3284
+ /* Check if it's a type name */
3285
+ type = find_type (next_ident , 0 );
3286
+ if (type )
3287
+ could_be_type = true;
3288
+ }
3289
+
3290
+ /* Restore position */
3291
+ SOURCE -> size = saved_size ;
3292
+ next_char = saved_char ;
3293
+ next_token = saved_token ;
3294
+
3295
+ /* If it's not a type, skip the declaration block */
3296
+ if (!could_be_type )
3297
+ type = NULL ;
3298
+ } else {
3299
+ /* Normal type checking without asterisk */
3300
+ int find_type_flag = lex_accept (T_struct ) ? 2 : 1 ;
3301
+ if (find_type_flag == 1 && lex_accept (T_union ))
3302
+ find_type_flag = 2 ;
3303
+ type = find_type (token , find_type_flag );
3273
3304
}
3274
- type = find_type ( token , find_type_flag );
3305
+
3275
3306
if (type ) {
3276
3307
var = require_typed_var (parent , type );
3277
3308
read_full_var_decl (var , 0 , 0 );
@@ -3280,9 +3311,7 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
3280
3311
if (lex_accept (T_assign )) {
3281
3312
if (lex_peek (T_open_curly , NULL ) &&
3282
3313
(var -> array_size > 0 || var -> is_ptr > 0 )) {
3283
- parse_array_init (
3284
- var , parent , & bb ,
3285
- 1 ); /* FIXED: Emit code for locals in functions */
3314
+ parse_array_init (var , parent , & bb , 1 );
3286
3315
} else {
3287
3316
read_expr (parent , & bb );
3288
3317
read_ternary_operation (parent , & bb );
@@ -3305,8 +3334,7 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
3305
3334
if (lex_accept (T_assign )) {
3306
3335
if (lex_peek (T_open_curly , NULL ) &&
3307
3336
(nv -> array_size > 0 || nv -> is_ptr > 0 )) {
3308
- parse_array_init (nv , parent , & bb ,
3309
- 1 ); /* FIXED: Emit code for locals */
3337
+ parse_array_init (nv , parent , & bb , 1 );
3310
3338
} else {
3311
3339
read_expr (parent , & bb );
3312
3340
0 commit comments