--- a/compiler/TSemanticAnalyser.st Mon Sep 14 11:19:10 2015 +0100
+++ b/compiler/TSemanticAnalyser.st Mon Sep 14 15:03:03 2015 +0100
@@ -6,15 +6,18 @@
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
- category:'Languages-Tea-Compiler'
+ category:'Languages-Tea-Compiler-Internals'
!
!TSemanticAnalyser class methodsFor:'documentation'!
documentation
"
- This pass analyzes the tree, creates scopes and
- initializes variable bindings.
+ This is the very first pass on the code. Its responsibility is:
+ * initialize bindings including types (except for message sends as those
+ depends on type analysis)
+ * initialize scopes (i.e, assign scopes and populate them
+ with variables)
[author:]
Jan Vrany <jan.vrany@fit.cvut.cz>
@@ -28,46 +31,7 @@
"
! !
-!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>"
-!
+!TSemanticAnalyser methodsFor:'visiting'!
visitArgument: anRBVariableNode
| binding |
@@ -86,6 +50,53 @@
"Modified: / 02-09-2015 / 08:58:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!TSemanticAnalyser methodsFor:'visitor-double dispatching'!
+
+acceptBlockNode: aBlockNode
+ | scope |
+ aBlockNode parent isSpecialFormNode ifTrue:[
+ scope := currentScope subScope: aBlockNode.
+ ] ifFalse:[
+ scope := TScope new.
+ ].
+ aBlockNode scope: scope.
+ super acceptBlockNode: aBlockNode
+
+ "Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 14-09-2015 / 14:04:06 / 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 bindingForSelf |
+
+ scope := TScope node: aMethodNode.
+ bindingForSelf := TArgumentBinding name:'self'.
+ bindingForSelf index: self.
+ scope addVariable: bindingForSelf.
+
+ 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>"
+! !
+
!TSemanticAnalyser class methodsFor:'documentation'!
version