Testing ALL the types
This commit is contained in:
parent
f1e415b038
commit
6f40b6216b
|
@ -19,6 +19,7 @@ func (this *Tree) analyzeTypedef (pos lexer.Position, name string) (entity.Type,
|
|||
|
||||
func (this *Tree) analyzeType (ty entity.Type) (entity.Type, error) {
|
||||
if ty == entity.Void() { return ty, nil }
|
||||
if ty == nil { return entity.Void(), nil }
|
||||
var err error
|
||||
|
||||
switch ty.(type) {
|
||||
|
@ -36,7 +37,7 @@ func (this *Tree) analyzeType (ty entity.Type) (entity.Type, error) {
|
|||
ty := ty.(*entity.TypeArray)
|
||||
if ty.Length < 1 {
|
||||
return ty, participle.Errorf (
|
||||
ty.Pos, "array length must be > 1")
|
||||
ty.Pos, "array length must be > 0")
|
||||
}
|
||||
ty.Element, err = this.analyzeType(ty.Element)
|
||||
return ty, err
|
||||
|
@ -58,6 +59,15 @@ func (this *Tree) analyzeType (ty entity.Type) (entity.Type, error) {
|
|||
if err != nil { return ty, err }
|
||||
}
|
||||
return ty, nil
|
||||
case *entity.TypeInt:
|
||||
ty := ty.(*entity.TypeInt)
|
||||
if ty.Width < 1 {
|
||||
return ty, participle.Errorf (
|
||||
ty.Pos, "integer width must be > 0")
|
||||
}
|
||||
return ty, nil
|
||||
case *entity.TypeFloat, *entity.TypeWord:
|
||||
return ty, nil
|
||||
|
||||
default: panic(fmt.Sprint("BUG: analyzer doesnt know about type ", ty))
|
||||
}
|
||||
|
|
|
@ -79,7 +79,42 @@ AllBuiltin: (
|
|||
`)
|
||||
}
|
||||
|
||||
func TestStructMemberUniqueErr (test *testing.T) {
|
||||
func TestTypePointer (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
Ptr: *Int
|
||||
PtrPtr: **Int
|
||||
PtrPtrPtr: *PtrPtr
|
||||
ArrPtr: *5:Int
|
||||
SlicePtr: **:Int
|
||||
`)
|
||||
}
|
||||
|
||||
func TestTypeSlice (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
Slice: *:Int
|
||||
RaggedSlice: *:*:Int
|
||||
`)
|
||||
}
|
||||
|
||||
func TestTypeArrayErrSizeZero (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"array length must be > 0", 2, 8,
|
||||
`
|
||||
Array: 0:Int
|
||||
`)
|
||||
}
|
||||
|
||||
func TestTypeArray (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
Array: 5:Int
|
||||
Matrix: 5:6:Int
|
||||
`)
|
||||
}
|
||||
|
||||
func TestTypeStructMemberUniqueErr (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"x already listed in struct at stream0.fspl:3:2", 6, 2,
|
||||
`
|
||||
|
@ -91,7 +126,7 @@ Bird: (
|
|||
`)
|
||||
}
|
||||
|
||||
func TestStructMemberUnique (test *testing.T) {
|
||||
func TestTypeStructMemberUnique (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
Bird: (
|
||||
|
@ -102,7 +137,7 @@ Bird: (
|
|||
`)
|
||||
}
|
||||
|
||||
func TestInterfaceBehaviorUniqueErr (test *testing.T) {
|
||||
func TestTypeInterfaceBehaviorUniqueErr (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"fly already listed in interface at stream0.fspl:2:8", 2, 14,
|
||||
`
|
||||
|
@ -110,7 +145,7 @@ Bird: ([fly] [fly])
|
|||
`)
|
||||
}
|
||||
|
||||
func TestInterfaceBehaviorUnique (test *testing.T) {
|
||||
func TestTypeInterfaceBehaviorUnique (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
Bird: ([fly] [land])
|
||||
|
|
|
@ -109,6 +109,7 @@ func (this *TypeInterface) String () string {
|
|||
|
||||
// TypeInt represents any signed or unsigned integer type.
|
||||
type TypeInt struct {
|
||||
Pos lexer.Position
|
||||
Width int
|
||||
Signed bool
|
||||
}
|
||||
|
@ -116,6 +117,7 @@ func (*TypeInt) ty(){}
|
|||
|
||||
// TypeFloat represents any floating point type.
|
||||
type TypeFloat struct {
|
||||
Pos lexer.Position
|
||||
Width int
|
||||
}
|
||||
func (*TypeFloat) ty(){}
|
||||
|
@ -124,6 +126,7 @@ func (*TypeFloat) ty(){}
|
|||
// is chosen based on the machine word size (32 on 32 bit systems, 64 on 64 bit
|
||||
// systems, etc)
|
||||
type TypeWord struct {
|
||||
Pos lexer.Position
|
||||
Signed bool
|
||||
}
|
||||
func (*TypeWord) ty(){}
|
||||
|
|
Loading…
Reference in New Issue