From fb43f96acc5c97ead8910c754a17cb64860f35dd Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 24 Aug 2022 18:22:47 -0400 Subject: [PATCH 1/4] Added bit fields to tree and ToString for object member --- parser/tree-tostring.go | 4 ++++ parser/tree.go | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index adbfcbd..6694167 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -297,6 +297,10 @@ func (member ObjtMember) ToString (indent int) (output string) { output += member.permission.ToString() + " " output += member.name + ":" output += member.what.ToString() + + if member.bitWidth > 0 { + output += fmt.Sprint(":", member.bitWidth) + } isComplexInitialization := member.defaultValue.kind == ArgumentKindObjectInitializationValues || diff --git a/parser/tree.go b/parser/tree.go index a0394ed..c450bd7 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -178,8 +178,9 @@ type TypeSection struct { type ObjtMember struct { location file.Location name string - + what Type + bitWidth int permission types.Permission defaultValue Argument } @@ -188,7 +189,8 @@ type ObjtMember struct { type ObjtSection struct { location file.Location name string - + + // TODO: make this Identifier instead of Type inherits Type permission types.Permission // TODO: order matters here we need to store these in an array @@ -225,6 +227,7 @@ type FaceBehavior struct { type FaceSection struct { location file.Location name string + // TODO: make this Identifier instead of string inherits string permission types.Permission From 05aa0e61772ca1175c382bb1f55fdaa874c3cb88 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 24 Aug 2022 18:23:11 -0400 Subject: [PATCH 2/4] Added bitfields to object section test case --- parser/objt_test.go | 3 +++ tests/parser/objt/main.arf | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/parser/objt_test.go b/parser/objt_test.go index 68a4337..854272a 100644 --- a/parser/objt_test.go +++ b/parser/objt_test.go @@ -9,6 +9,9 @@ func TestObjt (test *testing.T) { objt ro Basic:Obj ro that:Basic ro this:Basic +objt ro BitFields:Obj + ro that:Int:1 + ro this:Int:24 objt ro ComplexInit:Obj ro basic:Int 87 ro complex0:Bird diff --git a/tests/parser/objt/main.arf b/tests/parser/objt/main.arf index a151314..ebd909c 100644 --- a/tests/parser/objt/main.arf +++ b/tests/parser/objt/main.arf @@ -4,6 +4,10 @@ objt ro Basic:Obj ro that:Basic ro this:Basic +objt ro BitFields:Obj + ro that:Int:1 + ro this:Int:24 298 + objt ro Init:Obj ro that:String "hello world" ro this:Int 23 From 731cc828ce21309a8ffe7da0a98ef32f34c152f0 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 24 Aug 2022 18:29:15 -0400 Subject: [PATCH 3/4] Added untested bit width parsing --- parser/objt.go | 9 +++++++++ parser/tree.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/parser/objt.go b/parser/objt.go index f384cff..9784f55 100644 --- a/parser/objt.go +++ b/parser/objt.go @@ -96,6 +96,15 @@ func (parser *ParsingOperation) parseObjtMember () ( if err != nil { return } member.what, err = parser.parseType() if err != nil { return } + + // if there is a bit width, get it + if parser.token.Is(lexer.TokenKindColon) { + err = parser.nextToken(lexer.TokenKindUInt) + if err != nil { return } + member.bitWidth = parser.token.Value().(uint64) + err = parser.nextToken() + if err != nil { return } + } // parse default value if parser.token.Is(lexer.TokenKindNewline) { diff --git a/parser/tree.go b/parser/tree.go index c450bd7..e1f2292 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -180,7 +180,7 @@ type ObjtMember struct { name string what Type - bitWidth int + bitWidth uint64 permission types.Permission defaultValue Argument } From e316eb7791b41451dd641f6922ebe2ca7b30a9d1 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 24 Aug 2022 18:37:44 -0400 Subject: [PATCH 4/4] Changed bit field syntax to use an & symbol --- parser/objt.go | 4 +++- parser/objt_test.go | 4 ++-- parser/tree-tostring.go | 2 +- tests/parser/objt/main.arf | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/parser/objt.go b/parser/objt.go index 9784f55..ec64e08 100644 --- a/parser/objt.go +++ b/parser/objt.go @@ -97,8 +97,10 @@ func (parser *ParsingOperation) parseObjtMember () ( member.what, err = parser.parseType() if err != nil { return } + println(parser.token.Describe()) + // if there is a bit width, get it - if parser.token.Is(lexer.TokenKindColon) { + if parser.token.Is(lexer.TokenKindBinaryAnd) { err = parser.nextToken(lexer.TokenKindUInt) if err != nil { return } member.bitWidth = parser.token.Value().(uint64) diff --git a/parser/objt_test.go b/parser/objt_test.go index 854272a..16a5439 100644 --- a/parser/objt_test.go +++ b/parser/objt_test.go @@ -10,8 +10,8 @@ objt ro Basic:Obj ro that:Basic ro this:Basic objt ro BitFields:Obj - ro that:Int:1 - ro this:Int:24 + ro that:Int & 1 + ro this:Int & 24 298 objt ro ComplexInit:Obj ro basic:Int 87 ro complex0:Bird diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index 6694167..114f681 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -299,7 +299,7 @@ func (member ObjtMember) ToString (indent int) (output string) { output += member.what.ToString() if member.bitWidth > 0 { - output += fmt.Sprint(":", member.bitWidth) + output += fmt.Sprint(" & ", member.bitWidth) } isComplexInitialization := diff --git a/tests/parser/objt/main.arf b/tests/parser/objt/main.arf index ebd909c..7bdaf3c 100644 --- a/tests/parser/objt/main.arf +++ b/tests/parser/objt/main.arf @@ -5,8 +5,8 @@ objt ro Basic:Obj ro this:Basic objt ro BitFields:Obj - ro that:Int:1 - ro this:Int:24 298 + ro that:Int & 1 + ro this:Int & 24 298 objt ro Init:Obj ro that:String "hello world"