From 41b3376fa3a1b99ad0699f32595e8b6be9bb6822 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 3 Aug 2025 22:19:06 -0400 Subject: [PATCH] generate: Add Generator.generateDecodeBranch stub --- generate/generate.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/generate/generate.go b/generate/generate.go index fa5c12a..0ceb666 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -485,7 +485,8 @@ func (this *Generator) generateDecodeValue(typ Type, valueSource, tagSource, abo } case TypeArray: // OTA: * - // TODO: branch + nn, err := this.generateDecodeBranch(typ, valueSource, tagSource) + n += nn; if err != nil { return n, err } case TypeTable: // KTV: ( )* nn, err := this.iprintf( @@ -496,7 +497,8 @@ func (this *Generator) generateDecodeValue(typ Type, valueSource, tagSource, abo n += nn; if err != nil { return n, err } case TypeTableDefined: // KTV: ( )* - // TODO: branch + nn, err := this.generateDecodeBranch(typ, valueSource, tagSource) + n += nn; if err != nil { return n, err } case TypeNamed: // WHATEVER: [WHATEVER] nn, err := this.iprintf("nn, err = %s.DecodeValue(decoder, %s)\n", valueSource, tagSource) @@ -510,6 +512,23 @@ func (this *Generator) generateDecodeValue(typ Type, valueSource, tagSource, abo return n, nil } + +// generateDencodeValue generates code to call an aggregate decoder function, +// for a specified type. The definition of the function is deferred so no +// duplicates are created. The function overwrites memory pointed to by the +// variable (or parenthetical statement) specified by valueSource, and the value +// will be encoded according to the tag stored in the variable (or parenthetical +// statement) specified by tagSource. the code generated is a BLOCK and expects +// these variables to be defined: +// +// - decoder *tape.Decoder +// - n int +// - err error +// - nn int +func (this *Generator) generateDecodeBranch(typ Type, valueSource, tagSource string) (n int, err error) { + // TODO +} + func (this *Generator) generateErrorCheck() (n int, err error) { return this.iprintf("n += nn; if err != nil { return n, err }\n") }