Skip to content

Commit f5fc6df

Browse files
committed
add offset tracking when visiting slices
Signed-off-by: Andres Taylor <andres@planetscale.com>
1 parent f2f00da commit f5fc6df

File tree

4 files changed

+161
-14
lines changed

4 files changed

+161
-14
lines changed

go/tools/asthelpergen/integration/ast_rewrite.go

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

go/tools/asthelpergen/rewrite_gen.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (r *rewriteGen) sliceMethod(t types.Type, slice *types.Slice, spi generator
222222
),
223223
}
224224
stmts = append(stmts, forBlock...)
225-
rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "notUsed", jen.Id("el"), jen.Index(jen.Id("idx")), false)
225+
rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "Offset", jen.Id("el"), jen.Index(jen.Id("idx")), false)
226226

227227
stmts = append(stmts,
228228
jen.For(jen.Id("x, el").Op(":=").Id("range node")).
@@ -336,12 +336,8 @@ func (r *rewriteGen) rewriteAllStructFields(t types.Type, strct *types.Struct, s
336336
}
337337

338338
spi.addType(slice.Elem())
339-
id := jen.Id("x")
340-
if fail {
341-
id = jen.Id("_")
342-
}
343339
output = append(output,
344-
jen.For(jen.List(id, jen.Id("el")).Op(":=").Id("range node."+field.Name())).
340+
jen.For(jen.List(jen.Id("x"), jen.Id("el")).Op(":=").Id("range node."+field.Name())).
345341
Block(r.rewriteChildSlice(t, slice.Elem(), field.Name(), jen.Id("el"), jen.Dot(field.Name()).Index(jen.Id("idx")), fail)...))
346342
fieldNumber++
347343
}
@@ -444,7 +440,15 @@ func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, pa
444440
param,
445441
funcBlock).Block(returnFalse()))
446442

443+
savePath := jen.If(jen.Id("a.collectPaths")).Block(
444+
jen.Id("a.cur.current").Op("=").Id("AddStepWithSliceIndex").Call(
445+
jen.Id("path"),
446+
jen.Id(printableTypeName(t)+fieldName+"8"),
447+
jen.Id("x")),
448+
)
449+
447450
return []jen.Code{
451+
savePath,
448452
rewriteField,
449453
}
450454
}

0 commit comments

Comments
 (0)