From adcc0385f4198d80ae0b2c7ac5c791920dfcda5a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 13 Jan 2025 04:13:38 -0600 Subject: [PATCH] corrected the mutex lock names --- generate.go | 35 +++++++++++++++++++++++++---------- generateMutex.go | 4 ++-- generateSort.go | 18 ++++++++++-------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/generate.go b/generate.go index 4632997..5c7b92a 100644 --- a/generate.go +++ b/generate.go @@ -43,7 +43,7 @@ func (pb *Files) makeNewSortfile(pf *File) error { continue } VARNAME := v.VarName - funcdef := newSortType(wSort, PARENT, VARNAME) + funcdef := msg.newSortType(wSort, PARENT, VARNAME) log.Printf("Adding %s\n", funcdef) } } @@ -56,7 +56,7 @@ func (pb *Files) makeNewSortfile(pf *File) error { APPLES := s.VarName LOCK := s.Lockname - msg := pf.findMsg(s.VarType) + msg := pf.findMsg(s.MsgName) if msg == nil { return fmt.Errorf("failed to find struct %s", s.VarType) } @@ -73,7 +73,7 @@ func (pb *Files) makeNewSortfile(pf *File) error { VARNAME := s.VarName LOCK := s.Lockname - msg := pf.findMsg(s.VarType) + msg := pf.findMsg(s.MsgName) if msg == nil { return fmt.Errorf("failed to find struct %s", s.VarType) } @@ -90,6 +90,11 @@ func (pb *Files) makeNewSortfile(pf *File) error { PARENT := s.MsgName 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) if msg == nil { 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 sortname := s.VarType + v.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) } else { // deprecate this THIS DOES NOT MAKE SENSE TO DO @@ -140,7 +145,7 @@ func (pb *Files) makeNewSortfile(pf *File) error { if PARENT == VARNAME { // 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" log.Printf("Adding %s\n", funcdef) } @@ -161,8 +166,13 @@ func (pb *Files) makeNewSortfile(pf *File) error { CHILD := s.VarType VARNAME := s.VarName + pmsg := pf.findMsg(s.MsgName) + if pmsg == nil { + return fmt.Errorf("failed to find struct %s", s.MsgName) + } + if PARENT == VARNAME { - funcdef := addAllFunc(wSort, PARENT, CHILD, VARNAME) + funcdef := pmsg.addAllFunc(wSort, PARENT, CHILD, VARNAME) 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 + pmsg := pf.findMsg(s.MsgName) + if pmsg == nil { + return fmt.Errorf("failed to find struct %s", s.MsgName) + } + msg := pf.findMsg(s.VarType) if msg == nil { return fmt.Errorf("failed to find struct %s", s.VarType) @@ -215,7 +230,7 @@ func (pb *Files) makeNewSortfile(pf *File) error { if PARENT == VARNAME { // special case because of the enforced .proto format 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 { log.Printf("Adding %s\n", funcdef) } else { @@ -255,9 +270,9 @@ func (pb *Files) makeNewSortfile(pf *File) error { FUNCNAME = "DeleteBy" + v.VarName var funcdef string 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 { - 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) } else { @@ -283,7 +298,7 @@ func (pb *Files) makeNewSortfile(pf *File) error { if PARENT == VARNAME { // special case because of the enforced .proto format // ONLY SUPPORT THIS 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) } else { // deprecate this diff --git a/generateMutex.go b/generateMutex.go index 9695cb1..c5eeb54 100644 --- a/generateMutex.go +++ b/generateMutex.go @@ -15,8 +15,8 @@ import ( func (msg *MsgName) getLockname(s string) string { if msg.NoMutex { - return "bad" - // return msg.Lockname + // return "bad" + return msg.Lockname } // leave this function stubbed in for development of autogenpb // if argv.Mutex { diff --git a/generateSort.go b/generateSort.go index 3f14e21..100f282 100644 --- a/generateSort.go +++ b/generateSort.go @@ -5,8 +5,8 @@ import ( "io" ) -func (msg *MsgName) newIterAll(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) string { - LOCK = msg.getLockname("x") +func (msg *MsgName) newIterAll(w io.Writer, FRUIT, APPLE, APPLES, LOCKold string) string { + LOCK := msg.getLockname("x") 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 // TODO; figure out what types this actually works on // 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? 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 + " }" } -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" fmt.Fprintln(w, funcdef, "{") @@ -113,7 +113,7 @@ func newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT, VARNAME stri 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 {" fmt.Fprintln(w, funcdef) @@ -129,7 +129,9 @@ func addAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string { 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 {" fmt.Fprintln(w, "") fmt.Fprintln(w, funcdef) @@ -143,8 +145,8 @@ func addLenFunc(w io.Writer, FRUIT, APPLES, LOCK string) string { return funcdef } -func (msg *MsgName) addSelectAll(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) string { - LOCK = msg.getLockname("x") +func (msg *MsgName) addSelectAll(w io.Writer, FRUIT, APPLE, APPLES, LOCKold string) string { + LOCK := msg.getLockname("x") funcdef := "func (x *" + FRUIT + ") selectAll" + APPLES + "() []*" + APPLE fmt.Fprintln(w, "// safely returns a slice of pointers to the "+APPLE+" protobufs")