author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 09 Apr 2014 09:56:45 +0200 | |
changeset 14192 | 5784c7eaf4a9 |
parent 14055 | d5de1e564e5d |
child 14507 | 10775bc746c4 |
permissions | -rw-r--r-- |
13864 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libtool' }" |
|
13 |
||
14 |
SortedCollection subclass:#ParseTreeIndex |
|
14192 | 15 |
instanceVariableNames:'tree source' |
13864 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-CodeView-Syntax' |
|
19 |
! |
|
20 |
||
21 |
Magnitude subclass:#Element |
|
22 |
instanceVariableNames:'next prev node' |
|
23 |
classVariableNames:'' |
|
24 |
poolDictionaries:'' |
|
25 |
privateIn:ParseTreeIndex |
|
26 |
! |
|
27 |
||
28 |
!ParseTreeIndex class methodsFor:'documentation'! |
|
29 |
||
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
For given parse tree, a ParseTreeIndex provides an |
|
47 |
fast access to individual (leave) nodes by keeping |
|
48 |
an index. Used by CodeView2 for various queries |
|
49 |
||
50 |
Experimental |
|
51 |
||
52 |
[author:] |
|
53 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
54 |
||
55 |
[instance variables:] |
|
56 |
||
57 |
[class variables:] |
|
58 |
||
59 |
[see also:] |
|
60 |
||
61 |
" |
|
62 |
! ! |
|
63 |
||
64 |
!ParseTreeIndex methodsFor:'accessing'! |
|
65 |
||
14192 | 66 |
source |
67 |
^ source |
|
68 |
! |
|
69 |
||
70 |
source:something |
|
71 |
source := something. |
|
72 |
! |
|
73 |
||
13864 | 74 |
tree |
75 |
^ tree |
|
76 |
! |
|
77 |
||
78 |
tree:aParseNode |
|
79 |
tree := aParseNode. |
|
80 |
! ! |
|
81 |
||
82 |
!ParseTreeIndex methodsFor:'utilities'! |
|
83 |
||
84 |
newElementFor: aParseNode |
|
85 |
||
86 |
^(Element new node: aParseNode) |
|
87 |
||
88 |
"Created: / 16-02-2012 / 21:00:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
89 |
! ! |
|
90 |
||
91 |
!ParseTreeIndex::Element class methodsFor:'documentation'! |
|
92 |
||
93 |
copyright |
|
94 |
" |
|
95 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
|
96 |
All Rights Reserved |
|
97 |
||
98 |
Permission is hereby granted, free of charge, to any person |
|
99 |
obtaining a copy of this software and associated documentation |
|
100 |
files (the 'Software'), to deal in the Software without |
|
101 |
restriction, including without limitation the rights to use, |
|
102 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
103 |
copies of the Software, and to permit persons to whom the |
|
104 |
Software is furnished to do so, subject to the following |
|
105 |
conditions: |
|
106 |
||
107 |
The above copyright notice and this permission notice shall be |
|
108 |
included in all copies or substantial portions of the Software. |
|
109 |
||
110 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
111 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
112 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
113 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
114 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
115 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
116 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
117 |
OTHER DEALINGS IN THE SOFTWARE. |
|
118 |
" |
|
119 |
! ! |
|
120 |
||
121 |
!ParseTreeIndex::Element methodsFor:'accessing'! |
|
122 |
||
123 |
assigned |
|
14055
d5de1e564e5d
Fixed ParseTreeIndex::Element
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13940
diff
changeset
|
124 |
| p | |
d5de1e564e5d
Fixed ParseTreeIndex::Element
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13940
diff
changeset
|
125 |
|
d5de1e564e5d
Fixed ParseTreeIndex::Element
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13940
diff
changeset
|
126 |
^ node isVariableNode |
d5de1e564e5d
Fixed ParseTreeIndex::Element
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13940
diff
changeset
|
127 |
and:[(p := node parent) notNil |
d5de1e564e5d
Fixed ParseTreeIndex::Element
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13940
diff
changeset
|
128 |
and:[p isAssignment |
d5de1e564e5d
Fixed ParseTreeIndex::Element
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13940
diff
changeset
|
129 |
and:[p variable == node]]]. |
13864 | 130 |
|
131 |
"Created: / 01-07-2013 / 21:53:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14055
d5de1e564e5d
Fixed ParseTreeIndex::Element
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13940
diff
changeset
|
132 |
"Modified: / 25-02-2014 / 20:52:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13864 | 133 |
! |
134 |
||
135 |
firstElementInChain |
|
136 |
|first prev| |
|
137 |
||
138 |
first := self. |
|
139 |
[ (prev := first previousElement) notNil ] whileTrue:[ |
|
140 |
first := prev. |
|
141 |
]. |
|
142 |
^ first |
|
143 |
||
144 |
"Created: / 21-08-2011 / 09:51:35 / cg" |
|
145 |
! |
|
146 |
||
147 |
name |
|
148 |
^node isVariable ifTrue:[node name] ifFalse:[nil] |
|
149 |
||
150 |
"Created: / 01-07-2013 / 21:56:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
151 |
! |
|
152 |
||
153 |
next |
|
154 |
^ next |
|
155 |
! |
|
156 |
||
157 |
next:aSyntaxElement |
|
158 |
next := aSyntaxElement. |
|
159 |
next prev: self. |
|
160 |
||
161 |
"Modified: / 14-02-2010 / 17:44:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
162 |
! |
|
163 |
||
164 |
nextElement |
|
165 |
^ next |
|
166 |
||
167 |
"Created: / 21-08-2011 / 09:47:11 / cg" |
|
168 |
! |
|
169 |
||
170 |
nextElement:aSyntaxElement |
|
171 |
next := aSyntaxElement. |
|
172 |
next prev: self. |
|
173 |
||
174 |
"Modified: / 14-02-2010 / 17:44:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
175 |
"Created: / 21-08-2011 / 09:47:15 / cg" |
|
176 |
! |
|
177 |
||
178 |
node |
|
179 |
^ node |
|
180 |
! |
|
181 |
||
182 |
node:something |
|
183 |
node := something. |
|
184 |
! |
|
185 |
||
186 |
prev |
|
187 |
^ prev |
|
188 |
! |
|
189 |
||
190 |
prev:aSyntaxElement |
|
191 |
prev := aSyntaxElement. |
|
192 |
! |
|
193 |
||
194 |
previousElement |
|
195 |
^ prev |
|
196 |
||
197 |
"Created: / 21-08-2011 / 09:47:23 / cg" |
|
198 |
! |
|
199 |
||
200 |
previousElement:aSyntaxElement |
|
201 |
prev := aSyntaxElement. |
|
202 |
||
203 |
"Created: / 21-08-2011 / 09:47:28 / cg" |
|
204 |
! |
|
205 |
||
206 |
start |
|
207 |
^ node startPosition |
|
208 |
||
209 |
"Modified: / 16-02-2012 / 20:56:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
210 |
! |
|
211 |
||
212 |
stop |
|
213 |
^ node endPosition |
|
214 |
||
215 |
"Modified: / 16-02-2012 / 20:56:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
216 |
! ! |
|
217 |
||
218 |
!ParseTreeIndex::Element methodsFor:'comparing'! |
|
219 |
||
220 |
< anObject |
|
221 |
||
222 |
anObject isNumber ifTrue:[^self stop < anObject]. |
|
223 |
anObject class == self class ifFalse:[^false]. |
|
224 |
||
225 |
^self stop < anObject start |
|
226 |
||
227 |
"Created: / 14-02-2010 / 13:39:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
228 |
! |
|
229 |
||
230 |
= anObject |
|
231 |
||
232 |
anObject class == self class ifFalse:[^false]. |
|
233 |
||
234 |
^self start == (anObject start) and: |
|
235 |
[self stop == (anObject stop) and: |
|
236 |
[self node class == (anObject node class)]]. |
|
237 |
||
238 |
"Created: / 14-02-2010 / 13:33:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
239 |
! |
|
240 |
||
241 |
hash |
|
242 |
||
243 |
^self start hash bitXor:[self stop hash bitXor:[node class hash]]. |
|
244 |
||
245 |
"Created: / 14-02-2010 / 13:30:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
246 |
! ! |
|
247 |
||
248 |
!ParseTreeIndex::Element methodsFor:'double dispatching'! |
|
249 |
||
250 |
lessFromInteger:anInteger |
|
251 |
||
252 |
^self stop < anInteger |
|
253 |
||
254 |
"Created: / 14-02-2010 / 13:49:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
255 |
! ! |
|
256 |
||
257 |
!ParseTreeIndex::Element methodsFor:'printing & storing'! |
|
258 |
||
259 |
printOn:aStream |
|
260 |
"append a printed representation if the receiver to the argument, aStream" |
|
261 |
||
262 |
super printOn:aStream. |
|
263 |
aStream nextPutAll:'('. |
|
264 |
node class name printOn: aStream. |
|
265 |
aStream nextPut:$). |
|
266 |
||
267 |
"Modified: / 21-08-2011 / 09:33:51 / cg" |
|
268 |
"Modified: / 16-02-2012 / 19:23:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
269 |
! ! |
|
270 |
||
271 |
!ParseTreeIndex::Element methodsFor:'testing'! |
|
272 |
||
13940 | 273 |
isGlobal |
274 |
^ node isGlobal |
|
275 |
! |
|
276 |
||
13864 | 277 |
isInstanceVariable |
278 |
^node isVariable and:[node isInstance] |
|
279 |
||
280 |
"Created: / 01-07-2013 / 21:54:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
281 |
! |
|
282 |
||
283 |
isSelector |
|
284 |
^ node class == SelectorNode |
|
285 |
||
286 |
"Created: / 21-08-2011 / 09:09:19 / cg" |
|
287 |
"Modified: / 16-02-2012 / 21:04:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
288 |
! |
|
289 |
||
290 |
isSelf |
|
291 |
^ node isSelf |
|
292 |
||
293 |
"Created: / 21-08-2011 / 09:31:20 / cg" |
|
294 |
"Modified: / 16-02-2012 / 19:25:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
295 |
! |
|
296 |
||
297 |
isVariable |
|
298 |
^ node isVariable |
|
299 |
||
300 |
"Created: / 21-08-2011 / 09:09:00 / cg" |
|
301 |
"Modified: / 16-02-2012 / 19:24:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
302 |
! |
|
303 |
||
304 |
isVariableOrSelf |
|
305 |
^ self isVariable or:[self isSelf] |
|
306 |
||
307 |
"Created: / 21-08-2011 / 09:31:33 / cg" |
|
308 |
! ! |
|
309 |
||
310 |
!ParseTreeIndex class methodsFor:'documentation'! |
|
311 |
||
312 |
version |
|
14192 | 313 |
^ '$Header: /cvs/stx/stx/libtool/ParseTreeIndex.st,v 1.4 2014-04-09 07:56:45 vrany Exp $' |
13864 | 314 |
! |
315 |
||
316 |
version_CVS |
|
14192 | 317 |
^ '$Header: /cvs/stx/stx/libtool/ParseTreeIndex.st,v 1.4 2014-04-09 07:56:45 vrany Exp $' |
13864 | 318 |
! ! |
319 |