Added TypeKindVariableArray

This commit is contained in:
Sasha Koshka 2022-09-04 22:27:06 -04:00
parent 57b98636d0
commit 7af575e865
4 changed files with 11 additions and 15 deletions

View File

@ -67,8 +67,8 @@ func (what Type) Mutable () (mutable bool) {
return
}
// Length returns the length of the type if the type is an array. If the result
// is 0, this means the array has an undefined/variable length.
// Length returns the length of the type if the type is a fixed length array.
// Otherwise, it just returns zero.
func (what Type) Length () (length uint64) {
if what.kind == TypeKindArray {
length = what.length

View File

@ -34,7 +34,7 @@ func (parser *ParsingOperation) parseType () (what Type, err error) {
err = parser.nextToken(lexer.TokenKindRBrace)
if err != nil { return }
} else if parser.token.Is(lexer.TokenKindElipsis) {
what.kind = TypeKindArray
what.kind = TypeKindVariableArray
err = parser.nextToken(lexer.TokenKindRBrace)
if err != nil { return }

View File

@ -74,12 +74,9 @@ func (what Type) ToString () (output string) {
output += what.points.ToString()
if what.kind == TypeKindArray {
output += " "
if what.length == 0 {
output += ".."
} else {
output += fmt.Sprint(what.length)
}
output += fmt.Sprint(" ", what.length)
} else if what.kind == TypeKindVariableArray {
output += " .."
}
output += "}"

View File

@ -38,7 +38,7 @@ type Section interface {
ToString (indent int) (output string)
}
// Identifier represents a chain of arguments separated by a dot.
// Identifier represents a chain of names separated by a dot.
type Identifier struct {
locatable
trail []string
@ -55,11 +55,11 @@ const (
// TypeKindPointer means it's a pointer
TypeKindPointer
// TypeKindArray means it's an array.
// TypeKindArray means it's a fixed length array.
TypeKindArray
// TODO: add a type kind for arrays with a variable amount of elements,
// because they are very much different concepts
// TypeKindVariableArray means it's an array of variable length.
TypeKindVariableArray
)
// Type represents a type specifier
@ -69,8 +69,7 @@ type Type struct {
mutable bool
kind TypeKind
// only applicable for arrays. a value of zero means it has an
// undefined/dynamic length.
// only applicable for fixed length arrays.
length uint64
// only applicable for basic.