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