summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/Makefile1
-rw-r--r--newsort.go23
-rw-r--r--protoParse.go2
-rw-r--r--sort.go31
4 files changed, 38 insertions, 19 deletions
diff --git a/example/Makefile b/example/Makefile
index 3c477bf..13c5919 100644
--- a/example/Makefile
+++ b/example/Makefile
@@ -6,7 +6,6 @@ full: clean auto goimports vet build
vet:
@GO111MODULE=off go vet
- @echo this go binary package should build okay
build:
rm -f fruit.newsort.pb.go
diff --git a/newsort.go b/newsort.go
index 43188cb..8a4925b 100644
--- a/newsort.go
+++ b/newsort.go
@@ -1,27 +1,27 @@
package main
import (
+ "fmt"
"os"
"strings"
-
- "go.wit.com/log"
)
-func (pb *Files) makeNewSortfile(pf *File) {
+func (pb *Files) makeNewSortfile(pf *File) error {
f, _ := os.OpenFile(pf.Filebase+".newsort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
header(f, pf)
pf.syncLock(f)
- if pf.Bases != nil {
- log.Info("THIS IS WHAT BASES?", pf.Bases.Name, pf.Bases)
+ if pf.Bases == nil {
+ return fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)
}
- if pf.Base != nil {
- log.Info("THIS IS WHAT BASE?", pf.Base.Name, pf.Base)
- pf.Base.iterTop(f)
- pf.Base.iterNext(f)
+ if pf.Base == nil {
+ return fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)
}
+ pf.Base.iterTop(f)
+ pf.Base.iterNext(f)
+
/*
for _, msg := range pf.MsgNames {
if msg.DoMutex {
@@ -35,8 +35,8 @@ func (pb *Files) makeNewSortfile(pf *File) {
}
*/
- // pf.appendUnique(f, msg, sortmap) // Append() enforce no unique keys
- return
+ pf.appendUnique(f, nil, sortmap) // Append() enforce no unique keys
+ return nil
// iterSortAll(f, sortmap)
if argv.Append != "" {
@@ -74,4 +74,5 @@ func (pb *Files) makeNewSortfile(pf *File) {
iterFind(f, sortmap)
}
iterEnd(f, sortmap)
+ return nil
}
diff --git a/protoParse.go b/protoParse.go
index 9aef560..024125d 100644
--- a/protoParse.go
+++ b/protoParse.go
@@ -122,7 +122,7 @@ func (f *File) parseForMessage(line string) *MsgName {
log.Info("found messge:", msgName)
msg := new(MsgName)
msg.Name = msgName
- msg.Lockname = msgName + "Mu"
+ msg.Lockname = f.Filebase + "Mu" // this should be lowercase. do not export the Mutex
if strings.Contains(line, "`autogenpb:mutex`") {
msg.DoMutex = true
diff --git a/sort.go b/sort.go
index ff0e951..1bf34bb 100644
--- a/sort.go
+++ b/sort.go
@@ -185,14 +185,15 @@ func iterEnd(w io.Writer, names map[string]string) {
func iterAppend(w io.Writer, names map[string]string) {
}
-func (pf *File) appendUnique(w io.Writer, msg *MsgName, names map[string]string) {
- var MSG string = msg.Name // msg.Name
+func (pf *File) appendUnique(w io.Writer, blah *MsgName, names map[string]string) {
+ var MSG string = pf.Bases.Name
var BASE string = names["Base"]
- var LOCK string = names["lock"]
+ var LOCK string = pf.Bases.Lockname
+
if argv.Mutex {
- LOCK = "Lock"
+ LOCK = pf.Bases.Name + ".Lock"
} else {
- LOCK = names["lock"] + ".Lock"
+ LOCK = "all.Lock"
}
fmt.Fprintln(w, "// enforces "+BASE+" is unique")
@@ -201,7 +202,7 @@ func (pf *File) appendUnique(w io.Writer, msg *MsgName, names map[string]string)
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " for _, p := range all."+MSG+" {")
- for _, KEY := range msg.Unique {
+ for _, KEY := range pf.Base.Unique {
fmt.Fprintln(w, " if p."+KEY+" == newP."+KEY+" {")
fmt.Fprintln(w, " return false")
fmt.Fprintln(w, " }")
@@ -212,6 +213,24 @@ func (pf *File) appendUnique(w io.Writer, msg *MsgName, names map[string]string)
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
+
+ for _, KEY := range pf.Base.Unique {
+ fmt.Fprintln(w, "// enforces "+BASE+" is unique")
+ fmt.Fprintln(w, "func (all *"+MSG+") AppendUnique"+KEY+"(newP *"+BASE+") bool {")
+ fmt.Fprintln(w, " "+LOCK+".RLock()")
+ fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " for _, p := range all."+MSG+" {")
+ fmt.Fprintln(w, " if p."+KEY+" == newP."+KEY+" {")
+ fmt.Fprintln(w, " return false")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " all."+MSG+" = append(all."+MSG+", newP)")
+ fmt.Fprintln(w, " return true")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, "")
+ }
}
func iterReplace(w io.Writer, names map[string]string) {