@@ -517,19 +517,20 @@ func toGoName(paramName string) string {
517517}
518518
519519func printRootBuilder (w io.Writer , root GoStruct , prefix string ) {
520- fmt .Fprintf (w , "func (b *%sBuilder) %s() %s%s {\n " , prefix , root .FullName , prefix , root .FullName )
520+ fmt .Fprintf (w , "func (b *%sBuilder) %s() (c %s%s) {\n " , prefix , root .FullName , prefix , root .FullName )
521521
522522 var appends []string
523523 for _ , cmd := range root .BuildDef .Command {
524524 appends = append (appends , fmt .Sprintf (`"%s"` , cmd ))
525525 }
526526
527527 if tag := rootCf (root ); tag != "" {
528- fmt .Fprintf (w , "\t return %s%s{cs: append( b.get(), %s), ks: InitSlot, cf: %s}\n " , prefix , root .FullName , strings . Join ( appends , ", " ) , tag )
528+ fmt .Fprintf (w , "\t c = %s%s{cs: b.get(), ks: InitSlot, cf: %s}\n " , prefix , root .FullName , tag )
529529 } else {
530- fmt .Fprintf (w , "\t return %s%s{cs: append( b.get(), %s), ks: InitSlot}\n " , prefix , root .FullName , strings . Join ( appends , ", " ) )
530+ fmt .Fprintf (w , "\t c = %s%s{cs: b.get(), ks: InitSlot}\n " , prefix , root .FullName )
531531 }
532-
532+ fmt .Fprintf (w , "\t c.cs.s = append(c.cs.s, %s)\n " , strings .Join (appends , ", " ))
533+ fmt .Fprintf (w , "\t return c\n " )
533534 fmt .Fprintf (w , "}\n \n " )
534535}
535536
@@ -624,11 +625,11 @@ func printBuilder(w io.Writer, parent, next GoStruct, prefix string) {
624625
625626 if len (appends ) == 0 && next .Variadic && len (next .BuildDef .Parameters ) == 1 && toGoType (next .BuildDef .Parameters [0 ].Type ) == "string" {
626627 appends = append (appends , toGoName (next .BuildDef .Parameters [0 ].Name )+ "..." )
627- fmt .Fprintf (w , "\t c.cs = append(c.cs, %s)\n " , strings .Join (appends , ", " ))
628+ fmt .Fprintf (w , "\t c.cs.s = append(c.cs.s , %s)\n " , strings .Join (appends , ", " ))
628629 } else if len (next .BuildDef .Parameters ) != 1 && next .Variadic && parent .FullName != next .FullName {
629630 // no parameter
630631 if len (appends ) != 0 {
631- fmt .Fprintf (w , "\t c.cs = append(c.cs, %s)\n " , strings .Join (appends , ", " ))
632+ fmt .Fprintf (w , "\t c.cs.s = append(c.cs.s , %s)\n " , strings .Join (appends , ", " ))
632633 }
633634 } else {
634635 allstring := true
@@ -642,21 +643,21 @@ func printBuilder(w io.Writer, parent, next GoStruct, prefix string) {
642643 for _ , p := range next .BuildDef .Parameters {
643644 appends = append (appends , toGoName (p .Name ))
644645 }
645- fmt .Fprintf (w , "\t c.cs = append(c.cs, %s)\n " , strings .Join (appends , ", " ))
646+ fmt .Fprintf (w , "\t c.cs.s = append(c.cs.s , %s)\n " , strings .Join (appends , ", " ))
646647 } else {
647648 if len (next .BuildDef .Parameters ) == 1 && next .Variadic {
648649 if len (appends ) != 0 {
649- fmt .Fprintf (w , "\t c.cs = append(c.cs, %s)\n " , strings .Join (appends , ", " ))
650+ fmt .Fprintf (w , "\t c.cs.s = append(c.cs.s , %s)\n " , strings .Join (appends , ", " ))
650651 }
651652 if toGoType (next .BuildDef .Parameters [0 ].Type ) == "string" {
652- fmt .Fprintf (w , "\t c.cs = append(c.cs, %s...)\n " , toGoName (next .BuildDef .Parameters [0 ].Name ))
653+ fmt .Fprintf (w , "\t c.cs.s = append(c.cs.s , %s...)\n " , toGoName (next .BuildDef .Parameters [0 ].Name ))
653654 } else {
654655 fmt .Fprintf (w , "\t for _, n := range %s {\n " , toGoName (next .BuildDef .Parameters [0 ].Name ))
655656 switch toGoType (next .BuildDef .Parameters [0 ].Type ) {
656657 case "float64" :
657- fmt .Fprintf (w , "\t \t c.cs = append(c.cs, strconv.FormatFloat(n, 'f', -1, 64))\n " )
658+ fmt .Fprintf (w , "\t \t c.cs.s = append(c.cs.s , strconv.FormatFloat(n, 'f', -1, 64))\n " )
658659 case "int64" :
659- fmt .Fprintf (w , "\t \t c.cs = append(c.cs, strconv.FormatInt(n, 10))\n " )
660+ fmt .Fprintf (w , "\t \t c.cs.s = append(c.cs.s , strconv.FormatInt(n, 10))\n " )
660661 default :
661662 panic ("unexpected param type " + next .BuildDef .Parameters [0 ].Type )
662663 }
@@ -678,9 +679,9 @@ func printBuilder(w io.Writer, parent, next GoStruct, prefix string) {
678679 panic ("unexpected param type " + next .BuildDef .Parameters [0 ].Type )
679680 }
680681 }
681- fmt .Fprintf (w , "\t c.cs = append(c.cs, %s)\n " , strings .Join (appends , ", " ))
682+ fmt .Fprintf (w , "\t c.cs.s = append(c.cs.s , %s)\n " , strings .Join (appends , ", " ))
682683 for _ , follow := range follows {
683- fmt .Fprintf (w , "\t c.cs = append(c.cs, %s)\n " , follow )
684+ fmt .Fprintf (w , "\t c.cs.s = append(c.cs.s , %s)\n " , follow )
684685 }
685686 }
686687 }
0 commit comments