summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--example/Makefile19
-rw-r--r--sortFunc.go90
3 files changed, 14 insertions, 96 deletions
diff --git a/Makefile b/Makefile
index 35922e1..7f0b91d 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
simple: build
make -C example clean simpleMutexGlobal goimports vet
make -C example clean simpleMutexProtoc goimports vet
+ # make -C example deleteproto
full: install clean auto goimports vet build test install
@echo everything worked and the example ran
diff --git a/example/Makefile b/example/Makefile
index c8b849f..22a8c65 100644
--- a/example/Makefile
+++ b/example/Makefile
@@ -10,13 +10,20 @@ modproto: clean withMutex goimports vet build
rawproto: clean withoutMutex goimports vet build
./example
+deleteproto: clean
+ ../autogenpb --proto fruit.proto --package main --delete
+ make build
+
vet:
@GO111MODULE=off go vet
-build:
+rawbuild:
+ GO111MODULE=off go build -v
+
+build: goimports vet
GO111MODULE=off go build -v
-simpleMutexProtoc:
+simpleMutexProtoc: clean
../autogenpb --proto fruit.proto --package main
# why does this fail to compile? I'm not sure. maybe someone smart can figure it out
@@ -24,18 +31,18 @@ simpleMutexProtoc:
# about the RWmutex lock being copied and GO fails to compile
# I'm don't grok what is going on. This autogenerated code should
# provide as simple as one could hope for automated way to try to debug it though!
-simpleMutexProtocWithDeleteCopy:
+simpleMutexProtocWithDeleteCopy: clean
../autogenpb --proto fruit.proto --package main --delete
-simpleMutexGlobal:
+simpleMutexGlobal: clean
../autogenpb --proto fruit.proto --package main --mutex=false
-withMutex:
+withMutex: clean
../autogenpb --proto fruit.proto --package main
../autogenpb --proto file.proto --package main
../autogenpb --proto patchset.proto --package main
-withoutMutex:
+withoutMutex: clean
../autogenpb --proto fruit.proto --package main --mutex=false
../autogenpb --proto file.proto --package main --mutex=false
../autogenpb --proto patchset.proto --package main --mutex=false
diff --git a/sortFunc.go b/sortFunc.go
index b3573a6..e5cfa20 100644
--- a/sortFunc.go
+++ b/sortFunc.go
@@ -117,93 +117,3 @@ func (pf *File) iterSelect(w io.Writer) {
fmt.Fprintln(w, " return tmp")
fmt.Fprintln(w, "}")
}
-
-func (pf *File) appendUniqueOld(w io.Writer) {
- var MSG string = pf.Bases.Name
- var BASE string = pf.Base.Name
- var LOCK string = pf.Bases.Lockname
-
- if argv.Mutex {
- // use the mutex lock from the modified protoc.pb.go file
- LOCK = "all.Lock"
- } else {
- LOCK = pf.Bases.Lockname
- }
-
- // append -- no check at all
- fmt.Fprintln(w, "// just a simple Append() with no checking (but still uses the mutex lock)")
- fmt.Fprintln(w, "func (all *"+MSG+") Append(newP *"+BASE+") bool {")
- fmt.Fprintln(w, " "+LOCK+".RLock()")
- fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
- fmt.Fprintln(w, "")
- fmt.Fprintln(w, " all."+MSG+" = append(all."+MSG+", newP)")
- fmt.Fprintln(w, " return true")
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w, "")
-
- // append for single keys
- 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, "")
- }
-
- // append check for every key
- if len(pf.Base.Unique) == 0 {
- // there are no keys defined
- return
- }
- fmt.Fprintln(w, "// enforces "+BASE+" is unique")
- fmt.Fprintln(w, "func (all *"+MSG+") AppendUnique(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+" {")
- for _, KEY := range pf.Base.Unique {
- 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 (pf *File) replaceFunc(w io.Writer) {
- var MSG string = pf.Bases.Name
- var BASE string = pf.Base.Name
- var LOCK string = pf.Bases.Lockname
-
- for _, KEY := range pf.Base.Unique {
- fmt.Fprintln(w, "// enforces "+KEY+" is unique")
- fmt.Fprintln(w, "func (all *"+MSG+") Replace"+KEY+"(newP *"+BASE+") bool { // todo: make unique name here")
- 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, "")
- }
-}