Skip to content

Commit 481ac73

Browse files
committed
* Fixed gtrace tool generation code style bug with leading spaces
1 parent 0382378 commit 481ac73

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Fixed gtrace tool generation code style bug with leading spaces
12
* Removed accounting load factor (unused field) in balancers
23
* Enabled by default anonymous credentials
34
* Enabled by default internal dns resolver

internal/cmd/gtrace/writer.go

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,11 @@ func (w *Writer) composeHookCall(fn *Func, h1, h2 string) {
357357
w.capture(h1, h2)
358358
w.code(`func`)
359359
args := w.funcParams(fn.Params)
360+
if fn.HasResult() {
361+
w.code(` `)
362+
}
360363
w.funcResults(fn)
361-
w.line(`{`)
364+
w.line(` {`)
362365
w.line(`if options.panicCallback != nil {`)
363366
w.block(func() {
364367
w.line("defer func() {")
@@ -454,33 +457,26 @@ func (w *Writer) options(trace *Trace) {
454457
func (w *Writer) hook(trace *Trace, hook Hook) {
455458
w.newScope(func() {
456459
t := w.declare("t")
457-
x := w.declare("c") // For context's trace.
458460
fn := w.declare("fn")
459461

460462
w.code(`func (`, t, ` `, trace.Name, `) `, unexported(hook.Name))
461463

462464
w.code(`(`)
463-
var ctx string
464465
var args []string
465466
for i, p := range hook.Func.Params {
466-
if i > 0 || ctx != "" {
467+
if i > 0 {
467468
w.code(`, `)
468469
}
469470
args = append(args, w.funcParam(p))
470471
}
471-
w.code(`) `)
472+
w.code(`)`)
473+
if hook.Func.HasResult() {
474+
w.code(` `)
475+
}
472476
w.funcResultsFlags(hook.Func, docs)
473-
w.line(`{`)
477+
w.line(` {`)
474478
w.block(func() {
475-
if ctx != "" {
476-
w.line(x, ` := Context`, trace.Name, `(`, ctx, `)`)
477-
w.code(`var fn `)
478-
w.funcSignature(hook.Func)
479-
w.line()
480-
w.composeHook(hook, t, x, fn)
481-
} else {
482-
w.line(fn, ` := `, t, `.`, hook.Name)
483-
}
479+
w.line(fn, ` := `, t, `.`, hook.Name)
484480
w.line(`if `, fn, ` == nil {`)
485481
w.block(func() {
486482
w.zeroReturn(hook.Func)
@@ -519,8 +515,9 @@ func (w *Writer) hookFuncCall(fn *Func, name string, args []string) {
519515
w.newScope(func() {
520516
w.code(`return func`)
521517
args := w.funcParams(r.Params)
518+
w.code(` `)
522519
w.funcResults(r)
523-
w.line(`{`)
520+
w.line(` {`)
524521
w.block(func() {
525522
w.hookFuncCall(r, res, args)
526523
})
@@ -643,9 +640,12 @@ func (w *Writer) hookShortcut(trace *Trace, hook Hook) {
643640
w.code(`, `)
644641
w.code(names[i], ` `, w.typeString(p.Type))
645642
}
646-
w.code(`) `)
643+
w.code(`)`)
644+
if hook.Func.HasResult() {
645+
w.code(` `)
646+
}
647647
w.shortcutFuncResultsFlags(hook.Func, docs)
648-
w.line(`{`)
648+
w.line(` {`)
649649
w.block(func() {
650650
for _, name := range names {
651651
w.capture(name)
@@ -691,9 +691,12 @@ func (w *Writer) hookFuncShortcut(fn *Func, name string) {
691691
}
692692
w.code(names[i], ` `, w.typeString(p.Type))
693693
}
694-
w.code(`) `)
694+
w.code(`)`)
695+
if fn.HasResult() {
696+
w.code(` `)
697+
}
695698
w.shortcutFuncResults(fn)
696-
w.line(`{`)
699+
w.line(` {`)
697700
w.block(func() {
698701
for _, name := range names {
699702
w.capture(name)
@@ -732,7 +735,7 @@ func (w *Writer) zeroReturn(fn *Func) {
732735
switch x := fn.Result[0].(type) {
733736
case *Func:
734737
w.funcSignature(x)
735-
w.line(`{`)
738+
w.line(` {`)
736739
w.block(func() {
737740
w.zeroReturn(x)
738741
})
@@ -752,7 +755,7 @@ func (w *Writer) funcParams(params []Param) (vars []string) {
752755
}
753756
vars = append(vars, w.funcParam(p))
754757
}
755-
w.code(`) `)
758+
w.code(`)`)
756759
return
757760
}
758761

@@ -814,8 +817,13 @@ func (w *Writer) funcSignatureFlags(fn *Func, flags flags) {
814817
w.code(w.typeString(p.Type))
815818
}
816819
}
817-
w.code(`) `)
818-
w.funcResultsFlags(fn, flags)
820+
w.code(`)`)
821+
if fn.HasResult() {
822+
if fn.isFuncResult() {
823+
w.code(` `)
824+
}
825+
w.funcResultsFlags(fn, flags)
826+
}
819827
}
820828

821829
func (w *Writer) funcSignature(fn *Func) {
@@ -838,8 +846,13 @@ func (w *Writer) shortcutFuncSignFlags(fn *Func, flags flags) {
838846
w.code(w.typeString(p.Type))
839847
}
840848
}
841-
w.code(`) `)
842-
w.shortcutFuncResultsFlags(fn, flags)
849+
w.code(`)`)
850+
if fn.HasResult() {
851+
if fn.isFuncResult() {
852+
w.code(` `)
853+
}
854+
w.shortcutFuncResultsFlags(fn, flags)
855+
}
843856
}
844857

845858
func (w *Writer) shortcutFuncResultsFlags(fn *Func, flags flags) {

trace/driver_gtrace.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)