aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encoding.go
diff options
context:
space:
mode:
authorPaul Chaignon <paul.chaignon@gmail.com>2023-11-09 16:54:42 +0100
committerAleksandr Nogikh <nogikh@google.com>2023-11-13 13:40:05 +0000
commitb941cfc45894745b4b99d06c762cd78d3c6beca5 (patch)
tree126dc7d3d53e1d0cda97788d4b0e069062057c6a /prog/encoding.go
parent78b9d1a14311a5bd82c219eb4fa815a54ad832bd (diff)
prog: support AUTO for structs
The AUTO token can currently be used in place of ConstType, LenType, and CsumType. This commit extends this support to StructType on the condition that they are made of the above types. It will allow us to simplify all the {AUTO, AUTO, AUTO, AUTO} in test programs. The following struct can therefore be written as AUTO. auto_struct1 { f0 len[parent, int32] f1 const[0x43, int32] } In addition, with this commit, AUTO can also stand for nested structs as long as all the leaf fields are ConstType, LenType, or CsumType. For example, the following struct can be written as AUTO. auto_struct2 { f0 len[parent, int32] f1 auto_struct1 } Suggested-by: Aleksandr Nogikh <nogikh@google.com> Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Diffstat (limited to 'prog/encoding.go')
-rw-r--r--prog/encoding.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index be883645b..6d7daeacb 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -489,9 +489,20 @@ func (p *parser) parseArgInt(typ Type, dir Dir) (Arg, error) {
}
func (p *parser) parseAuto(typ Type, dir Dir) (Arg, error) {
- switch typ.(type) {
+ switch t1 := typ.(type) {
case *ConstType, *LenType, *CsumType:
return p.auto(MakeConstArg(typ, dir, 0)), nil
+ case *StructType:
+ var inner []Arg
+ for len(inner) < len(t1.Fields) {
+ field := t1.Fields[len(inner)]
+ innerArg, err := p.parseAuto(field.Type, dir)
+ if err != nil {
+ return nil, err
+ }
+ inner = append(inner, innerArg)
+ }
+ return MakeGroupArg(typ, dir, inner), nil
default:
return nil, fmt.Errorf("wrong type %T for AUTO", typ)
}
@@ -562,7 +573,7 @@ func (p *parser) parseArgAddr(typ Type, dir Dir) (Arg, error) {
var inner Arg
if p.Char() == '=' {
p.Parse('=')
- if p.Char() == 'A' {
+ if p.HasNext("ANY") {
p.Parse('A')
p.Parse('N')
p.Parse('Y')