@@ -456,73 +456,114 @@ public function isPtr(Arg $arg)
456
456
457
457
public function generateDeclarations (Printer $ printer , Func $ f )
458
458
{
459
+ $ tables = array ();
459
460
if ($ f ->isResourceCreator ()) {
460
- $ printer ->put ("php_git2_t *result = NULL; \n" );
461
+ $ tables ["php_git2_t " ][] = array (
462
+ "name " => "*result " ,
463
+ "value " => "NULL " ,
464
+ );
461
465
} else if ($ f ->isArrayCreator ()) {
462
- $ printer ->put ("`type` *result = NULL; \n" , "type " , $ f ->getReturnType ());
466
+ $ tables [$ f ->getReturnType ()][] = array (
467
+ "name " => "*result " ,
468
+ "value " => "NULL " ,
469
+ );
463
470
if (preg_match ("/git_signature/ " , $ f ->getReturnType ())) {
464
- $ printer ->put ("zval *__result = NULL; \n" );
471
+ $ tables ["zval " ][] = array (
472
+ "name " => "*__result " ,
473
+ "value " => "NULL " ,
474
+ );
465
475
}
466
476
} else if ($ f ->isLongCreator ()) {
467
- $ printer ->put ("`type` result = 0; \n" , "type " , $ f ->getReturnType ());
477
+ $ tables [$ f ->getReturnType ()][] = array (
478
+ "name " => "result " ,
479
+ "value " => "0 " ,
480
+ );
468
481
} else if ($ f ->isStringCreator ()) {
469
- $ printer ->put ("`type` *result = NULL; \n" , "type " , $ f ->getReturnType ());
482
+ $ tables [$ f ->getReturnType ()][] = array (
483
+ "name " => "*result " ,
484
+ "value " => "NULL " ,
485
+ );
470
486
}
471
487
472
488
$ i = 0 ;
473
489
$ cnt = count ($ f ->getArguments ());
474
490
foreach ($ f ->getArguments () as $ arg ) {
475
491
/** @var Arg $arg */
476
492
if ($ i == 0 && $ f ->isResourceCreator ()) {
477
- $ printer ->put ("`type` `ptr``name` = NULL; \n" ,
478
- "type " , $ arg ->getType (),
479
- "ptr " , $ arg ->getPtr (),
480
- "name " , $ arg ->getName ()
493
+ $ tables [$ arg ->getType ()][] = array (
494
+ "name " => sprintf ("%s%s " , $ arg ->getPtr (), $ arg ->getName ()),
495
+ "value " => "NULL " ,
481
496
);
482
497
$ i ++;
483
498
continue ;
484
499
}
485
500
if ($ arg ->shouldWrite ()) {
486
- $ printer ->put ("`type` `ptr``name` = NULL; \n" ,
487
- "type " , $ arg ->getType (),
488
- "ptr " , $ arg ->getPtr (),
489
- "name " , $ arg ->getName ()
501
+ $ tables [$ arg ->getType ()][] = array (
502
+ "name " => sprintf ("%s%s " , $ arg ->getPtr (), $ arg ->getName ()),
503
+ "value " => "NULL " ,
490
504
);
491
505
} else {
492
506
/** @var Arg $arg */
493
- $ printer ->put ("`type` `ptr``name` = `value`; \n" ,
494
- "type " , $ arg ->getZendType (),
495
- "ptr " , $ this ->isPtr ($ arg ),
496
- "name " , $ arg ->getName (),
497
- "value " , $ arg ->getDefaultValue ()
507
+ $ tables [$ arg ->getZendType ()][] = array (
508
+ "name " => sprintf ("%s%s " , $ this ->isPtr ($ arg ), $ arg ->getName ()),
509
+ "value " => $ arg ->getDefaultValue (),
498
510
);
499
511
if ($ this ->shouldResource ($ arg )) {
500
- $ printer -> put ( " `type` *_`name` = NULL; \n" ,
501
- "type " , " php_git2_t " ,
502
- "name " , $ arg -> getName ()
512
+ $ tables [ " php_git2_t " ][] = array (
513
+ "name " => sprintf ( " *_%s " , $ arg -> getName ()) ,
514
+ "value " => " NULL " ,
503
515
);
504
516
}
505
517
506
518
if (preg_match ("/char/ " , $ arg ->getZendType ())) {
507
- $ printer ->put ("int `name`_len = 0; \n" ,
508
- "name " , $ arg ->getName ());
519
+ $ tables ["int " ][] = array (
520
+ "name " => sprintf ("%s_len " , $ arg ->getName ()),
521
+ "value " => "0 " ,
522
+ );
509
523
}
510
524
}
511
525
512
526
if ($ arg ->getType () == "git_oid " ) {
513
- $ printer ->put ("git_oid __`name`; \n" , "name " , $ arg ->getName ());
527
+ $ tables ["git_oid " ][] = array (
528
+ "name " => sprintf ("__%s " , $ arg ->getName ()),
529
+ "value " => "{0} " ,
530
+ );
514
531
}
515
532
516
533
$ i ++;
517
534
}
518
535
if ($ f ->getReturnType () == "int " ) {
519
- $ printer ->put ("`type` error = 0; \n" , "type " , $ f ->getReturnType ());
536
+ $ tables [$ f ->getReturnType ()][] = array (
537
+ "name " => "error " ,
538
+ "value " => "0 " ,
539
+ );
520
540
}
521
541
if (preg_match ("/git_oid/ " , $ f ->getReturnType ())) {
522
- $ printer ->put ("char __result[GIT2_OID_HEXSIZE] = {0}; \n" );
542
+ $ tables ["char " ][] = array (
543
+ "name " => "__result[GIT2_OID_HEXSIZE] " ,
544
+ "value " => "{0} " ,
545
+ );
523
546
}
524
547
if (preg_match ("/_owner$/ " , $ f ->getName ())) {
525
- $ printer ->put ("php_git2_t *__result = NULL; \n" );
548
+ $ tables ["php_git2_t " ][] = array (
549
+ "name " => "*__result " ,
550
+ "value " => "NULL " ,
551
+ );
552
+ }
553
+
554
+
555
+ foreach ($ tables as $ type => $ values ) {
556
+ $ printer ->put ("`type` " , "type " , $ type );
557
+ $ i = 0 ;
558
+ $ cnt = count ($ values );
559
+ foreach ($ values as $ val ) {
560
+ $ printer ->put ("`name` = `value` " , "name " , $ val ['name ' ], "value " , $ val ["value " ]);
561
+ if ($ i +1 < $ cnt ) {
562
+ $ printer ->put (", " );
563
+ }
564
+ $ i ++;
565
+ }
566
+ $ printer ->put ("; \n" );
526
567
}
527
568
}
528
569
@@ -897,9 +938,10 @@ public function generateMakeResourceIfNeeded(Printer $printer, Func $f, $name =
897
938
{
898
939
if ($ f ->isResourceCreator () || $ force ) {
899
940
$ arg = $ f ->first ();
900
- $ printer ->put ("if (php_git2_make_resource(&`name`, PHP_GIT2_TYPE_`type`, `name `, 1 TSRMLS_CC)) { \n" ,
941
+ $ printer ->put ("if (php_git2_make_resource(&`name`, PHP_GIT2_TYPE_`type`, `target `, 1 TSRMLS_CC)) { \n" ,
901
942
"name " , $ name ,
902
- "type " , strtoupper ($ this ->getNormarizedTypeName ($ arg ))
943
+ "type " , strtoupper ($ this ->getNormarizedTypeName ($ arg )),
944
+ "target " , "out "
903
945
);
904
946
$ printer ->block (function (Printer $ printer ) {
905
947
$ printer ->put ("RETURN_FALSE; \n" );
0 commit comments