@@ -123,7 +123,7 @@ declaration_specifiers(zend_ffi_dcl *dcl):
123
123
{ zend_ffi_set_abi(dcl, ZEND_FFI_ABI_THISCALL);}
124
124
| " _Alignas"
125
125
" ("
126
- ( &type_name
126
+ ( &type_name_start
127
127
{ zend_ffi_dcl align_dcl = ZEND_FFI_ATTR_INIT;}
128
128
type_name(&align_dcl)
129
129
{ zend_ffi_align_as_type(dcl, &align_dcl);}
@@ -331,7 +331,6 @@ enumerator(zend_ffi_dcl *enum_dcl, int64_t *min, int64_t *max, int64_t *last):
331
331
;
332
332
333
333
declarator(zend_ffi_dcl * dcl, const char ** name, size_t * name_len):
334
- /* " char" is used as a terminator of nested declaration */
335
334
{ zend_ffi_dcl nested_dcl = { ZEND_FFI_DCL_CHAR, 0 , 0 , 0 , NULL} ;}
336
335
{ zend_bool nested = 0 ;}
337
336
pointer(dcl)?
@@ -346,44 +345,35 @@ declarator(zend_ffi_dcl *dcl, const char **name, size_t *name_len):
346
345
{ if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);}
347
346
;
348
347
349
- abstract_declarator(zend_ffi_dcl * dcl, const char ** name, size_t * name_len):
350
- /* " char" is used as a terminator of nested declaration */
348
+ abstract_declarator(zend_ffi_dcl * dcl):
351
349
{ zend_ffi_dcl nested_dcl = { ZEND_FFI_DCL_CHAR, 0 , 0 , 0 , NULL} ;}
352
350
{ zend_bool nested = 0 ;}
353
351
pointer(dcl)?
354
- ( &nested_abstract_declarator
355
- nested_abstract_declarator(&nested_dcl, name, name_len)
352
+ ( &nested_declarator_start
353
+ " ("
354
+ attributes(&nested_dcl)?
355
+ abstract_declarator(&nested_dcl)
356
+ " )"
356
357
{ nested = 1 ;}
357
- | ID(name, name_len)
358
- | /* empty */
359
- )
358
+ )?
360
359
array_or_function_declarators(dcl)?
361
360
{ if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);}
362
361
;
363
362
364
- nested_abstract_declarator (zend_ffi_dcl * dcl, const char ** name, size_t * name_len):
363
+ parameter_declarator (zend_ffi_dcl * dcl, const char ** name, size_t * name_len):
365
364
{ zend_ffi_dcl nested_dcl = { ZEND_FFI_DCL_CHAR, 0 , 0 , 0 , NULL} ;}
366
365
{ zend_bool nested = 0 ;}
367
- " ("
368
- attributes(&nested_dcl)?
369
- ( pointer(dcl)
370
- ( &nested_abstract_declarator
371
- nested_abstract_declarator(&nested_dcl, name, name_len)
372
- { nested = 1 ;}
373
- | ID(name, name_len)
374
- | /* empty */
375
- )
376
- array_or_function_declarators(dcl)?
377
- | ( &nested_abstract_declarator
378
- nested_abstract_declarator(&nested_dcl, name, name_len)
379
- array_or_function_declarators(dcl)?
380
- { nested = 1 ;}
381
- | ID(name, name_len)
382
- array_or_function_declarators(dcl)?
383
- | array_or_function_declarators(dcl)
384
- )
366
+ pointer(dcl)?
367
+ ( &nested_declarator_start
368
+ " ("
369
+ attributes(&nested_dcl)?
370
+ parameter_declarator(&nested_dcl, name, name_len)
371
+ " )"
372
+ { nested = 1 ;}
373
+ | ID(name, name_len)
374
+ | /* empty */
385
375
)
386
- " ) "
376
+ array_or_function_declarators(dcl)?
387
377
{ if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);}
388
378
;
389
379
@@ -451,17 +441,15 @@ parameter_declaration(HashTable **args):
451
441
{ FFI_G(allow_vla) = 1 ;}
452
442
{ zend_ffi_dcl param_dcl = ZEND_FFI_ATTR_INIT;}
453
443
specifier_qualifier_list(¶m_dcl)
454
- abstract_declarator (¶m_dcl, &name, &name_len)
444
+ parameter_declarator (¶m_dcl, &name, &name_len)
455
445
/* attributes(¶m_dcl)? conflict ???*/
456
446
{ zend_ffi_add_arg(args, name, name_len, ¶m_dcl);}
457
447
{ FFI_G(allow_vla) = old_allow_vla;}
458
448
;
459
449
460
450
type_name(zend_ffi_dcl * dcl):
461
- { const char * name = NULL;}
462
- { size_t name_len = 0 ;}
463
451
specifier_qualifier_list(dcl)
464
- abstract_declarator(dcl, &name, &name_len )
452
+ abstract_declarator(dcl)
465
453
;
466
454
467
455
attributes(zend_ffi_dcl * dcl):
@@ -685,7 +673,7 @@ multiplicative_expression(zend_ffi_val *val):
685
673
cast_expression(zend_ffi_val * val):
686
674
{ int do_cast = 0 ;}
687
675
{ zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT;}
688
- ( &( " (" type_name " ) " )
676
+ ( &( " (" type_name_start )
689
677
" ("
690
678
type_name(&dcl)
691
679
" )"
@@ -751,7 +739,7 @@ unary_expression(zend_ffi_val *val):
751
739
cast_expression(val)
752
740
{ zend_ffi_expr_bool_not(val);}
753
741
| " sizeof"
754
- ( &( " (" type_name " ) " )
742
+ ( &( " (" type_name_start )
755
743
" ("
756
744
type_name(&dcl)
757
745
" )"
@@ -765,7 +753,7 @@ unary_expression(zend_ffi_val *val):
765
753
" )"
766
754
{ zend_ffi_expr_alignof_type(val, &dcl);}
767
755
| (" __alignof" |" __alignof__" )
768
- ( &( " (" type_name " ) " )
756
+ ( &( " (" type_name_start )
769
757
" ("
770
758
type_name(&dcl)
771
759
" )"
@@ -776,6 +764,57 @@ unary_expression(zend_ffi_val *val):
776
764
)
777
765
;
778
766
767
+ /* lookahead rules */
768
+ nested_declarator_start:
769
+ " ("
770
+ ( ?{ !zend_ffi_is_typedef_name((const char* )yy_text, yy_pos - yy_text)}
771
+ ID
772
+ | " __attribute"
773
+ | " __attribute__"
774
+ | " __declspec"
775
+ | " *"
776
+ | " ("
777
+ | " ["
778
+ )
779
+ ;
780
+
781
+ type_name_start:
782
+ ( ?{ zend_ffi_is_typedef_name((const char* )yy_text, yy_pos - yy_text)}
783
+ ID
784
+ | " void"
785
+ | " char"
786
+ | " short"
787
+ | " int"
788
+ | " long"
789
+ | " float"
790
+ | " double"
791
+ | " signed"
792
+ | " unsigned"
793
+ | " _Bool"
794
+ | " _Complex"
795
+ | " complex"
796
+ | " __complex"
797
+ | " __complex__"
798
+ | " struct"
799
+ | " union"
800
+ | " enum"
801
+ | " const"
802
+ | " __const"
803
+ | " __const__"
804
+ | " restrict"
805
+ | " __restict"
806
+ | " __restrict__"
807
+ | " volatile"
808
+ | " __volatile"
809
+ | " __volatile__"
810
+ | " _Atomic"
811
+ | " __attribute"
812
+ | " __attribute__"
813
+ | " __declspec"
814
+ )
815
+ ;
816
+
817
+ /* scanner rules */
779
818
ID(const char ** name, size_t * name_len):
780
819
/ [ A- Za- z_][ A- Za- z_0- 9 ] */
781
820
{ * name = (const char* )yy_text; * name_len = yy_pos - yy_text;}
0 commit comments