@@ -456,73 +456,114 @@ public function isPtr(Arg $arg)
456456
457457 public function generateDeclarations (Printer $ printer , Func $ f )
458458 {
459+ $ tables = array ();
459460 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+ );
461465 } 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+ );
463470 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+ );
465475 }
466476 } 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+ );
468481 } 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+ );
470486 }
471487
472488 $ i = 0 ;
473489 $ cnt = count ($ f ->getArguments ());
474490 foreach ($ f ->getArguments () as $ arg ) {
475491 /** @var Arg $arg */
476492 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 " ,
481496 );
482497 $ i ++;
483498 continue ;
484499 }
485500 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 " ,
490504 );
491505 } else {
492506 /** @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 (),
498510 );
499511 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 " ,
503515 );
504516 }
505517
506518 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+ );
509523 }
510524 }
511525
512526 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+ );
514531 }
515532
516533 $ i ++;
517534 }
518535 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+ );
520540 }
521541 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+ );
523546 }
524547 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" );
526567 }
527568 }
528569
@@ -897,9 +938,10 @@ public function generateMakeResourceIfNeeded(Printer $printer, Func $f, $name =
897938 {
898939 if ($ f ->isResourceCreator () || $ force ) {
899940 $ 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" ,
901942 "name " , $ name ,
902- "type " , strtoupper ($ this ->getNormarizedTypeName ($ arg ))
943+ "type " , strtoupper ($ this ->getNormarizedTypeName ($ arg )),
944+ "target " , "out "
903945 );
904946 $ printer ->block (function (Printer $ printer ) {
905947 $ printer ->put ("RETURN_FALSE; \n" );
0 commit comments