compiler/TSemanticAnalyser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 14 Sep 2015 11:19:10 +0100
changeset 8 eec72263ed75
parent 7 7556e3d41d80
child 9 569bf5707c7e
permissions -rw-r--r--
Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation

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

"{ NameSpace: Smalltalk }"

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

!TSemanticAnalyser class methodsFor:'documentation'!

documentation
"
    This pass analyzes the tree, creates scopes and
    initializes variable bindings.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!TSemanticAnalyser methodsFor:'visitor-double dispatching'!

acceptBlockNode: aBlockNode
    aBlockNode scope: (currentScope subScope: aBlockNode).
    super acceptBlockNode: aBlockNode

    "Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-09-2015 / 07:20:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

acceptLiteralNode: aRBLiteralNode
    super acceptLiteralNode: aRBLiteralNode.
    aRBLiteralNode binding: (TConstantBinding value: aRBLiteralNode value).

    "Created: / 25-08-2015 / 23:17:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-09-2015 / 10:34:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

acceptMethodNode: aMethodNode
    | scope bindingSelf |

    scope   := TScope node: aMethodNode.
    bindingSelf := TArgumentBinding name:'self'.
    bindingSelf index: self.
    scope addVariable: bindingSelf.

    aMethodNode scope: scope.

    super acceptMethodNode: aMethodNode

    "Created: / 25-08-2015 / 22:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-09-2015 / 09:30:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

acceptVariableNode: aVariableNode
    aVariableNode binding: (aVariableNode scope lookupVariable: aVariableNode name).
    super acceptVariableNode: aVariableNode

    "Created: / 25-08-2015 / 23:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

visitArgument: anRBVariableNode
    | binding |

    anRBVariableNode parent isSequence ifTrue:[ 
        binding := TLocalBinding name:anRBVariableNode name.
    ] ifFalse:[ 
        binding := TArgumentBinding name:anRBVariableNode name.
        binding index: (anRBVariableNode parent arguments indexOf: anRBVariableNode)                                
                       + (currentScope isMethodScope ifTrue:[1] ifFalse:[0])     
    ].
    anRBVariableNode parent scope addVariable: binding.
    super visitArgument: anRBVariableNode.

    "Created: / 25-08-2015 / 22:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-09-2015 / 08:58:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TSemanticAnalyser class methodsFor:'documentation'!

version
    ^ 'Path: jv/tea/compiler/TSemanticAnalyzer.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:58.729+01'
!

version_HG
    ^ 'Path: jv/tea/compiler/TSemanticAnalyzer.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:58.729+01'
! !