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