author | Claus Gittinger <cg@exept.de> |
Fri, 08 Feb 2019 18:45:32 +0100 | |
changeset 4333 | 06e11aae91bd |
parent 2676 | 2ede084fe2a1 |
child 3841 | a22f33410bdf |
permissions | -rw-r--r-- |
2574 | 1 |
"{ Package: 'stx:libcomp' }" |
2 |
||
2583 | 3 |
ParseNodeVisitor subclass:#ParseNodeValidator |
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
4 |
instanceVariableNames:'stack source' |
2574 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'System-Compiler-Support' |
|
8 |
! |
|
9 |
||
10 |
!ParseNodeValidator class methodsFor:'documentation'! |
|
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
A helper class used to validate parse tree, i.e. parent instvar, |
|
15 |
startPosition/endPositions. Useful only for Parser debugging/hacking. |
|
16 |
||
17 |
[author:] |
|
18 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
19 |
||
20 |
[instance variables:] |
|
21 |
||
22 |
[class variables:] |
|
23 |
||
24 |
[see also:] |
|
25 |
||
26 |
" |
|
27 |
! ! |
|
28 |
||
29 |
!ParseNodeValidator class methodsFor:'validation'! |
|
30 |
||
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
31 |
validate: aParseNode source: source |
2574 | 32 |
|
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
33 |
^self basicNew validate: aParseNode source: source |
2574 | 34 |
|
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
35 |
"Created: / 27-07-2011 / 13:43:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2574 | 36 |
! |
37 |
||
2622
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
38 |
validateClass: cls stopOnError: stopOnError |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
39 |
|
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
40 |
| validate | |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
41 |
|
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
42 |
validate := [:mth| |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
43 |
[ |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
44 |
| src | |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
45 |
src := mth source. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
46 |
self validate: (Parser parseMethod: src) tree source: src. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
47 |
] on: Error do:[:ex| |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
48 |
Transcript |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
49 |
cr; |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
50 |
show: mth printString; |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
51 |
show: '...FAILED!!'; |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
52 |
cr. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
53 |
stopOnError ifTrue:[ |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
54 |
ex pass |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
55 |
]. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
56 |
]. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
57 |
]. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
58 |
cls theMetaclass methodsDo: validate. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
59 |
cls theNonMetaclass methodsDo: validate. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
60 |
|
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
61 |
"Created: / 01-08-2011 / 12:47:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
62 |
! |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
63 |
|
2574 | 64 |
validateImage |
65 |
||
66 |
self validateImage: false. |
|
67 |
||
68 |
"Created: / 20-07-2011 / 20:41:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
69 |
! |
|
70 |
||
71 |
validateImage: stopOnError |
|
72 |
||
2622
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
73 |
| i | |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
74 |
i := 0. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
75 |
|
2574 | 76 |
Smalltalk allClassesDo:[:cls| |
77 |
cls isLoaded ifTrue:[ |
|
2622
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
78 |
i == 50 ifTrue:[ |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
79 |
Transcript cr. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
80 |
i := 0. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
81 |
]. |
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
82 |
i := i + 1. |
2574 | 83 |
Transcript nextPut:$.. |
2622
3a766e3136fa
start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2611
diff
changeset
|
84 |
self validateClass: cls stopOnError: stopOnError |
2574 | 85 |
]. |
86 |
]. |
|
87 |
||
88 |
"Created: / 20-07-2011 / 20:42:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
89 |
! ! |
|
90 |
||
91 |
!ParseNodeValidator methodsFor:'validation'! |
|
92 |
||
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
93 |
validate: tree source: src |
2574 | 94 |
|
2583 | 95 |
tree isNil ifTrue:[^self]. |
96 |
||
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
97 |
source := src. |
2600 | 98 |
stack := Stack with: nil. |
2574 | 99 |
|
2583 | 100 |
^self visit: tree |
2574 | 101 |
|
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
102 |
"Created: / 27-07-2011 / 13:43:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
103 |
! |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
104 |
|
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
105 |
validateNode:node |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
106 |
|
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
107 |
self assert: node startPosition isInteger. |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
108 |
self assert: node endPosition isInteger. |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
109 |
self assert: node parent == stack top |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
110 |
|
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
111 |
"Modified: / 27-07-2011 / 13:47:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2574 | 112 |
! ! |
113 |
||
2600 | 114 |
!ParseNodeValidator methodsFor:'visiting'! |
115 |
||
116 |
visit:anObject |
|
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
117 |
|accept stmt| |
2600 | 118 |
|
2611
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
119 |
accept := |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
120 |
[:node | |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
121 |
stack push:node. |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
122 |
node acceptVisitor:self. |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
123 |
stack pop. |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
124 |
self validateNode:node. ]. |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
125 |
^ anObject isStatementNode |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
126 |
ifTrue: |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
127 |
[ stmt := anObject. |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
128 |
[ stmt isNil ] whileFalse: |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
129 |
[ accept value:stmt. |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
130 |
stmt := stmt nextStatement. ] ] |
42a3145f3ff5
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2600
diff
changeset
|
131 |
ifFalse:[ accept value:anObject. ] |
2600 | 132 |
|
133 |
"Created: / 25-07-2011 / 23:14:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2668
7068a6453819
added: #visitVariableNode:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2622
diff
changeset
|
134 |
! |
7068a6453819
added: #visitVariableNode:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2622
diff
changeset
|
135 |
|
2674 | 136 |
visitBlockNode:anObject |
137 |
||
138 |
self assert: (source at: anObject startPosition) == $[. |
|
139 |
self assert: (source at: anObject endPosition) == $]. |
|
140 |
||
141 |
super visitBlockNode: anObject. |
|
142 |
||
143 |
"Modified: / 25-07-2011 / 22:38:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
144 |
"Created: / 20-08-2011 / 23:21:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
145 |
"Created: / 21-08-2011 / 13:52:50 / cg" |
|
146 |
! |
|
147 |
||
2668
7068a6453819
added: #visitVariableNode:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2622
diff
changeset
|
148 |
visitVariableNode:anObject |
7068a6453819
added: #visitVariableNode:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2622
diff
changeset
|
149 |
|
2676
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
150 |
| s e | |
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
151 |
s := anObject startPosition. |
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
152 |
e := anObject endPosition. |
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
153 |
(s ~~ -1 and:[e ~~ -1 and:[ |
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
154 |
#(MethodVariable InstanceVariable) includes: anObject type]]) ifTrue:[ |
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
155 |
self assert: anObject name = |
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
156 |
(source copyFrom: anObject startPosition to: anObject endPosition). |
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
157 |
]. |
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
158 |
|
2668
7068a6453819
added: #visitVariableNode:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2622
diff
changeset
|
159 |
super visitVariableNode: anObject. |
7068a6453819
added: #visitVariableNode:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2622
diff
changeset
|
160 |
|
7068a6453819
added: #visitVariableNode:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2622
diff
changeset
|
161 |
"Created: / 20-08-2011 / 23:21:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2674 | 162 |
"Modified: / 21-08-2011 / 13:51:55 / cg" |
2676
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
163 |
"Modified: / 25-08-2011 / 14:03:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2600 | 164 |
! ! |
165 |
||
2574 | 166 |
!ParseNodeValidator class methodsFor:'documentation'! |
167 |
||
168 |
version |
|
2676
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
169 |
^ '$Header: /cvs/stx/stx/libcomp/ParseNodeValidator.st,v 1.8 2011-08-25 13:38:46 vrany Exp $' |
2574 | 170 |
! |
171 |
||
172 |
version_CVS |
|
2676
2ede084fe2a1
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
173 |
^ '$Header: /cvs/stx/stx/libcomp/ParseNodeValidator.st,v 1.8 2011-08-25 13:38:46 vrany Exp $' |
2574 | 174 |
! ! |