Skip to content

Commit

Permalink
add offset tracking when visiting slices
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Jan 30, 2025
1 parent f2f00da commit f5fc6df
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 14 deletions.
20 changes: 19 additions & 1 deletion go/tools/asthelpergen/integration/ast_rewrite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions go/tools/asthelpergen/rewrite_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (r *rewriteGen) sliceMethod(t types.Type, slice *types.Slice, spi generator
),
}
stmts = append(stmts, forBlock...)
rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "notUsed", jen.Id("el"), jen.Index(jen.Id("idx")), false)
rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "Offset", jen.Id("el"), jen.Index(jen.Id("idx")), false)

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

spi.addType(slice.Elem())
id := jen.Id("x")
if fail {
id = jen.Id("_")
}
output = append(output,
jen.For(jen.List(id, jen.Id("el")).Op(":=").Id("range node."+field.Name())).
jen.For(jen.List(jen.Id("x"), jen.Id("el")).Op(":=").Id("range node."+field.Name())).
Block(r.rewriteChildSlice(t, slice.Elem(), field.Name(), jen.Id("el"), jen.Dot(field.Name()).Index(jen.Id("idx")), fail)...))
fieldNumber++
}
Expand Down Expand Up @@ -444,7 +440,15 @@ func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, pa
param,
funcBlock).Block(returnFalse()))

savePath := jen.If(jen.Id("a.collectPaths")).Block(
jen.Id("a.cur.current").Op("=").Id("AddStepWithSliceIndex").Call(
jen.Id("path"),
jen.Id(printableTypeName(t)+fieldName+"8"),
jen.Id("x")),
)

return []jen.Code{
savePath,
rewriteField,
}
}
Expand Down
Loading

0 comments on commit f5fc6df

Please sign in to comment.