Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating copy-on-rewrite logic #12135

Merged
merged 5 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go/tools/asthelpergen/asthelpergen.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"golang.org/x/tools/go/packages"
)

const licenseFileHeader = `Copyright 2021 The Vitess Authors.
const licenseFileHeader = `Copyright 2023 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -244,6 +244,7 @@ func GenerateASTHelpers(options *Options) (map[string]*jen.File, error) {
newCloneGen(pName, &options.Clone),
newVisitGen(pName),
newRewriterGen(pName, types.TypeString(nt, noQualifier)),
newCOWGen(pName, nt),
)

it, err := generator.GenerateCode()
Expand Down
20 changes: 10 additions & 10 deletions go/tools/asthelpergen/clone_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *cloneGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorSP
funcName := cloneName + name

c.addFunc(funcName,
//func (n Bytes) Clone() Bytes {
// func (n Bytes) Clone() Bytes {
jen.Func().Id(funcName).Call(jen.Id("n").Id(typeString)).Id(typeString).Block(
// if n == nil { return nil }
ifNilReturnNil("n"),
Expand All @@ -116,9 +116,9 @@ func (c *cloneGen) copySliceElement(t types.Type, elType types.Type, spi generat
return jen.Id("copy").Call(jen.Id("res"), jen.Id("n"))
}

//for i := range n {
// for i := range n {
// res[i] = CloneAST(x)
//}
// }
spi.addType(elType)

return jen.For(jen.List(jen.Id("i"), jen.Id("x"))).Op(":=").Range().Id("n").Block(
Expand All @@ -128,17 +128,17 @@ func (c *cloneGen) copySliceElement(t types.Type, elType types.Type, spi generat

func (c *cloneGen) interfaceMethod(t types.Type, iface *types.Interface, spi generatorSPI) error {

//func CloneAST(in AST) AST {
// func CloneAST(in AST) AST {
// if in == nil {
// return nil
//}
// }
// switch in := in.(type) {
//case *RefContainer:
// case *RefContainer:
// return in.CloneRefOfRefContainer()
//}
// }
// // this should never happen
// return nil
//}
// }

typeString := types.TypeString(t, noQualifier)
typeName := printableTypeName(t)
Expand Down Expand Up @@ -196,7 +196,7 @@ func (c *cloneGen) ptrToBasicMethod(t types.Type, _ *types.Basic, spi generatorS
func (c *cloneGen) ptrToOtherMethod(t types.Type, ptr *types.Pointer, spi generatorSPI) error {
receiveType := types.TypeString(t, noQualifier)

funcName := "Clone" + printableTypeName(t)
funcName := cloneName + printableTypeName(t)
c.addFunc(funcName,
jen.Func().Id(funcName).Call(jen.Id("n").Id(receiveType)).Id(receiveType).Block(
ifNilReturnNil("n"),
Expand Down Expand Up @@ -224,7 +224,7 @@ func (c *cloneGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi gene
receiveType := types.TypeString(t, noQualifier)
funcName := cloneName + printableTypeName(t)

//func CloneRefOfType(n *Type) *Type
// func CloneRefOfType(n *Type) *Type
funcDeclaration := jen.Func().Id(funcName).Call(jen.Id("n").Id(receiveType)).Id(receiveType)

if slices.Contains(c.exclude, receiveType) {
Expand Down
Loading