From 3e9ff7dcd651b89aba8d2f162514c29cbb05be48 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 11 Sep 2022 16:15:02 -0400 Subject: [PATCH] Altered syntax tree accordingly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🦀🦀🦀 Object sections are gone 🦀🦀🦀 and members are now stored in the type specifier. --- parser/accessors.go | 45 ++++++++++++++++++++------------------------- parser/tree.go | 38 +++++++++++++++----------------------- 2 files changed, 35 insertions(+), 48 deletions(-) diff --git a/parser/accessors.go b/parser/accessors.go index bdfcd72..eca4312 100644 --- a/parser/accessors.go +++ b/parser/accessors.go @@ -29,12 +29,6 @@ func (section TypeSection) Kind () (kind SectionKind) { return } -// Kind returns the section's kind (SectionKindObjt). -func (section ObjtSection) Kind () (kind SectionKind) { - kind = SectionKindObjt - return -} - // Kind returns the section's kind (SectionKindEnum). func (section EnumSection) Kind () (kind SectionKind) { kind = SectionKindEnum @@ -111,6 +105,26 @@ func (what Type) Points () (points Type) { return } +// MembersLength returns the amount of new members the type specifier defines. +// If it defines no new members, it returns zero. +func (what Type) MembersLength () (length int) { + length = len(what.members) + return +} + +// Member returns the member at index. +func (what Type) Member (index int) (member TypeMember) { + member = what.members[index] + return +} + +// BitWidth returns the bit width of the type member. If it is zero, it should +// be treated as unspecified. +func (member TypeMember) BitWidth () (width uint64) { + width = member.bitWidth + return +} + // Values returns an iterator for the initialization values. func (values ObjectInitializationValues) Sections () ( iterator types.Iterator[Argument], @@ -144,25 +158,6 @@ func (argument Argument) Value () (value any) { return } -// BitWidth returns the bit width of the object member. If it is zero, it should -// be treated as unspecified. -func (member ObjtMember) BitWidth () (width uint64) { - width = member.bitWidth - return -} - -// Length returns the amount of members in the section. -func (section ObjtSection) Length () (length int) { - length = len(section.members) - return -} - -// Item returns the member at index. -func (section ObjtSection) Item (index int) (member ObjtMember) { - member = section.members[index] - return -} - // Length returns the amount of members in the section. func (section EnumSection) Length () (length int) { length = len(section.members) diff --git a/parser/tree.go b/parser/tree.go index a1be9dd..a9d2345 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -20,7 +20,6 @@ type SectionKind int const ( SectionKindType = iota - SectionKindObjt SectionKindEnum SectionKindFace SectionKindData @@ -59,6 +58,17 @@ const ( TypeKindVariableArray ) +// TypeMember represents a member variable of a type specifier. +type TypeMember struct { + locatable + nameable + typeable + permissionable + valuable + + bitWidth uint64 +} + // Type represents a type specifier type Type struct { locatable @@ -72,6 +82,9 @@ type Type struct { // not applicable for basic. points *Type + + // if non-nil, this type defines new members. + members []TypeMember } // Declaration represents a variable declaration. @@ -173,7 +186,7 @@ type DataSection struct { external bool } -// TypeSection represents a blind type definition. +// TypeSection represents a type definition. type TypeSection struct { locatable nameable @@ -182,27 +195,6 @@ type TypeSection struct { valuable } -// ObjtMember represents a part of an object type definition. -type ObjtMember struct { - locatable - nameable - typeable - permissionable - valuable - - bitWidth uint64 -} - -// ObjtSection represents an object type definition. -type ObjtSection struct { - locatable - nameable - permissionable - inherits Identifier - - members []ObjtMember -} - // EnumMember represents a member of an enum section. type EnumMember struct { locatable