compiler/TSemanticAnalyser.st
changeset 15 10a95d798b36
parent 13 97090c2baa33
child 16 17a2d1d9f205
equal deleted inserted replaced
14:fa42d3f1a578 15:10a95d798b36
    38     anRBVariableNode parent isSequence ifTrue:[ 
    38     anRBVariableNode parent isSequence ifTrue:[ 
    39         binding := TLocalBinding name:anRBVariableNode name.
    39         binding := TLocalBinding name:anRBVariableNode name.
    40     ] ifFalse:[ 
    40     ] ifFalse:[ 
    41         binding := TArgumentBinding name:anRBVariableNode name.
    41         binding := TArgumentBinding name:anRBVariableNode name.
    42         binding index: (anRBVariableNode parent arguments indexOf: anRBVariableNode)                                
    42         binding index: (anRBVariableNode parent arguments indexOf: anRBVariableNode)                                
    43                        + (anRBVariableNode parent scope isMethodScope ifTrue:[1] ifFalse:[0])     
    43                        + (anRBVariableNode parent scope hasSelfArgument ifTrue:[1] ifFalse:[0])     
    44     ].
    44     ].
    45     anRBVariableNode parent scope addVariable: binding.
    45     anRBVariableNode parent scope addVariable: binding.
    46     super visitArgument: anRBVariableNode.
    46     super visitArgument: anRBVariableNode.
    47 
    47 
    48     "Created: / 25-08-2015 / 22:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    48     "Created: / 25-08-2015 / 22:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    49     "Modified: / 19-09-2015 / 06:17:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    49     "Modified: / 23-09-2015 / 18:48:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    50 ! !
    50 ! !
    51 
    51 
    52 !TSemanticAnalyser methodsFor:'visitor-double dispatching'!
    52 !TSemanticAnalyser methodsFor:'visitor-double dispatching'!
    53 
    53 
    54 acceptBlockNode: aBlockNode
    54 acceptBlockNode: aBlockNode
    55     | scope |
    55     | scope binding |
    56     aBlockNode parent isSpecialFormNode ifTrue:[ 
    56     aBlockNode parent isSpecialFormNode ifTrue:[ 
    57         scope := TScope node: aBlockNode parent: aBlockNode parent scope
    57         scope := TScope node: aBlockNode parent: aBlockNode parent scope
    58     ] ifFalse:[ 
    58     ] ifFalse:[ 
    59         scope := TScope node: aBlockNode
    59         scope := TScope node: aBlockNode
    60     ].
    60     ].
    61     aBlockNode scope: scope.
    61     aBlockNode scope: scope.
       
    62 
       
    63     binding := TBlockBinding new.
       
    64     binding parameterTypes: aBlockNode parameterTypes.
       
    65     binding returnType: aBlockNode returnType.
       
    66     aBlockNode binding: binding.
       
    67 
    62     super acceptBlockNode: aBlockNode
    68     super acceptBlockNode: aBlockNode
    63 
    69 
    64     "Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    70     "Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    65     "Modified: / 19-09-2015 / 06:16:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    71     "Modified: / 23-09-2015 / 16:31:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    72 !
       
    73 
       
    74 acceptIfTrueIfFalseNode: node 
       
    75     node arguments first isBlock ifFalse:[ 
       
    76         context reportSemanticError: 'First argument (true block) of ifTrue:ifFalse: special form is not a block'.
       
    77     ] ifTrue:[ 
       
    78         node arguments first arguments notEmptyOrNil ifTrue:[ 
       
    79             context reportSemanticError: 'First argument (true block) of ifTrue::ifFalse: special form may not have any arguments'.
       
    80         ]
       
    81     ].  
       
    82     node arguments second isBlock ifFalse:[ 
       
    83         context reportSemanticError: 'Second argument (false block) of ifTrue:ifFalse: special form is not a block'.
       
    84     ] ifTrue:[ 
       
    85         node arguments second arguments notEmptyOrNil ifTrue:[ 
       
    86             context reportSemanticError: 'Second argument (false block) of ifTrue::ifFalse: special form may not have any arguments'.
       
    87         ]
       
    88     ].  
       
    89 
       
    90     ^ self acceptMessageNode: node.
       
    91 
       
    92     "Created: / 23-09-2015 / 14:20:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    93 !
       
    94 
       
    95 acceptIfTrueNode: node
       
    96     node arguments first isBlock ifFalse:[ 
       
    97         context reportSemanticError: 'Argument (true block) of ifTrue: special form is not a block'.
       
    98     ] ifTrue:[ 
       
    99         node arguments first arguments notEmptyOrNil ifTrue:[ 
       
   100             context reportSemanticError: 'Argument (true block) of ifTrue: special form may not have any arguments'.
       
   101         ]
       
   102     ].     
       
   103     self acceptMessageNode: node
       
   104 
       
   105     "Created: / 23-09-2015 / 14:18:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    66 !
   106 !
    67 
   107 
    68 acceptLiteralNode: aRBLiteralNode
   108 acceptLiteralNode: aRBLiteralNode
    69     | value |
   109     | value |
    70 
   110 
    87 acceptMethodNode: aMethodNode
   127 acceptMethodNode: aMethodNode
    88     | scope bindingForSelf |
   128     | scope bindingForSelf |
    89 
   129 
    90     scope   := TScope node: aMethodNode.
   130     scope   := TScope node: aMethodNode.
    91     bindingForSelf := TArgumentBinding name:'self'.
   131     bindingForSelf := TArgumentBinding name:'self'.
    92     bindingForSelf index: self.
   132     bindingForSelf index: 1.
    93     scope addVariable: bindingForSelf.
   133     scope addVariable: bindingForSelf.
    94 
   134 
    95     aMethodNode scope: scope.
   135     aMethodNode scope: scope.
    96 
   136 
    97     super acceptMethodNode: aMethodNode
   137     super acceptMethodNode: aMethodNode
    98 
   138 
    99     "Created: / 25-08-2015 / 22:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   139     "Created: / 25-08-2015 / 22:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   100     "Modified: / 13-09-2015 / 09:30:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   140     "Modified: / 23-09-2015 / 18:31:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   101 !
   141 !
   102 
   142 
   103 acceptVariableNode: aVariableNode
   143 acceptVariableNode: aVariableNode
   104     | binding |
   144     | binding |
   105 
   145 
   111     aVariableNode binding: binding.
   151     aVariableNode binding: binding.
   112     super acceptVariableNode: aVariableNode
   152     super acceptVariableNode: aVariableNode
   113 
   153 
   114     "Created: / 25-08-2015 / 23:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   154     "Created: / 25-08-2015 / 23:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   115     "Modified: / 20-09-2015 / 06:14:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   155     "Modified: / 20-09-2015 / 06:14:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   156 !
       
   157 
       
   158 acceptWhileTrueNode: node
       
   159     node receiver isBlock ifFalse:[ 
       
   160         context reportSemanticError: 'Receiver (condition) of whileTrue: special form is not a block'.
       
   161     ] ifTrue:[ 
       
   162         node receiver arguments notEmptyOrNil ifTrue:[ 
       
   163             context reportSemanticError: 'Receiver (condition) of whileTrue: special form may not have any arguments'.
       
   164         ]
       
   165     ].
       
   166     node arguments first isBlock ifFalse:[ 
       
   167         context reportSemanticError: 'Argument (loop body) of whileTrue: special form is not a block'.
       
   168     ] ifTrue:[ 
       
   169         node arguments first arguments notEmptyOrNil ifTrue:[ 
       
   170             context reportSemanticError: 'Argument (loop body) of whileTrue: special form may not have any arguments'.
       
   171         ]
       
   172     ].
       
   173     super acceptWhileTrueNode: node
       
   174 
       
   175     "Created: / 23-09-2015 / 14:10:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   116 ! !
   176 ! !
   117 
   177 
   118 !TSemanticAnalyser class methodsFor:'documentation'!
   178 !TSemanticAnalyser class methodsFor:'documentation'!
   119 
   179 
   120 version
   180 version