corrected the mutex lock names

This commit is contained in:
Jeff Carr 2025-01-13 04:13:38 -06:00
parent f74f364187
commit adcc0385f4
3 changed files with 37 additions and 20 deletions

View File

@ -43,7 +43,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
continue continue
} }
VARNAME := v.VarName VARNAME := v.VarName
funcdef := newSortType(wSort, PARENT, VARNAME) funcdef := msg.newSortType(wSort, PARENT, VARNAME)
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
} }
} }
@ -56,7 +56,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
APPLES := s.VarName APPLES := s.VarName
LOCK := s.Lockname LOCK := s.Lockname
msg := pf.findMsg(s.VarType) msg := pf.findMsg(s.MsgName)
if msg == nil { if msg == nil {
return fmt.Errorf("failed to find struct %s", s.VarType) return fmt.Errorf("failed to find struct %s", s.VarType)
} }
@ -73,7 +73,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
VARNAME := s.VarName VARNAME := s.VarName
LOCK := s.Lockname LOCK := s.Lockname
msg := pf.findMsg(s.VarType) msg := pf.findMsg(s.MsgName)
if msg == nil { if msg == nil {
return fmt.Errorf("failed to find struct %s", s.VarType) return fmt.Errorf("failed to find struct %s", s.VarType)
} }
@ -90,6 +90,11 @@ func (pb *Files) makeNewSortfile(pf *File) error {
PARENT := s.MsgName PARENT := s.MsgName
VARNAME := s.VarName VARNAME := s.VarName
pmsg := pf.findMsg(s.MsgName)
if pmsg == nil {
return fmt.Errorf("failed to find struct %s", s.MsgName)
}
msg := pf.findMsg(s.VarType) msg := pf.findMsg(s.VarType)
if msg == nil { if msg == nil {
return fmt.Errorf("failed to find struct %s", s.VarType) return fmt.Errorf("failed to find struct %s", s.VarType)
@ -112,7 +117,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
sortby = "SortBy" + v.VarName sortby = "SortBy" + v.VarName
sortname := s.VarType + v.VarName sortname := s.VarType + v.VarName
selectName := "selectAll" + VARNAME selectName := "selectAll" + VARNAME
funcdef := newSortBy(wSort, PARENT, s.VarType, sortname, sortby, selectName, v.VarName) funcdef := pmsg.newSortBy(wSort, PARENT, s.VarType, sortname, sortby, selectName, v.VarName)
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
} else { } else {
// deprecate this THIS DOES NOT MAKE SENSE TO DO // deprecate this THIS DOES NOT MAKE SENSE TO DO
@ -140,7 +145,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
if PARENT == VARNAME { if PARENT == VARNAME {
// special case // special case
funcdef := addLenFunc(wSort, PARENT, VARNAME, LOCK) // + " " + v.VarType + " name:" + v.VarName funcdef := msg.addLenFunc(wSort, PARENT, VARNAME, LOCK) // + " " + v.VarType + " name:" + v.VarName
funcdef += " # is special struct=varname" funcdef += " # is special struct=varname"
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
} }
@ -161,8 +166,13 @@ func (pb *Files) makeNewSortfile(pf *File) error {
CHILD := s.VarType CHILD := s.VarType
VARNAME := s.VarName VARNAME := s.VarName
pmsg := pf.findMsg(s.MsgName)
if pmsg == nil {
return fmt.Errorf("failed to find struct %s", s.MsgName)
}
if PARENT == VARNAME { if PARENT == VARNAME {
funcdef := addAllFunc(wSort, PARENT, CHILD, VARNAME) funcdef := pmsg.addAllFunc(wSort, PARENT, CHILD, VARNAME)
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
} }
@ -195,6 +205,11 @@ func (pb *Files) makeNewSortfile(pf *File) error {
} }
// special case because of the enforced .proto format // ONLY SUPPORT THIS // special case because of the enforced .proto format // ONLY SUPPORT THIS
pmsg := pf.findMsg(s.MsgName)
if pmsg == nil {
return fmt.Errorf("failed to find struct %s", s.MsgName)
}
msg := pf.findMsg(s.VarType) msg := pf.findMsg(s.VarType)
if msg == nil { if msg == nil {
return fmt.Errorf("failed to find struct %s", s.VarType) return fmt.Errorf("failed to find struct %s", s.VarType)
@ -215,7 +230,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
if PARENT == VARNAME { if PARENT == VARNAME {
// special case because of the enforced .proto format // special case because of the enforced .proto format
FUNCNAME = "FindBy" + v.VarName FUNCNAME = "FindBy" + v.VarName
funcdef := msg.generateFindBy(wSort, FUNCNAME, PARENT, s, v) funcdef := pmsg.generateFindBy(wSort, FUNCNAME, PARENT, s, v)
// func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string { // func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string {
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
} else { } else {
@ -255,9 +270,9 @@ func (pb *Files) makeNewSortfile(pf *File) error {
FUNCNAME = "DeleteBy" + v.VarName FUNCNAME = "DeleteBy" + v.VarName
var funcdef string var funcdef string
if argv.Delete { if argv.Delete {
funcdef = msg.deleteByWithCopy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName) funcdef = pmsg.deleteByWithCopy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName)
} else { } else {
funcdef = msg.deleteBy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName) funcdef = pmsg.deleteBy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName)
} }
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
} else { } else {
@ -283,7 +298,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
if PARENT == VARNAME { if PARENT == VARNAME {
// special case because of the enforced .proto format // ONLY SUPPORT THIS // special case because of the enforced .proto format // ONLY SUPPORT THIS
FUNCNAME = "AppendBy" + v.VarName FUNCNAME = "AppendBy" + v.VarName
funcdef := msg.addAppendBy(wSort, PARENT, FUNCNAME, VARNAME, v.VarName, s.VarType) funcdef := pmsg.addAppendBy(wSort, PARENT, FUNCNAME, VARNAME, v.VarName, s.VarType)
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
} else { } else {
// deprecate this // deprecate this

View File

@ -15,8 +15,8 @@ import (
func (msg *MsgName) getLockname(s string) string { func (msg *MsgName) getLockname(s string) string {
if msg.NoMutex { if msg.NoMutex {
return "bad" // return "bad"
// return msg.Lockname return msg.Lockname
} }
// leave this function stubbed in for development of autogenpb // leave this function stubbed in for development of autogenpb
// if argv.Mutex { // if argv.Mutex {

View File

@ -5,8 +5,8 @@ import (
"io" "io"
) )
func (msg *MsgName) newIterAll(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) string { func (msg *MsgName) newIterAll(w io.Writer, FRUIT, APPLE, APPLES, LOCKold string) string {
LOCK = msg.getLockname("x") LOCK := msg.getLockname("x")
funcdef := "func (x *" + FRUIT + ") all" + APPLES + "() []*" + APPLE + " {" funcdef := "func (x *" + FRUIT + ") all" + APPLES + "() []*" + APPLE + " {"
@ -79,7 +79,7 @@ func newIter(w io.Writer, msg *MsgName) string {
// maybe there are better ways in GO now adays // that's fine though. this is easy to read // maybe there are better ways in GO now adays // that's fine though. this is easy to read
// TODO; figure out what types this actually works on // TODO; figure out what types this actually works on
// TODO; add timestamppb compare // TODO; add timestamppb compare
func newSortType(w io.Writer, STRUCT, VARNAME string) string { func (msg *MsgName) newSortType(w io.Writer, STRUCT, VARNAME string) string {
// Can these be lower case? Should they be lower case? maybe sort.Sort() requires upper case? // Can these be lower case? Should they be lower case? maybe sort.Sort() requires upper case?
fmt.Fprintln(w, "// sort struct by", VARNAME) fmt.Fprintln(w, "// sort struct by", VARNAME)
@ -93,7 +93,7 @@ func newSortType(w io.Writer, STRUCT, VARNAME string) string {
return "type " + STRUCT + VARNAME + " []*" + STRUCT + " // { return a[i]." + VARNAME + " < a[j]." + VARNAME + " }" return "type " + STRUCT + VARNAME + " []*" + STRUCT + " // { return a[i]." + VARNAME + " < a[j]." + VARNAME + " }"
} }
func newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT, VARNAME string) string { func (msg *MsgName) newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT, VARNAME string) string {
funcdef := "func (x *" + STRUCT + ") " + SORTBY + "() *" + ITER + "Iterator" funcdef := "func (x *" + STRUCT + ") " + SORTBY + "() *" + ITER + "Iterator"
fmt.Fprintln(w, funcdef, "{") fmt.Fprintln(w, funcdef, "{")
@ -113,7 +113,7 @@ func newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT, VARNAME stri
return funcdef return funcdef
} }
func addAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string { func (msg *MsgName) addAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string {
funcdef := "func (x *" + FRUIT + ") All() *" + APPLE + "Iterator {" funcdef := "func (x *" + FRUIT + ") All() *" + APPLE + "Iterator {"
fmt.Fprintln(w, funcdef) fmt.Fprintln(w, funcdef)
@ -129,7 +129,9 @@ func addAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string {
return funcdef return funcdef
} }
func addLenFunc(w io.Writer, FRUIT, APPLES, LOCK string) string { func (msg *MsgName) addLenFunc(w io.Writer, FRUIT, APPLES, LOCKold string) string {
LOCK := msg.getLockname("x")
funcdef := "func (x *" + FRUIT + ") Len() int {" funcdef := "func (x *" + FRUIT + ") Len() int {"
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
fmt.Fprintln(w, funcdef) fmt.Fprintln(w, funcdef)
@ -143,8 +145,8 @@ func addLenFunc(w io.Writer, FRUIT, APPLES, LOCK string) string {
return funcdef return funcdef
} }
func (msg *MsgName) addSelectAll(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) string { func (msg *MsgName) addSelectAll(w io.Writer, FRUIT, APPLE, APPLES, LOCKold string) string {
LOCK = msg.getLockname("x") LOCK := msg.getLockname("x")
funcdef := "func (x *" + FRUIT + ") selectAll" + APPLES + "() []*" + APPLE funcdef := "func (x *" + FRUIT + ") selectAll" + APPLES + "() []*" + APPLE
fmt.Fprintln(w, "// safely returns a slice of pointers to the "+APPLE+" protobufs") fmt.Fprintln(w, "// safely returns a slice of pointers to the "+APPLE+" protobufs")