0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
44
|
3 |
All Rights Reserved
|
0
|
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 |
|
|
13 |
Scanner subclass:#Parser
|
|
14 |
instanceVariableNames:'classToCompileFor selfValue
|
44
|
15 |
contextToEvaluateIn
|
|
16 |
selector
|
|
17 |
methodArgs methodArgNames
|
|
18 |
methodVars methodVarNames
|
|
19 |
tree
|
|
20 |
currentBlock
|
84
|
21 |
parseForCode
|
44
|
22 |
usedInstVars usedClassVars usedVars
|
84
|
23 |
modifiedInstVars modifiedClassVars modifiedGlobals
|
44
|
24 |
usesSuper
|
84
|
25 |
usedGlobals usedSymbols usedMessages
|
44
|
26 |
localVarDefPosition
|
|
27 |
evalExitBlock
|
|
28 |
selfNode superNode
|
97
|
29 |
hasPrimitiveCode primitiveNr primitiveResource
|
53
|
30 |
logged
|
49
|
31 |
warnedUndefVars warnSTXHereExtensionUsed
|
44
|
32 |
correctedSource'
|
10
|
33 |
classVariableNames:'PrevClass PrevInstVarNames
|
44
|
34 |
PrevClassVarNames PrevClassInstVarNames
|
98
|
35 |
LazyCompilation ArraysAreImmutable
|
|
36 |
ImplicitSelfSends'
|
0
|
37 |
poolDictionaries:''
|
|
38 |
category:'System-Compiler'
|
|
39 |
!
|
|
40 |
|
|
41 |
Parser comment:'
|
4
|
42 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
44
|
43 |
All Rights Reserved
|
23
|
44 |
|
98
|
45 |
$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.46 1995-07-23 02:23:59 claus Exp $
|
19
|
46 |
'!
|
|
47 |
|
|
48 |
!Parser class methodsFor:'documentation'!
|
|
49 |
|
20
|
50 |
copyright
|
|
51 |
"
|
|
52 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
44
|
53 |
All Rights Reserved
|
20
|
54 |
|
|
55 |
This software is furnished under a license and may be used
|
|
56 |
only in accordance with the terms of that license and with the
|
|
57 |
inclusion of the above copyright notice. This software may not
|
|
58 |
be provided or otherwise made available to, or used by, any
|
|
59 |
other person. No title to or ownership of the software is
|
|
60 |
hereby transferred.
|
|
61 |
"
|
|
62 |
!
|
|
63 |
|
|
64 |
version
|
|
65 |
"
|
98
|
66 |
$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.46 1995-07-23 02:23:59 claus Exp $
|
20
|
67 |
"
|
|
68 |
!
|
|
69 |
|
19
|
70 |
documentation
|
|
71 |
"
|
|
72 |
Parser is used for both parsing and evaluating smalltalk expressions;
|
|
73 |
it first builds a parseTree which is then interpreted (evaluate) or
|
|
74 |
compiled. Compilation is done in the subclass ByteCodeCompiler and/or
|
|
75 |
the (planned) MachineCodeCompiler.
|
|
76 |
|
|
77 |
methods of main interrest are:
|
44
|
78 |
Parser evaluateExpression:...
|
19
|
79 |
|
|
80 |
and:
|
44
|
81 |
Parser parseExpression:...
|
|
82 |
Parser parseMethod:...
|
19
|
83 |
|
|
84 |
there is protocol to parse complete methods, selector specs, body only etc.
|
|
85 |
|
|
86 |
Parser is also used to find the referenced/modified inst/classvars of
|
|
87 |
a method - this is done by sending parseXXX message to a parser and asking
|
|
88 |
the parser for referencedXVars or modifiedXVars (see SystemBrowser).
|
|
89 |
|
|
90 |
You can also use parsers for all kinds of other things (ChangesBrowser for
|
|
91 |
example analyzes the expressions in the changelist ...) by looking at the
|
|
92 |
parsers tree. (Although this is somewhat dangerous, since it exports the
|
20
|
93 |
compilers internals ... better style is to add specialized query methods here,
|
|
94 |
which will be done incrementally.)
|
19
|
95 |
|
|
96 |
One instance of Parser is created to parse one method or expression - i.e.
|
|
97 |
its not suggested to reuse parsers.
|
|
98 |
|
|
99 |
Instance variables:
|
|
100 |
|
44
|
101 |
classToCompileFor <Class> the class (or nil) we are compiling for
|
19
|
102 |
|
44
|
103 |
selfValue <any> value to use as self when interpreting
|
19
|
104 |
|
44
|
105 |
contextToEvaluateIn <Context> the context (or nil) when interpreting
|
19
|
106 |
|
44
|
107 |
selector <Symbol> the selector of the parsed method
|
|
108 |
(valid after parseMethodSpecification)
|
|
109 |
methodArgs internal
|
19
|
110 |
|
44
|
111 |
methodArgNames <Collection> the names of the arguments
|
|
112 |
(valid after parseMethodSpecification)
|
19
|
113 |
|
44
|
114 |
methodVars internal
|
0
|
115 |
|
44
|
116 |
methodVarNames <Collection> the names of the method locals
|
|
117 |
(valid after parseMethodBodyVarSpec)
|
19
|
118 |
|
44
|
119 |
tree <ParseTree> the parse tree - valid after parsing
|
19
|
120 |
|
44
|
121 |
currentBlock if currently parsing for a block
|
19
|
122 |
|
44
|
123 |
usedInstVars set of all accessed instances variables
|
|
124 |
(valid after parsing)
|
19
|
125 |
|
44
|
126 |
usedClassVars same for classVars
|
19
|
127 |
|
44
|
128 |
usedVars all used variables (inst, class & globals)
|
19
|
129 |
|
44
|
130 |
modifiedInstVars set of all modified instance variables
|
19
|
131 |
|
44
|
132 |
modifiedClassVars same for clasVars
|
19
|
133 |
|
44
|
134 |
localVarDefPosition <Integer> the character offset of the local variable
|
|
135 |
def. (i.e. the first '|' if any)
|
|
136 |
Not yet used - prepared for automatic add of
|
|
137 |
undefined variables
|
19
|
138 |
|
44
|
139 |
evalExitBlock internal for interpretation
|
0
|
140 |
|
44
|
141 |
selfNode <Node> cached one-and-only 'self' node
|
|
142 |
superNode <Node> cached one-and-only 'super' node
|
19
|
143 |
|
44
|
144 |
hasPrimitiveCode <Boolean> true, if it contains ST/X style primitive code
|
19
|
145 |
|
44
|
146 |
primitiveNr <Integer> the parsed ST-80 type primitive number (or nil)
|
19
|
147 |
|
44
|
148 |
logged
|
19
|
149 |
|
44
|
150 |
warnedUndefVars <Set> set of all variables which the parser has
|
|
151 |
already output a warning (to avoid multiple
|
|
152 |
warnings about the same variable)
|
19
|
153 |
|
|
154 |
Class variables:
|
|
155 |
|
44
|
156 |
PrevClass <Class> class, of which properties are
|
|
157 |
cached in:
|
19
|
158 |
|
44
|
159 |
PrevInstVarNames <Collection> instance variablenames of cached class
|
|
160 |
PrevClassVarNames <Collection> class variablenames of cached class
|
|
161 |
PrevClassInstVarNames <Collection> class instance variablenames of cached class
|
19
|
162 |
|
66
|
163 |
LazyCompilation <Boolean> EXPERIMENTAL: lazy compilation
|
|
164 |
|
|
165 |
ArraysAreImmutable <Boolean> if true, create array literals
|
|
166 |
as instances of ImmutableArray,
|
|
167 |
which cannot be stored into.
|
|
168 |
Default is false, for compatibility.
|
|
169 |
Can be turned on while developping
|
|
170 |
new code to make certain that side
|
|
171 |
effects are avoided.
|
19
|
172 |
"
|
|
173 |
! !
|
0
|
174 |
|
|
175 |
!Parser class methodsFor:'evaluating expressions'!
|
|
176 |
|
19
|
177 |
evaluate:aStringOrStream
|
71
|
178 |
"return the result of evaluating an expression in aStringOrStream.
|
|
179 |
No doit-entry is added to the changeLog."
|
0
|
180 |
|
19
|
181 |
^ self
|
44
|
182 |
evaluate:aStringOrStream
|
|
183 |
in:nil
|
|
184 |
receiver:nil
|
|
185 |
notifying:nil
|
|
186 |
logged:false
|
|
187 |
ifFail:nil
|
71
|
188 |
compile:true
|
19
|
189 |
|
|
190 |
"
|
|
191 |
Compiler evaluate:'1 + 2'
|
|
192 |
Compiler evaluate:'''hello world'' asSortedCollection displayString printNL'
|
|
193 |
Compiler evaluate:'''hello world'' asSortedCollection printNL'
|
|
194 |
"
|
0
|
195 |
!
|
|
196 |
|
71
|
197 |
evaluate:aStringOrStream compile:compile
|
|
198 |
"return the result of evaluating aString,
|
|
199 |
The compile argument specifies if the string should be compiled down to
|
|
200 |
bytecode or instead be interpreted from the parseTree.
|
|
201 |
The first should be done for doIts etc, where a readable walkback is
|
|
202 |
required.
|
|
203 |
The latter is better done for constants, styleSheet and resource
|
|
204 |
reading and simple sends, where the overhead of compilation is bigger
|
|
205 |
than the interpretation overhead."
|
|
206 |
|
|
207 |
^ self
|
|
208 |
evaluate:aStringOrStream
|
|
209 |
in:nil
|
|
210 |
receiver:nil
|
|
211 |
notifying:nil
|
|
212 |
logged:false
|
|
213 |
ifFail:nil
|
|
214 |
compile:compile
|
|
215 |
!
|
|
216 |
|
20
|
217 |
evaluate:aStringOrStream ifFail:failBlock
|
|
218 |
"return the result of evaluating an expression in aStringOrStream.
|
71
|
219 |
In case of any syntax errors, return the value of failBlock.
|
|
220 |
No doit-entry is added to the changeLog."
|
20
|
221 |
|
|
222 |
^ self
|
44
|
223 |
evaluate:aStringOrStream
|
|
224 |
in:nil
|
|
225 |
receiver:nil
|
|
226 |
notifying:nil
|
|
227 |
logged:false
|
|
228 |
ifFail:failBlock
|
71
|
229 |
compile:true
|
20
|
230 |
"
|
|
231 |
Compiler evaluate:'1 +' ifFail:['oops']
|
|
232 |
"
|
|
233 |
!
|
|
234 |
|
|
235 |
evaluate:aStringOrStream logged:logged
|
71
|
236 |
"return the result of evaluating an expression in aStringOrStream.
|
|
237 |
The argument log controls if an entry is added to the changeLog."
|
20
|
238 |
|
|
239 |
^ self
|
44
|
240 |
evaluate:aStringOrStream
|
|
241 |
in:nil
|
|
242 |
receiver:nil
|
|
243 |
notifying:nil
|
|
244 |
logged:logged
|
|
245 |
ifFail:nil
|
71
|
246 |
compile:true
|
|
247 |
"
|
|
248 |
Compiler evaluate:'''some string''' logged:false
|
|
249 |
Compiler evaluate:'''some string''' logged:true
|
|
250 |
"
|
20
|
251 |
!
|
|
252 |
|
0
|
253 |
evaluate:aStringOrStream notifying:requestor
|
|
254 |
"return the result of evaluating aString,
|
|
255 |
errors are reported to requestor"
|
|
256 |
|
19
|
257 |
^ self
|
44
|
258 |
evaluate:aStringOrStream
|
|
259 |
in:nil
|
|
260 |
receiver:nil
|
|
261 |
notifying:requestor
|
|
262 |
logged:false
|
|
263 |
ifFail:nil
|
71
|
264 |
compile:true
|
|
265 |
!
|
|
266 |
|
|
267 |
evaluate:aStringOrStream notifying:requestor compile:compile
|
|
268 |
"return the result of evaluating aString,
|
|
269 |
errors are reported to requestor.
|
|
270 |
The compile argument specifies if the string should be compiled down to
|
|
271 |
bytecode or instead be interpreted from the parseTree.
|
|
272 |
The first should be done for doIts etc, where a readable walkback is
|
|
273 |
required.
|
|
274 |
The latter is better done for constants, styleSheet and resource
|
|
275 |
reading and simple sends, where the overhead of compilation is bigger
|
|
276 |
than the interpretation overhead."
|
|
277 |
|
|
278 |
^ self
|
|
279 |
evaluate:aStringOrStream
|
|
280 |
in:nil
|
|
281 |
receiver:nil
|
|
282 |
notifying:requestor
|
|
283 |
logged:false
|
|
284 |
ifFail:nil
|
|
285 |
compile:compile
|
0
|
286 |
!
|
|
287 |
|
20
|
288 |
evaluate:aStringOrStream receiver:anObject notifying:requestor
|
0
|
289 |
"return the result of evaluating aString,
|
|
290 |
errors are reported to requestor. Allow access to
|
|
291 |
anObject as self and to its instVars (used in the inspector)"
|
|
292 |
|
19
|
293 |
^ self
|
44
|
294 |
evaluate:aStringOrStream
|
|
295 |
in:nil
|
|
296 |
receiver:anObject
|
|
297 |
notifying:requestor
|
|
298 |
logged:false
|
|
299 |
ifFail:nil
|
71
|
300 |
compile:true
|
|
301 |
|
|
302 |
"
|
|
303 |
Compiler evaluate:'self x' receiver:(1 @ 2) notifying:nil
|
|
304 |
"
|
0
|
305 |
!
|
|
306 |
|
71
|
307 |
evaluate:aStringOrStream receiver:anObject notifying:requestor compile:compile
|
|
308 |
"return the result of evaluating aString,
|
|
309 |
errors are reported to requestor. Allow access to
|
|
310 |
anObject as self and to its instVars (used in the inspector).
|
|
311 |
The compile argument specifies if the string should be compiled down to
|
|
312 |
bytecode or instead be interpreted from the parseTree.
|
|
313 |
The first should be done for doIts etc, where a readable walkback is
|
|
314 |
required.
|
|
315 |
The latter is better done for constants, styleSheet and resource
|
|
316 |
reading and simple sends, where the overhead of compilation is bigger
|
|
317 |
than the interpretation overhead."
|
|
318 |
|
20
|
319 |
^ self
|
44
|
320 |
evaluate:aStringOrStream
|
|
321 |
in:nil
|
|
322 |
receiver:anObject
|
|
323 |
notifying:requestor
|
|
324 |
logged:false
|
|
325 |
ifFail:nil
|
71
|
326 |
compile:compile
|
|
327 |
!
|
|
328 |
|
|
329 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor ifFail:failBlock
|
|
330 |
"return the result of evaluating aStringOrStream, errors are reported to requestor.
|
|
331 |
Allow access to anObject as self and to its instVars (used in the inspector).
|
|
332 |
No doIt entry is added to the change-file.
|
|
333 |
If the failBlock argument is non-nil, it is evaluated if an error occurs."
|
|
334 |
|
|
335 |
^ self
|
|
336 |
evaluate:aStringOrStream
|
|
337 |
in:nil
|
|
338 |
receiver:anObject
|
|
339 |
notifying:requestor
|
|
340 |
logged:false
|
|
341 |
ifFail:nil
|
|
342 |
compile:true
|
20
|
343 |
!
|
|
344 |
|
|
345 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock
|
|
346 |
"return the result of evaluating aStringOrStream, errors are reported to requestor.
|
|
347 |
Allow access to anObject as self and to its instVars (used in the inspector).
|
|
348 |
If logged is true, an entry is added to the change-file. If the failBlock argument
|
|
349 |
is non-nil, it is evaluated if an error occurs."
|
|
350 |
|
71
|
351 |
^ self
|
|
352 |
evaluate:aStringOrStream
|
|
353 |
in:aContext
|
|
354 |
receiver:anObject
|
|
355 |
notifying:requestor
|
|
356 |
logged:logged
|
|
357 |
ifFail:failBlock
|
|
358 |
compile:true
|
|
359 |
!
|
|
360 |
|
|
361 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile
|
|
362 |
"return the result of evaluating aStringOrStream, errors are reported to requestor.
|
|
363 |
Allow access to anObject as self and to its instVars (used in the inspector).
|
|
364 |
If logged is true, an entry is added to the change-file. If the failBlock argument
|
|
365 |
is non-nil, it is evaluated if an error occurs.
|
|
366 |
Finally, compile specifies if the string should be compiled down to
|
|
367 |
bytecode or instead be interpreted from the parseTree.
|
|
368 |
The first should be done for doIts etc, where a readable walkback is
|
|
369 |
required.
|
|
370 |
The latter is better done for constants, styleSheet and resource
|
|
371 |
reading and simple sends, where the overhead of compilation is bigger
|
|
372 |
than the interpretation overhead."
|
|
373 |
|
52
|
374 |
|parser tree mustBackup loggedString chgStream value s sReal m|
|
0
|
375 |
|
|
376 |
aStringOrStream isNil ifTrue:[^ nil].
|
|
377 |
aStringOrStream isStream ifTrue:[
|
44
|
378 |
parser := self for:aStringOrStream.
|
|
379 |
mustBackup := true
|
0
|
380 |
] ifFalse:[
|
44
|
381 |
loggedString := aStringOrStream.
|
|
382 |
parser := self for:(ReadStream on:aStringOrStream).
|
|
383 |
mustBackup := false
|
0
|
384 |
].
|
84
|
385 |
parser parseForCode.
|
0
|
386 |
parser setSelf:anObject.
|
|
387 |
parser setContext:aContext.
|
|
388 |
parser notifying:requestor.
|
|
389 |
parser nextToken.
|
79
|
390 |
tree := parser parseMethodBodyOrEmpty.
|
0
|
391 |
|
|
392 |
"if reading from a stream, backup for next expression"
|
|
393 |
mustBackup ifTrue:[
|
44
|
394 |
parser backupPosition
|
0
|
395 |
].
|
|
396 |
|
|
397 |
(parser errorFlag or:[tree == #Error]) ifTrue:[
|
44
|
398 |
failBlock notNil ifTrue:[
|
|
399 |
^ failBlock value
|
|
400 |
].
|
|
401 |
^ #Error
|
0
|
402 |
].
|
|
403 |
tree notNil ifTrue:[
|
44
|
404 |
(logged
|
|
405 |
and:[loggedString notNil
|
|
406 |
and:[Smalltalk logDoits]]) ifTrue:[
|
|
407 |
chgStream := Class changesStream.
|
|
408 |
chgStream notNil ifTrue:[
|
|
409 |
chgStream nextChunkPut:loggedString.
|
|
410 |
chgStream cr.
|
|
411 |
chgStream close
|
|
412 |
].
|
|
413 |
].
|
35
|
414 |
|
49
|
415 |
"
|
71
|
416 |
if compile is false, or the parse tree is that of a constant,
|
|
417 |
quickly return its value.
|
|
418 |
This is used for example, when reading simple objects
|
|
419 |
via #readFrom:.
|
|
420 |
The overhead of compiling a method is avoided in this case.
|
49
|
421 |
"
|
76
|
422 |
(compile not
|
|
423 |
or:[tree isConstant
|
|
424 |
or:[aStringOrStream isStream]]) ifTrue:[
|
49
|
425 |
^ tree evaluate
|
|
426 |
] ifFalse:[
|
|
427 |
"
|
|
428 |
if I am the ByteCodeCompiler,
|
|
429 |
generate a dummy method, execute it and return the value.
|
52
|
430 |
otherwise, just evaluate the tree; slower, but not too bad ...
|
|
431 |
This allows systems to be delivered without the ByteCodeCompiler,
|
|
432 |
and still evaluate expressions (neede for example, to read resource
|
53
|
433 |
files or to process .rc files).
|
49
|
434 |
"
|
52
|
435 |
self == Parser ifTrue:[
|
49
|
436 |
parser evalExitBlock:[:value | parser release. ^ value].
|
51
|
437 |
value := tree evaluate.
|
|
438 |
parser evalExitBlock:nil.
|
52
|
439 |
] ifFalse:[
|
|
440 |
aStringOrStream isStream ifTrue:[
|
76
|
441 |
s := parser collectedSource. "/ does not work yet ...
|
52
|
442 |
] ifFalse:[
|
|
443 |
s := aStringOrStream
|
|
444 |
].
|
|
445 |
sReal := 'doIt ^[\' withCRs , s , '\] value' withCRs.
|
87
|
446 |
m := self
|
|
447 |
compile:sReal
|
|
448 |
forClass:anObject class
|
|
449 |
inCategory:'_temporary_'
|
|
450 |
notifying:requestor
|
|
451 |
install:false
|
|
452 |
skipIfSame:false
|
|
453 |
silent:true.
|
52
|
454 |
m notNil ifTrue:[
|
53
|
455 |
m ~~ #Error ifTrue:[
|
|
456 |
"
|
|
457 |
fake: patch the source string, to what the user expects
|
|
458 |
in the browser
|
|
459 |
"
|
|
460 |
m source:' \' withCRs , s .
|
|
461 |
value := m valueWithReceiver:anObject
|
|
462 |
arguments:#()
|
|
463 |
selector:#doIt
|
61
|
464 |
search:nil
|
|
465 |
sender:nil.
|
53
|
466 |
] ifFalse:[
|
|
467 |
parser evalExitBlock:[:value | parser release. ^ value].
|
|
468 |
value := tree evaluate.
|
|
469 |
parser evalExitBlock:nil.
|
|
470 |
]
|
52
|
471 |
].
|
|
472 |
]
|
49
|
473 |
]
|
0
|
474 |
].
|
35
|
475 |
parser release.
|
|
476 |
^ value
|
0
|
477 |
! !
|
|
478 |
|
66
|
479 |
!Parser class methodsFor:'initialization '!
|
|
480 |
|
|
481 |
initialize
|
98
|
482 |
LazyCompilation := false. "/ usually set to true in your .rc file
|
|
483 |
ArraysAreImmutable := false. "/ usually left true for ST-80 compatibility
|
|
484 |
ImplicitSelfSends := false
|
66
|
485 |
! !
|
|
486 |
|
0
|
487 |
!Parser class methodsFor:'instance creation'!
|
|
488 |
|
21
|
489 |
for:aStringOrStream in:aClass
|
|
490 |
"return a new parser, reading code for aClass from aStringOrStream"
|
19
|
491 |
|
0
|
492 |
|parser|
|
|
493 |
|
21
|
494 |
parser := self for:aStringOrStream.
|
0
|
495 |
parser setClassToCompileFor:aClass.
|
|
496 |
^ parser
|
|
497 |
! !
|
|
498 |
|
|
499 |
!Parser class methodsFor:'parsing'!
|
|
500 |
|
7
|
501 |
selectorInExpression:aString
|
47
|
502 |
"parse an expression - return the selector. Even malformed expressions
|
|
503 |
(such as missing receiver or missing arg are parsed.
|
|
504 |
Used for the SystemBrowsers implementors/senders query-box initial text.
|
21
|
505 |
Returns nil if unparsable."
|
7
|
506 |
|
|
507 |
|tree parser|
|
|
508 |
|
|
509 |
(aString isNil or:[aString isEmpty]) ifTrue:[^ nil].
|
|
510 |
|
21
|
511 |
tree := self withSelf:nil
|
44
|
512 |
parseExpression:aString
|
|
513 |
notifying:nil
|
|
514 |
ignoreErrors:true
|
|
515 |
ignoreWarnings:true.
|
21
|
516 |
|
|
517 |
"
|
|
518 |
special: take the expression of the right side, if its an
|
|
519 |
assignment or return
|
|
520 |
"
|
7
|
521 |
(tree notNil and:[tree ~~ #Error]) ifTrue:[
|
44
|
522 |
tree isAssignment ifTrue:[
|
|
523 |
tree expression isMessage ifTrue:[
|
|
524 |
tree := tree expression
|
|
525 |
]
|
|
526 |
].
|
|
527 |
tree isReturnNode ifTrue:[
|
|
528 |
tree expression isMessage ifTrue:[
|
|
529 |
tree := tree expression
|
|
530 |
]
|
|
531 |
].
|
19
|
532 |
|
44
|
533 |
tree isMessage ifTrue:[
|
|
534 |
^ tree selector
|
|
535 |
].
|
7
|
536 |
].
|
|
537 |
|
21
|
538 |
"
|
|
539 |
mhmh, try expression without receiver
|
|
540 |
"
|
7
|
541 |
parser := self for:(ReadStream on:aString).
|
|
542 |
parser ignoreErrors.
|
|
543 |
parser nextToken.
|
|
544 |
^ parser degeneratedKeywordExpressionForSelector
|
|
545 |
|
|
546 |
"
|
20
|
547 |
Parser selectorInExpression:'foo at:1 put:(5 * bar)'
|
|
548 |
Parser selectorInExpression:'(foo at:1) at:1'
|
47
|
549 |
Parser selectorInExpression:'a + 4'
|
|
550 |
Parser selectorInExpression:'a negated'
|
20
|
551 |
Parser selectorInExpression:'at:1 put:5'
|
47
|
552 |
Parser selectorInExpression:'at:1 put:'
|
|
553 |
Parser selectorInExpression:'a at:1 put:5'
|
|
554 |
Parser selectorInExpression:'a at:1 put:'
|
20
|
555 |
Parser selectorInExpression:'a := foo at:1 put:5'
|
7
|
556 |
"
|
|
557 |
!
|
|
558 |
|
0
|
559 |
parseExpression:aString
|
21
|
560 |
"parse aString as an expression;
|
|
561 |
Return the parseTree (if ok), nil (for an empty string
|
|
562 |
or comment only) or #Error (syntactic error)."
|
0
|
563 |
|
21
|
564 |
^ self withSelf:nil
|
44
|
565 |
parseExpression:aString
|
|
566 |
notifying:nil
|
|
567 |
ignoreErrors:true "silence on Transcript"
|
|
568 |
ignoreWarnings:true
|
0
|
569 |
!
|
|
570 |
|
7
|
571 |
withSelf:anObject parseExpression:aString notifying:someOne
|
|
572 |
"parse aString as an expression with self set to anObject;
|
21
|
573 |
Return the parseTree (if ok), nil (for an empty string
|
|
574 |
or comment only ) or #Error (syntactic error).
|
|
575 |
|
|
576 |
Errors and warnings are forwarded to someOne (usually some
|
|
577 |
codeView) which can highlight it and show a popup box."
|
7
|
578 |
|
21
|
579 |
^ self withSelf:anObject
|
44
|
580 |
parseExpression:aString
|
|
581 |
notifying:someOne
|
|
582 |
ignoreErrors:false
|
|
583 |
ignoreWarnings:false
|
7
|
584 |
!
|
|
585 |
|
|
586 |
withSelf:anObject parseExpression:aString notifying:someOne ignoreErrors:ignore
|
0
|
587 |
"parse aString as an expression with self set to anObject;
|
21
|
588 |
Return the parseTree (if ok), nil (for an empty string
|
|
589 |
or comment only ) or #Error (syntactic error).
|
|
590 |
|
|
591 |
Errors and warnings are forwarded to someOne (usually some
|
|
592 |
codeView) which can highlight it and show a popup box."
|
|
593 |
|
|
594 |
^ self withSelf:anObject
|
44
|
595 |
parseExpression:aString
|
|
596 |
notifying:someOne
|
|
597 |
ignoreErrors:ignore
|
|
598 |
ignoreWarnings:ignore
|
21
|
599 |
!
|
|
600 |
|
|
601 |
withSelf:anObject parseExpression:aString notifying:someOne ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings
|
|
602 |
"parse aString as an expression with self set to anObject;
|
|
603 |
Return the parseTree (if ok), nil (for an empty string
|
|
604 |
or comment only ) or #Error (syntactic error).
|
|
605 |
|
|
606 |
Errors and warnings are forwarded to someOne (usually some
|
|
607 |
codeView) which can highlight it and show a popup box,
|
|
608 |
iff ignoreErrors/ignoreWarnings is true respectively."
|
0
|
609 |
|
35
|
610 |
|parser tree token|
|
0
|
611 |
|
|
612 |
aString isNil ifTrue:[^ nil].
|
|
613 |
parser := self for:(ReadStream on:aString).
|
|
614 |
parser setSelf:anObject.
|
|
615 |
parser notifying:someOne.
|
21
|
616 |
ignoreErrors ifTrue:[parser ignoreErrors].
|
|
617 |
ignoreWarnings ifTrue:[parser ignoreWarnings].
|
35
|
618 |
token := parser nextToken.
|
|
619 |
(token == $^) ifTrue:[
|
44
|
620 |
parser nextToken.
|
35
|
621 |
].
|
0
|
622 |
tree := parser expression.
|
|
623 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ #Error].
|
|
624 |
^ tree
|
|
625 |
!
|
|
626 |
|
|
627 |
parseMethodSpecification:aString
|
|
628 |
"parse a methods selector & arg specification;
|
21
|
629 |
Return a parser (if ok), nil (empty) or #Error (syntax).
|
|
630 |
The parser can be queried for selector, receiver etc."
|
0
|
631 |
|
|
632 |
^ self parseMethodSpecification:aString in:nil
|
20
|
633 |
|
|
634 |
"
|
|
635 |
|p|
|
|
636 |
|
|
637 |
p := Parser parseMethodSpecification:'foo:arg1 bar:arg2 baz:arg3'.
|
|
638 |
'nArgs: ' print. p numberOfMethodArgs printNL.
|
|
639 |
'args: ' print. p methodArgs printNL.
|
|
640 |
'sel: ' print. p selector printNL
|
|
641 |
"
|
0
|
642 |
!
|
|
643 |
|
|
644 |
parseMethodSpecification:aString in:aClass
|
|
645 |
"parse a methods selector & arg spec for a given class;
|
21
|
646 |
Return a parser (if ok), nil (empty) or #Error (syntax).
|
|
647 |
The parser can be queried for selector, receiver etc."
|
0
|
648 |
|
35
|
649 |
^ self parseMethodSpecification:aString
|
44
|
650 |
in:aClass
|
|
651 |
ignoreErrors:false
|
|
652 |
ignoreWarnings:false
|
35
|
653 |
!
|
|
654 |
|
|
655 |
parseMethodSpecification:aString in:aClass ignoreErrors:noErrors ignoreWarnings:noWarnings
|
|
656 |
"parse a methods selector & arg spec for a given class;
|
|
657 |
Return a parser (if ok), nil (empty) or #Error (syntax).
|
|
658 |
The parser can be queried for selector, receiver etc.
|
|
659 |
noErrors and noWarnings specify if error- and warningMessages are
|
|
660 |
to be output onto the Transcript."
|
|
661 |
|
0
|
662 |
|parser tree|
|
|
663 |
|
|
664 |
aString isNil ifTrue:[^ nil].
|
|
665 |
parser := self for:(ReadStream on:aString) in:aClass.
|
35
|
666 |
noErrors ifTrue:[
|
44
|
667 |
parser ignoreErrors
|
35
|
668 |
].
|
|
669 |
noWarnings ifTrue:[
|
44
|
670 |
parser ignoreWarnings
|
35
|
671 |
].
|
0
|
672 |
parser nextToken.
|
|
673 |
tree := parser parseMethodSpec.
|
|
674 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ #Error].
|
|
675 |
^ parser
|
|
676 |
!
|
|
677 |
|
|
678 |
parseMethodArgAndVarSpecification:aString
|
21
|
679 |
"parse a methods selector, arg and var spec (i.e. locals);
|
|
680 |
Return a parser (if ok), nil (empty) or #Error (syntax).
|
|
681 |
The parser can be queried for selector, receiver etc."
|
0
|
682 |
|
|
683 |
^ self parseMethodArgAndVarSpecification:aString in:nil
|
20
|
684 |
|
|
685 |
"
|
|
686 |
|p|
|
|
687 |
|
21
|
688 |
p := Parser
|
44
|
689 |
parseMethodArgAndVarSpecification:'
|
|
690 |
foo:arg1 bar:arg2 baz:arg3
|
|
691 |
|l1 l2|'.
|
21
|
692 |
|
20
|
693 |
'nArgs: ' print. p numberOfMethodArgs printNL.
|
|
694 |
'args: ' print. p methodArgs printNL.
|
|
695 |
'sel: ' print. p selector printNL.
|
|
696 |
'nLocal: ' print. p numberOfMethodVars printNL.
|
|
697 |
'locals: ' print. p methodVars printNL.
|
|
698 |
"
|
0
|
699 |
!
|
|
700 |
|
|
701 |
parseMethodArgAndVarSpecification:aString in:aClass
|
21
|
702 |
"parse a methods selector, arg and var spec in a given class;
|
|
703 |
Return a parser (if ok), nil (empty) or #Error (syntax).
|
|
704 |
The parser can be queried for selector, receiver, args and locals"
|
0
|
705 |
|
|
706 |
|parser|
|
|
707 |
|
|
708 |
aString isNil ifTrue:[^ nil].
|
|
709 |
parser := self for:(ReadStream on:aString) in:aClass.
|
|
710 |
parser nextToken.
|
|
711 |
(parser parseMethodSpec == #Error) ifTrue:[^ nil].
|
|
712 |
(parser parseMethodBodyVarSpec == #Error) ifTrue:[^ nil].
|
|
713 |
parser errorFlag ifTrue:[^ nil].
|
|
714 |
^ parser
|
|
715 |
!
|
|
716 |
|
|
717 |
parseMethod:aString
|
21
|
718 |
"parse a method.
|
|
719 |
Return a parser (if ok), nil (empty) or #Error (syntax).
|
|
720 |
The parser can be queried for selector, receiver, args, locals,
|
|
721 |
used selectors etc."
|
0
|
722 |
|
|
723 |
^ self parseMethod:aString in:nil
|
20
|
724 |
|
|
725 |
"
|
|
726 |
|p|
|
|
727 |
|
21
|
728 |
p := Parser
|
44
|
729 |
parseMethod:'
|
|
730 |
foo:arg1 bar:arg2 baz:arg3
|
|
731 |
|l1 l2|
|
|
732 |
l1 := 0.
|
|
733 |
l2 := arg1.
|
|
734 |
^ self'.
|
21
|
735 |
|
20
|
736 |
'nArgs: ' print. p numberOfMethodArgs printNL.
|
|
737 |
'args: ' print. p methodArgs printNL.
|
|
738 |
'sel: ' print. p selector printNL.
|
|
739 |
'nLocal: ' print. p numberOfMethodVars printNL.
|
|
740 |
'locals: ' print. p methodVars printNL.
|
|
741 |
'tree: ' printNL. p tree printAllOn:Stdout. Stdout cr.
|
|
742 |
"
|
0
|
743 |
!
|
|
744 |
|
|
745 |
parseMethod:aString in:aClass
|
21
|
746 |
"parse a method in a given class.
|
|
747 |
Return a parser (if ok), nil (empty) or #Error (syntax).
|
|
748 |
The parser can be queried for selector, receiver, args, locals,
|
|
749 |
used selectors, modified instvars, referenced classvars etc."
|
0
|
750 |
|
50
|
751 |
^ self parseMethod:aString in:aClass warnings:true
|
|
752 |
!
|
|
753 |
|
|
754 |
parseMethod:aString in:aClass warnings:warnBoolean
|
|
755 |
"parse a method in a given class.
|
|
756 |
Return a parser (if ok), nil (empty) or #Error (syntax).
|
|
757 |
The parser can be queried for selector, receiver, args, locals,
|
|
758 |
used selectors, modified instvars, referenced classvars etc."
|
|
759 |
|
0
|
760 |
|parser tree|
|
|
761 |
|
|
762 |
aString isNil ifTrue:[^ nil].
|
|
763 |
parser := self for:(ReadStream on:aString) in:aClass.
|
50
|
764 |
warnBoolean ifFalse:[parser ignoreWarnings].
|
0
|
765 |
tree := parser parseMethod.
|
|
766 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ nil].
|
|
767 |
^ parser
|
|
768 |
! !
|
|
769 |
|
20
|
770 |
!Parser class methodsFor:'unparsing'!
|
|
771 |
|
|
772 |
methodSpecificationForSelector:aSelector
|
|
773 |
"given a selector such as #foo:bar:, return a string that could
|
|
774 |
serve as a methods specification source code.
|
|
775 |
To be used for code generators"
|
|
776 |
|
|
777 |
^ self methodSpecificationForSelector:aSelector
|
44
|
778 |
argNames:#('arg1' 'arg2' 'arg3' 'arg4' 'arg5' 'arg6'
|
|
779 |
'arg7' 'arg8' 'arg9' 'arg10' 'arg11' 'arg12'
|
|
780 |
'arg13' 'arg14' 'arg15')
|
20
|
781 |
"
|
|
782 |
Parser methodSpecificationForSelector:#foo:bar:
|
21
|
783 |
Parser methodSpecificationForSelector:#+
|
20
|
784 |
Parser methodSpecificationForSelector:#negated
|
|
785 |
"
|
|
786 |
!
|
|
787 |
|
|
788 |
methodSpecificationForSelector:aSelector argNames:argNames
|
|
789 |
"given a selector such as #foo:bar:, return a string that could
|
|
790 |
serve as a methods specification source code.
|
|
791 |
To be used for code generators"
|
|
792 |
|
|
793 |
|s nargs parts|
|
|
794 |
|
|
795 |
s := WriteStream on:String new.
|
44
|
796 |
nargs := aSelector numArgs.
|
20
|
797 |
nargs == 0 ifTrue:[
|
44
|
798 |
s nextPutAll:aSelector
|
20
|
799 |
] ifFalse:[
|
44
|
800 |
parts := aSelector partsIfSelector.
|
|
801 |
1 to:nargs do:[:i |
|
|
802 |
s nextPutAll:(parts at:i); space;
|
|
803 |
nextPutAll:(argNames at:i); space.
|
|
804 |
]
|
20
|
805 |
].
|
|
806 |
^ s contents
|
|
807 |
|
|
808 |
"
|
|
809 |
Parser methodSpecificationForSelector:#foo:bar: argNames:#('one' 'two' 'three')
|
|
810 |
Parser methodSpecificationForSelector:#+ argNames:#('one')
|
|
811 |
Parser methodSpecificationForSelector:#negated
|
|
812 |
"
|
|
813 |
! !
|
|
814 |
|
19
|
815 |
!Parser class methodsFor:'controlling compilation'!
|
|
816 |
|
80
|
817 |
compileLazy
|
|
818 |
"return true if compiling lazy"
|
|
819 |
|
|
820 |
^ LazyCompilation.
|
|
821 |
!
|
|
822 |
|
19
|
823 |
compileLazy:aBoolean
|
|
824 |
"turn on/off lazy compilation - return previous setting.
|
|
825 |
Actually this flag belongs into the ByteCodeCompiler subclass,
|
|
826 |
but it also controls the reporting of some errors here; therefore
|
|
827 |
its located here"
|
|
828 |
|
|
829 |
|oldLazy|
|
|
830 |
|
|
831 |
oldLazy := LazyCompilation.
|
|
832 |
LazyCompilation := aBoolean.
|
|
833 |
^ oldLazy
|
|
834 |
|
66
|
835 |
"
|
97
|
836 |
usually set in your .rc file
|
|
837 |
|
66
|
838 |
Compiler compileLazy:false
|
97
|
839 |
Compiler compileLazy:true
|
66
|
840 |
"
|
|
841 |
!
|
|
842 |
|
80
|
843 |
arraysAreImmutable
|
|
844 |
"return true if arrays are immutable literals"
|
|
845 |
|
|
846 |
^ ArraysAreImmutable
|
|
847 |
!
|
|
848 |
|
66
|
849 |
arraysAreImmutable:aBoolean
|
|
850 |
"turn on/off immutable array literals - default is false for ST-80 compatibilty."
|
|
851 |
|
|
852 |
ArraysAreImmutable := aBoolean.
|
|
853 |
|
|
854 |
"
|
97
|
855 |
can be added to your private.rc file:
|
|
856 |
|
|
857 |
Compiler arraysAreImmutable:true
|
66
|
858 |
Compiler arraysAreImmutable:false
|
|
859 |
"
|
98
|
860 |
!
|
|
861 |
|
|
862 |
implicitSelfSends
|
|
863 |
"return true if undefined variables with
|
|
864 |
lowercase first character are to be turned
|
|
865 |
into implicit self sends"
|
|
866 |
|
|
867 |
^ ImplicitSelfSends
|
|
868 |
!
|
|
869 |
|
|
870 |
implicitSelfSends:aBoolean
|
|
871 |
"turn on/off implicit self sends"
|
|
872 |
|
|
873 |
ImplicitSelfSends := aBoolean
|
|
874 |
|
|
875 |
"
|
|
876 |
Compiler implicitSelfSends:true
|
|
877 |
Compiler implicitSelfSends:false
|
|
878 |
"
|
19
|
879 |
! !
|
|
880 |
|
0
|
881 |
!Parser methodsFor:'ST-80 compatibility'!
|
|
882 |
|
|
883 |
evaluate:aString in:aClass to:to notifying:aRequestor ifFail:failBlock
|
35
|
884 |
|parseTree value|
|
0
|
885 |
|
|
886 |
aString isNil ifTrue:[^ nil].
|
|
887 |
self initializeFor:(ReadStream on:aString).
|
|
888 |
self setClassToCompileFor:aClass.
|
|
889 |
selfValue := nil.
|
|
890 |
requestor := aRequestor.
|
|
891 |
|
|
892 |
self nextToken.
|
|
893 |
parseTree := self parseMethodBody.
|
|
894 |
(errorFlag or:[tree == #Error]) ifTrue:[^ #Error].
|
|
895 |
parseTree notNil ifTrue:[
|
44
|
896 |
self evalExitBlock:[:value | ^ failBlock value].
|
|
897 |
value := parseTree evaluate
|
0
|
898 |
].
|
35
|
899 |
self release.
|
|
900 |
^ value
|
0
|
901 |
! !
|
|
902 |
|
|
903 |
!Parser class methodsFor:'changes'!
|
|
904 |
|
44
|
905 |
update:something with:someArgument from:changedObject
|
0
|
906 |
"aClass has changed its definition - flush name caches if we have to"
|
|
907 |
|
44
|
908 |
(changedObject == PrevClass) ifTrue:[
|
|
909 |
something == #definition ifTrue:[
|
|
910 |
self flushNameCache
|
|
911 |
]
|
0
|
912 |
]
|
7
|
913 |
!
|
|
914 |
|
44
|
915 |
flushNameCache
|
7
|
916 |
"unconditional flush name caches"
|
|
917 |
|
10
|
918 |
PrevClass notNil ifTrue:[
|
44
|
919 |
PrevClass removeDependent:Parser
|
7
|
920 |
].
|
10
|
921 |
PrevClass := nil.
|
|
922 |
PrevInstVarNames := nil.
|
|
923 |
PrevClassVarNames := nil.
|
|
924 |
PrevClassInstVarNames := nil.
|
7
|
925 |
|
44
|
926 |
"Parser flushNameCache"
|
0
|
927 |
! !
|
|
928 |
|
|
929 |
!Parser methodsFor:'setup'!
|
|
930 |
|
19
|
931 |
initialize
|
|
932 |
super initialize.
|
|
933 |
|
44
|
934 |
hasPrimitiveCode := false.
|
49
|
935 |
warnSTXHereExtensionUsed := WarnSTXSpecials.
|
84
|
936 |
usesSuper := false.
|
|
937 |
parseForCode := false.
|
|
938 |
!
|
|
939 |
|
|
940 |
parseForCode
|
|
941 |
"turns off certain statistics (keeping referenced variables, modified vars etc.)
|
|
942 |
Use this when parsing for compilation or evaluation"
|
|
943 |
|
|
944 |
parseForCode := true
|
19
|
945 |
!
|
|
946 |
|
0
|
947 |
setClassToCompileFor:aClass
|
|
948 |
"set the class to be used for parsing/evaluating"
|
|
949 |
|
|
950 |
classToCompileFor := aClass.
|
10
|
951 |
(classToCompileFor ~~ PrevClass) ifTrue:[
|
44
|
952 |
PrevClass notNil ifTrue:[
|
|
953 |
Parser update:PrevClass
|
|
954 |
]
|
0
|
955 |
]
|
|
956 |
!
|
|
957 |
|
|
958 |
setSelf:anObject
|
|
959 |
"set the value to be used for self while evaluating"
|
|
960 |
|
|
961 |
selfValue := anObject.
|
|
962 |
classToCompileFor := anObject class.
|
10
|
963 |
(classToCompileFor ~~ PrevClass) ifTrue:[
|
44
|
964 |
PrevClass notNil ifTrue:[
|
|
965 |
Parser update:PrevClass
|
|
966 |
]
|
0
|
967 |
]
|
|
968 |
!
|
|
969 |
|
|
970 |
setContext:aContext
|
|
971 |
"set the context used while evaluating"
|
|
972 |
|
|
973 |
contextToEvaluateIn := aContext
|
|
974 |
! !
|
|
975 |
|
44
|
976 |
!Parser methodsFor:'queries'!
|
0
|
977 |
|
44
|
978 |
usesSuper
|
|
979 |
"return true if the parsed method uses super (valid after parsing)"
|
0
|
980 |
|
44
|
981 |
^ usesSuper
|
0
|
982 |
!
|
|
983 |
|
|
984 |
selector
|
19
|
985 |
"return the selector (valid after parsing spec)"
|
0
|
986 |
|
|
987 |
^ selector
|
|
988 |
!
|
|
989 |
|
|
990 |
numberOfMethodArgs
|
19
|
991 |
"return the number of methodargs (valid after parsing spec)"
|
0
|
992 |
|
|
993 |
^ methodArgs size
|
|
994 |
!
|
|
995 |
|
|
996 |
methodArgs
|
19
|
997 |
"return an array with methodarg names (valid after parsing spec)"
|
0
|
998 |
|
|
999 |
^ methodArgNames
|
|
1000 |
!
|
|
1001 |
|
|
1002 |
numberOfMethodVars
|
19
|
1003 |
"return the number of method variables (valid after parsing)"
|
0
|
1004 |
|
|
1005 |
^ methodVars size
|
|
1006 |
!
|
|
1007 |
|
|
1008 |
methodVars
|
19
|
1009 |
"return a collection with method variablenames (valid after parsing)"
|
0
|
1010 |
|
|
1011 |
^ methodVarNames
|
|
1012 |
!
|
|
1013 |
|
3
|
1014 |
usedVars
|
19
|
1015 |
"return a collection with variablenames refd by method (valid after parsing)"
|
3
|
1016 |
|
|
1017 |
^ usedVars
|
|
1018 |
!
|
|
1019 |
|
0
|
1020 |
usedInstVars
|
19
|
1021 |
"return a collection with instvariablenames refd by method (valid after parsing)"
|
0
|
1022 |
|
|
1023 |
^ usedInstVars
|
|
1024 |
!
|
|
1025 |
|
|
1026 |
usedClassVars
|
19
|
1027 |
"return a collection with classvariablenames refd by method (valid after parsing)"
|
0
|
1028 |
|
|
1029 |
^ usedClassVars
|
|
1030 |
!
|
|
1031 |
|
84
|
1032 |
usedGlobals
|
|
1033 |
"return a collection with globalnames refd by method (valid after parsing)"
|
|
1034 |
|
|
1035 |
^ usedGlobals
|
|
1036 |
!
|
|
1037 |
|
0
|
1038 |
modifiedInstVars
|
19
|
1039 |
"return a collection with instvariablenames modified by method (valid after parsing)"
|
0
|
1040 |
|
|
1041 |
^ modifiedInstVars
|
|
1042 |
!
|
|
1043 |
|
|
1044 |
modifiedClassVars
|
19
|
1045 |
"return a collection with classvariablenames modified by method (valid after parsing)"
|
0
|
1046 |
|
|
1047 |
^ modifiedClassVars
|
|
1048 |
!
|
|
1049 |
|
84
|
1050 |
modifiedGlobals
|
|
1051 |
"return a collection with globalnames modified by method (valid after parsing)"
|
|
1052 |
|
|
1053 |
^ modifiedGlobals
|
|
1054 |
!
|
|
1055 |
|
44
|
1056 |
hasPrimitiveCode
|
|
1057 |
"return true if there was any ST/X style primitive code (valid after parsing)"
|
|
1058 |
|
|
1059 |
^ hasPrimitiveCode
|
47
|
1060 |
!
|
|
1061 |
|
|
1062 |
instVarNames
|
|
1063 |
"caching allInstVarNames for next compilation saves time ..."
|
|
1064 |
|
|
1065 |
(PrevInstVarNames isNil or:[PrevClass ~~ classToCompileFor]) ifTrue:[
|
|
1066 |
PrevClass notNil ifTrue:[
|
|
1067 |
PrevClass removeDependent:Parser
|
|
1068 |
].
|
|
1069 |
PrevClass := classToCompileFor.
|
|
1070 |
PrevInstVarNames := classToCompileFor allInstVarNames.
|
|
1071 |
PrevClassInstVarNames := nil.
|
|
1072 |
PrevClassVarNames := nil.
|
|
1073 |
PrevClass addDependent:Parser
|
|
1074 |
].
|
|
1075 |
|
|
1076 |
^ PrevInstVarNames
|
|
1077 |
!
|
|
1078 |
|
|
1079 |
classInstVarNames
|
|
1080 |
"caching allInstVarNames for next compilation saves time ..."
|
|
1081 |
|
|
1082 |
PrevClassInstVarNames isNil ifTrue:[
|
|
1083 |
PrevClassInstVarNames := classToCompileFor class allInstVarNames
|
|
1084 |
].
|
|
1085 |
^ PrevClassInstVarNames
|
|
1086 |
!
|
|
1087 |
|
|
1088 |
classVarNames
|
|
1089 |
"caching allClassVarNames for next compilation saves time ..."
|
|
1090 |
|
|
1091 |
|aClass className|
|
|
1092 |
|
|
1093 |
PrevClassVarNames isNil ifTrue:[
|
|
1094 |
aClass := classToCompileFor.
|
|
1095 |
classToCompileFor isMeta ifTrue:[
|
|
1096 |
className := aClass name.
|
96
|
1097 |
className := className copyWithoutLast:5.
|
47
|
1098 |
aClass := Smalltalk at:(className asSymbol).
|
|
1099 |
aClass isNil ifTrue:[
|
|
1100 |
aClass := classToCompileFor
|
|
1101 |
]
|
|
1102 |
].
|
|
1103 |
PrevClassVarNames := aClass allClassVarNames
|
|
1104 |
].
|
|
1105 |
^ PrevClassVarNames
|
44
|
1106 |
! !
|
|
1107 |
|
|
1108 |
!Parser methodsFor:'accessing'!
|
|
1109 |
|
|
1110 |
tree
|
|
1111 |
"return the parsetree"
|
|
1112 |
|
|
1113 |
^tree
|
|
1114 |
!
|
|
1115 |
|
|
1116 |
tree:aTree
|
|
1117 |
"private: set the tree - for internal use only"
|
|
1118 |
|
|
1119 |
tree := aTree
|
|
1120 |
!
|
|
1121 |
|
|
1122 |
correctedSource
|
|
1123 |
^ correctedSource
|
|
1124 |
!
|
|
1125 |
|
19
|
1126 |
primitiveNumber
|
|
1127 |
"return the ST-80 style primitiveNumber or nil (valid after parsing)"
|
|
1128 |
|
|
1129 |
^ primitiveNr
|
|
1130 |
!
|
|
1131 |
|
97
|
1132 |
primitiveResource
|
|
1133 |
"return the ST-80 style resource info or nil (valid after parsing)."
|
|
1134 |
|
|
1135 |
^ primitiveResource
|
|
1136 |
!
|
|
1137 |
|
0
|
1138 |
errorFlag
|
19
|
1139 |
"return true if there where any errors (valid after parsing)"
|
|
1140 |
|
0
|
1141 |
^ errorFlag
|
|
1142 |
!
|
|
1143 |
|
|
1144 |
evalExitBlock:aBlock
|
|
1145 |
"when evaluating a return expression, this block is evaluated"
|
|
1146 |
|
|
1147 |
evalExitBlock := aBlock
|
35
|
1148 |
!
|
|
1149 |
|
|
1150 |
release
|
|
1151 |
methodArgs := methodVars := tree := selfNode := superNode := nil.
|
|
1152 |
super release.
|
90
|
1153 |
!
|
|
1154 |
|
|
1155 |
targetClass:aClass
|
|
1156 |
classToCompileFor := aClass
|
0
|
1157 |
! !
|
|
1158 |
|
|
1159 |
!Parser methodsFor:'error handling'!
|
|
1160 |
|
|
1161 |
showErrorMessage:aMessage position:pos
|
19
|
1162 |
"redefined since parser can give more detailed info about
|
|
1163 |
the class & selector where the error occured."
|
|
1164 |
|
71
|
1165 |
|text|
|
|
1166 |
|
19
|
1167 |
ignoreErrors ifFalse:[
|
44
|
1168 |
Smalltalk silentLoading == true ifFalse:[
|
|
1169 |
Transcript show:(pos printString).
|
|
1170 |
Transcript show:' '.
|
|
1171 |
selector notNil ifTrue:[
|
|
1172 |
Transcript show:aMessage.
|
|
1173 |
classToCompileFor notNil ifTrue:[
|
71
|
1174 |
text := ' in ' , classToCompileFor name , '>>' , selector
|
44
|
1175 |
] ifFalse:[
|
71
|
1176 |
text := ' in ' , selector
|
44
|
1177 |
]
|
|
1178 |
] ifFalse:[
|
|
1179 |
classToCompileFor notNil ifTrue:[
|
71
|
1180 |
text := aMessage , ' (' , classToCompileFor name , ')'
|
44
|
1181 |
] ifFalse:[
|
71
|
1182 |
text := aMessage
|
44
|
1183 |
]
|
71
|
1184 |
].
|
|
1185 |
Transcript showCr:text.
|
44
|
1186 |
]
|
0
|
1187 |
]
|
|
1188 |
!
|
|
1189 |
|
|
1190 |
parseError:aMessage position:position to:endPos
|
53
|
1191 |
"report an error"
|
0
|
1192 |
|
|
1193 |
|m|
|
|
1194 |
|
|
1195 |
errorFlag := true.
|
91
|
1196 |
m := 'Error: ' , aMessage.
|
0
|
1197 |
self notifyError:m position:position to:endPos.
|
|
1198 |
exitBlock notNil ifTrue:[exitBlock value].
|
|
1199 |
^ false
|
|
1200 |
!
|
|
1201 |
|
|
1202 |
parseError:aMessage position:position
|
53
|
1203 |
"report an error"
|
0
|
1204 |
|
|
1205 |
^ self parseError:aMessage position:position to:nil
|
|
1206 |
!
|
|
1207 |
|
|
1208 |
parseError:aMessage
|
53
|
1209 |
"report an error"
|
0
|
1210 |
|
|
1211 |
^ self parseError:aMessage position:tokenPosition to:nil
|
|
1212 |
!
|
|
1213 |
|
|
1214 |
correctableError:message position:pos1 to:pos2
|
3
|
1215 |
"report an error which can be corrected by compiler -
|
|
1216 |
return true if correction is wanted"
|
0
|
1217 |
|
|
1218 |
|correctIt|
|
|
1219 |
|
|
1220 |
requestor isNil ifTrue:[
|
44
|
1221 |
self showErrorMessage:message position:pos1.
|
|
1222 |
correctIt := false
|
0
|
1223 |
] ifFalse:[
|
83
|
1224 |
correctIt := requestor correctableError:message position:pos1 to:pos2 from:self
|
0
|
1225 |
].
|
|
1226 |
correctIt ifFalse:[
|
44
|
1227 |
exitBlock notNil ifTrue:[exitBlock value]
|
0
|
1228 |
].
|
|
1229 |
^ correctIt
|
|
1230 |
!
|
|
1231 |
|
|
1232 |
undefError:aName position:pos1 to:pos2
|
3
|
1233 |
"report an undefined variable error - return true, if it should be
|
86
|
1234 |
corrected. If not corrected, only one warning is made per undefined
|
|
1235 |
variable."
|
|
1236 |
|
95
|
1237 |
|doCorrect msg idx|
|
86
|
1238 |
|
|
1239 |
"
|
|
1240 |
alredy warned about this one ?
|
|
1241 |
"
|
|
1242 |
warnedUndefVars notNil ifTrue:[
|
|
1243 |
(warnedUndefVars includes:aName) ifTrue:[
|
|
1244 |
"already warned about this one"
|
|
1245 |
^ false
|
44
|
1246 |
].
|
86
|
1247 |
].
|
|
1248 |
|
|
1249 |
(requestor isNil or:[requestor isStream]) ifTrue:[
|
56
|
1250 |
aName first isUppercase ifFalse:[
|
|
1251 |
self showErrorMessage:('Error: ' , aName , ' is undefined') position:pos1.
|
|
1252 |
].
|
86
|
1253 |
doCorrect := false.
|
|
1254 |
] ifFalse:[
|
|
1255 |
"
|
|
1256 |
ask requestor for correct/continue/abort ...
|
|
1257 |
it is supposed to raise abort or return true/false.
|
|
1258 |
True return means that correction is wanted.
|
|
1259 |
"
|
95
|
1260 |
msg := 'Warning: ' , aName , ' is undefined'.
|
|
1261 |
classToCompileFor notNil ifTrue:[
|
|
1262 |
"is it an instance-variable marked inaccessable ?"
|
|
1263 |
|
|
1264 |
idx := (self instVarNames) indexOf:(aName , '*') startingAt:1.
|
|
1265 |
idx ~~ 0 ifTrue:[
|
|
1266 |
msg := 'Warning: ' , aName , ' is a hidden instvar (not accessable from ST-code)'.
|
|
1267 |
]
|
|
1268 |
].
|
|
1269 |
|
|
1270 |
doCorrect := self correctableError:msg position:pos1 to:pos2
|
86
|
1271 |
].
|
|
1272 |
|
|
1273 |
doCorrect ifFalse:[
|
44
|
1274 |
warnedUndefVars isNil ifTrue:[
|
|
1275 |
warnedUndefVars := Set new.
|
|
1276 |
].
|
|
1277 |
warnedUndefVars add:aName.
|
3
|
1278 |
].
|
0
|
1279 |
|
86
|
1280 |
^ doCorrect
|
0
|
1281 |
!
|
|
1282 |
|
53
|
1283 |
identifierExpectedIn:what
|
|
1284 |
|msg|
|
|
1285 |
|
|
1286 |
(#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[
|
|
1287 |
msg := 'Reserved keyword in '
|
|
1288 |
] ifFalse:[
|
|
1289 |
msg := 'Identifier expected in '
|
|
1290 |
].
|
|
1291 |
self syntaxError:msg , what position:tokenPosition to:source position - 1.
|
|
1292 |
^ #Error
|
|
1293 |
!
|
|
1294 |
|
0
|
1295 |
exitWith:something
|
|
1296 |
"this is the longjump out of evaluation via a return expression"
|
|
1297 |
|
|
1298 |
evalExitBlock value:something
|
|
1299 |
! !
|
|
1300 |
|
|
1301 |
!Parser methodsFor:'parsing'!
|
|
1302 |
|
|
1303 |
parseMethod
|
19
|
1304 |
"parse a method.
|
|
1305 |
Return the parseTree or #Error.
|
|
1306 |
|
|
1307 |
method ::= methodSpec methodBody
|
|
1308 |
"
|
0
|
1309 |
|
|
1310 |
|parseTree|
|
|
1311 |
|
|
1312 |
self nextToken.
|
|
1313 |
(self parseMethodSpec == #Error) ifTrue:[^ #Error].
|
|
1314 |
parseTree := self parseMethodBody.
|
|
1315 |
(parseTree == #Error) ifFalse:[
|
44
|
1316 |
self tree:parseTree
|
0
|
1317 |
].
|
|
1318 |
^ parseTree
|
|
1319 |
!
|
|
1320 |
|
|
1321 |
parseMethodSpec
|
|
1322 |
"parse a methods selector & arg specification;
|
19
|
1323 |
Set selector and methodArgs in the receiver as a side effect.
|
|
1324 |
Return the receiver or #Error.
|
|
1325 |
|
|
1326 |
methodSpec ::= { KEYWORD IDENTIFIER }
|
44
|
1327 |
| binaryOperator IDENTIFIER
|
|
1328 |
| IDENTIFIER
|
19
|
1329 |
"
|
0
|
1330 |
|
|
1331 |
|var|
|
|
1332 |
|
|
1333 |
(tokenType == #Keyword) ifTrue:[
|
44
|
1334 |
selector := ''.
|
|
1335 |
[tokenType == #Keyword] whileTrue:[
|
|
1336 |
selector := selector , tokenName.
|
|
1337 |
self nextToken.
|
|
1338 |
(tokenType ~~ #Identifier) ifTrue:[^ #Error].
|
|
1339 |
var := Variable name:tokenName.
|
|
1340 |
methodArgs isNil ifTrue:[
|
|
1341 |
methodArgs := Array with:var.
|
|
1342 |
methodArgNames := Array with:tokenName
|
|
1343 |
] ifFalse:[
|
|
1344 |
(methodArgNames includes:tokenName) ifTrue:[
|
|
1345 |
self syntaxError:'redefinition of ''' , tokenName , ''' in argument list.'
|
|
1346 |
position:tokenPosition
|
|
1347 |
to:(tokenPosition + tokenName size - 1)
|
|
1348 |
].
|
|
1349 |
methodArgs := methodArgs copyWith:var.
|
|
1350 |
methodArgNames := methodArgNames copyWith:tokenName
|
|
1351 |
].
|
|
1352 |
self nextToken
|
|
1353 |
].
|
|
1354 |
selector := selector asSymbol.
|
|
1355 |
^ self
|
0
|
1356 |
].
|
|
1357 |
(tokenType == #Identifier) ifTrue:[
|
44
|
1358 |
selector := tokenName asSymbol.
|
|
1359 |
self nextToken.
|
|
1360 |
^ self
|
0
|
1361 |
].
|
|
1362 |
(tokenType == #BinaryOperator) ifTrue:[
|
44
|
1363 |
selector := tokenName asSymbol.
|
|
1364 |
self nextToken.
|
|
1365 |
(tokenType ~~ #Identifier) ifTrue:[^ #Error].
|
|
1366 |
var := Variable name:tokenName.
|
78
|
1367 |
"/ methodArgs isNil ifTrue:[
|
44
|
1368 |
methodArgs := Array with:var.
|
78
|
1369 |
methodArgNames := Array with:tokenName.
|
|
1370 |
"/ ] ifFalse:[
|
|
1371 |
"/ methodArgs := methodArgs copyWith:var.
|
|
1372 |
"/ methodArgNames := methodArgNames copyWith:tokenName
|
|
1373 |
"/ ].
|
44
|
1374 |
self nextToken.
|
|
1375 |
^ self
|
0
|
1376 |
].
|
|
1377 |
^ #Error
|
|
1378 |
!
|
|
1379 |
|
19
|
1380 |
parseMethodBody
|
|
1381 |
"parse a methods body (locals & statements).
|
|
1382 |
No more tokens may follow.
|
|
1383 |
Return a node-tree, or #Error
|
|
1384 |
|
|
1385 |
methodBody ::= '<' st80Primitive '>' #EOF
|
44
|
1386 |
| '<' st80Primitive '>' methodBodyVarSpec statementList #EOF
|
19
|
1387 |
|
|
1388 |
"
|
|
1389 |
|stats|
|
|
1390 |
|
79
|
1391 |
stats := self parseMethodBodyOrEmpty.
|
19
|
1392 |
(stats == #Error) ifFalse:[
|
44
|
1393 |
(tokenType ~~ #EOF) ifTrue:[
|
|
1394 |
"/ just for the nicer error message
|
49
|
1395 |
(#(Self Nil True False Super Here) includes:tokenType) ifTrue:[
|
44
|
1396 |
self parseError:tokenName , ' unexpected (missing ''.'' before ' , tokenName , ' ?)'
|
|
1397 |
position:tokenPosition to:(tokenPosition + tokenName size - 1)
|
|
1398 |
] ifFalse:[
|
|
1399 |
self parseError:(tokenType printString , ' unexpected').
|
|
1400 |
].
|
|
1401 |
^#Error
|
|
1402 |
]
|
19
|
1403 |
].
|
|
1404 |
^ stats
|
|
1405 |
!
|
|
1406 |
|
79
|
1407 |
parseMethodBodyOrEmpty
|
0
|
1408 |
"parse a methods body (locals & statements);
|
19
|
1409 |
return a node-tree, nil or #Error.
|
|
1410 |
empty (or comment only) input is accepted and returns nil.
|
|
1411 |
|
|
1412 |
methodBodyOrNil ::= '<' st80Primitive '>'
|
44
|
1413 |
| '<' st80Primitive '>' methodBodyVarSpec statementList
|
|
1414 |
| <empty>
|
19
|
1415 |
"
|
0
|
1416 |
|
71
|
1417 |
|stats pos wmsg|
|
0
|
1418 |
|
|
1419 |
((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[
|
44
|
1420 |
"an ST-80 primitive - parsed but ignored"
|
71
|
1421 |
pos := tokenPosition.
|
44
|
1422 |
self nextToken.
|
|
1423 |
primitiveNr := self parseST80Primitive.
|
|
1424 |
(primitiveNr == #Error) ifTrue:[^ #Error].
|
60
|
1425 |
primitiveNr < 0 ifTrue:[
|
79
|
1426 |
wmsg := 'ST-80 directive ignored'.
|
|
1427 |
primitiveNr := nil.
|
60
|
1428 |
] ifFalse:[
|
78
|
1429 |
wmsg := 'ST-80 primitive may not work'
|
71
|
1430 |
].
|
|
1431 |
self warning:wmsg position:pos
|
0
|
1432 |
].
|
|
1433 |
|
|
1434 |
(self parseMethodBodyVarSpec == #Error) ifTrue:[^ #Error].
|
|
1435 |
|
|
1436 |
(tokenType ~~ #EOF) ifTrue:[
|
44
|
1437 |
stats := self statementList
|
0
|
1438 |
].
|
|
1439 |
^ stats
|
|
1440 |
!
|
|
1441 |
|
19
|
1442 |
parseMethodBodyVarSpec
|
|
1443 |
"parse a methods local variable specification.
|
|
1444 |
Leave spec of locals in methodLocals as a side effect.
|
|
1445 |
Return #Error or nil.
|
0
|
1446 |
|
19
|
1447 |
methodBodyVarSpec ::= '|' { IDENTIFIER } '|'
|
44
|
1448 |
| <empty>
|
19
|
1449 |
"
|
0
|
1450 |
|
53
|
1451 |
|var pos msg|
|
0
|
1452 |
|
|
1453 |
(tokenType == $|) ifTrue:[
|
44
|
1454 |
"memorize position for declaration in correction"
|
|
1455 |
localVarDefPosition := tokenPosition.
|
|
1456 |
self nextToken.
|
53
|
1457 |
pos := tokenPosition.
|
44
|
1458 |
[tokenType == #Identifier] whileTrue:[
|
|
1459 |
var := Variable name:tokenName.
|
|
1460 |
methodVars isNil ifTrue:[
|
|
1461 |
methodVars := Array with:var.
|
|
1462 |
methodVarNames := Array with:tokenName
|
|
1463 |
] ifFalse:[
|
53
|
1464 |
(methodVarNames includes:tokenName) ifTrue:[
|
|
1465 |
self parseError:'redefinition of ''' , tokenName , ''' in local variables'
|
|
1466 |
position:tokenPosition to:tokenPosition + tokenName size -1.
|
|
1467 |
] ifFalse:[
|
|
1468 |
methodVars := methodVars copyWith:var.
|
|
1469 |
methodVarNames := methodVarNames copyWith:tokenName
|
|
1470 |
]
|
44
|
1471 |
].
|
53
|
1472 |
self nextToken.
|
|
1473 |
pos := tokenPosition
|
44
|
1474 |
].
|
|
1475 |
(tokenType ~~ $|) ifTrue:[
|
53
|
1476 |
(#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[
|
|
1477 |
msg := 'Reserved keyword in local var declaration'
|
|
1478 |
] ifFalse:[
|
|
1479 |
msg := 'Identifier or | expected in local var declaration'
|
|
1480 |
].
|
|
1481 |
self syntaxError:msg position:tokenPosition to:source position-1.
|
44
|
1482 |
^ #Error
|
|
1483 |
].
|
|
1484 |
self nextToken
|
0
|
1485 |
].
|
|
1486 |
^ nil
|
|
1487 |
!
|
|
1488 |
|
7
|
1489 |
parseST80Primitive
|
|
1490 |
"parse an ST-80 type primitive as '< primitive: nr >';
|
19
|
1491 |
return primitive number or #Error.
|
97
|
1492 |
Also, ST-80 style resource specs are parsed; the result is
|
|
1493 |
left (as side effect) in primitiveResource.
|
|
1494 |
(maybe someone else knows what to do with it ...)
|
|
1495 |
|
|
1496 |
Well, as we now have this mechanism, I'll use it to mark methods which
|
|
1497 |
do keyboard processing ... <resource: keyboard ( keys )>
|
|
1498 |
For faster finding of used keyboard accelerators.
|
19
|
1499 |
|
|
1500 |
st80Primitive ::= 'primitive:' INTEGER
|
97
|
1501 |
st80Primitive ::= 'resource:' SYMBOL - ignored; leave SYMBOL in primitiveResource
|
|
1502 |
st80Primitive ::= 'resource:' SYMBOL (...) - ignored; leave (SYMBOL (...)) in primitiveResource
|
19
|
1503 |
"
|
0
|
1504 |
|
97
|
1505 |
|primNumber keys|
|
0
|
1506 |
|
60
|
1507 |
(tokenType ~~ #Keyword) ifTrue:[
|
|
1508 |
self parseError:'bad primitive definition (keyword expected)'.
|
44
|
1509 |
^ #Error
|
0
|
1510 |
].
|
60
|
1511 |
(tokenName = 'primitive:') ifTrue:[
|
|
1512 |
self nextToken.
|
|
1513 |
(tokenType == #Integer) ifFalse:[
|
|
1514 |
self parseError:'primitive number expected'.
|
|
1515 |
^ #Error
|
|
1516 |
].
|
|
1517 |
primNumber := tokenValue.
|
97
|
1518 |
self nextToken.
|
60
|
1519 |
] ifFalse:[
|
|
1520 |
(tokenName = 'resource:') ifTrue:[
|
|
1521 |
self nextToken.
|
97
|
1522 |
(tokenType ~~ #Symbol) ifTrue:[
|
60
|
1523 |
self parseError:'symbol expected'.
|
|
1524 |
^ #Error
|
|
1525 |
].
|
|
1526 |
primNumber := -1.
|
97
|
1527 |
primitiveResource := tokenValue.
|
|
1528 |
|
|
1529 |
primitiveResource == #keyboard ifTrue:[
|
|
1530 |
self nextToken.
|
|
1531 |
tokenType == $( ifTrue:[
|
|
1532 |
self nextToken.
|
|
1533 |
keys := OrderedCollection new.
|
|
1534 |
[tokenType == $) ] whileFalse:[
|
|
1535 |
keys add:tokenValue.
|
|
1536 |
self nextToken.
|
|
1537 |
].
|
|
1538 |
primitiveResource := Array with:primitiveResource
|
|
1539 |
with:keys.
|
|
1540 |
self nextToken.
|
|
1541 |
]
|
|
1542 |
] ifFalse:[
|
|
1543 |
self nextToken.
|
|
1544 |
].
|
60
|
1545 |
] ifFalse:[
|
97
|
1546 |
self parseError:'unrecognized primitive'.
|
60
|
1547 |
^ #Error
|
|
1548 |
].
|
0
|
1549 |
].
|
97
|
1550 |
|
0
|
1551 |
((tokenType == #BinaryOperator) and:[tokenName = '>']) ifFalse:[
|
44
|
1552 |
self parseError:'bad primitive definition (> expected)'.
|
|
1553 |
^ #Error
|
0
|
1554 |
].
|
|
1555 |
self nextToken.
|
|
1556 |
^ primNumber
|
|
1557 |
!
|
|
1558 |
|
|
1559 |
statementList
|
|
1560 |
"parse a statementlist; return a node-tree, nil or #Error.
|
53
|
1561 |
Statements must be separated by periods.
|
|
1562 |
|
|
1563 |
statementList ::= <statement>
|
|
1564 |
| <statementList> . <statement>
|
|
1565 |
"
|
0
|
1566 |
|
|
1567 |
|thisStatement prevStatement firstStatement correctIt periodPos|
|
|
1568 |
|
|
1569 |
thisStatement := self statement.
|
|
1570 |
(thisStatement == #Error) ifTrue:[^ #Error].
|
|
1571 |
firstStatement := thisStatement.
|
|
1572 |
[tokenType == $.] whileTrue:[
|
44
|
1573 |
periodPos := tokenPosition.
|
|
1574 |
self nextToken.
|
|
1575 |
(tokenType == $]) ifTrue:[
|
|
1576 |
currentBlock isNil ifTrue:[
|
|
1577 |
self parseError:'block nesting error'.
|
|
1578 |
errorFlag := true
|
0
|
1579 |
"
|
44
|
1580 |
*** I had a warning here (since it was not defined
|
|
1581 |
*** in the blue-book; but PD-code contains a lot of
|
|
1582 |
*** code with periods at the end so that the warnings
|
|
1583 |
*** became annoying
|
0
|
1584 |
|
44
|
1585 |
] ifFalse:[
|
|
1586 |
self warning:'period after last statement' position:periodPos
|
0
|
1587 |
"
|
44
|
1588 |
].
|
|
1589 |
^ firstStatement
|
|
1590 |
].
|
|
1591 |
(tokenType == #EOF) ifTrue:[
|
|
1592 |
currentBlock notNil ifTrue:[
|
|
1593 |
self parseError:'block nesting error (expected '']'')'.
|
|
1594 |
errorFlag := true
|
0
|
1595 |
"
|
44
|
1596 |
*** I had a warning here (since it was not defined
|
|
1597 |
*** in the blue-book; but PD-code contains a lot of
|
|
1598 |
*** code with periods at the end so that the warnings
|
|
1599 |
*** became annoying
|
0
|
1600 |
|
44
|
1601 |
] ifFalse:[
|
|
1602 |
self warning:'period after last statement' position:periodPos
|
0
|
1603 |
"
|
44
|
1604 |
].
|
|
1605 |
^ firstStatement
|
|
1606 |
].
|
0
|
1607 |
|
44
|
1608 |
prevStatement := thisStatement.
|
62
|
1609 |
prevStatement isReturnNode ifTrue:[
|
44
|
1610 |
self warning:'statements after return' position:tokenPosition
|
|
1611 |
].
|
0
|
1612 |
"
|
44
|
1613 |
periodPos := tokenPosition.
|
|
1614 |
self nextToken.
|
0
|
1615 |
"
|
|
1616 |
|
44
|
1617 |
((tokenType == $]) or:[tokenType == #EOF]) ifTrue:[
|
|
1618 |
(currentBlock isNil and:[tokenType == $]]) ifTrue:[
|
|
1619 |
self parseError:'block nesting error'.
|
|
1620 |
errorFlag := true
|
|
1621 |
] ifFalse:[
|
|
1622 |
correctIt := self correctableError:'period after last statement in block'
|
|
1623 |
position:periodPos to:(periodPos + 1).
|
|
1624 |
correctIt ifTrue:[
|
|
1625 |
(self correctByDeleting == #Error) ifTrue:[
|
|
1626 |
errorFlag := true
|
|
1627 |
]
|
|
1628 |
]
|
|
1629 |
].
|
|
1630 |
^ firstStatement
|
|
1631 |
].
|
|
1632 |
thisStatement := self statement.
|
|
1633 |
(thisStatement == #Error) ifTrue:[^ #Error].
|
|
1634 |
prevStatement nextStatement:thisStatement
|
0
|
1635 |
].
|
|
1636 |
^ firstStatement
|
|
1637 |
!
|
|
1638 |
|
|
1639 |
statement
|
19
|
1640 |
"parse a statement; return a node-tree or #Error.
|
|
1641 |
|
|
1642 |
statement ::= '^' expression
|
44
|
1643 |
| PRIMITIVECODE
|
|
1644 |
| expression
|
19
|
1645 |
"
|
0
|
1646 |
|
|
1647 |
|expr node|
|
|
1648 |
|
|
1649 |
(tokenType == $^) ifTrue:[
|
44
|
1650 |
self nextToken.
|
|
1651 |
expr := self expression.
|
|
1652 |
(expr == #Error) ifTrue:[^ #Error].
|
|
1653 |
node := ReturnNode expression:expr.
|
|
1654 |
node home:self blockHome:currentBlock.
|
|
1655 |
^ node
|
0
|
1656 |
].
|
|
1657 |
(tokenType == #Primitive) ifTrue:[
|
44
|
1658 |
self nextToken.
|
|
1659 |
hasPrimitiveCode := true.
|
|
1660 |
^ PrimitiveNode code:''
|
0
|
1661 |
].
|
|
1662 |
(tokenType == #EOF) ifTrue:[
|
44
|
1663 |
self syntaxError:'period after last statement'.
|
|
1664 |
^ #Error
|
0
|
1665 |
].
|
|
1666 |
expr := self expression.
|
13
|
1667 |
(expr == #Error) ifTrue:[^ #Error].
|
0
|
1668 |
"
|
|
1669 |
classToCompileFor notNil ifTrue:[
|
44
|
1670 |
currentBlock isNil ifTrue:[
|
62
|
1671 |
expr isPrimary ifTrue:[
|
44
|
1672 |
self warning:'useless computation - missing ^ ?'
|
|
1673 |
]
|
|
1674 |
]
|
0
|
1675 |
].
|
|
1676 |
"
|
|
1677 |
^ StatementNode expression:expr
|
|
1678 |
!
|
|
1679 |
|
|
1680 |
expression
|
19
|
1681 |
"parse a cascade-expression; return a node-tree, nil or #Error.
|
|
1682 |
|
|
1683 |
expression ::= keywordExpression
|
44
|
1684 |
| keywordExpression cascade
|
19
|
1685 |
|
|
1686 |
cascade ::= ';' expressionSendPart
|
44
|
1687 |
| cascade ';' expressionSendPart
|
19
|
1688 |
|
|
1689 |
expressionSendPart ::= { KEYWORD binaryExpression }
|
44
|
1690 |
| BINARYOPERATOR unaryExpression
|
|
1691 |
| IDENTIFIER
|
19
|
1692 |
"
|
0
|
1693 |
|
21
|
1694 |
|receiver arg sel args pos pos2 lno|
|
0
|
1695 |
|
3
|
1696 |
pos := tokenPosition.
|
0
|
1697 |
receiver := self keywordExpression.
|
|
1698 |
(receiver == #Error) ifTrue:[^ #Error].
|
15
|
1699 |
(tokenType == $;) ifTrue:[
|
44
|
1700 |
[tokenType == $;] whileTrue:[
|
|
1701 |
receiver isMessage ifFalse:[
|
|
1702 |
self syntaxError:'left side of cascade must be a message expression'
|
|
1703 |
position:pos to:tokenPosition
|
|
1704 |
].
|
|
1705 |
self nextToken.
|
|
1706 |
(tokenType == #Identifier) ifTrue:[
|
|
1707 |
sel := self selectorCheck:tokenName for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1).
|
|
1708 |
receiver := CascadeNode receiver:receiver selector:sel.
|
|
1709 |
receiver lineNumber:tokenLineNr.
|
84
|
1710 |
parseForCode ifFalse:[self rememberSelectorUsed:sel].
|
44
|
1711 |
self nextToken.
|
|
1712 |
] ifFalse:[
|
|
1713 |
(tokenType == #BinaryOperator) ifTrue:[
|
|
1714 |
sel := self selectorCheck:tokenName for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1).
|
|
1715 |
lno := tokenLineNr.
|
|
1716 |
self nextToken.
|
|
1717 |
arg := self unaryExpression.
|
|
1718 |
(arg == #Error) ifTrue:[^ #Error].
|
|
1719 |
receiver := CascadeNode receiver:receiver selector:sel arg:arg.
|
|
1720 |
receiver lineNumber:lno.
|
84
|
1721 |
parseForCode ifFalse:[self rememberSelectorUsed:sel].
|
44
|
1722 |
] ifFalse:[
|
|
1723 |
(tokenType == #Keyword) ifTrue:[
|
|
1724 |
pos := tokenPosition.
|
|
1725 |
lno := tokenLineNr.
|
|
1726 |
sel := tokenName.
|
|
1727 |
self nextToken.
|
|
1728 |
arg := self binaryExpression.
|
|
1729 |
(arg == #Error) ifTrue:[^ #Error].
|
|
1730 |
args := Array with:arg.
|
|
1731 |
[tokenType == #Keyword] whileTrue:[
|
|
1732 |
sel := sel , tokenName.
|
|
1733 |
self nextToken.
|
|
1734 |
arg := self binaryExpression.
|
|
1735 |
(arg == #Error) ifTrue:[^ #Error].
|
|
1736 |
args := args copyWith:arg.
|
|
1737 |
pos2 := tokenPosition
|
|
1738 |
].
|
|
1739 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2.
|
|
1740 |
receiver := CascadeNode receiver:receiver selector:sel args:args.
|
|
1741 |
receiver lineNumber:lno.
|
84
|
1742 |
parseForCode ifFalse:[self rememberSelectorUsed:sel].
|
44
|
1743 |
] ifFalse:[
|
|
1744 |
(tokenType == #Error) ifTrue:[^ #Error].
|
|
1745 |
self syntaxError:('invalid cascade; ' , tokenType printString , ' unexpected')
|
|
1746 |
position:tokenPosition to:source position - 1.
|
|
1747 |
^ #Error
|
|
1748 |
]
|
|
1749 |
]
|
|
1750 |
]
|
|
1751 |
].
|
15
|
1752 |
|
44
|
1753 |
"obscure (uspecified ?) if selector follows; Question:
|
15
|
1754 |
|
44
|
1755 |
is
|
|
1756 |
'expr sel1; sel2 sel3'
|
15
|
1757 |
|
44
|
1758 |
to be parsed as:
|
|
1759 |
(t := expr.
|
|
1760 |
t sel1.
|
|
1761 |
t sel2) sel3
|
15
|
1762 |
|
44
|
1763 |
or:
|
|
1764 |
(t := expr.
|
|
1765 |
t sel1.
|
|
1766 |
t sel2 sel3)
|
|
1767 |
"
|
|
1768 |
((tokenType == #Identifier)
|
|
1769 |
or:[(tokenType == #BinaryOperator)
|
|
1770 |
or:[tokenType == #Keyword]]) ifTrue:[
|
|
1771 |
self syntaxError:'ambigous cascade - please group using ( ...)'
|
|
1772 |
position:tokenPosition to:source position - 1.
|
|
1773 |
^ #Error
|
|
1774 |
]
|
0
|
1775 |
].
|
|
1776 |
^ receiver
|
|
1777 |
!
|
|
1778 |
|
|
1779 |
keywordExpression
|
53
|
1780 |
"parse a keyword-expression; return a node-tree, nil or #Error.
|
|
1781 |
|
|
1782 |
keywordExpression ::= binaryexpression
|
|
1783 |
| { KEYWORD-PART binaryExpression }
|
|
1784 |
"
|
0
|
1785 |
|
3
|
1786 |
|receiver sel arg args pos1 pos2 try lno note|
|
0
|
1787 |
|
|
1788 |
receiver := self binaryExpression.
|
|
1789 |
(receiver == #Error) ifTrue:[^ #Error].
|
|
1790 |
(tokenType == #Keyword) ifTrue:[
|
44
|
1791 |
pos1 := tokenPosition.
|
78
|
1792 |
pos2 := tokenPosition + tokenName size - 1.
|
44
|
1793 |
sel := tokenName.
|
|
1794 |
lno := tokenLineNr.
|
|
1795 |
self nextToken.
|
|
1796 |
arg := self binaryExpression.
|
|
1797 |
(arg == #Error) ifTrue:[^ #Error].
|
|
1798 |
args := Array with:arg.
|
|
1799 |
[tokenType == #Keyword] whileTrue:[
|
|
1800 |
sel := sel , tokenName.
|
78
|
1801 |
pos2 := tokenPosition + tokenName size - 1.
|
44
|
1802 |
self nextToken.
|
|
1803 |
arg := self binaryExpression.
|
|
1804 |
(arg == #Error) ifTrue:[^ #Error].
|
|
1805 |
args := args copyWith:arg.
|
|
1806 |
].
|
|
1807 |
sel := self selectorCheck:sel for:receiver position:pos1 to:pos2.
|
|
1808 |
try := MessageNode receiver:receiver selector:sel args:args.
|
|
1809 |
(try isMemberOf:String) ifTrue:[
|
|
1810 |
self parseError:try position:pos1 to:pos2.
|
47
|
1811 |
errorFlag := false. "ok, user wants it - so he'll get it"
|
44
|
1812 |
receiver := MessageNode receiver:receiver selector:sel args:args fold:false.
|
|
1813 |
note := receiver plausibilityCheck.
|
|
1814 |
note notNil ifTrue:[
|
|
1815 |
self warning:note position:pos1 to:pos2
|
|
1816 |
].
|
|
1817 |
] ifFalse:[
|
|
1818 |
receiver := try
|
|
1819 |
].
|
84
|
1820 |
receiver lineNumber:lno.
|
|
1821 |
parseForCode ifFalse:[self rememberSelectorUsed:sel].
|
0
|
1822 |
].
|
|
1823 |
^ receiver
|
|
1824 |
!
|
|
1825 |
|
7
|
1826 |
degeneratedKeywordExpressionForSelector
|
|
1827 |
"parse a keyword-expression without receiver - for the selector
|
53
|
1828 |
only. return the selector or nil. This is not used in normal parsing,
|
|
1829 |
but instead to extract the selector from a code fragment.
|
|
1830 |
(for example, the system browsers implementors-function uses this)"
|
7
|
1831 |
|
47
|
1832 |
|sel arg rec|
|
7
|
1833 |
|
|
1834 |
(tokenType == #Keyword) ifTrue:[
|
44
|
1835 |
sel := tokenName.
|
|
1836 |
self nextToken.
|
|
1837 |
arg := self binaryExpression.
|
|
1838 |
(arg == #Error) ifTrue:[^ sel].
|
|
1839 |
[tokenType == #Keyword] whileTrue:[
|
|
1840 |
sel := sel , tokenName.
|
|
1841 |
self nextToken.
|
|
1842 |
arg := self binaryExpression.
|
|
1843 |
(arg == #Error) ifTrue:[^ sel].
|
|
1844 |
].
|
|
1845 |
^ sel
|
7
|
1846 |
].
|
47
|
1847 |
|
|
1848 |
(rec := self primary) ~~ #Error ifTrue:[
|
|
1849 |
sel := self degeneratedKeywordExpressionForSelector.
|
|
1850 |
sel isNil ifTrue:[
|
|
1851 |
rec isMessage ifTrue:[
|
|
1852 |
sel := rec selector
|
|
1853 |
] ifFalse:[
|
|
1854 |
rec isAssignment ifTrue:[
|
|
1855 |
rec expression isMessage ifTrue:[
|
|
1856 |
sel := rec expression selector
|
|
1857 |
]
|
|
1858 |
]
|
|
1859 |
]
|
|
1860 |
]
|
|
1861 |
].
|
|
1862 |
^ sel
|
7
|
1863 |
!
|
|
1864 |
|
0
|
1865 |
binaryExpression
|
|
1866 |
"parse a binary-expression; return a node-tree, nil or #Error"
|
|
1867 |
|
|
1868 |
|receiver arg sel pos try lno note|
|
|
1869 |
|
|
1870 |
receiver := self unaryExpression.
|
|
1871 |
(receiver == #Error) ifTrue:[^ #Error].
|
|
1872 |
|
|
1873 |
"special kludge: since Scanner cannot know if -digit is a binary
|
|
1874 |
expression or a negative constant, handle cases here"
|
|
1875 |
|
|
1876 |
[(tokenType == #BinaryOperator) or:[(tokenType == $|)
|
|
1877 |
or:[(tokenType == #Integer) and:[tokenValue < 0]]]] whileTrue:[
|
44
|
1878 |
pos := tokenPosition.
|
0
|
1879 |
|
44
|
1880 |
lno := tokenLineNr.
|
0
|
1881 |
|
44
|
1882 |
"kludge here: bar and minus are not scanned as binop "
|
|
1883 |
(tokenType == $|) ifTrue:[
|
|
1884 |
sel := '|'.
|
|
1885 |
self nextToken
|
|
1886 |
] ifFalse:[
|
|
1887 |
(tokenType == #BinaryOperator) ifTrue:[
|
|
1888 |
sel := self selectorCheck:tokenName for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1).
|
|
1889 |
self nextToken
|
|
1890 |
] ifFalse:[
|
|
1891 |
sel := '-'.
|
|
1892 |
tokenValue := tokenValue negated
|
|
1893 |
]
|
|
1894 |
].
|
|
1895 |
arg := self unaryExpression.
|
|
1896 |
(arg == #Error) ifTrue:[^ #Error].
|
|
1897 |
try := BinaryNode receiver:receiver selector:sel arg:arg.
|
|
1898 |
(try isMemberOf:String) ifTrue:[
|
|
1899 |
self parseError:try position:pos to:tokenPosition.
|
47
|
1900 |
errorFlag := false. "ok, user wants it - so he'll get it"
|
44
|
1901 |
receiver := BinaryNode receiver:receiver selector:sel arg:arg fold:false.
|
|
1902 |
note := receiver plausibilityCheck.
|
|
1903 |
note notNil ifTrue:[
|
|
1904 |
self warning:note position:pos to:tokenPosition
|
|
1905 |
].
|
|
1906 |
] ifFalse:[
|
|
1907 |
receiver := try
|
|
1908 |
].
|
|
1909 |
receiver lineNumber:lno.
|
84
|
1910 |
parseForCode ifFalse:[self rememberSelectorUsed:sel].
|
0
|
1911 |
].
|
|
1912 |
^ receiver
|
|
1913 |
!
|
|
1914 |
|
|
1915 |
unaryExpression
|
|
1916 |
"parse a unary-expression; return a node-tree, nil or #Error"
|
|
1917 |
|
19
|
1918 |
|receiver sel pos pos2 try|
|
0
|
1919 |
|
|
1920 |
receiver := self primary.
|
|
1921 |
(receiver == #Error) ifTrue:[^ #Error].
|
|
1922 |
[tokenType == #Identifier] whileTrue:[
|
44
|
1923 |
pos := tokenPosition.
|
|
1924 |
pos2 := pos + tokenName size - 1.
|
|
1925 |
sel := self selectorCheck:tokenName for:receiver position:pos to:pos2.
|
|
1926 |
try := UnaryNode receiver:receiver selector:sel.
|
|
1927 |
(try isMemberOf:String) ifTrue:[
|
87
|
1928 |
self parseError:try position:pos to:pos2.
|
47
|
1929 |
errorFlag := false. "ok, user wants it - so he'll get it"
|
44
|
1930 |
receiver := UnaryNode receiver:receiver selector:sel fold:false.
|
|
1931 |
] ifFalse:[
|
|
1932 |
receiver := try
|
|
1933 |
].
|
|
1934 |
receiver lineNumber:tokenLineNr.
|
84
|
1935 |
parseForCode ifFalse:[self rememberSelectorUsed:sel].
|
44
|
1936 |
self nextToken.
|
0
|
1937 |
].
|
|
1938 |
^ receiver
|
|
1939 |
!
|
|
1940 |
|
|
1941 |
primary
|
|
1942 |
"parse a primary-expression; return a node-tree, nil or #Error"
|
|
1943 |
|
84
|
1944 |
|val var expr pos name t cls|
|
0
|
1945 |
|
|
1946 |
pos := tokenPosition.
|
44
|
1947 |
(tokenType == #Self) ifTrue:[
|
|
1948 |
self nextToken.
|
|
1949 |
(tokenType == $_) ifTrue:[
|
|
1950 |
self parseError:'assignment to self' position:pos to:tokenPosition.
|
|
1951 |
^ #Error
|
|
1952 |
].
|
|
1953 |
selfNode isNil ifTrue:[
|
|
1954 |
selfNode := SelfNode value:selfValue
|
|
1955 |
].
|
|
1956 |
^ selfNode
|
|
1957 |
].
|
0
|
1958 |
(tokenType == #Identifier) ifTrue:[
|
49
|
1959 |
"
|
|
1960 |
must check for variable first, to be backward compatible
|
|
1961 |
with other smalltalks.
|
|
1962 |
"
|
|
1963 |
self variableOrError == #Error ifTrue:[
|
|
1964 |
tokenName = 'here' ifTrue:[
|
|
1965 |
tokenType := #Here.
|
|
1966 |
warnSTXHereExtensionUsed ifTrue:[
|
50
|
1967 |
self warning:'here-sends are a nonstandard feature of ST/X'
|
|
1968 |
position:pos to:pos+3.
|
|
1969 |
"
|
|
1970 |
only warn once
|
|
1971 |
"
|
49
|
1972 |
warnSTXHereExtensionUsed := false
|
|
1973 |
]
|
|
1974 |
]
|
|
1975 |
]
|
|
1976 |
].
|
|
1977 |
|
|
1978 |
(tokenType == #Identifier) ifTrue:[
|
44
|
1979 |
var := self variable.
|
|
1980 |
(var == #Error) ifTrue:[
|
|
1981 |
errorFlag := true
|
|
1982 |
].
|
|
1983 |
self nextToken.
|
|
1984 |
(tokenType == $_) ifFalse:[
|
|
1985 |
^ var
|
|
1986 |
].
|
|
1987 |
(var ~~ #Error) ifTrue:[
|
|
1988 |
t := var type.
|
|
1989 |
(t == #MethodArg) ifTrue:[
|
|
1990 |
self parseError:'assignment to method argument' position:pos to:tokenPosition.
|
|
1991 |
errorFlag := true
|
|
1992 |
] ifFalse:[
|
|
1993 |
(t == #BlockArg) ifTrue:[
|
|
1994 |
self parseError:'assignment to block argument' position:pos to:tokenPosition.
|
|
1995 |
errorFlag := true
|
|
1996 |
] ifFalse:[
|
|
1997 |
(t == #InstanceVariable) ifTrue:[
|
|
1998 |
name := PrevInstVarNames at:(var index).
|
84
|
1999 |
parseForCode ifFalse:[
|
|
2000 |
modifiedInstVars isNil ifTrue:[
|
|
2001 |
modifiedInstVars := Set new
|
|
2002 |
].
|
44
|
2003 |
modifiedInstVars add:name
|
|
2004 |
]
|
|
2005 |
] ifFalse:[
|
|
2006 |
(t == #ClassVariable) ifTrue:[
|
|
2007 |
name := var name.
|
|
2008 |
name := name copyFrom:((name indexOf:$:) + 1).
|
84
|
2009 |
parseForCode ifFalse:[
|
|
2010 |
modifiedClassVars isNil ifTrue:[
|
|
2011 |
modifiedClassVars := Set new
|
|
2012 |
].
|
44
|
2013 |
modifiedClassVars add:name
|
|
2014 |
]
|
|
2015 |
] ifFalse:[
|
|
2016 |
(t == #GlobalVariable) ifTrue:[
|
84
|
2017 |
(cls := Smalltalk classNamed:var name) notNil ifTrue:[
|
|
2018 |
cls name = var name ifTrue:[
|
|
2019 |
self warning:'assignment to global which contains class' position:pos to:tokenPosition.
|
|
2020 |
]
|
|
2021 |
].
|
|
2022 |
parseForCode ifFalse:[
|
|
2023 |
modifiedGlobals isNil ifTrue:[
|
|
2024 |
modifiedGlobals := Set new
|
|
2025 |
].
|
|
2026 |
modifiedGlobals add:var name
|
44
|
2027 |
]
|
|
2028 |
]
|
|
2029 |
]
|
|
2030 |
]
|
|
2031 |
]
|
|
2032 |
]
|
|
2033 |
].
|
0
|
2034 |
|
44
|
2035 |
self nextToken.
|
|
2036 |
expr := self expression.
|
|
2037 |
(errorFlag or:[expr == #Error]) ifTrue:[^ #Error].
|
|
2038 |
^ AssignmentNode variable:var expression:expr
|
0
|
2039 |
].
|
49
|
2040 |
|
44
|
2041 |
((tokenType == #Integer)
|
|
2042 |
or:[(tokenType == #Character)
|
|
2043 |
or:[(tokenType == #Float)
|
|
2044 |
or:[(tokenType == #String)
|
|
2045 |
or:[(tokenType == #Symbol)]]]]) ifTrue:[
|
|
2046 |
val := ConstantNode type:tokenType value:tokenValue.
|
|
2047 |
self nextToken.
|
|
2048 |
(tokenType == $_) ifTrue:[
|
|
2049 |
self parseError:'assignment to a constant' position:pos to:tokenPosition.
|
|
2050 |
^ #Error
|
|
2051 |
].
|
|
2052 |
^ val
|
0
|
2053 |
].
|
|
2054 |
(tokenType == #Nil) ifTrue:[
|
44
|
2055 |
self nextToken.
|
|
2056 |
(tokenType == $_) ifTrue:[
|
|
2057 |
self parseError:'assignment to nil' position:pos to:tokenPosition.
|
|
2058 |
^ #Error
|
|
2059 |
].
|
|
2060 |
^ ConstantNode type:#Nil value:nil
|
0
|
2061 |
].
|
|
2062 |
(tokenType == #True) ifTrue:[
|
44
|
2063 |
self nextToken.
|
|
2064 |
(tokenType == $_) ifTrue:[
|
|
2065 |
self parseError:'assignment to true' position:pos to:tokenPosition.
|
|
2066 |
^ #Error
|
|
2067 |
].
|
|
2068 |
^ ConstantNode type:#True value:true
|
0
|
2069 |
].
|
|
2070 |
(tokenType == #False) ifTrue:[
|
44
|
2071 |
self nextToken.
|
|
2072 |
(tokenType == $_) ifTrue:[
|
|
2073 |
self parseError:'assignment to false' position:pos to:tokenPosition.
|
|
2074 |
^ #Error
|
|
2075 |
].
|
|
2076 |
^ ConstantNode type:#False value:false
|
0
|
2077 |
].
|
|
2078 |
(tokenType == #Super) ifTrue:[
|
44
|
2079 |
usesSuper := true.
|
|
2080 |
self nextToken.
|
|
2081 |
(tokenType == $_) ifTrue:[
|
|
2082 |
self parseError:'assignment to super' position:pos to:tokenPosition.
|
|
2083 |
^ #Error
|
|
2084 |
].
|
|
2085 |
(classToCompileFor isNil or:[classToCompileFor superclass isNil]) ifTrue:[
|
49
|
2086 |
self warning:'superclass is (currently ?) nil' position:pos to:(pos + 4).
|
44
|
2087 |
].
|
|
2088 |
superNode isNil ifTrue:[
|
|
2089 |
superNode := SuperNode value:selfValue inClass:classToCompileFor
|
|
2090 |
].
|
|
2091 |
^ superNode
|
0
|
2092 |
].
|
49
|
2093 |
(tokenType == #Here) ifTrue:[
|
|
2094 |
self nextToken.
|
|
2095 |
(tokenType == $_) ifTrue:[
|
|
2096 |
self parseError:'assignment to here' position:pos to:tokenPosition.
|
|
2097 |
^ #Error
|
|
2098 |
].
|
|
2099 |
classToCompileFor isNil ifTrue:[
|
|
2100 |
self warning:'in which class are you ?' position:pos to:(pos + 3).
|
|
2101 |
].
|
|
2102 |
^ SuperNode value:selfValue inClass:classToCompileFor here:true
|
|
2103 |
].
|
0
|
2104 |
(tokenType == #ThisContext) ifTrue:[
|
44
|
2105 |
self nextToken.
|
|
2106 |
(tokenType == $_) ifTrue:[
|
|
2107 |
self parseError:'assignment to thisContext' position:pos to:tokenPosition.
|
|
2108 |
^ #Error
|
|
2109 |
].
|
|
2110 |
^ VariableNode type:#ThisContext
|
0
|
2111 |
].
|
|
2112 |
(tokenType == #HashLeftParen) ifTrue:[
|
44
|
2113 |
self nextToken.
|
|
2114 |
val := self array.
|
|
2115 |
self nextToken.
|
|
2116 |
(tokenType == $_) ifTrue:[
|
|
2117 |
self parseError:'assignment to a constant' position:pos to:tokenPosition.
|
|
2118 |
^ #Error
|
|
2119 |
].
|
|
2120 |
^ ConstantNode type:#Array value:val
|
0
|
2121 |
].
|
|
2122 |
(tokenType == #HashLeftBrack) ifTrue:[
|
44
|
2123 |
self nextToken.
|
|
2124 |
val := self byteArray.
|
|
2125 |
self nextToken.
|
|
2126 |
(tokenType == $_) ifTrue:[
|
|
2127 |
self parseError:'assignment to a constant' position:pos to:tokenPosition.
|
|
2128 |
^ #Error
|
|
2129 |
].
|
|
2130 |
^ ConstantNode type:#Array value:val
|
0
|
2131 |
].
|
|
2132 |
(tokenType == $() ifTrue:[
|
44
|
2133 |
self nextToken.
|
|
2134 |
val := self expression.
|
|
2135 |
(val == #Error) ifTrue:[^ #Error].
|
|
2136 |
(tokenType ~~ $) ) ifTrue:[
|
|
2137 |
tokenType isCharacter ifTrue:[
|
|
2138 |
self syntaxError:'missing '')'' (i.e. ''' , tokenType asString , ''' unexpected)' withCRs position:pos to:tokenPosition.
|
|
2139 |
] ifFalse:[
|
|
2140 |
self syntaxError:'missing '')''' position:pos to:tokenPosition.
|
|
2141 |
].
|
|
2142 |
^ #Error
|
|
2143 |
].
|
|
2144 |
self nextToken.
|
|
2145 |
(tokenType == $_) ifTrue:[
|
|
2146 |
self parseError:'invalid assignment' position:pos to:tokenPosition.
|
|
2147 |
^ #Error
|
|
2148 |
].
|
|
2149 |
val parenthized:true.
|
|
2150 |
^ val
|
0
|
2151 |
].
|
|
2152 |
(tokenType == $[ ) ifTrue:[
|
44
|
2153 |
val := self block.
|
|
2154 |
self nextToken.
|
|
2155 |
(tokenType == $_) ifTrue:[
|
|
2156 |
self parseError:'invalid assignment' position:pos to:tokenPosition.
|
|
2157 |
^ #Error
|
|
2158 |
].
|
|
2159 |
^ val
|
0
|
2160 |
].
|
19
|
2161 |
|
0
|
2162 |
(tokenType == #Error) ifTrue:[^ #Error].
|
44
|
2163 |
tokenType isCharacter ifTrue:[
|
|
2164 |
self syntaxError:('error in primary; '
|
|
2165 |
, tokenType printString ,
|
|
2166 |
' unexpected') position:tokenPosition to:tokenPosition
|
0
|
2167 |
] ifFalse:[
|
44
|
2168 |
(#(BinaryOperator Keyword) includes:tokenType) ifTrue:[
|
|
2169 |
self syntaxError:('error in primary; '
|
|
2170 |
, tokenType printString , '(' , tokenName , ') ' ,
|
|
2171 |
' unexpected')
|
|
2172 |
] ifFalse:[
|
|
2173 |
self syntaxError:('error in primary; '
|
|
2174 |
, tokenType printString ,
|
|
2175 |
' unexpected')
|
|
2176 |
]
|
0
|
2177 |
].
|
|
2178 |
^ #Error
|
|
2179 |
!
|
|
2180 |
|
|
2181 |
variableOrError
|
|
2182 |
"parse a variable; return a node-tree, nil or #Error"
|
|
2183 |
|
21
|
2184 |
^ self variableOrError:tokenName
|
|
2185 |
!
|
|
2186 |
|
|
2187 |
variableOrError:varName
|
|
2188 |
"parse a variable; return a node-tree, nil or #Error"
|
|
2189 |
|
19
|
2190 |
|var instIndex aClass searchBlock args vars
|
53
|
2191 |
tokenSymbol|
|
0
|
2192 |
|
|
2193 |
"is it a block-arg or block-var ?"
|
|
2194 |
searchBlock := currentBlock.
|
|
2195 |
[searchBlock notNil] whileTrue:[
|
47
|
2196 |
vars := searchBlock variables.
|
|
2197 |
vars notNil ifTrue:[
|
|
2198 |
instIndex := vars findFirst:[:aBlockVar | aBlockVar name = varName].
|
|
2199 |
instIndex ~~ 0 ifTrue:[
|
|
2200 |
^ VariableNode type:#BlockVariable
|
|
2201 |
name:varName
|
|
2202 |
token:(vars at:instIndex)
|
|
2203 |
index:instIndex
|
|
2204 |
block:searchBlock
|
|
2205 |
].
|
|
2206 |
].
|
|
2207 |
|
44
|
2208 |
args := searchBlock arguments.
|
|
2209 |
args notNil ifTrue:[
|
|
2210 |
instIndex := args findFirst:[:aBlockArg | aBlockArg name = varName].
|
|
2211 |
instIndex ~~ 0 ifTrue:[
|
|
2212 |
^ VariableNode type:#BlockArg
|
|
2213 |
name:varName
|
|
2214 |
token:(args at:instIndex)
|
|
2215 |
index:instIndex
|
|
2216 |
block:searchBlock
|
|
2217 |
].
|
19
|
2218 |
|
44
|
2219 |
].
|
0
|
2220 |
|
44
|
2221 |
searchBlock := searchBlock home
|
0
|
2222 |
].
|
|
2223 |
|
|
2224 |
"is it a method-variable ?"
|
|
2225 |
methodVars notNil ifTrue:[
|
44
|
2226 |
instIndex := methodVarNames indexOf:varName.
|
|
2227 |
instIndex ~~ 0 ifTrue:[
|
|
2228 |
var := methodVars at:instIndex.
|
|
2229 |
var used:true.
|
|
2230 |
^ VariableNode type:#MethodVariable
|
|
2231 |
name:varName
|
|
2232 |
token:var
|
|
2233 |
index:instIndex
|
|
2234 |
]
|
0
|
2235 |
].
|
|
2236 |
|
|
2237 |
"is it a method-argument ?"
|
|
2238 |
methodArgs notNil ifTrue:[
|
44
|
2239 |
instIndex := methodArgNames indexOf:varName.
|
|
2240 |
instIndex ~~ 0 ifTrue:[
|
|
2241 |
^ VariableNode type:#MethodArg
|
|
2242 |
name:varName
|
|
2243 |
token:(methodArgs at:instIndex)
|
|
2244 |
index:instIndex
|
|
2245 |
]
|
0
|
2246 |
].
|
|
2247 |
|
|
2248 |
classToCompileFor notNil ifTrue:[
|
80
|
2249 |
"is it an instance-variable ?"
|
|
2250 |
|
98
|
2251 |
instIndex := (self instVarNames) lastIndexOf:varName.
|
44
|
2252 |
instIndex ~~ 0 ifTrue:[
|
84
|
2253 |
parseForCode ifFalse:[self rememberInstVarUsed:varName].
|
44
|
2254 |
^ VariableNode type:#InstanceVariable
|
|
2255 |
name:varName
|
|
2256 |
index:instIndex
|
|
2257 |
selfValue:selfValue
|
80
|
2258 |
].
|
|
2259 |
|
|
2260 |
"is it a class-instance-variable ?"
|
|
2261 |
|
98
|
2262 |
instIndex := (self classInstVarNames) lastIndexOf:varName.
|
44
|
2263 |
instIndex ~~ 0 ifTrue:[
|
|
2264 |
aClass := self inWhichClassIsClassInstVar:varName.
|
|
2265 |
aClass notNil ifTrue:[
|
84
|
2266 |
parseForCode ifFalse:[self rememberClassVarUsed:varName].
|
44
|
2267 |
^ VariableNode type:#ClassInstanceVariable
|
|
2268 |
name:varName
|
|
2269 |
index:instIndex
|
|
2270 |
selfClass:aClass
|
|
2271 |
]
|
80
|
2272 |
].
|
|
2273 |
|
|
2274 |
"is it a class-variable ?"
|
|
2275 |
|
98
|
2276 |
instIndex := (self classVarNames) lastIndexOf:varName.
|
44
|
2277 |
instIndex ~~ 0 ifTrue:[
|
|
2278 |
aClass := self inWhichClassIsClassVar:varName.
|
|
2279 |
aClass notNil ifTrue:[
|
84
|
2280 |
parseForCode ifFalse:[self rememberClassVarUsed:varName].
|
98
|
2281 |
^ VariableNode type:#ClassVariable class:aClass name:varName
|
44
|
2282 |
]
|
|
2283 |
]
|
0
|
2284 |
].
|
|
2285 |
|
|
2286 |
"is it a global-variable ?"
|
63
|
2287 |
tokenSymbol := varName asSymbolIfInterned.
|
|
2288 |
tokenSymbol notNil ifTrue:[
|
47
|
2289 |
(Smalltalk includesKey:tokenSymbol) ifTrue:[
|
84
|
2290 |
parseForCode ifFalse:[self rememberGlobalUsed:varName].
|
47
|
2291 |
^ VariableNode type:#GlobalVariable name:tokenSymbol
|
|
2292 |
]
|
0
|
2293 |
].
|
|
2294 |
^ #Error
|
|
2295 |
!
|
|
2296 |
|
|
2297 |
variable
|
|
2298 |
"parse a variable; if undefined, notify error and correct if user wants to"
|
|
2299 |
|
|
2300 |
|v|
|
|
2301 |
|
|
2302 |
v := self variableOrError.
|
|
2303 |
(v == #Error) ifFalse:[^ v].
|
|
2304 |
v := self correctVariable.
|
|
2305 |
(v == #Error) ifFalse:[^ v].
|
98
|
2306 |
parseForCode ifFalse:[
|
|
2307 |
self rememberGlobalUsed:tokenName
|
|
2308 |
] ifTrue:[
|
|
2309 |
tokenName first isLowercase ifTrue:[
|
|
2310 |
ImplicitSelfSends ifTrue:[
|
|
2311 |
selfNode isNil ifTrue:[
|
|
2312 |
selfNode := SelfNode value:selfValue
|
|
2313 |
].
|
|
2314 |
^ UnaryNode receiver:selfNode selector:('implicit_' , tokenName) asSymbol.
|
|
2315 |
]
|
|
2316 |
]
|
|
2317 |
].
|
13
|
2318 |
^ VariableNode type:#GlobalVariable name:tokenName asSymbol
|
0
|
2319 |
!
|
|
2320 |
|
|
2321 |
inWhichClassIsClassVar:aString
|
|
2322 |
"search class-chain for the classvariable named aString
|
|
2323 |
- return the class or nil if not found"
|
|
2324 |
|
|
2325 |
|aClass className baseClass|
|
|
2326 |
|
|
2327 |
aClass := classToCompileFor.
|
|
2328 |
aClass isMeta ifTrue:[
|
44
|
2329 |
className := aClass name.
|
96
|
2330 |
className := className copyWithoutLast:5.
|
44
|
2331 |
baseClass := Smalltalk at:(className asSymbol).
|
|
2332 |
baseClass notNil ifTrue:[
|
|
2333 |
aClass := baseClass
|
|
2334 |
]
|
0
|
2335 |
].
|
84
|
2336 |
^ aClass whichClassDefinesClassVar:aString
|
|
2337 |
"/ [aClass notNil] whileTrue:[
|
|
2338 |
"/ (aClass classVarNames includes:aString) ifTrue:[ ^ aClass].
|
|
2339 |
"/ aClass := aClass superclass
|
|
2340 |
"/ ].
|
|
2341 |
"/ ^ nil
|
0
|
2342 |
!
|
|
2343 |
|
|
2344 |
inWhichClassIsClassInstVar:aString
|
|
2345 |
"search class-chain for the class-instance variable named aString
|
|
2346 |
- return the class or nil if not found"
|
|
2347 |
|
|
2348 |
|aClass|
|
|
2349 |
|
|
2350 |
aClass := classToCompileFor.
|
|
2351 |
[aClass notNil] whileTrue:[
|
44
|
2352 |
(aClass class instVarNames includes:aString) ifTrue:[ ^ aClass].
|
|
2353 |
aClass := aClass superclass
|
0
|
2354 |
].
|
|
2355 |
^ nil
|
|
2356 |
!
|
|
2357 |
|
98
|
2358 |
blockExpression
|
|
2359 |
"parse a blockExpression; return a node-tree, nil or #Error.
|
|
2360 |
Not used by ST/X's parser, but added for ST-80 compatibility."
|
|
2361 |
|
|
2362 |
tokenType ~~ $[ ifTrue:[
|
|
2363 |
self syntaxError:'[ expected'.
|
|
2364 |
^ #Error.
|
|
2365 |
].
|
|
2366 |
^ self block
|
|
2367 |
!
|
|
2368 |
|
0
|
2369 |
block
|
|
2370 |
"parse a block; return a node-tree, nil or #Error"
|
|
2371 |
|
23
|
2372 |
|node args argNames arg pos lno|
|
0
|
2373 |
|
7
|
2374 |
lno := tokenLineNr.
|
0
|
2375 |
self nextToken.
|
|
2376 |
(tokenType == $: ) ifTrue:[
|
44
|
2377 |
[tokenType == $:] whileTrue:[
|
|
2378 |
pos := tokenPosition.
|
|
2379 |
self nextToken.
|
|
2380 |
(tokenType == #Identifier) ifFalse:[
|
53
|
2381 |
^ self identifierExpectedIn:'block-arg declaration'
|
44
|
2382 |
].
|
|
2383 |
arg := Variable name:tokenName.
|
|
2384 |
args isNil ifTrue:[
|
|
2385 |
args := Array with:arg.
|
|
2386 |
argNames := Array with:tokenName.
|
|
2387 |
] ifFalse:[
|
|
2388 |
(argNames includes:tokenName) ifTrue:[
|
|
2389 |
self syntaxError:'redefinition of ''' , tokenName , ''' in argument list.'
|
|
2390 |
position:tokenPosition
|
|
2391 |
to:(tokenPosition + tokenName size - 1)
|
|
2392 |
].
|
|
2393 |
args := args copyWith:arg.
|
|
2394 |
argNames := argNames copyWith:tokenName.
|
|
2395 |
].
|
|
2396 |
self nextToken
|
|
2397 |
].
|
|
2398 |
(tokenType ~~ $| ) ifTrue:[
|
|
2399 |
"ST-80 allows [:arg ]"
|
|
2400 |
(tokenType == $] ) ifTrue:[
|
|
2401 |
node := BlockNode arguments:args home:currentBlock variables:nil.
|
|
2402 |
node lineNumber:lno.
|
|
2403 |
^ node
|
|
2404 |
].
|
|
2405 |
self syntaxError:'| expected after block-arg declaration'.
|
|
2406 |
^ #Error
|
|
2407 |
].
|
|
2408 |
self nextToken
|
0
|
2409 |
].
|
23
|
2410 |
node := self blockBody:args.
|
|
2411 |
(node notNil and:[node ~~ #Error]) ifTrue:[
|
44
|
2412 |
node lineNumber:lno.
|
23
|
2413 |
].
|
|
2414 |
^ node
|
|
2415 |
!
|
|
2416 |
|
|
2417 |
blockBody:args
|
|
2418 |
"parse a blocks body; return a node-tree, nil or #Error"
|
|
2419 |
|
53
|
2420 |
|stats node var vars lno names|
|
23
|
2421 |
|
|
2422 |
lno := tokenLineNr.
|
0
|
2423 |
(tokenType == $| ) ifTrue:[
|
44
|
2424 |
self nextToken.
|
|
2425 |
[tokenType == $|] whileFalse:[
|
|
2426 |
(tokenType == #Identifier) ifFalse:[
|
53
|
2427 |
^ self identifierExpectedIn:'block-var declaration'
|
44
|
2428 |
].
|
|
2429 |
var := Variable name:tokenName.
|
|
2430 |
vars isNil ifTrue:[
|
53
|
2431 |
vars := Array with:var.
|
|
2432 |
names := Array with:tokenName
|
44
|
2433 |
] ifFalse:[
|
53
|
2434 |
(names includes:tokenName) ifTrue:[
|
|
2435 |
self parseError:'redefinition of ''' , tokenName , ''' in local variables'
|
|
2436 |
position:tokenPosition to:tokenPosition + tokenName size -1.
|
|
2437 |
] ifFalse:[
|
|
2438 |
vars := vars copyWith:var.
|
|
2439 |
names := names copyWith:tokenName
|
|
2440 |
]
|
44
|
2441 |
].
|
53
|
2442 |
self nextToken.
|
44
|
2443 |
].
|
|
2444 |
self nextToken
|
0
|
2445 |
].
|
3
|
2446 |
node := BlockNode arguments:args home:currentBlock variables:vars.
|
7
|
2447 |
node lineNumber:lno.
|
0
|
2448 |
currentBlock := node.
|
|
2449 |
stats := self blockStatementList.
|
|
2450 |
node statements:stats.
|
|
2451 |
currentBlock := node home.
|
|
2452 |
(stats == #Error) ifTrue:[^ #Error].
|
|
2453 |
^ node
|
|
2454 |
!
|
|
2455 |
|
|
2456 |
blockStatementList
|
|
2457 |
"parse a blocks statementlist; return a node-tree, nil or #Error"
|
|
2458 |
|
|
2459 |
|thisStatement prevStatement firstStatement|
|
|
2460 |
|
|
2461 |
(tokenType == $] ) ifTrue:[^ nil].
|
|
2462 |
thisStatement := self statement.
|
|
2463 |
(thisStatement == #Error) ifTrue:[^ #Error].
|
|
2464 |
firstStatement := thisStatement.
|
|
2465 |
[tokenType == $] ] whileFalse:[
|
44
|
2466 |
(tokenType == $.) ifFalse:[
|
53
|
2467 |
((tokenType == #EOF) or:[tokenType == $)]) ifTrue:[
|
44
|
2468 |
self syntaxError:'missing '']'' in block'
|
|
2469 |
] ifFalse:[
|
|
2470 |
self syntaxError:'missing ''.'' in block'
|
|
2471 |
].
|
|
2472 |
^ #Error
|
|
2473 |
] ifTrue:[
|
|
2474 |
prevStatement := thisStatement.
|
|
2475 |
self nextToken.
|
|
2476 |
tokenType == $] ifTrue:[
|
0
|
2477 |
"
|
44
|
2478 |
*** I had a warning here (since it was not defined
|
|
2479 |
*** in the blue-book; but PD-code contains a lot of
|
|
2480 |
*** code with periods at the end so that the warnings
|
|
2481 |
*** became annoying
|
0
|
2482 |
|
44
|
2483 |
self warning:'period after last statement in block'.
|
0
|
2484 |
"
|
44
|
2485 |
^ firstStatement
|
|
2486 |
].
|
|
2487 |
thisStatement := self statement.
|
|
2488 |
(thisStatement == #Error) ifTrue:[^ #Error].
|
|
2489 |
prevStatement nextStatement:thisStatement
|
|
2490 |
]
|
0
|
2491 |
].
|
|
2492 |
^ firstStatement
|
|
2493 |
!
|
|
2494 |
|
|
2495 |
array
|
66
|
2496 |
|arr elements elem pos1|
|
0
|
2497 |
|
|
2498 |
pos1 := tokenPosition.
|
66
|
2499 |
elements := OrderedCollection new:20.
|
0
|
2500 |
[tokenType ~~ $) ] whileTrue:[
|
44
|
2501 |
elem := self arrayConstant.
|
|
2502 |
(elem == #Error) ifTrue:[
|
|
2503 |
(tokenType == #EOF) ifTrue:[
|
|
2504 |
self syntaxError:'unterminated array-constant; '')'' expected'
|
|
2505 |
position:pos1 to:tokenPosition
|
|
2506 |
].
|
|
2507 |
^ #Error
|
|
2508 |
].
|
66
|
2509 |
elements add:elem.
|
44
|
2510 |
self nextToken
|
0
|
2511 |
].
|
66
|
2512 |
arr := Array withAll:elements.
|
|
2513 |
|
|
2514 |
(ArraysAreImmutable and:[ImmutableArray notNil]) ifTrue:[
|
|
2515 |
arr changeClassTo:ImmutableArray.
|
|
2516 |
].
|
|
2517 |
^ arr
|
0
|
2518 |
!
|
|
2519 |
|
|
2520 |
byteArray
|
7
|
2521 |
"started with ST-80 R4 - allow byteArray constants as #[ ... ]"
|
|
2522 |
|
45
|
2523 |
|bytes index limit newArray elem pos1 pos2|
|
0
|
2524 |
|
|
2525 |
pos1 := tokenPosition.
|
53
|
2526 |
bytes := ByteArray uninitializedNew:5000.
|
45
|
2527 |
index := 0. limit := 5000.
|
0
|
2528 |
[tokenType ~~ $] ] whileTrue:[
|
44
|
2529 |
pos2 := tokenPosition.
|
45
|
2530 |
"
|
|
2531 |
this is not good programming style, but speeds up
|
|
2532 |
reading of huge byte arrays (i.e. stored Images ...)
|
|
2533 |
"
|
|
2534 |
(tokenType == #Integer) ifTrue:[
|
|
2535 |
elem := tokenValue
|
|
2536 |
] ifFalse:[
|
|
2537 |
elem := self arrayConstant.
|
53
|
2538 |
(elem == #Error) ifTrue:[
|
|
2539 |
(tokenType == #EOF) ifTrue:[
|
|
2540 |
self syntaxError:'unterminated bytearray-constant; '']'' expected'
|
|
2541 |
position:pos1 to:tokenPosition
|
|
2542 |
].
|
|
2543 |
^ #Error
|
|
2544 |
].
|
45
|
2545 |
].
|
53
|
2546 |
((elem isMemberOf:SmallInteger) and:[elem between:0 and:255]) ifTrue:[
|
45
|
2547 |
index := index + 1.
|
|
2548 |
bytes at:index put:elem.
|
|
2549 |
index == limit ifTrue:[
|
53
|
2550 |
newArray := ByteArray uninitializedNew:(limit * 2).
|
45
|
2551 |
newArray replaceFrom:1 to:limit with:bytes startingAt:1.
|
|
2552 |
limit := limit * 2.
|
|
2553 |
bytes := newArray
|
|
2554 |
].
|
44
|
2555 |
] ifFalse:[
|
|
2556 |
self parseError:'invalid ByteArray element' position:pos2 to:tokenPosition - 1
|
|
2557 |
].
|
45
|
2558 |
self nextToken.
|
0
|
2559 |
].
|
53
|
2560 |
newArray := ByteArray uninitializedNew:index.
|
45
|
2561 |
newArray replaceFrom:1 to:index with:bytes startingAt:1.
|
|
2562 |
^ newArray
|
0
|
2563 |
!
|
|
2564 |
|
|
2565 |
arrayConstant
|
|
2566 |
(tokenType == #String) ifTrue:[
|
44
|
2567 |
^ tokenValue
|
0
|
2568 |
].
|
|
2569 |
(tokenType == #Nil) ifTrue:[
|
44
|
2570 |
^ nil
|
0
|
2571 |
].
|
|
2572 |
(tokenType == #Integer) ifTrue:[
|
44
|
2573 |
^ tokenValue
|
0
|
2574 |
].
|
|
2575 |
(tokenType == #Character) ifTrue:[
|
44
|
2576 |
^ tokenValue
|
0
|
2577 |
].
|
|
2578 |
(tokenType == #Float) ifTrue:[
|
44
|
2579 |
^ tokenValue
|
0
|
2580 |
].
|
|
2581 |
(tokenType == #True) ifTrue:[
|
44
|
2582 |
^ true
|
0
|
2583 |
].
|
|
2584 |
(tokenType == #False) ifTrue:[
|
44
|
2585 |
^ false
|
0
|
2586 |
].
|
|
2587 |
(tokenType == #Error) ifTrue:[
|
44
|
2588 |
^ #Error
|
0
|
2589 |
].
|
|
2590 |
(tokenType == #BinaryOperator) ifTrue:[
|
44
|
2591 |
^ tokenName asSymbol
|
0
|
2592 |
].
|
|
2593 |
(tokenType == #Keyword) ifTrue:[
|
44
|
2594 |
^ tokenName asSymbol
|
0
|
2595 |
].
|
|
2596 |
(tokenType == #Identifier) ifTrue:[
|
44
|
2597 |
^ tokenName asSymbol
|
0
|
2598 |
].
|
|
2599 |
(tokenType == $() ifTrue:[
|
44
|
2600 |
self nextToken.
|
|
2601 |
^ self array
|
0
|
2602 |
].
|
|
2603 |
(tokenType == $[) ifTrue:[
|
44
|
2604 |
self nextToken.
|
|
2605 |
^ self byteArray
|
0
|
2606 |
].
|
|
2607 |
(tokenType == #Symbol) ifTrue:[
|
|
2608 |
"
|
44
|
2609 |
self warning:'no # for symbols within array-constants'.
|
0
|
2610 |
"
|
44
|
2611 |
^ tokenValue
|
0
|
2612 |
].
|
|
2613 |
(tokenType == #HashLeftParen) ifTrue:[
|
|
2614 |
"
|
44
|
2615 |
self warning:'no # for arrays within array-constants'.
|
0
|
2616 |
"
|
44
|
2617 |
self nextToken.
|
|
2618 |
^ self array
|
0
|
2619 |
].
|
|
2620 |
(tokenType == #HashLeftBrack) ifTrue:[
|
|
2621 |
"
|
44
|
2622 |
self warning:'no # for arrays within array-constants'.
|
0
|
2623 |
"
|
44
|
2624 |
self nextToken.
|
|
2625 |
^ self byteArray
|
0
|
2626 |
].
|
|
2627 |
(tokenType == #EOF) ifTrue:[
|
44
|
2628 |
"just for the better error-hilight; let caller handle error"
|
|
2629 |
^ #Error
|
0
|
2630 |
].
|
|
2631 |
self syntaxError:('error in array-constant; '
|
44
|
2632 |
, tokenType printString
|
|
2633 |
, ' unexpected').
|
0
|
2634 |
^ #Error
|
|
2635 |
! !
|
|
2636 |
|
84
|
2637 |
!Parser methodsFor:'statistic'!
|
|
2638 |
|
|
2639 |
rememberSelectorUsed:sel
|
|
2640 |
usedMessages isNil ifTrue:[
|
|
2641 |
usedMessages := IdentitySet new.
|
|
2642 |
].
|
|
2643 |
usedMessages add:sel
|
|
2644 |
!
|
|
2645 |
|
|
2646 |
rememberVariableUsed:name
|
|
2647 |
usedVars isNil ifTrue:[
|
|
2648 |
usedVars := Set new
|
|
2649 |
].
|
|
2650 |
usedVars add:name
|
|
2651 |
!
|
|
2652 |
|
|
2653 |
rememberGlobalUsed:name
|
|
2654 |
usedGlobals isNil ifTrue:[
|
|
2655 |
usedGlobals := Set new
|
|
2656 |
].
|
|
2657 |
usedGlobals add:name.
|
|
2658 |
self rememberVariableUsed:name
|
|
2659 |
!
|
|
2660 |
|
|
2661 |
rememberClassVarUsed:name
|
|
2662 |
usedClassVars isNil ifTrue:[
|
|
2663 |
usedClassVars := Set new
|
|
2664 |
].
|
|
2665 |
usedClassVars add:name.
|
|
2666 |
self rememberVariableUsed:name
|
|
2667 |
!
|
|
2668 |
|
|
2669 |
rememberInstVarUsed:name
|
|
2670 |
usedInstVars isNil ifTrue:[
|
|
2671 |
usedInstVars := Set new
|
|
2672 |
].
|
|
2673 |
usedInstVars add:name.
|
|
2674 |
self rememberVariableUsed:name
|
|
2675 |
! !
|
|
2676 |
|
0
|
2677 |
!Parser methodsFor:'error correction'!
|
|
2678 |
|
|
2679 |
correctByDeleting
|
|
2680 |
"correct (by deleting token) if user wants to;
|
19
|
2681 |
return #Error if there was no correction;
|
|
2682 |
nil if there was one."
|
0
|
2683 |
|
|
2684 |
(self confirm:'confirm deleting') ifFalse:[^ #Error].
|
|
2685 |
|
19
|
2686 |
"
|
|
2687 |
tell requestor (i.e. CodeView) about the change
|
|
2688 |
this will update what the requestor shows.
|
|
2689 |
"
|
0
|
2690 |
requestor deleteSelection.
|
19
|
2691 |
|
|
2692 |
"
|
|
2693 |
get the updated source-string
|
|
2694 |
which is needed, when we eventually install the new method
|
|
2695 |
"
|
|
2696 |
correctedSource := requestor currentSourceCode.
|
0
|
2697 |
^ nil
|
|
2698 |
!
|
|
2699 |
|
15
|
2700 |
findBestVariablesFor:aString
|
|
2701 |
"collect known variables with their spelling distances to aString;
|
0
|
2702 |
return the 10 best suggestions"
|
|
2703 |
|
|
2704 |
|names dists searchBlock args vars globalVarName aClass className baseClass n|
|
|
2705 |
|
15
|
2706 |
names := OrderedCollection new.
|
|
2707 |
dists := OrderedCollection new.
|
0
|
2708 |
|
|
2709 |
"block arguments"
|
|
2710 |
searchBlock := currentBlock.
|
|
2711 |
[searchBlock notNil] whileTrue:[
|
44
|
2712 |
args := searchBlock arguments.
|
|
2713 |
args notNil ifTrue:[
|
|
2714 |
args do:[:aBlockArg |
|
|
2715 |
names add:(aBlockArg name).
|
|
2716 |
dists add:(aString spellAgainst: "levenshteinTo:"(aBlockArg name))
|
|
2717 |
]
|
|
2718 |
].
|
0
|
2719 |
|
44
|
2720 |
vars := searchBlock variables.
|
|
2721 |
vars notNil ifTrue:[
|
|
2722 |
vars do:[:aBlockVar |
|
|
2723 |
names add:(aBlockVar name).
|
|
2724 |
dists add:(aString spellAgainst: "levenshteinTo:"(aBlockVar name))
|
|
2725 |
]
|
|
2726 |
].
|
|
2727 |
searchBlock := searchBlock home
|
0
|
2728 |
].
|
|
2729 |
|
|
2730 |
"method-variables"
|
|
2731 |
methodVars notNil ifTrue:[
|
44
|
2732 |
methodVarNames do:[:methodVarName |
|
|
2733 |
names add:methodVarName.
|
|
2734 |
dists add:(aString spellAgainst: "levenshteinTo:"methodVarName)
|
|
2735 |
]
|
0
|
2736 |
].
|
|
2737 |
|
|
2738 |
"method-arguments"
|
|
2739 |
methodArgs notNil ifTrue:[
|
44
|
2740 |
methodArgNames do:[:methodArgName |
|
|
2741 |
names add:methodArgName.
|
|
2742 |
dists add:(aString spellAgainst: "levenshteinTo:"methodArgName)
|
|
2743 |
]
|
0
|
2744 |
].
|
|
2745 |
|
|
2746 |
"instance-variables"
|
|
2747 |
classToCompileFor notNil ifTrue:[
|
44
|
2748 |
PrevInstVarNames do:[:instVarName |
|
|
2749 |
names add:instVarName.
|
|
2750 |
dists add:(aString spellAgainst: "levenshteinTo:"instVarName)
|
|
2751 |
]
|
0
|
2752 |
].
|
|
2753 |
|
|
2754 |
"class-variables"
|
|
2755 |
classToCompileFor notNil ifTrue:[
|
44
|
2756 |
PrevClassVarNames do:[:classVarName |
|
|
2757 |
names add:classVarName.
|
|
2758 |
dists add:(aString spellAgainst: "levenshteinTo:"classVarName)
|
|
2759 |
].
|
7
|
2760 |
|
96
|
2761 |
"/ aClass := classToCompileFor.
|
|
2762 |
"/ aClass isMeta ifTrue:[
|
|
2763 |
"/ className := aClass name.
|
|
2764 |
"/ className := className copyWithoutLast:5.
|
|
2765 |
"/ baseClass := Smalltalk at:(className asSymbol).
|
|
2766 |
"/ baseClass notNil ifTrue:[
|
|
2767 |
"/ aClass := baseClass
|
|
2768 |
"/ ]
|
|
2769 |
"/ ].
|
|
2770 |
"/ [aClass notNil] whileTrue:[
|
|
2771 |
"/ (aClass classVarNames) do:[:classVarName |
|
|
2772 |
"/ names add:classVarName.
|
|
2773 |
"/ dists add:(aString spellAgainst: "levenshteinTo:"classVarName)
|
|
2774 |
"/ ].
|
|
2775 |
"/ aClass := aClass superclass
|
|
2776 |
"/ ]
|
|
2777 |
|
0
|
2778 |
].
|
|
2779 |
|
|
2780 |
"globals"
|
77
|
2781 |
Smalltalk keysDo:[:aKey |
|
44
|
2782 |
globalVarName := aKey asString.
|
|
2783 |
"only compare strings where length is about right"
|
|
2784 |
((globalVarName size - aString size) abs < 3) ifTrue:[
|
|
2785 |
names add:globalVarName.
|
|
2786 |
dists add:(aString spellAgainst: "levenshteinTo:"globalVarName)
|
|
2787 |
]
|
0
|
2788 |
].
|
|
2789 |
|
|
2790 |
"misc"
|
7
|
2791 |
#('self' 'super' 'nil' 'thisContext') do:[:name |
|
44
|
2792 |
names add:name.
|
|
2793 |
dists add:(aString spellAgainst: "levenshteinTo:"name)
|
0
|
2794 |
].
|
|
2795 |
|
|
2796 |
(dists size ~~ 0) ifTrue:[
|
44
|
2797 |
dists sortWith:names.
|
|
2798 |
dists := dists reverse.
|
|
2799 |
names := names reverse.
|
|
2800 |
n := names size min:10.
|
|
2801 |
names := names copyTo:n.
|
20
|
2802 |
|
44
|
2803 |
"if it starts with a lower case character, add all local & instvar names"
|
|
2804 |
(aString at:1) isLowercase ifTrue:[
|
|
2805 |
methodVarNames size > 0 ifTrue:[
|
|
2806 |
names add:'---- method locals ----'.
|
49
|
2807 |
methodVarNames asSortedCollection do:[:methodVarName |
|
44
|
2808 |
names add:methodVarName.
|
|
2809 |
].
|
|
2810 |
].
|
20
|
2811 |
|
|
2812 |
|
44
|
2813 |
methodArgs notNil ifTrue:[
|
|
2814 |
names add:'---- method arguments ----'.
|
49
|
2815 |
methodArgNames asSortedCollection do:[:methodArgName |
|
44
|
2816 |
names add:methodArgName.
|
|
2817 |
]
|
|
2818 |
].
|
20
|
2819 |
|
44
|
2820 |
names add:'---- instance variables ----'.
|
49
|
2821 |
PrevInstVarNames asSortedCollection do:[:instVarName |
|
44
|
2822 |
(names includes:instVarName) ifFalse:[
|
|
2823 |
names add:instVarName.
|
|
2824 |
]
|
|
2825 |
]
|
|
2826 |
].
|
20
|
2827 |
|
44
|
2828 |
^ names
|
0
|
2829 |
].
|
|
2830 |
^ nil
|
|
2831 |
!
|
|
2832 |
|
19
|
2833 |
correctVariable
|
|
2834 |
"notify error and correct if user wants to;
|
|
2835 |
return #Error if there was no correction
|
|
2836 |
or a ParseNode as returned by variable"
|
|
2837 |
|
|
2838 |
|correctIt varName suggestedNames newName pos1 pos2|
|
|
2839 |
|
|
2840 |
pos1 := tokenPosition.
|
|
2841 |
varName := tokenName.
|
|
2842 |
pos2 := pos1 + varName size - 1.
|
|
2843 |
|
|
2844 |
"OLD:
|
|
2845 |
(varName at:1) isLowercase ifTrue:[
|
44
|
2846 |
correctIt := self undefError:varName position:pos1 to:pos2.
|
|
2847 |
correctIt ifFalse:[^ #Error]
|
19
|
2848 |
] ifFalse:[
|
44
|
2849 |
correctIt := self warning:(varName , ' is undefined') position:pos1 to:pos2.
|
|
2850 |
correctIt ifFalse:[
|
|
2851 |
^ VariableNode type:#GlobalVariable name:(varName asSymbol)
|
|
2852 |
]
|
19
|
2853 |
].
|
|
2854 |
"
|
|
2855 |
|
|
2856 |
correctIt := self undefError:varName position:pos1 to:pos2.
|
|
2857 |
correctIt ifFalse:[
|
44
|
2858 |
(varName at:1) isLowercase ifTrue:[
|
|
2859 |
^ #Error
|
|
2860 |
] ifFalse:[
|
|
2861 |
^ VariableNode type:#GlobalVariable name:(varName asSymbol)
|
|
2862 |
]
|
19
|
2863 |
].
|
|
2864 |
|
|
2865 |
suggestedNames := self findBestVariablesFor:varName.
|
|
2866 |
suggestedNames notNil ifTrue:[
|
44
|
2867 |
newName := self askForCorrection:'correct variable to: ' fromList:suggestedNames.
|
|
2868 |
newName isNil ifTrue:[^ #Error].
|
19
|
2869 |
"
|
44
|
2870 |
newName := suggestedNames at:1.
|
|
2871 |
(self confirm:('confirm correction to: ' , newName)) ifFalse:[^ #Error]
|
19
|
2872 |
"
|
|
2873 |
] ifFalse:[
|
98
|
2874 |
self information:'no good correction found'.
|
44
|
2875 |
^ #Error
|
19
|
2876 |
].
|
|
2877 |
|
|
2878 |
"
|
|
2879 |
tell requestor (i.e. CodeView) about the change
|
|
2880 |
this will update what the requestor shows.
|
|
2881 |
"
|
|
2882 |
requestor replaceSelectionBy:newName.
|
|
2883 |
"
|
|
2884 |
get the updated source-string
|
|
2885 |
which is needed, when we eventually install the new method
|
|
2886 |
"
|
|
2887 |
correctedSource := requestor currentSourceCode.
|
|
2888 |
|
|
2889 |
"redo parse with new value"
|
|
2890 |
tokenName := newName.
|
|
2891 |
^ self variableOrError
|
|
2892 |
!
|
|
2893 |
|
|
2894 |
askForCorrection:aString fromList:aList
|
|
2895 |
"launch a selection box, which allows user to enter correction.
|
23
|
2896 |
return newString or nil (for abort)"
|
19
|
2897 |
|
|
2898 |
|box|
|
|
2899 |
|
85
|
2900 |
"in systems without widgets ..."
|
19
|
2901 |
ListSelectionBox isNil ifTrue:[
|
44
|
2902 |
^ self confirm:aString
|
19
|
2903 |
].
|
85
|
2904 |
box := ListSelectionBox title:aString.
|
19
|
2905 |
box initialText:(aList at:1).
|
|
2906 |
box list:aList.
|
|
2907 |
box okText:'correct'.
|
|
2908 |
box action:[:aString | ^ aString].
|
|
2909 |
box showAtPointer.
|
|
2910 |
^ nil
|
|
2911 |
!
|
|
2912 |
|
15
|
2913 |
findBestSelectorsFor:aString
|
|
2914 |
"collect known selectors with their spelling distances to aString;
|
|
2915 |
return the 10 best suggestions"
|
|
2916 |
|
19
|
2917 |
|info n|
|
15
|
2918 |
|
|
2919 |
info := SortedCollection new.
|
|
2920 |
info sortBlock:[:a :b | a value > b value].
|
|
2921 |
|
|
2922 |
n := 0.
|
|
2923 |
|
|
2924 |
Symbol allInstancesDo:[:sym |
|
44
|
2925 |
|dist|
|
15
|
2926 |
|
44
|
2927 |
dist := aString spellAgainst:sym.
|
|
2928 |
dist > 20 ifTrue:[
|
|
2929 |
info add:(sym -> dist).
|
|
2930 |
n := n + 1.
|
|
2931 |
n > 10 ifTrue:[
|
|
2932 |
info removeLast.
|
|
2933 |
]
|
|
2934 |
]
|
15
|
2935 |
].
|
|
2936 |
|
|
2937 |
^ info asOrderedCollection collect:[:a | a key]
|
|
2938 |
|
19
|
2939 |
"Time millisecondsToRun:[Parser new findBestSelectorsFor:'foo']"
|
|
2940 |
"Parser new findBestSelectorsFor:'findBestSel'"
|
|
2941 |
"Parser new findBestSelectorsFor:'fildBestSelectrFr'"
|
15
|
2942 |
!
|
|
2943 |
|
19
|
2944 |
correctSelector:aSelectorString message:msg position:pos1 to:pos2
|
0
|
2945 |
"notify error and correct if user wants to;
|
|
2946 |
return #Error if there was no correction
|
|
2947 |
or a ParseNode as returned by variable"
|
|
2948 |
|
23
|
2949 |
|correctIt suggestedNames newSelector|
|
0
|
2950 |
|
19
|
2951 |
"
|
|
2952 |
sorry, but I cannot handle keywords with more than one-part
|
|
2953 |
currently (too much work - maybe Ill do it later when everything else works :-)
|
|
2954 |
"
|
|
2955 |
(aSelectorString occurrencesOf:$:) > 1 ifTrue:[
|
44
|
2956 |
self warning:msg position:pos1 to:pos2.
|
|
2957 |
^ aSelectorString
|
0
|
2958 |
].
|
|
2959 |
|
19
|
2960 |
correctIt := self correctableError:msg position:pos1 to:pos2.
|
|
2961 |
correctIt ifFalse:[^ aSelectorString].
|
|
2962 |
|
|
2963 |
suggestedNames := self findBestSelectorsFor:aSelectorString.
|
0
|
2964 |
suggestedNames notNil ifTrue:[
|
44
|
2965 |
newSelector := self askForCorrection:'correct selector to: ' fromList:suggestedNames.
|
|
2966 |
newSelector isNil ifTrue:[^ aSelectorString].
|
0
|
2967 |
] ifFalse:[
|
98
|
2968 |
self information:'no good correction found'.
|
44
|
2969 |
^ aSelectorString
|
0
|
2970 |
].
|
|
2971 |
|
19
|
2972 |
"
|
|
2973 |
tell requestor (i.e. CodeView) about the change
|
|
2974 |
this will update what the requestor shows.
|
|
2975 |
"
|
0
|
2976 |
|
19
|
2977 |
requestor replaceSelectionBy:newSelector keepCursor:false.
|
|
2978 |
"
|
|
2979 |
get the updated source-string
|
|
2980 |
which is needed, when we eventually install the new method
|
|
2981 |
"
|
|
2982 |
correctedSource := requestor currentSourceCode.
|
|
2983 |
|
|
2984 |
^ newSelector
|
0
|
2985 |
!
|
|
2986 |
|
19
|
2987 |
selectorCheck:aSelectorString for:receiver position:pos1 to:pos2
|
47
|
2988 |
"just a quick check: if a selector is totally unknown as a symbol,
|
|
2989 |
or has the same name as a variable or cannot be understood.
|
19
|
2990 |
Simple, but catches many typos"
|
|
2991 |
|
60
|
2992 |
|ok err sym rec superCls|
|
21
|
2993 |
|
45
|
2994 |
"
|
|
2995 |
if compiling lazy, or errors are to be ignored, or there
|
|
2996 |
is no requestor, do not check
|
|
2997 |
"
|
21
|
2998 |
(LazyCompilation == true) ifTrue:[^ aSelectorString].
|
|
2999 |
(ignoreErrors or:[ignoreWarnings]) ifTrue:[^ aSelectorString].
|
60
|
3000 |
(requestor isNil or:[requestor isStream]) ifTrue:[^ aSelectorString].
|
0
|
3001 |
|
21
|
3002 |
err := ' is currently nowhere implemented'.
|
|
3003 |
"
|
47
|
3004 |
if the selector has the name of a variable, use another message
|
|
3005 |
"
|
|
3006 |
((methodVarNames notNil and:[methodVarNames includes:aSelectorString])
|
|
3007 |
or:[(methodArgNames notNil and:[methodArgNames includes:aSelectorString])
|
|
3008 |
or:[(self instVarNames notNil and:[self instVarNames includes:aSelectorString])
|
|
3009 |
or:[(self classInstVarNames notNil and:[self classInstVarNames includes:aSelectorString])
|
|
3010 |
or:[(self classVarNames notNil and:[self classVarNames includes:aSelectorString])]]]]) ifTrue:[
|
|
3011 |
err := ' is currently nowhere implemented ..
|
|
3012 |
.. but a variable with that name is defined.
|
|
3013 |
|
|
3014 |
Missing ''.'' after the previous expression ?'.
|
|
3015 |
].
|
|
3016 |
|
|
3017 |
"
|
21
|
3018 |
check if the selector is known at all
|
|
3019 |
- if not, it cannot be understood
|
|
3020 |
"
|
64
|
3021 |
ok := false.
|
63
|
3022 |
sym := aSelectorString asSymbolIfInterned.
|
|
3023 |
sym notNil ifTrue:[
|
64
|
3024 |
ok := true.
|
44
|
3025 |
receiver notNil ifTrue:[
|
|
3026 |
"
|
|
3027 |
if the receiver is a constant, we can check if it responds
|
|
3028 |
to this selector
|
|
3029 |
"
|
|
3030 |
receiver isConstant ifTrue:[
|
|
3031 |
ok := receiver evaluate respondsTo:sym.
|
|
3032 |
err := ' will not be understood here'.
|
|
3033 |
] ifFalse:[
|
|
3034 |
"
|
|
3035 |
if the receiver is a global, we check it too ...
|
|
3036 |
"
|
|
3037 |
receiver type == #GlobalVariable ifTrue:[
|
47
|
3038 |
"dont check autoloaded classes - it may work after
|
|
3039 |
loading"
|
|
3040 |
|
|
3041 |
rec := receiver evaluate.
|
|
3042 |
(rec notNil
|
|
3043 |
and:[rec isBehavior
|
|
3044 |
and:[rec isLoaded not]]) ifTrue:[^ aSelectorString].
|
|
3045 |
|
|
3046 |
ok := rec respondsTo:sym.
|
44
|
3047 |
err := ' may not be understood here'.
|
|
3048 |
] ifFalse:[
|
49
|
3049 |
"if its a super send, we can do more checking"
|
|
3050 |
receiver isSuper ifTrue:[
|
50
|
3051 |
receiver isHere ifFalse:[
|
60
|
3052 |
((superCls := classToCompileFor superclass) notNil
|
84
|
3053 |
and:[(superCls whichClassIncludesSelector:sym) isNil]) ifTrue:[
|
50
|
3054 |
err := ' is currently not implemented in any superclass'.
|
|
3055 |
ok := false
|
49
|
3056 |
]
|
|
3057 |
] ifTrue:[
|
84
|
3058 |
(classToCompileFor whichClassIncludesSelector:sym) isNil ifTrue:[
|
50
|
3059 |
err := ' is currently not implemented in this class'.
|
|
3060 |
ok := false
|
45
|
3061 |
]
|
|
3062 |
]
|
|
3063 |
].
|
49
|
3064 |
|
|
3065 |
(receiver isUnaryMessage
|
|
3066 |
and:[receiver selector == #class
|
|
3067 |
and:[receiver receiver type == #Self]]) ifTrue:[
|
|
3068 |
"its a message to self class - can check this too ..."
|
84
|
3069 |
(classToCompileFor class whichClassIncludesSelector:sym) isNil ifTrue:[
|
49
|
3070 |
ok := false.
|
|
3071 |
classToCompileFor allSubclasses do:[:subclass |
|
|
3072 |
(subclass class implements:sym) ifTrue:[
|
|
3073 |
ok := true
|
|
3074 |
]
|
|
3075 |
].
|
|
3076 |
err := ' is currently not implemented in the class'.
|
|
3077 |
]
|
|
3078 |
]
|
44
|
3079 |
]
|
|
3080 |
]
|
|
3081 |
]
|
21
|
3082 |
].
|
49
|
3083 |
|
21
|
3084 |
ok ifFalse:[
|
0
|
3085 |
|
19
|
3086 |
"OLD: "
|
44
|
3087 |
self warning:('#' , aSelectorString , err) position:pos1 to:pos2
|
19
|
3088 |
" "
|
|
3089 |
|
|
3090 |
"NEW: - not finished - need more interfaces
|
|
3091 |
(currently produces warning output on Transcript while filing in
|
|
3092 |
|
|
3093 |
|
44
|
3094 |
^ self correctSelector:aSelectorString message:('#' , aSelectorString , err) position:pos1 to:pos2
|
19
|
3095 |
"
|
0
|
3096 |
].
|
19
|
3097 |
^ aSelectorString
|
0
|
3098 |
! !
|