compiler/TTypechecker.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 16 Sep 2015 05:29:43 +0100
changeset 11 6d39860d0fdb
parent 9 569bf5707c7e
child 13 97090c2baa33
permissions -rw-r--r--
First shot on #ifTrie:ifFalse: special form

"{ Package: 'jv:tea/compiler' }"

"{ NameSpace: Smalltalk }"

TCompilerPass subclass:#TTypechecker
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Tea-Compiler-Internals'
!

!TTypechecker methodsFor:'visitor-double dispatching'!

acceptIfTrueIfFalseNode: node
    | receiverType booleanType |

    receiverType := node receiver binding type.
    booleanType := context environment binding lookupClassBoolean type.

    receiverType = booleanType ifFalse:[ 
        context reportTypeError: 'receiver of ifTrue:ifFalse: special form must be of type tBoolean (is ' , receiverType printString.
    ].

    "Created: / 14-09-2015 / 14:24:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 15-09-2015 / 08:29:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

acceptIfTrueNode: node
    | receiverType booleanType |

    receiverType := node binding type.
    booleanType := context environment binding lookupClassBoolean.

    receiverType = booleanType ifFalse:[ 
        context reportTypeError: 'receiver of ifTrue: special form must be of type tBoolean (is ' , receiverType printString.
    ].

    "Created: / 14-09-2015 / 14:18:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

acceptMessageNode: aMessageNode 
    | receiverType receiverBinding methodBinding |

    super acceptMessageNode: aMessageNode.
    receiverType := aMessageNode receiver binding type.
    receiverType isSimpleType ifTrue:[ 
        receiverBinding := context environment binding lookupClassNamed: receiverType name.
        methodBinding := receiverBinding lookupMethodNamed: aMessageNode selector.
        1 to: aMessageNode arguments size do:[:paramIdx |  
            | actualParamType formalParamType |    
            actualParamType := (aMessageNode arguments at: paramIdx) binding type.
            formalParamType := methodBinding parameterTypes at: paramIdx.
            (actualParamType isSubtypeOf: formalParamType) ifFalse:[ 
                context reportTypeError: ('Type mismatch for parameter %1 (expected %2, got %3)' bindWith: paramIdx with: formalParamType with: actualParamType).
                ^ self.
            ].
        ].
        aMessageNode binding: methodBinding.
        ^ self.
    ].
    self notYetImplemented

    "Created: / 02-09-2015 / 10:34:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 14-09-2015 / 14:22:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !