now to rename the files

This commit is contained in:
Jeff Carr 2025-01-11 03:42:14 -06:00
parent 74641713f8
commit d8464bf21f
3 changed files with 14 additions and 96 deletions

View File

@ -4,6 +4,7 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
simple: build simple: build
make -C example clean simpleMutexGlobal goimports vet make -C example clean simpleMutexGlobal goimports vet
make -C example clean simpleMutexProtoc goimports vet make -C example clean simpleMutexProtoc goimports vet
# make -C example deleteproto
full: install clean auto goimports vet build test install full: install clean auto goimports vet build test install
@echo everything worked and the example ran @echo everything worked and the example ran

View File

@ -10,13 +10,20 @@ modproto: clean withMutex goimports vet build
rawproto: clean withoutMutex goimports vet build rawproto: clean withoutMutex goimports vet build
./example ./example
deleteproto: clean
../autogenpb --proto fruit.proto --package main --delete
make build
vet: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet
build: rawbuild:
GO111MODULE=off go build -v GO111MODULE=off go build -v
simpleMutexProtoc: build: goimports vet
GO111MODULE=off go build -v
simpleMutexProtoc: clean
../autogenpb --proto fruit.proto --package main ../autogenpb --proto fruit.proto --package main
# why does this fail to compile? I'm not sure. maybe someone smart can figure it out # 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 # about the RWmutex lock being copied and GO fails to compile
# I'm don't grok what is going on. This autogenerated code should # 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! # 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 ../autogenpb --proto fruit.proto --package main --delete
simpleMutexGlobal: simpleMutexGlobal: clean
../autogenpb --proto fruit.proto --package main --mutex=false ../autogenpb --proto fruit.proto --package main --mutex=false
withMutex: withMutex: clean
../autogenpb --proto fruit.proto --package main ../autogenpb --proto fruit.proto --package main
../autogenpb --proto file.proto --package main ../autogenpb --proto file.proto --package main
../autogenpb --proto patchset.proto --package main ../autogenpb --proto patchset.proto --package main
withoutMutex: withoutMutex: clean
../autogenpb --proto fruit.proto --package main --mutex=false ../autogenpb --proto fruit.proto --package main --mutex=false
../autogenpb --proto file.proto --package main --mutex=false ../autogenpb --proto file.proto --package main --mutex=false
../autogenpb --proto patchset.proto --package main --mutex=false ../autogenpb --proto patchset.proto --package main --mutex=false

View File

@ -117,93 +117,3 @@ func (pf *File) iterSelect(w io.Writer) {
fmt.Fprintln(w, " return tmp") fmt.Fprintln(w, " return tmp")
fmt.Fprintln(w, "}") 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, "")
}
}