Removed Void as a concept
This commit is contained in:
parent
24af8e0b49
commit
d435a1b1be
|
@ -66,8 +66,7 @@ func (this *Tree) canAssign (
|
|||
}
|
||||
|
||||
// base type
|
||||
case *entity.TypeVoid,
|
||||
*entity.TypePointer,
|
||||
case *entity.TypePointer,
|
||||
*entity.TypeSlice,
|
||||
*entity.TypeArray,
|
||||
*entity.TypeStruct,
|
||||
|
@ -190,8 +189,7 @@ func (this *Tree) areStructurallyEquivalent (left, right entity.Type) bool {
|
|||
}
|
||||
|
||||
// terminals
|
||||
case *entity.TypeVoid,
|
||||
*entity.TypeInt,
|
||||
case *entity.TypeInt,
|
||||
*entity.TypeFloat,
|
||||
*entity.TypeWord,
|
||||
*entity.TypeBool:
|
||||
|
|
|
@ -174,7 +174,7 @@ func (this *Tree) analyzeSubscript (
|
|||
subscript.Slice)
|
||||
if err != nil { return nil, err }
|
||||
subscript.Slice = slice
|
||||
subscript.Ty = voidIfNil(into)
|
||||
subscript.Ty = into
|
||||
|
||||
offset, err := this.analyzeExpression (
|
||||
builtinType("Index"), weak,
|
||||
|
@ -232,7 +232,7 @@ func (this *Tree) analyzeDereference (
|
|||
dereference.Pointer)
|
||||
if err != nil { return nil, err }
|
||||
dereference.Pointer = pointer
|
||||
dereference.Ty = voidIfNil(into)
|
||||
dereference.Ty = into
|
||||
|
||||
return pointer, nil
|
||||
}
|
||||
|
@ -471,7 +471,6 @@ func (this *Tree) analyzeBlock (
|
|||
}
|
||||
|
||||
final := len(block.Steps) - 1
|
||||
block.Ty = &entity.TypeVoid { }
|
||||
for index, step := range block.Steps {
|
||||
if index == final && into != nil {
|
||||
expression, ok := step.(entity.Expression)
|
||||
|
@ -567,7 +566,7 @@ func (this *Tree) analyzeLoop (
|
|||
entity.Expression,
|
||||
error,
|
||||
) {
|
||||
loop.Ty = voidIfNil(into)
|
||||
loop.Ty = into
|
||||
this.pushLoop(loop)
|
||||
defer this.popLoop()
|
||||
|
||||
|
@ -598,7 +597,7 @@ func (this *Tree) analyzeBreak (
|
|||
}
|
||||
brk.Loop = loop
|
||||
|
||||
if !loop.Type().Equals(&entity.TypeVoid { }) && brk.Value == nil {
|
||||
if loop.Type() != nil && brk.Value == nil {
|
||||
return nil, participle.Errorf (
|
||||
brk.Pos,
|
||||
"break statement must have value")
|
||||
|
@ -634,7 +633,7 @@ func (this *Tree) analyzeReturn (
|
|||
ty = ret.Declaration.(*entity.Method).Signature.Return
|
||||
}
|
||||
|
||||
if !ty.Equals(&entity.TypeVoid { }) && ret.Value == nil {
|
||||
if ty != nil && ret.Value == nil {
|
||||
return nil, participle.Errorf (
|
||||
ret.Pos,
|
||||
"break statement must have value")
|
||||
|
|
|
@ -103,8 +103,7 @@ func (this *Tree) analyzeMethodOrBehavior (
|
|||
ty := ty.(*entity.TypePointer)
|
||||
return this.analyzeMethodOrBehavior(pos, ty.Referenced, name)
|
||||
|
||||
case *entity.TypeVoid,
|
||||
*entity.TypeSlice,
|
||||
case *entity.TypeSlice,
|
||||
*entity.TypeArray,
|
||||
*entity.TypeStruct,
|
||||
*entity.TypeInt,
|
||||
|
|
|
@ -60,9 +60,7 @@ func (this *Tree) analyzeTypeInternal (
|
|||
error,
|
||||
) {
|
||||
// edge cases
|
||||
void := &entity.TypeVoid { }
|
||||
if ty == nil { return void, nil }
|
||||
if ty.Equals(void) { return ty, nil }
|
||||
if ty == nil { return nil, nil }
|
||||
var err error
|
||||
|
||||
// if we are analyzing a typedef, we will need to update incomplete type
|
||||
|
@ -201,11 +199,3 @@ func (this *Tree) analyzeBehavior (behavior *entity.Signature) (*entity.Signatur
|
|||
behavior.Return, err = this.analyzeType(behavior.Return, false)
|
||||
return behavior, err
|
||||
}
|
||||
|
||||
func voidIfNil (ty entity.Type) entity.Type {
|
||||
if ty == nil {
|
||||
return &entity.TypeVoid { }
|
||||
} else {
|
||||
return ty
|
||||
}
|
||||
}
|
||||
|
|
|
@ -365,7 +365,7 @@ type Break struct {
|
|||
}
|
||||
func (*Break) expression(){}
|
||||
func (*Break) statement(){}
|
||||
func (this *Break) Type () Type { return &TypeVoid { } }
|
||||
func (this *Break) Type () Type { return nil }
|
||||
func (this *Break) String () string {
|
||||
if this.Value == nil {
|
||||
return "[break]"
|
||||
|
@ -388,7 +388,7 @@ type Return struct {
|
|||
}
|
||||
func (*Return) expression(){}
|
||||
func (*Return) statement(){}
|
||||
func (this *Return) Type () Type { return &TypeVoid { } }
|
||||
func (this *Return) Type () Type { return nil }
|
||||
func (this *Return) String () string {
|
||||
if this.Value == nil {
|
||||
return "[return]"
|
||||
|
|
|
@ -11,15 +11,6 @@ type Type interface {
|
|||
ty ()
|
||||
}
|
||||
|
||||
// TypeVoid represents the absence of a type.
|
||||
type TypeVoid struct { }
|
||||
func (*TypeVoid) ty(){}
|
||||
func (*TypeVoid) Equals (ty Type) bool {
|
||||
_, equals := ty.(*TypeVoid)
|
||||
return equals
|
||||
}
|
||||
func (*TypeVoid) String () string { return "Void" }
|
||||
|
||||
// TypeNamed refers to a user-defined or built in named type.
|
||||
type TypeNamed struct {
|
||||
Pos lexer.Position
|
||||
|
|
Loading…
Reference in New Issue