@@ -20,7 +20,7 @@ const xx_token_names xx_tokens[] =
20
20
{ XX_T_INTEGER , "INTEGER" },
21
21
{ XX_T_DOUBLE , "DOUBLE" },
22
22
{ XX_T_STRING , "STRING" },
23
- { XX_T_IDENTIFIER , "IDENTIFIER" },
23
+ { XX_T_IDENTIFIER , "IDENTIFIER" },
24
24
{ XX_T_AT , "@" },
25
25
{ XX_T_COMMA , "," },
26
26
{ XX_T_ASSIGN , "=" },
@@ -72,7 +72,7 @@ static void xx_parse_with_token(void* xx_parser, int opcode, int parsercode, xx_
72
72
/**
73
73
* Parses a programm and returning an intermediate array representation
74
74
*/
75
- void xx_parse_program (zval * return_value , char * program , size_t program_length , char * file_path , zval * * error_msg ) {
75
+ void xx_parse_program (zval * return_value , char * program , size_t program_length , char * file_path , zval * error_msg ) {
76
76
77
77
char * error ;
78
78
xx_scanner_state * state ;
@@ -433,16 +433,15 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
433
433
case XX_T_TYPE_VAR :
434
434
xx_ (xx_parser , XX_TYPE_VAR , NULL , parser_status );
435
435
break ;
436
- case XX_T_TYPE_OBJECT :
437
- xx_ (xx_parser , XX_TYPE_OBJECT , NULL , parser_status );
438
- break ;
439
- case XX_T_TYPE_RESOURCE :
440
- xx_ (xx_parser , XX_TYPE_RESOURCE , NULL , parser_status );
441
- break ;
442
- case XX_T_TYPE_CALLABLE :
443
- xx_ (xx_parser , XX_TYPE_CALLABLE , NULL , parser_status );
444
- break ;
445
-
436
+ case XX_T_TYPE_OBJECT :
437
+ xx_ (xx_parser , XX_TYPE_OBJECT , NULL , parser_status );
438
+ break ;
439
+ case XX_T_TYPE_RESOURCE :
440
+ xx_ (xx_parser , XX_TYPE_RESOURCE , NULL , parser_status );
441
+ break ;
442
+ case XX_T_TYPE_CALLABLE :
443
+ xx_ (xx_parser , XX_TYPE_CALLABLE , NULL , parser_status );
444
+ break ;
446
445
case XX_T_ADD :
447
446
xx_ (xx_parser , XX_ADD , NULL , parser_status );
448
447
break ;
@@ -521,12 +520,24 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
521
520
522
521
default :
523
522
parser_status -> status = XX_PARSING_FAILED ;
524
- if (! * error_msg ) {
523
+ if (error_msg && Z_TYPE_P ( error_msg ) != IS_ARRAY ) {
525
524
int length = (48 + strlen (file_path ));
526
525
error = emalloc (sizeof (char ) * length );
527
526
snprintf (error , length , "Scanner: unknown opcode %d on in %s line %d" , token .opcode , file_path , state -> active_line );
528
- //ZVAL_STRING(*error_msg, error, 1);
527
+
528
+ array_init (error_msg );
529
+ #if PHP_VERSION_ID >= 70000
530
+ add_assoc_string (error_msg , "type" , "error" );
531
+ add_assoc_string (error_msg , "message" , error );
532
+ add_assoc_string (error_msg , "file" , state -> active_file );
529
533
efree (error );
534
+ #else
535
+ add_assoc_string (error_msg , "type" , "error" , 1 );
536
+ add_assoc_string (error_msg , "message" , error , 0 );
537
+ add_assoc_string (error_msg , "file" , state -> active_file , 1 );
538
+ #endif
539
+ add_assoc_long (error_msg , "line" , state -> active_line );
540
+ add_assoc_long (error_msg , "char" , state -> active_char );
530
541
}
531
542
break ;
532
543
}
@@ -543,20 +554,27 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
543
554
switch (scanner_status ) {
544
555
case XX_SCANNER_RETCODE_ERR :
545
556
case XX_SCANNER_RETCODE_IMPOSSIBLE :
546
- {
557
+ if ( error_msg && Z_TYPE_P ( error_msg ) == IS_NULL ) {
547
558
error = emalloc (sizeof (char ) * 1024 );
548
559
if (state -> start ) {
549
560
snprintf (error , 1024 , "Scanner error: %d %s" , scanner_status , state -> start );
550
561
} else {
551
562
snprintf (error , 1024 , "Scanner error: %d" , scanner_status );
552
563
}
553
- #if PHP_VERSION_ID < 70000
554
- ALLOC_INIT_ZVAL (* error_msg );
555
- ZVAL_STRING (* error_msg , error , 1 );
564
+
565
+ array_init (error_msg );
566
+ #if PHP_VERSION_ID >= 70000
567
+ add_assoc_string (error_msg , "type" , "error" );
568
+ add_assoc_string (error_msg , "message" , error );
569
+ add_assoc_string (error_msg , "file" , state -> active_file );
570
+ efree (error );
556
571
#else
557
- ZVAL_STRING (* error_msg , error );
572
+ add_assoc_string (error_msg , "type" , "error" , 1 );
573
+ add_assoc_string (error_msg , "message" , error , 0 );
574
+ add_assoc_string (error_msg , "file" , state -> active_file , 1 );
558
575
#endif
559
- efree (error );
576
+ add_assoc_long (error_msg , "line" , state -> active_line );
577
+ add_assoc_long (error_msg , "char" , state -> active_char );
560
578
status = FAILURE ;
561
579
}
562
580
break ;
@@ -570,18 +588,31 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
570
588
571
589
if (parser_status -> status != XX_PARSING_OK ) {
572
590
status = FAILURE ;
573
- if (parser_status -> syntax_error ) {
574
- #if PHP_VERSION_ID < 70000
575
- if (!* error_msg ) {
576
- ALLOC_INIT_ZVAL (* error_msg );
577
- ZVAL_STRING (* error_msg , parser_status -> syntax_error , 1 );
578
- }
591
+ if (parser_status -> syntax_error && error_msg && Z_TYPE_P (error_msg ) != IS_ARRAY ) {
592
+ array_init (error_msg );
593
+ #if PHP_VERSION_ID >= 70000
594
+ add_assoc_string (error_msg , "type" , "error" );
595
+ add_assoc_string (error_msg , "message" , parser_status -> syntax_error );
596
+ add_assoc_string (error_msg , "file" , state -> active_file );
597
+ efree (parser_status -> syntax_error );
579
598
#else
580
- if (Z_TYPE_P (* error_msg ) == IS_UNDEF ) {
581
- ZVAL_STRING (* error_msg , parser_status -> syntax_error );
582
- }
599
+ add_assoc_string (error_msg , "type" , "error" , 1 );
600
+ add_assoc_string (error_msg , "message" , parser_status -> syntax_error , 0 );
601
+ add_assoc_string (error_msg , "file" , state -> active_file , 1 );
602
+ #endif
603
+ add_assoc_long (error_msg , "line" , state -> active_line );
604
+ add_assoc_long (error_msg , "char" , state -> active_char );
605
+
606
+ parser_status -> syntax_error = NULL ;
607
+ }
608
+ else if (error_msg && Z_TYPE_P (error_msg ) != IS_ARRAY ) {
609
+ #if PHP_VERSION_ID >= 70000
610
+ assert (Z_TYPE (parser_status -> ret ) == IS_ARRAY );
611
+ ZVAL_ZVAL (error_msg , & parser_status -> ret , 1 , 1 );
612
+ #else
613
+ assert (Z_TYPE_P (parser_status -> ret ) == IS_ARRAY );
614
+ ZVAL_ZVAL (error_msg , parser_status -> ret , 1 , 1 );
583
615
#endif
584
- efree (parser_status -> syntax_error );
585
616
}
586
617
}
587
618
0 commit comments