|
1 "{ Package: 'jv:tea/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 TProgramNodeVisitor subclass:#TSemanticAnalyzer |
|
6 instanceVariableNames:'' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'Languages-Tea-Compiler-Analysis' |
|
10 ! |
|
11 |
|
12 !TSemanticAnalyzer class methodsFor:'documentation'! |
|
13 |
|
14 documentation |
|
15 " |
|
16 This pass analyzes the tree, creates scopes and |
|
17 initializes variable bindings. |
|
18 |
|
19 [author:] |
|
20 Jan Vrany <jan.vrany@fit.cvut.cz> |
|
21 |
|
22 [instance variables:] |
|
23 |
|
24 [class variables:] |
|
25 |
|
26 [see also:] |
|
27 |
|
28 " |
|
29 ! ! |
|
30 |
|
31 !TSemanticAnalyzer methodsFor:'visiting'! |
|
32 |
|
33 visitArgument: anRBVariableNode |
|
34 | binding | |
|
35 |
|
36 anRBVariableNode parent isSequence ifTrue:[ |
|
37 binding := TLocalBinding type:anRBVariableNode typeSpec asType |
|
38 name:anRBVariableNode name. |
|
39 ] ifFalse:[ |
|
40 binding := TArgumentBinding type:anRBVariableNode typeSpec asType |
|
41 name:anRBVariableNode name. |
|
42 ]. |
|
43 anRBVariableNode parent scope addVariable: binding. |
|
44 super visitArgument: anRBVariableNode. |
|
45 |
|
46 "Created: / 25-08-2015 / 22:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
47 ! ! |
|
48 |
|
49 !TSemanticAnalyzer methodsFor:'visitor-double dispatching'! |
|
50 |
|
51 acceptBlockNode: aBlockNode |
|
52 aBlockNode scope: (aBlockNode parent scope subScope: aBlockNode). |
|
53 super acceptBlockNode: aBlockNode |
|
54 |
|
55 "Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
56 ! |
|
57 |
|
58 acceptLiteralNode: aRBLiteralNode |
|
59 aRBLiteralNode binding: (TConstantBinding value: aRBLiteralNode value). |
|
60 super acceptLiteralNode: aRBLiteralNode |
|
61 |
|
62 "Created: / 25-08-2015 / 23:17:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
63 ! |
|
64 |
|
65 acceptMethodNode: aMethodNode |
|
66 aMethodNode scope: (TScope node: aMethodNode). |
|
67 super acceptMethodNode: aMethodNode |
|
68 |
|
69 "Created: / 25-08-2015 / 22:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
70 ! |
|
71 |
|
72 acceptVariableNode: aVariableNode |
|
73 aVariableNode binding: (aVariableNode scope lookupVariable: aVariableNode name). |
|
74 super acceptVariableNode: aVariableNode |
|
75 |
|
76 "Created: / 25-08-2015 / 23:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
77 ! ! |
|
78 |