author | Claus Gittinger <cg@exept.de> |
Sat, 08 Feb 1997 20:02:43 +0100 | |
changeset 493 | 77e0d6979865 |
parent 492 | fe778fd0ce46 |
child 494 | bb3e71c90dfd |
permissions | -rw-r--r-- |
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 |
|
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
14 |
instanceVariableNames:'classToCompileFor selfValue contextToEvaluateIn selector |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
15 |
methodArgs methodArgNames methodVars methodVarNames tree |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
16 |
currentBlock parseForCode usedInstVars usedClassVars usedVars |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
17 |
modifiedInstVars modifiedClassVars modifiedGlobals usesSuper |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
18 |
usedGlobals usedSymbols usedMessages localVarDefPosition |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
19 |
evalExitBlock selfNode superNode hasPrimitiveCode |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
20 |
hasNonOptionalPrimitiveCode primitiveNr primitiveResource logged |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
21 |
warnedUndefVars warnSTXHereExtensionUsed correctedSource |
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
22 |
foldConstants lineNumberInfo currentNamespace |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
23 |
currentUsedNamespaces' |
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
24 |
classVariableNames:'PrevClass PrevInstVarNames PrevClassVarNames |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
25 |
PrevClassInstVarNames LazyCompilation ArraysAreImmutable |
376 | 26 |
ImplicitSelfSends WarnST80Directives FoldConstants LineNumberInfo' |
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
27 |
poolDictionaries:'' |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
28 |
category:'System-Compiler' |
0 | 29 |
! |
30 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
31 |
!Parser class methodsFor:'documentation'! |
19 | 32 |
|
20 | 33 |
copyright |
34 |
" |
|
35 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
44 | 36 |
All Rights Reserved |
20 | 37 |
|
38 |
This software is furnished under a license and may be used |
|
39 |
only in accordance with the terms of that license and with the |
|
40 |
inclusion of the above copyright notice. This software may not |
|
41 |
be provided or otherwise made available to, or used by, any |
|
42 |
other person. No title to or ownership of the software is |
|
43 |
hereby transferred. |
|
44 |
" |
|
45 |
! |
|
46 |
||
19 | 47 |
documentation |
48 |
" |
|
49 |
Parser is used for both parsing and evaluating smalltalk expressions; |
|
50 |
it first builds a parseTree which is then interpreted (evaluate) or |
|
51 |
compiled. Compilation is done in the subclass ByteCodeCompiler and/or |
|
52 |
the (planned) MachineCodeCompiler. |
|
53 |
||
173
247ae4b8af76
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
171
diff
changeset
|
54 |
methods of main interest are: |
260 | 55 |
Parser evaluateExpression:... |
19 | 56 |
|
57 |
and: |
|
260 | 58 |
Parser parseExpression:... |
59 |
Parser parseMethod:... |
|
19 | 60 |
|
61 |
there is protocol to parse complete methods, selector specs, body only etc. |
|
62 |
||
63 |
Parser is also used to find the referenced/modified inst/classvars of |
|
64 |
a method - this is done by sending parseXXX message to a parser and asking |
|
65 |
the parser for referencedXVars or modifiedXVars (see SystemBrowser). |
|
66 |
||
67 |
You can also use parsers for all kinds of other things (ChangesBrowser for |
|
68 |
example analyzes the expressions in the changelist ...) by looking at the |
|
69 |
parsers tree. (Although this is somewhat dangerous, since it exports the |
|
20 | 70 |
compilers internals ... better style is to add specialized query methods here, |
71 |
which will be done incrementally.) |
|
19 | 72 |
|
73 |
One instance of Parser is created to parse one method or expression - i.e. |
|
74 |
its not suggested to reuse parsers. |
|
75 |
||
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
76 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
77 |
Constant folding: |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
78 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
79 |
The parser has various modes for constant folding; by default, only numeric |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
80 |
expressions involving integers and floats are constant folded |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
81 |
(i.e. something like 'Float pi sin' or '1.5 + 0.3' will be reduced to a constant). |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
82 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
83 |
Constant folding can be turned off completely (setting FoldConstants to nil) |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
84 |
to ``secure folding'', which only folds constant numbers (#level1) or to #full. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
85 |
In full mode, more constant expressions are folded (for example: '1.0 @ 1.0' is |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
86 |
reduced to a constant point), but the resulting code may not be compatible with other |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
87 |
smalltalk systems (consider the case, where the point is modified using #x: or #y: messages). |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
88 |
Therefore, this mode is a bit dangerous and disabled by default. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
89 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
90 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
91 |
Immutable arrays: |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
92 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
93 |
Immutable arrays are experimental and being evaluated. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
94 |
Consider the case of a method returning '#(1 2 3 4)', and that array being modified |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
95 |
by some other method (using #at:put:). Since the array-return is actually a return of |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
96 |
a reference to the compiler created array, the next invokation of the method will |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
97 |
return the modified array. These are hard to find bugs. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
98 |
By an option, the compiler can generate immutable arrays, which dont allow modification |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
99 |
of its elements. For clean code, you should enable this option during development. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
100 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
101 |
As mentioned above, this is experimental. If it is reported to be a useful feature, |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
102 |
the immutable feature will be extended to strings, point-literals etc. in a future version |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
103 |
of st/x. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
104 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
105 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
106 |
|
260 | 107 |
[Instance variables:] |
108 |
||
109 |
classToCompileFor <Class> the class (or nil) we are compiling for |
|
110 |
||
111 |
selfValue <any> value to use as self when interpreting |
|
112 |
||
113 |
contextToEvaluateIn <Context> the context (or nil) when interpreting |
|
114 |
||
115 |
selector <Symbol> the selector of the parsed method |
|
116 |
(valid after parseMethodSpecification) |
|
117 |
methodArgs internal |
|
118 |
||
119 |
methodArgNames <Collection> the names of the arguments |
|
120 |
(valid after parseMethodSpecification) |
|
121 |
||
122 |
methodVars internal |
|
123 |
||
124 |
methodVarNames <Collection> the names of the method locals |
|
125 |
(valid after parseMethodBodyVarSpec) |
|
126 |
||
127 |
tree <ParseTree> the parse tree - valid after parsing |
|
128 |
||
129 |
currentBlock if currently parsing for a block |
|
130 |
||
131 |
usedInstVars set of all accessed instances variables |
|
132 |
(valid after parsing) |
|
133 |
||
134 |
usedClassVars same for classVars |
|
135 |
||
136 |
usedVars all used variables (inst, class & globals) |
|
137 |
||
138 |
modifiedInstVars set of all modified instance variables |
|
139 |
||
140 |
modifiedClassVars same for clasVars |
|
141 |
||
142 |
localVarDefPosition <Integer> the character offset of the local variable |
|
143 |
def. (i.e. the first '|' if any) |
|
144 |
Not yet used - prepared for automatic add of |
|
145 |
undefined variables |
|
146 |
||
147 |
evalExitBlock internal for interpretation |
|
148 |
||
149 |
selfNode <Node> cached one-and-only 'self' node |
|
150 |
superNode <Node> cached one-and-only 'super' node |
|
151 |
||
152 |
hasPrimitiveCode <Boolean> true, if it contains ST/X style primitive code |
|
153 |
hasNonOptionalPrimitiveCode |
|
154 |
<Boolean> true, if it contains ST/X style primitive code |
|
155 |
which is NOT flagged by the OPTIONAL directive. |
|
156 |
||
157 |
primitiveNr <Integer> the parsed ST-80 type primitive number (or nil) |
|
158 |
||
159 |
logged |
|
160 |
||
161 |
warnedUndefVars <Set> set of all variables which the parser has |
|
162 |
already output a warning (to avoid multiple |
|
163 |
warnings about the same variable) |
|
164 |
||
165 |
[Class variables:] |
|
166 |
||
167 |
PrevClass <Class> class, of which properties are |
|
168 |
cached in: |
|
169 |
||
170 |
PrevInstVarNames <Collection> instance variablenames of cached class |
|
171 |
PrevClassVarNames <Collection> class variablenames of cached class |
|
172 |
PrevClassInstVarNames <Collection> class instance variablenames of cached class |
|
173 |
||
174 |
LazyCompilation <Boolean> EXPERIMENTAL: lazy compilation |
|
175 |
||
176 |
ArraysAreImmutable <Boolean> if true, create array literals |
|
177 |
as instances of ImmutableArray, |
|
178 |
which cannot be stored into. |
|
179 |
Default is false, for compatibility. |
|
180 |
Can be turned on while developping |
|
181 |
new code to make certain that side |
|
182 |
effects are avoided. |
|
183 |
||
184 |
WarnST80Directives <Boolean> if true, give warnings about |
|
185 |
ST-80 directives (resource defs) |
|
186 |
which are ignored in st/x. |
|
187 |
defaults to false. |
|
188 |
||
189 |
FoldConstants <Symbol> controls how constant folding should be |
|
190 |
done. |
|
191 |
Can be one of: |
|
192 |
nil - no constant folding |
|
193 |
#level1 - numeric optimizations only |
|
194 |
#level2 - secure optimizations only |
|
195 |
#full - full folding |
|
196 |
||
197 |
level1: arithmetic on constant numbers |
|
198 |
||
199 |
level2: above PLUS array conversions with #asFloatArray, |
|
200 |
#asDoubleArray, string concatenation |
|
201 |
||
202 |
full: constant points. |
|
203 |
||
204 |
[see also:] |
|
205 |
ByteCodeCompiler Scanner ObjectFileLoader |
|
206 |
Workspace |
|
207 |
SystemBrowser |
|
263 | 208 |
|
209 |
[author:] |
|
210 |
Claus Gittinger |
|
19 | 211 |
" |
141 | 212 |
! ! |
213 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
214 |
!Parser class methodsFor:'instance creation'! |
141 | 215 |
|
216 |
for:aStringOrStream in:aClass |
|
217 |
"return a new parser, reading code for aClass from aStringOrStream" |
|
218 |
||
219 |
|parser| |
|
220 |
||
221 |
parser := self for:aStringOrStream. |
|
222 |
parser setClassToCompileFor:aClass. |
|
223 |
^ parser |
|
224 |
! ! |
|
225 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
226 |
!Parser class methodsFor:'changes'! |
141 | 227 |
|
228 |
flushNameCache |
|
229 |
"unconditional flush name caches" |
|
230 |
||
231 |
PrevClass notNil ifTrue:[ |
|
232 |
PrevClass removeDependent:Parser |
|
233 |
]. |
|
234 |
PrevClass := nil. |
|
235 |
PrevInstVarNames := nil. |
|
236 |
PrevClassVarNames := nil. |
|
237 |
PrevClassInstVarNames := nil. |
|
238 |
||
239 |
"Parser flushNameCache" |
|
240 |
! |
|
241 |
||
242 |
update:something with:someArgument from:changedObject |
|
243 |
"aClass has changed its definition - flush name caches if we have to" |
|
244 |
||
245 |
(changedObject == PrevClass) ifTrue:[ |
|
246 |
something == #definition ifTrue:[ |
|
247 |
self flushNameCache |
|
248 |
] |
|
249 |
] |
|
250 |
! ! |
|
251 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
252 |
!Parser class methodsFor:'controlling compilation'! |
141 | 253 |
|
254 |
arraysAreImmutable |
|
255 |
"return true if arrays are immutable literals" |
|
256 |
||
257 |
^ ArraysAreImmutable |
|
258 |
! |
|
259 |
||
260 |
arraysAreImmutable:aBoolean |
|
261 |
"turn on/off immutable array literals - default is false for ST-80 compatibilty." |
|
262 |
||
263 |
ArraysAreImmutable := aBoolean. |
|
264 |
||
265 |
" |
|
266 |
can be added to your private.rc file: |
|
267 |
||
268 |
Compiler arraysAreImmutable:true |
|
269 |
Compiler arraysAreImmutable:false |
|
270 |
" |
|
271 |
! |
|
272 |
||
273 |
compileLazy |
|
274 |
"return true if compiling lazy" |
|
275 |
||
276 |
^ LazyCompilation. |
|
277 |
! |
|
278 |
||
279 |
compileLazy:aBoolean |
|
280 |
"turn on/off lazy compilation - return previous setting. |
|
281 |
Actually this flag belongs into the ByteCodeCompiler subclass, |
|
282 |
but it also controls the reporting of some errors here; therefore |
|
283 |
its located here" |
|
284 |
||
285 |
|oldLazy| |
|
286 |
||
287 |
oldLazy := LazyCompilation. |
|
288 |
LazyCompilation := aBoolean. |
|
289 |
^ oldLazy |
|
290 |
||
291 |
" |
|
292 |
usually set in your .rc file |
|
293 |
||
294 |
Compiler compileLazy:false |
|
295 |
Compiler compileLazy:true |
|
296 |
" |
|
297 |
! |
|
298 |
||
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
299 |
foldConstants |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
300 |
"return a symbol describing how constants are to be folded" |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
301 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
302 |
^ FoldConstants |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
303 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
304 |
"Created: 9.2.1996 / 17:40:13 / cg" |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
305 |
! |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
306 |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
307 |
foldConstants:aSymbol |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
308 |
"set the symbol describing how constants are to be folded. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
309 |
It can be: |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
310 |
nil - no constant folding |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
311 |
#level1 - numeric constants only |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
312 |
#level2 - level1 PLUS array conversions PLUS string concatenation |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
313 |
#full - level2 PLUS constant points, constant rectangles (dangerous)" |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
314 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
315 |
FoldConstants := aSymbol |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
316 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
317 |
"Created: 9.2.1996 / 17:40:34 / cg" |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
318 |
! |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
319 |
|
141 | 320 |
implicitSelfSends |
321 |
"return true if undefined variables with |
|
322 |
lowercase first character are to be turned |
|
323 |
into implicit self sends" |
|
324 |
||
325 |
^ ImplicitSelfSends |
|
326 |
! |
|
327 |
||
328 |
implicitSelfSends:aBoolean |
|
329 |
"turn on/off implicit self sends" |
|
330 |
||
331 |
ImplicitSelfSends := aBoolean |
|
332 |
||
333 |
" |
|
334 |
Compiler implicitSelfSends:true |
|
335 |
Compiler implicitSelfSends:false |
|
336 |
" |
|
377 | 337 |
! |
338 |
||
339 |
lineNumberInfo |
|
340 |
^ LineNumberInfo |
|
341 |
! |
|
342 |
||
343 |
lineNumberInfo:aBoolean |
|
344 |
LineNumberInfo := aBoolean |
|
19 | 345 |
! ! |
0 | 346 |
|
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
347 |
!Parser class methodsFor:'defaults'! |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
348 |
|
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
349 |
maxLineNumber |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
350 |
"return the maximum lineNumber that is possibly |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
351 |
encoded in a methods byteCode debugging information. |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
352 |
Since lineNumber entries only have 1 byte available, |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
353 |
this is 255 for byteCode methods." |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
354 |
|
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
355 |
^ 255 |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
356 |
|
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
357 |
"Created: 14.2.1997 / 16:52:54 / cg" |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
358 |
! ! |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
359 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
360 |
!Parser class methodsFor:'evaluating expressions'! |
0 | 361 |
|
19 | 362 |
evaluate:aStringOrStream |
71 | 363 |
"return the result of evaluating an expression in aStringOrStream. |
364 |
No doit-entry is added to the changeLog." |
|
0 | 365 |
|
19 | 366 |
^ self |
44 | 367 |
evaluate:aStringOrStream |
368 |
in:nil |
|
369 |
receiver:nil |
|
370 |
notifying:nil |
|
371 |
logged:false |
|
372 |
ifFail:nil |
|
71 | 373 |
compile:true |
19 | 374 |
|
375 |
" |
|
376 |
Compiler evaluate:'1 + 2' |
|
377 |
Compiler evaluate:'''hello world'' asSortedCollection displayString printNL' |
|
378 |
Compiler evaluate:'''hello world'' asSortedCollection printNL' |
|
379 |
" |
|
0 | 380 |
! |
381 |
||
71 | 382 |
evaluate:aStringOrStream compile:compile |
383 |
"return the result of evaluating aString, |
|
384 |
The compile argument specifies if the string should be compiled down to |
|
385 |
bytecode or instead be interpreted from the parseTree. |
|
386 |
The first should be done for doIts etc, where a readable walkback is |
|
387 |
required. |
|
388 |
The latter is better done for constants, styleSheet and resource |
|
389 |
reading and simple sends, where the overhead of compilation is bigger |
|
390 |
than the interpretation overhead." |
|
391 |
||
392 |
^ self |
|
393 |
evaluate:aStringOrStream |
|
394 |
in:nil |
|
395 |
receiver:nil |
|
396 |
notifying:nil |
|
397 |
logged:false |
|
398 |
ifFail:nil |
|
399 |
compile:compile |
|
400 |
! |
|
401 |
||
20 | 402 |
evaluate:aStringOrStream ifFail:failBlock |
403 |
"return the result of evaluating an expression in aStringOrStream. |
|
71 | 404 |
In case of any syntax errors, return the value of failBlock. |
405 |
No doit-entry is added to the changeLog." |
|
20 | 406 |
|
407 |
^ self |
|
44 | 408 |
evaluate:aStringOrStream |
409 |
in:nil |
|
410 |
receiver:nil |
|
411 |
notifying:nil |
|
412 |
logged:false |
|
413 |
ifFail:failBlock |
|
71 | 414 |
compile:true |
20 | 415 |
" |
416 |
Compiler evaluate:'1 +' ifFail:['oops'] |
|
417 |
" |
|
418 |
! |
|
419 |
||
71 | 420 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor ifFail:failBlock |
421 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
422 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
423 |
No doIt entry is added to the change-file. |
|
424 |
If the failBlock argument is non-nil, it is evaluated if an error occurs." |
|
425 |
||
426 |
^ self |
|
427 |
evaluate:aStringOrStream |
|
428 |
in:nil |
|
429 |
receiver:anObject |
|
430 |
notifying:requestor |
|
431 |
logged:false |
|
432 |
ifFail:nil |
|
433 |
compile:true |
|
20 | 434 |
! |
435 |
||
436 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock |
|
437 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
438 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
439 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
440 |
is non-nil, it is evaluated if an error occurs." |
|
441 |
||
71 | 442 |
^ self |
443 |
evaluate:aStringOrStream |
|
444 |
in:aContext |
|
445 |
receiver:anObject |
|
446 |
notifying:requestor |
|
447 |
logged:logged |
|
448 |
ifFail:failBlock |
|
449 |
compile:true |
|
450 |
! |
|
451 |
||
452 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile |
|
453 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
454 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
455 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
456 |
is non-nil, it is evaluated if an error occurs. |
|
457 |
Finally, compile specifies if the string should be compiled down to |
|
458 |
bytecode or instead be interpreted from the parseTree. |
|
459 |
The first should be done for doIts etc, where a readable walkback is |
|
460 |
required. |
|
461 |
The latter is better done for constants, styleSheet and resource |
|
462 |
reading and simple sends, where the overhead of compilation is bigger |
|
463 |
than the interpretation overhead." |
|
464 |
||
492
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
465 |
^ self |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
466 |
evaluate:aStringOrStream |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
467 |
in:aContext |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
468 |
receiver:anObject |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
469 |
notifying:requestor |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
470 |
logged:logged |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
471 |
ifFail:failBlock |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
472 |
compile:compile |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
473 |
defaultNameSpace:nil |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
474 |
|
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
475 |
"Modified: 8.2.1997 / 19:35:40 / cg" |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
476 |
! |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
477 |
|
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
478 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile defaultNameSpace:aNameSpaceOrNil |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
479 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
480 |
Allow access to anObject as self and to its instVars (used in the inspector). |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
481 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
482 |
is non-nil, it is evaluated if an error occurs. |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
483 |
Finally, compile specifies if the string should be compiled down to |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
484 |
bytecode or instead be interpreted from the parseTree. |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
485 |
The first should be done for doIts etc, where a readable walkback is |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
486 |
required. |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
487 |
The latter is better done for constants, styleSheet and resource |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
488 |
reading and simple sends, where the overhead of compilation is bigger |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
489 |
than the interpretation overhead." |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
490 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
491 |
|parser tree mustBackup loggedString chgStream value s sReal spc| |
0 | 492 |
|
493 |
aStringOrStream isNil ifTrue:[^ nil]. |
|
493
77e0d6979865
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
492
diff
changeset
|
494 |
(mustBackup := aStringOrStream isStream) ifTrue:[ |
260 | 495 |
s := aStringOrStream. |
0 | 496 |
] ifFalse:[ |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
497 |
loggedString := aStringOrStream. |
260 | 498 |
s := ReadStream on:aStringOrStream. |
0 | 499 |
]. |
260 | 500 |
parser := self for:s. |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
501 |
parser parseForCode. |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
502 |
parser foldConstants:nil. |
0 | 503 |
parser setSelf:anObject. |
504 |
parser setContext:aContext. |
|
505 |
parser notifying:requestor. |
|
506 |
parser nextToken. |
|
492
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
507 |
parser currentNameSpace:aNameSpaceOrNil. |
79 | 508 |
tree := parser parseMethodBodyOrEmpty. |
0 | 509 |
|
510 |
"if reading from a stream, backup for next expression" |
|
511 |
mustBackup ifTrue:[ |
|
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
512 |
parser backupPosition |
0 | 513 |
]. |
514 |
||
515 |
(parser errorFlag or:[tree == #Error]) ifTrue:[ |
|
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
516 |
failBlock notNil ifTrue:[ |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
517 |
^ failBlock value |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
518 |
]. |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
519 |
^ #Error |
0 | 520 |
]. |
260 | 521 |
|
0 | 522 |
tree notNil ifTrue:[ |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
523 |
(logged |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
524 |
and:[loggedString notNil |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
525 |
and:[Smalltalk logDoits]]) ifTrue:[ |
489 | 526 |
Class updateChangeFileQuerySignal raise ifTrue:[ |
527 |
chgStream := Class changesStream. |
|
528 |
chgStream notNil ifTrue:[ |
|
529 |
chgStream nextChunkPut:loggedString. |
|
530 |
chgStream cr. |
|
531 |
chgStream close |
|
532 |
] |
|
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
533 |
]. |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
534 |
]. |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
535 |
|
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
536 |
" |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
537 |
during the evaluation, handle nameSpace queries |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
538 |
from the value as defined by any namespace directive. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
539 |
This, if its a class definition expression, the class will |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
540 |
be installed there. |
260 | 541 |
" |
492
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
542 |
spc := aNameSpaceOrNil. |
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
543 |
Class nameSpaceQuerySignal handle:[:ex | |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
544 |
spc isNil ifTrue:[ |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
545 |
spc := parser getNameSpace. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
546 |
spc isNil ifTrue:[ |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
547 |
(requestor respondsTo:#currentNameSpace) ifTrue:[ |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
548 |
spc := requestor currentNameSpace |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
549 |
] ifFalse:[ |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
550 |
spc := Class nameSpaceQuerySignal raise. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
551 |
] |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
552 |
] |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
553 |
]. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
554 |
ex proceedWith:spc. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
555 |
] do:[ |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
556 |
|method| |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
557 |
|
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
558 |
" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
559 |
if compile is false, or the parse tree is that of a constant, |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
560 |
or a variable, quickly return its value. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
561 |
This is used for example, when reading simple objects |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
562 |
via #readFrom:. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
563 |
The overhead of compiling a method is avoided in this case. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
564 |
" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
565 |
(compile not |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
566 |
or:[tree isConstant |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
567 |
or:[tree isVariable |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
568 |
or:[aStringOrStream isStream]]]) ifTrue:[ |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
569 |
^ tree evaluate |
260 | 570 |
]. |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
571 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
572 |
" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
573 |
if I am the ByteCodeCompiler, |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
574 |
generate a dummy method, execute it and return the value. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
575 |
otherwise, just evaluate the tree; slower, but not too bad ... |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
576 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
577 |
This allows systems to be delivered without the ByteCodeCompiler, |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
578 |
and still evaluate expressions |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
579 |
(needed to read resource files or to process .rc files). |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
580 |
" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
581 |
self == Parser ifTrue:[ |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
582 |
parser evalExitBlock:[:value | parser release. ^ value]. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
583 |
value := tree evaluate. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
584 |
parser evalExitBlock:nil. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
585 |
] ifFalse:[ |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
586 |
aStringOrStream isStream ifTrue:[ |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
587 |
s := parser collectedSource. "/ does not work yet ... |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
588 |
] ifFalse:[ |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
589 |
s := aStringOrStream |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
590 |
]. |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
591 |
|
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
592 |
"/ actually, its a block, to allow |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
593 |
"/ easy return ... |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
594 |
|
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
595 |
sReal := 'doIt ^[\' withCRs , s , '\] value' withCRs. |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
596 |
|
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
597 |
method := self |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
598 |
compile:sReal |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
599 |
forClass:anObject class |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
600 |
inCategory:'_temporary_' |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
601 |
notifying:requestor |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
602 |
install:false |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
603 |
skipIfSame:false |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
604 |
silent:true |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
605 |
foldConstants:false. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
606 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
607 |
method notNil ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
608 |
method ~~ #Error ifTrue:[ |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
609 |
" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
610 |
fake: patch the source string, to what the user expects |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
611 |
in the browser |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
612 |
" |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
613 |
method source:' \' withCRs , s . |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
614 |
" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
615 |
dont do any just-in-time compilation on it. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
616 |
" |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
617 |
method checked:true. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
618 |
|
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
619 |
value := method |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
620 |
valueWithReceiver:anObject |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
621 |
arguments:nil "/ (Array with:m) |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
622 |
selector:#doIt "/ #doIt: |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
623 |
search:nil |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
624 |
sender:nil. |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
625 |
] ifFalse:[ |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
626 |
parser evalExitBlock:[:value | parser release. ^ value]. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
627 |
value := tree evaluate. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
628 |
parser evalExitBlock:nil. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
629 |
] |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
630 |
]. |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
631 |
] |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
632 |
] |
0 | 633 |
]. |
35 | 634 |
parser release. |
635 |
^ value |
|
260 | 636 |
|
492
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
637 |
"Created: 8.2.1997 / 19:34:44 / cg" |
493
77e0d6979865
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
492
diff
changeset
|
638 |
"Modified: 8.2.1997 / 20:02:22 / cg" |
141 | 639 |
! |
640 |
||
641 |
evaluate:aStringOrStream logged:logged |
|
642 |
"return the result of evaluating an expression in aStringOrStream. |
|
643 |
The argument log controls if an entry is added to the changeLog." |
|
644 |
||
645 |
^ self |
|
646 |
evaluate:aStringOrStream |
|
647 |
in:nil |
|
648 |
receiver:nil |
|
649 |
notifying:nil |
|
650 |
logged:logged |
|
651 |
ifFail:nil |
|
652 |
compile:true |
|
653 |
" |
|
654 |
Compiler evaluate:'''some string''' logged:false |
|
655 |
Compiler evaluate:'''some string''' logged:true |
|
656 |
" |
|
657 |
! |
|
658 |
||
659 |
evaluate:aStringOrStream notifying:requestor |
|
660 |
"return the result of evaluating aString, |
|
661 |
errors are reported to requestor" |
|
662 |
||
663 |
^ self |
|
664 |
evaluate:aStringOrStream |
|
665 |
in:nil |
|
666 |
receiver:nil |
|
667 |
notifying:requestor |
|
668 |
logged:false |
|
669 |
ifFail:nil |
|
670 |
compile:true |
|
671 |
! |
|
672 |
||
673 |
evaluate:aStringOrStream notifying:requestor compile:compile |
|
674 |
"return the result of evaluating aString, |
|
675 |
errors are reported to requestor. |
|
676 |
The compile argument specifies if the string should be compiled down to |
|
677 |
bytecode or instead be interpreted from the parseTree. |
|
678 |
The first should be done for doIts etc, where a readable walkback is |
|
679 |
required. |
|
680 |
The latter is better done for constants, styleSheet and resource |
|
681 |
reading and simple sends, where the overhead of compilation is bigger |
|
682 |
than the interpretation overhead." |
|
683 |
||
684 |
^ self |
|
685 |
evaluate:aStringOrStream |
|
686 |
in:nil |
|
687 |
receiver:nil |
|
688 |
notifying:requestor |
|
689 |
logged:false |
|
690 |
ifFail:nil |
|
691 |
compile:compile |
|
692 |
! |
|
693 |
||
694 |
evaluate:aStringOrStream receiver:anObject notifying:requestor |
|
695 |
"return the result of evaluating aString, |
|
696 |
errors are reported to requestor. Allow access to |
|
697 |
anObject as self and to its instVars (used in the inspector)" |
|
698 |
||
699 |
^ self |
|
700 |
evaluate:aStringOrStream |
|
701 |
in:nil |
|
702 |
receiver:anObject |
|
703 |
notifying:requestor |
|
704 |
logged:false |
|
705 |
ifFail:nil |
|
706 |
compile:true |
|
707 |
||
708 |
" |
|
709 |
Compiler evaluate:'self x' receiver:(1 @ 2) notifying:nil |
|
710 |
" |
|
711 |
! |
|
712 |
||
713 |
evaluate:aStringOrStream receiver:anObject notifying:requestor compile:compile |
|
714 |
"return the result of evaluating aString, |
|
715 |
errors are reported to requestor. Allow access to |
|
716 |
anObject as self and to its instVars (used in the inspector). |
|
717 |
The compile argument specifies if the string should be compiled down to |
|
718 |
bytecode or instead be interpreted from the parseTree. |
|
719 |
The first should be done for doIts etc, where a readable walkback is |
|
720 |
required. |
|
721 |
The latter is better done for constants, styleSheet and resource |
|
722 |
reading and simple sends, where the overhead of compilation is bigger |
|
723 |
than the interpretation overhead." |
|
724 |
||
725 |
^ self |
|
726 |
evaluate:aStringOrStream |
|
727 |
in:nil |
|
728 |
receiver:anObject |
|
729 |
notifying:requestor |
|
730 |
logged:false |
|
731 |
ifFail:nil |
|
732 |
compile:compile |
|
0 | 733 |
! ! |
734 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
735 |
!Parser class methodsFor:'initialization '! |
66 | 736 |
|
737 |
initialize |
|
98 | 738 |
LazyCompilation := false. "/ usually set to true in your .rc file |
739 |
ArraysAreImmutable := false. "/ usually left true for ST-80 compatibility |
|
207
6ab9eb3c1cf0
by default, dont warn about ST80 directives
Claus Gittinger <cg@exept.de>
parents:
202
diff
changeset
|
740 |
ImplicitSelfSends := false. |
6ab9eb3c1cf0
by default, dont warn about ST80 directives
Claus Gittinger <cg@exept.de>
parents:
202
diff
changeset
|
741 |
WarnST80Directives := false. |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
742 |
FoldConstants := #level1. |
377 | 743 |
LineNumberInfo := false. |
744 |
||
745 |
" |
|
746 |
self initialize |
|
747 |
" |
|
66 | 748 |
! ! |
749 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
750 |
!Parser class methodsFor:'parsing'! |
141 | 751 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
752 |
blockAtLine:line in:aMethod orSource:aString numArgs:nA numVars:nV |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
753 |
"given a lineNr in some method, |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
754 |
return the containing BlockNode or nil. |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
755 |
The given lineNr must be within a block for this to work. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
756 |
This is used by the debugger, to guess reverse from a lineNumber, |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
757 |
to the corresponding block, in order to find out the blocks |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
758 |
variable names (mhmh - all of this wasnt't needed, if blocks stored |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
759 |
their characterPosition internally)." |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
760 |
|
429 | 761 |
|compiler tree mSource who mClass blocks |
397 | 762 |
maxSoFar innerBlock m| |
763 |
||
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
764 |
(line isNil or:[line == self maxLineNumber]) ifTrue:[ |
457
ad25339043ef
care for nil-lineNumber when looking for a block
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
765 |
^ nil |
ad25339043ef
care for nil-lineNumber when looking for a block
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
766 |
]. |
ad25339043ef
care for nil-lineNumber when looking for a block
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
767 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
768 |
aMethod notNil ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
769 |
m := aMethod. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
770 |
who := m who. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
771 |
who isNil ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
772 |
m isWrapped ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
773 |
m := m wrapper. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
774 |
m notNil ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
775 |
who := m who. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
776 |
] |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
777 |
] |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
778 |
]. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
779 |
who notNil ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
780 |
mClass := who methodClass. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
781 |
mClass isNil ifTrue:[ ^ nil]. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
782 |
]. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
783 |
|
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
784 |
mSource := m source. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
785 |
mSource isNil ifTrue:[^ nil]. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
786 |
] ifFalse:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
787 |
aString notNil ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
788 |
mSource := aString. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
789 |
mClass := UndefinedObject |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
790 |
] ifFalse:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
791 |
^ nil |
397 | 792 |
] |
793 |
]. |
|
794 |
||
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
795 |
"create a compiler, let it parse and create the parsetree" |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
796 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
797 |
compiler := self for:(ReadStream on:mSource) in:mClass. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
798 |
compiler parseForCode. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
799 |
compiler notifying:nil. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
800 |
compiler ignoreWarnings. |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
801 |
compiler ignoreErrors. |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
802 |
compiler lineNumberInfo:#full. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
803 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
804 |
aMethod notNil ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
805 |
(compiler parseMethodSpec == #Error) ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
806 |
^ nil. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
807 |
]. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
808 |
|
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
809 |
who notNil ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
810 |
compiler selector ~~ (who methodSelector) ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
811 |
^ nil |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
812 |
] |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
813 |
]. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
814 |
] ifFalse:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
815 |
compiler nextToken. |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
816 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
817 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
818 |
tree := compiler parseMethodBody. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
819 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
820 |
(compiler errorFlag or:[tree == #Error]) ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
821 |
^ nil |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
822 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
823 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
824 |
blocks := OrderedCollection new. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
825 |
tree collectBlocksInto:blocks. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
826 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
827 |
blocks := blocks select:[:aBlock | |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
828 |
line between: aBlock lineNumber and:aBlock endLineNumber |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
829 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
830 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
831 |
blocks size == 1 ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
832 |
^ blocks at:1 |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
833 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
834 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
835 |
nA notNil ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
836 |
blocks := blocks select:[:aBlock | |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
837 |
aBlock numArgs == nA |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
838 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
839 |
blocks size == 1 ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
840 |
^ blocks at:1 |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
841 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
842 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
843 |
nV notNil ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
844 |
blocks := blocks select:[:aBlock | |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
845 |
aBlock numVars == nV |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
846 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
847 |
blocks size == 1 ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
848 |
^ blocks at:1 |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
849 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
850 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
851 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
852 |
"/ look for the inner one |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
853 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
854 |
maxSoFar := 0. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
855 |
blocks do:[:aBlock | |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
856 |
aBlock lineNumber > maxSoFar ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
857 |
innerBlock := aBlock. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
858 |
maxSoFar := aBlock lineNumber |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
859 |
] |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
860 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
861 |
^ innerBlock. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
862 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
863 |
"Created: 11.1.1997 / 23:29:13 / cg" |
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
864 |
"Modified: 14.2.1997 / 16:51:25 / cg" |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
865 |
! |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
866 |
|
141 | 867 |
parseExpression:aString |
868 |
"parse aString as an expression; |
|
869 |
Return the parseTree (if ok), nil (for an empty string |
|
258 | 870 |
or comment only) or #Error (syntactic error). |
871 |
Error and warning messages are suppressed." |
|
141 | 872 |
|
873 |
^ self withSelf:nil |
|
258 | 874 |
parseExpression:aString |
875 |
notifying:nil |
|
876 |
ignoreErrors:true "silence on Transcript" |
|
877 |
ignoreWarnings:true |
|
878 |
||
879 |
"Modified: 24.4.1996 / 13:18:21 / cg" |
|
141 | 880 |
! |
881 |
||
882 |
parseMethod:aString |
|
883 |
"parse a method. |
|
884 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
885 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 886 |
used selectors etc. |
887 |
Error and warning messages are sent to the Transcript." |
|
141 | 888 |
|
889 |
^ self parseMethod:aString in:nil |
|
890 |
||
891 |
" |
|
892 |
|p| |
|
893 |
||
894 |
p := Parser |
|
258 | 895 |
parseMethod:' |
896 |
foo:arg1 bar:arg2 baz:arg3 |
|
897 |
|l1 l2| |
|
898 |
l1 := 0. |
|
899 |
l2 := arg1. |
|
900 |
^ self'. |
|
141 | 901 |
|
902 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
903 |
'args: ' print. p methodArgs printNL. |
|
904 |
'sel: ' print. p selector printNL. |
|
905 |
'nLocal: ' print. p numberOfMethodVars printNL. |
|
906 |
'locals: ' print. p methodVars printNL. |
|
907 |
'tree: ' printNL. p tree printAllOn:Stdout. Stdout cr. |
|
908 |
" |
|
258 | 909 |
|
910 |
"Modified: 24.4.1996 / 13:18:02 / cg" |
|
141 | 911 |
! |
912 |
||
913 |
parseMethod:aString in:aClass |
|
914 |
"parse a method in a given class. |
|
915 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
916 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 917 |
used selectors, modified instvars, referenced classvars etc. |
918 |
Error and warning messages are sent to the Transcript." |
|
141 | 919 |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
920 |
^ self |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
921 |
parseMethod:aString |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
922 |
in:aClass |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
923 |
ignoreErrors:false |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
924 |
ignoreWarnings:false |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
925 |
|
258 | 926 |
"Modified: 24.4.1996 / 13:18:34 / cg" |
141 | 927 |
! |
928 |
||
929 |
parseMethod:aString in:aClass ignoreErrors:noErrors ignoreWarnings:noWarnings |
|
930 |
"parse a method in a given class. |
|
931 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
932 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 933 |
used selectors, modified instvars, referenced classvars etc. |
934 |
The noErrors and noWarnings arguments specify if error and warning |
|
935 |
messages should be sent to the Transcript or suppressed." |
|
141 | 936 |
|
937 |
|parser tree| |
|
938 |
||
939 |
aString isNil ifTrue:[^ nil]. |
|
940 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
941 |
noErrors ifTrue:[ |
|
258 | 942 |
parser ignoreErrors |
141 | 943 |
]. |
944 |
noWarnings ifTrue:[ |
|
258 | 945 |
parser ignoreWarnings |
141 | 946 |
]. |
947 |
tree := parser parseMethod. |
|
948 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ nil]. |
|
949 |
^ parser |
|
258 | 950 |
|
951 |
"Modified: 24.4.1996 / 13:19:23 / cg" |
|
141 | 952 |
! |
953 |
||
954 |
parseMethod:aString in:aClass warnings:warnBoolean |
|
955 |
"parse a method in a given class. |
|
956 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
957 |
The parser can be queried for selector, receiver, args, locals, |
|
958 |
used selectors, modified instvars, referenced classvars etc. |
|
258 | 959 |
The warnBoolean arguments specifies if warning |
960 |
messages should be sent to the Transcript or suppressed. |
|
961 |
||
962 |
This method is OBSOLETE, and left in for backward compatibility." |
|
963 |
||
964 |
self obsoleteMethodWarning. |
|
141 | 965 |
^ self |
258 | 966 |
parseMethod:aString |
967 |
in:aClass |
|
968 |
ignoreErrors:false |
|
969 |
ignoreWarnings:warnBoolean not |
|
970 |
||
971 |
"Modified: 24.4.1996 / 13:28:05 / cg" |
|
141 | 972 |
! |
973 |
||
974 |
parseMethodArgAndVarSpecification:aString |
|
975 |
"parse a methods selector, arg and var spec (i.e. locals); |
|
976 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
258 | 977 |
The parser can be queried for selector, receiver etc. |
978 |
Error and warning messages are sent to the Transcript. |
|
979 |
This method is OBSOLETE." |
|
980 |
||
981 |
self obsoleteMethodWarning. |
|
141 | 982 |
^ self parseMethodArgAndVarSpecification:aString in:nil |
983 |
||
984 |
" |
|
985 |
|p| |
|
986 |
||
987 |
p := Parser |
|
258 | 988 |
parseMethodArgAndVarSpecification:' |
989 |
foo:arg1 bar:arg2 baz:arg3 |
|
990 |
|l1 l2|'. |
|
141 | 991 |
|
992 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
993 |
'args: ' print. p methodArgs printNL. |
|
994 |
'sel: ' print. p selector printNL. |
|
995 |
'nLocal: ' print. p numberOfMethodVars printNL. |
|
996 |
'locals: ' print. p methodVars printNL. |
|
997 |
" |
|
258 | 998 |
|
999 |
"Modified: 24.4.1996 / 13:29:43 / cg" |
|
141 | 1000 |
! |
1001 |
||
1002 |
parseMethodArgAndVarSpecification:aString in:aClass |
|
1003 |
"parse a methods selector, arg and var spec in a given class; |
|
1004 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
258 | 1005 |
The parser can be queried for selector, receiver, args and locals. |
1006 |
Error and warning messages are sent to the Transcript. |
|
1007 |
This method is OBSOLETE." |
|
1008 |
||
1009 |
self obsoleteMethodWarning. |
|
141 | 1010 |
^ self parseMethodArgAndVarSpecification:aString |
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1011 |
in:aClass |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1012 |
ignoreErrors:false |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1013 |
ignoreWarnings:false |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1014 |
parseBody:false |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1015 |
|
258 | 1016 |
"Modified: 24.4.1996 / 13:30:03 / cg" |
141 | 1017 |
! |
1018 |
||
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1019 |
parseMethodArgAndVarSpecification:aString in:aClass ignoreErrors:noErrors ignoreWarnings:noWarnings parseBody:body |
141 | 1020 |
"parse a methods selector, arg and var spec in a given class; |
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1021 |
If parseBody is true, also parse the statements |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1022 |
(for primitives & resourceSpecs). |
258 | 1023 |
The noErrors and noWarnings arguments specify if error and warning |
1024 |
messages should be sent to the Transcript or suppressed. |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1025 |
|
141 | 1026 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
1027 |
The parser can be queried for selector, receiver, args and locals" |
|
19 | 1028 |
|
0 | 1029 |
|parser| |
1030 |
||
141 | 1031 |
aString isNil ifTrue:[^ nil]. |
1032 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1033 |
noErrors ifTrue:[ |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1034 |
parser ignoreErrors |
141 | 1035 |
]. |
1036 |
noWarnings ifTrue:[ |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1037 |
parser ignoreWarnings |
141 | 1038 |
]. |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1039 |
"/ parser nextToken. |
141 | 1040 |
(parser parseMethodSpec == #Error) ifTrue:[^ nil]. |
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1041 |
"/ |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1042 |
"/ used to be #parseMethodBodyVarSpec |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1043 |
"/ - now, alternatively parse body for resource & primitive specs .. |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1044 |
"/ |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1045 |
body ifTrue:[ |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1046 |
(parser parseMethodBodyOrEmpty == #Error) ifTrue:[^ nil]. |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1047 |
] ifFalse:[ |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1048 |
(parser parseMethodBodyVarSpec == #Error) ifTrue:[^ nil]. |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1049 |
]. |
141 | 1050 |
parser errorFlag ifTrue:[^ nil]. |
0 | 1051 |
^ parser |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1052 |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1053 |
"Created: 24.4.1996 / 13:13:06 / cg" |
265 | 1054 |
"Modified: 27.4.1996 / 16:58:02 / cg" |
141 | 1055 |
! |
1056 |
||
1057 |
parseMethodArgAndVarSpecificationSilent:aString |
|
1058 |
"parse a methods selector, arg and var spec (i.e. locals); |
|
1059 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1060 |
The parser can be queried for selector, receiver etc. |
|
258 | 1061 |
Like #parseMethodArgAndVarSpecification:, but does NOT |
141 | 1062 |
display error/warning messages on the transcript." |
1063 |
||
1064 |
^ self parseMethodArgAndVarSpecificationSilent:aString in:nil |
|
258 | 1065 |
|
1066 |
"Modified: 24.4.1996 / 13:30:54 / cg" |
|
141 | 1067 |
! |
1068 |
||
1069 |
parseMethodArgAndVarSpecificationSilent:aString in:aClass |
|
1070 |
"parse a methods selector, arg and var spec in a given class; |
|
1071 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1072 |
The parser can be queried for selector, receiver, args and locals. |
|
1073 |
Like #parseMethodArgAndVarSpecification:in:, but does not |
|
1074 |
display error/warning messages on the transcript." |
|
1075 |
||
1076 |
^ self parseMethodArgAndVarSpecification:aString |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1077 |
in:aClass |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1078 |
ignoreErrors:true |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1079 |
ignoreWarnings:true |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1080 |
parseBody:false |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1081 |
|
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1082 |
"Modified: 24.4.1996 / 13:14:27 / cg" |
141 | 1083 |
! |
1084 |
||
1085 |
parseMethodSilent:aString |
|
1086 |
"parse a method. |
|
1087 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1088 |
The parser can be queried for selector, receiver, args, locals, |
|
1089 |
used selectors etc. |
|
258 | 1090 |
Like #parseMethod:, but warning/error messages are suppressed." |
141 | 1091 |
|
1092 |
^ self parseMethodSilent:aString in:nil |
|
258 | 1093 |
|
1094 |
"Modified: 24.4.1996 / 13:32:44 / cg" |
|
141 | 1095 |
! |
1096 |
||
1097 |
parseMethodSilent:aString in:aClass |
|
1098 |
"parse a method in a given class. |
|
1099 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1100 |
The parser can be queried for selector, receiver, args, locals, |
|
1101 |
used selectors, modified instvars, referenced classvars etc. |
|
258 | 1102 |
Like #parseMethod:in:, but warning/error messages are suppressed." |
1103 |
||
1104 |
^ self |
|
1105 |
parseMethod:aString |
|
1106 |
in:aClass |
|
1107 |
ignoreErrors:true |
|
1108 |
ignoreWarnings:true |
|
1109 |
||
1110 |
"Modified: 24.4.1996 / 13:32:57 / cg" |
|
141 | 1111 |
! |
1112 |
||
1113 |
parseMethodSpecification:aString |
|
1114 |
"parse a methods selector & arg specification; |
|
1115 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1116 |
The parser can be queried for selector, receiver etc." |
|
1117 |
||
1118 |
^ self parseMethodSpecification:aString in:nil |
|
1119 |
||
1120 |
" |
|
1121 |
|p| |
|
1122 |
||
1123 |
p := Parser parseMethodSpecification:'foo:arg1 bar:arg2 baz:arg3'. |
|
1124 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
1125 |
'args: ' print. p methodArgs printNL. |
|
1126 |
'sel: ' print. p selector printNL |
|
1127 |
" |
|
1128 |
! |
|
1129 |
||
1130 |
parseMethodSpecification:aString in:aClass |
|
1131 |
"parse a methods selector & arg spec for a given class; |
|
1132 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1133 |
The parser can be queried for selector, receiver etc." |
|
1134 |
||
1135 |
^ self parseMethodSpecification:aString |
|
1136 |
in:aClass |
|
1137 |
ignoreErrors:false |
|
1138 |
ignoreWarnings:false |
|
1139 |
! |
|
1140 |
||
1141 |
parseMethodSpecification:aString in:aClass ignoreErrors:noErrors ignoreWarnings:noWarnings |
|
1142 |
"parse a methods selector & arg spec for a given class; |
|
1143 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1144 |
The parser can be queried for selector, receiver etc. |
|
1145 |
noErrors and noWarnings specify if error- and warningMessages are |
|
1146 |
to be output onto the Transcript." |
|
1147 |
||
1148 |
|parser tree| |
|
1149 |
||
1150 |
aString isNil ifTrue:[^ nil]. |
|
1151 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1152 |
noErrors ifTrue:[ |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1153 |
parser ignoreErrors |
141 | 1154 |
]. |
1155 |
noWarnings ifTrue:[ |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1156 |
parser ignoreWarnings |
141 | 1157 |
]. |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1158 |
"/ parser nextToken. |
141 | 1159 |
tree := parser parseMethodSpec. |
1160 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ #Error]. |
|
1161 |
^ parser |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1162 |
|
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1163 |
"Modified: 20.4.1996 / 20:09:48 / cg" |
141 | 1164 |
! |
1165 |
||
1166 |
parseMethodSpecificationSilent:aString |
|
1167 |
"parse a methods selector & arg specification; |
|
1168 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1169 |
The parser can be queried for selector, receiver etc. |
|
1170 |
Like #parseMethodSpecification:, but does not display any error/warning Messages on the transcript." |
|
1171 |
||
1172 |
^ self parseMethodSpecificationSilent:aString in:nil |
|
1173 |
! |
|
1174 |
||
1175 |
parseMethodSpecificationSilent:aString in:aClass |
|
1176 |
"parse a methods selector & arg spec for a given class; |
|
1177 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1178 |
The parser can be queried for selector, receiver etc. |
|
1179 |
Like #parseMethodSpecification:in:, but does not display any error/warning Messages on the transcript." |
|
1180 |
||
1181 |
^ self parseMethodSpecification:aString |
|
1182 |
in:aClass |
|
1183 |
ignoreErrors:true |
|
1184 |
ignoreWarnings:true |
|
1185 |
||
1186 |
"Created: 31.10.1995 / 14:37:49 / cg" |
|
1187 |
! |
|
0 | 1188 |
|
7 | 1189 |
selectorInExpression:aString |
47 | 1190 |
"parse an expression - return the selector. Even malformed expressions |
1191 |
(such as missing receiver or missing arg are parsed. |
|
1192 |
Used for the SystemBrowsers implementors/senders query-box initial text. |
|
21 | 1193 |
Returns nil if unparsable." |
7 | 1194 |
|
1195 |
|tree parser| |
|
1196 |
||
1197 |
(aString isNil or:[aString isEmpty]) ifTrue:[^ nil]. |
|
1198 |
||
21 | 1199 |
tree := self withSelf:nil |
451 | 1200 |
parseExpression:aString |
1201 |
notifying:nil |
|
1202 |
ignoreErrors:true |
|
1203 |
ignoreWarnings:true. |
|
21 | 1204 |
|
1205 |
" |
|
1206 |
special: take the expression of the right side, if its an |
|
1207 |
assignment or return |
|
1208 |
" |
|
7 | 1209 |
(tree notNil and:[tree ~~ #Error]) ifTrue:[ |
451 | 1210 |
(tree isAssignment |
1211 |
or:[tree isReturnNode]) ifTrue:[ |
|
1212 |
tree expression isMessage ifTrue:[ |
|
1213 |
tree := tree expression |
|
1214 |
] |
|
1215 |
]. |
|
1216 |
||
1217 |
tree isMessage ifTrue:[ |
|
1218 |
^ tree selector |
|
1219 |
]. |
|
7 | 1220 |
]. |
1221 |
||
21 | 1222 |
" |
1223 |
mhmh, try expression without receiver |
|
1224 |
" |
|
7 | 1225 |
parser := self for:(ReadStream on:aString). |
1226 |
parser ignoreErrors. |
|
1227 |
parser nextToken. |
|
1228 |
^ parser degeneratedKeywordExpressionForSelector |
|
1229 |
||
1230 |
" |
|
20 | 1231 |
Parser selectorInExpression:'foo at:1 put:(5 * bar)' |
1232 |
Parser selectorInExpression:'(foo at:1) at:1' |
|
47 | 1233 |
Parser selectorInExpression:'a + 4' |
1234 |
Parser selectorInExpression:'a negated' |
|
20 | 1235 |
Parser selectorInExpression:'at:1 put:5' |
47 | 1236 |
Parser selectorInExpression:'at:1 put:' |
1237 |
Parser selectorInExpression:'a at:1 put:5' |
|
1238 |
Parser selectorInExpression:'a at:1 put:' |
|
20 | 1239 |
Parser selectorInExpression:'a := foo at:1 put:5' |
7 | 1240 |
" |
451 | 1241 |
|
1242 |
"Modified: 17.12.1996 / 12:12:47 / cg" |
|
7 | 1243 |
! |
1244 |
||
1245 |
withSelf:anObject parseExpression:aString notifying:someOne |
|
1246 |
"parse aString as an expression with self set to anObject; |
|
21 | 1247 |
Return the parseTree (if ok), nil (for an empty string |
1248 |
or comment only ) or #Error (syntactic error). |
|
1249 |
||
1250 |
Errors and warnings are forwarded to someOne (usually some |
|
1251 |
codeView) which can highlight it and show a popup box." |
|
7 | 1252 |
|
21 | 1253 |
^ self withSelf:anObject |
44 | 1254 |
parseExpression:aString |
1255 |
notifying:someOne |
|
1256 |
ignoreErrors:false |
|
1257 |
ignoreWarnings:false |
|
7 | 1258 |
! |
1259 |
||
1260 |
withSelf:anObject parseExpression:aString notifying:someOne ignoreErrors:ignore |
|
0 | 1261 |
"parse aString as an expression with self set to anObject; |
21 | 1262 |
Return the parseTree (if ok), nil (for an empty string |
1263 |
or comment only ) or #Error (syntactic error). |
|
1264 |
||
1265 |
Errors and warnings are forwarded to someOne (usually some |
|
1266 |
codeView) which can highlight it and show a popup box." |
|
1267 |
||
1268 |
^ self withSelf:anObject |
|
44 | 1269 |
parseExpression:aString |
1270 |
notifying:someOne |
|
1271 |
ignoreErrors:ignore |
|
1272 |
ignoreWarnings:ignore |
|
21 | 1273 |
! |
1274 |
||
1275 |
withSelf:anObject parseExpression:aString notifying:someOne ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
|
1276 |
"parse aString as an expression with self set to anObject; |
|
1277 |
Return the parseTree (if ok), nil (for an empty string |
|
1278 |
or comment only ) or #Error (syntactic error). |
|
1279 |
||
1280 |
Errors and warnings are forwarded to someOne (usually some |
|
1281 |
codeView) which can highlight it and show a popup box, |
|
1282 |
iff ignoreErrors/ignoreWarnings is true respectively." |
|
0 | 1283 |
|
35 | 1284 |
|parser tree token| |
0 | 1285 |
|
1286 |
aString isNil ifTrue:[^ nil]. |
|
1287 |
parser := self for:(ReadStream on:aString). |
|
1288 |
parser setSelf:anObject. |
|
1289 |
parser notifying:someOne. |
|
21 | 1290 |
ignoreErrors ifTrue:[parser ignoreErrors]. |
1291 |
ignoreWarnings ifTrue:[parser ignoreWarnings]. |
|
35 | 1292 |
token := parser nextToken. |
1293 |
(token == $^) ifTrue:[ |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1294 |
parser nextToken. |
35 | 1295 |
]. |
0 | 1296 |
tree := parser expression. |
1297 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ #Error]. |
|
1298 |
^ tree |
|
1299 |
! ! |
|
1300 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
1301 |
!Parser class methodsFor:'unparsing'! |
20 | 1302 |
|
1303 |
methodSpecificationForSelector:aSelector |
|
1304 |
"given a selector such as #foo:bar:, return a string that could |
|
1305 |
serve as a methods specification source code. |
|
1306 |
To be used for code generators" |
|
1307 |
||
1308 |
^ self methodSpecificationForSelector:aSelector |
|
44 | 1309 |
argNames:#('arg1' 'arg2' 'arg3' 'arg4' 'arg5' 'arg6' |
1310 |
'arg7' 'arg8' 'arg9' 'arg10' 'arg11' 'arg12' |
|
1311 |
'arg13' 'arg14' 'arg15') |
|
20 | 1312 |
" |
1313 |
Parser methodSpecificationForSelector:#foo:bar: |
|
21 | 1314 |
Parser methodSpecificationForSelector:#+ |
20 | 1315 |
Parser methodSpecificationForSelector:#negated |
1316 |
" |
|
1317 |
! |
|
1318 |
||
1319 |
methodSpecificationForSelector:aSelector argNames:argNames |
|
1320 |
"given a selector such as #foo:bar:, return a string that could |
|
1321 |
serve as a methods specification source code. |
|
1322 |
To be used for code generators" |
|
1323 |
||
1324 |
|s nargs parts| |
|
1325 |
||
1326 |
s := WriteStream on:String new. |
|
44 | 1327 |
nargs := aSelector numArgs. |
20 | 1328 |
nargs == 0 ifTrue:[ |
44 | 1329 |
s nextPutAll:aSelector |
20 | 1330 |
] ifFalse:[ |
44 | 1331 |
parts := aSelector partsIfSelector. |
1332 |
1 to:nargs do:[:i | |
|
1333 |
s nextPutAll:(parts at:i); space; |
|
1334 |
nextPutAll:(argNames at:i); space. |
|
1335 |
] |
|
20 | 1336 |
]. |
1337 |
^ s contents |
|
1338 |
||
1339 |
" |
|
1340 |
Parser methodSpecificationForSelector:#foo:bar: argNames:#('one' 'two' 'three') |
|
1341 |
Parser methodSpecificationForSelector:#+ argNames:#('one') |
|
1342 |
Parser methodSpecificationForSelector:#negated |
|
1343 |
" |
|
1344 |
! ! |
|
1345 |
||
0 | 1346 |
!Parser methodsFor:'ST-80 compatibility'! |
1347 |
||
1348 |
evaluate:aString in:aClass to:to notifying:aRequestor ifFail:failBlock |
|
35 | 1349 |
|parseTree value| |
0 | 1350 |
|
1351 |
aString isNil ifTrue:[^ nil]. |
|
1352 |
self initializeFor:(ReadStream on:aString). |
|
1353 |
self setClassToCompileFor:aClass. |
|
1354 |
selfValue := nil. |
|
1355 |
requestor := aRequestor. |
|
1356 |
||
1357 |
self nextToken. |
|
1358 |
parseTree := self parseMethodBody. |
|
1359 |
(errorFlag or:[tree == #Error]) ifTrue:[^ #Error]. |
|
1360 |
parseTree notNil ifTrue:[ |
|
44 | 1361 |
self evalExitBlock:[:value | ^ failBlock value]. |
1362 |
value := parseTree evaluate |
|
0 | 1363 |
]. |
35 | 1364 |
self release. |
1365 |
^ value |
|
0 | 1366 |
! ! |
1367 |
||
44 | 1368 |
!Parser methodsFor:'accessing'! |
1369 |
||
1370 |
correctedSource |
|
1371 |
^ correctedSource |
|
1372 |
! |
|
1373 |
||
141 | 1374 |
errorFlag |
1375 |
"return true if there where any errors (valid after parsing)" |
|
1376 |
||
1377 |
^ errorFlag |
|
1378 |
! |
|
1379 |
||
1380 |
evalExitBlock:aBlock |
|
1381 |
"when evaluating a return expression, this block is evaluated" |
|
1382 |
||
1383 |
evalExitBlock := aBlock |
|
1384 |
! |
|
1385 |
||
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1386 |
getNameSpace |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1387 |
"retrieve the nameSpace, as found in a Namespace directive" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1388 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1389 |
^ currentNamespace |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1390 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1391 |
"Modified: 8.11.1996 / 13:45:35 / cg" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1392 |
! |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1393 |
|
19 | 1394 |
primitiveNumber |
1395 |
"return the ST-80 style primitiveNumber or nil (valid after parsing)" |
|
1396 |
||
1397 |
^ primitiveNr |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1398 |
! |
97 | 1399 |
|
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1400 |
primitiveResources |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1401 |
"return the ST-80 style resource info or nil (valid after parsing)." |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1402 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1403 |
^ primitiveResource |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1404 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1405 |
"Created: 29.5.1996 / 17:28:00 / cg" |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1406 |
! |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1407 |
|
35 | 1408 |
release |
1409 |
methodArgs := methodVars := tree := selfNode := superNode := nil. |
|
1410 |
super release. |
|
90 | 1411 |
! |
1412 |
||
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1413 |
setNameSpace:aNameSpaceName |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1414 |
currentNamespace := Namespace fullName:aNameSpaceName |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1415 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1416 |
"Modified: 8.11.1996 / 13:43:14 / cg" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1417 |
! |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1418 |
|
141 | 1419 |
targetClass |
1420 |
^ classToCompileFor |
|
1421 |
! |
|
1422 |
||
90 | 1423 |
targetClass:aClass |
117 | 1424 |
classToCompileFor := aClass |
1425 |
! |
|
1426 |
||
141 | 1427 |
tree |
1428 |
"return the parsetree" |
|
1429 |
||
1430 |
^tree |
|
1431 |
! |
|
1432 |
||
1433 |
tree:aTree |
|
1434 |
"private: set the tree - for internal use only" |
|
1435 |
||
1436 |
tree := aTree |
|
1437 |
! ! |
|
1438 |
||
1439 |
!Parser methodsFor:'error correction'! |
|
1440 |
||
1441 |
askForCorrection:aString fromList:aList |
|
1442 |
"launch a selection box, which allows user to enter correction. |
|
1443 |
return newString or nil (for abort)" |
|
1444 |
||
1445 |
|box| |
|
1446 |
||
1447 |
"in systems without widgets ..." |
|
1448 |
ListSelectionBox isNil ifTrue:[ |
|
1449 |
^ self confirm:aString |
|
1450 |
]. |
|
1451 |
box := ListSelectionBox title:aString. |
|
1452 |
box initialText:(aList at:1). |
|
1453 |
box list:aList. |
|
1454 |
box okText:'correct'. |
|
1455 |
box action:[:aString | ^ aString]. |
|
1456 |
box showAtPointer. |
|
1457 |
^ nil |
|
1458 |
! |
|
1459 |
||
1460 |
correctByDeleting |
|
1461 |
"correct (by deleting token) if user wants to; |
|
1462 |
return #Error if there was no correction; |
|
1463 |
nil if there was one." |
|
1464 |
||
1465 |
(self confirm:'confirm deleting') ifFalse:[^ #Error]. |
|
1466 |
||
1467 |
" |
|
1468 |
tell requestor (i.e. CodeView) about the change |
|
1469 |
this will update what the requestor shows. |
|
1470 |
" |
|
1471 |
requestor deleteSelection. |
|
1472 |
||
1473 |
" |
|
1474 |
get the updated source-string |
|
1475 |
which is needed, when we eventually install the new method |
|
1476 |
" |
|
1477 |
correctedSource := requestor currentSourceCode. |
|
1478 |
^ nil |
|
1479 |
! |
|
1480 |
||
1481 |
correctSelector:aSelectorString message:msg position:pos1 to:pos2 |
|
1482 |
"notify error and correct if user wants to; |
|
1483 |
return #Error if there was no correction |
|
1484 |
or a ParseNode as returned by variable" |
|
1485 |
||
1486 |
|correctIt suggestedNames newSelector| |
|
1487 |
||
1488 |
" |
|
1489 |
sorry, but I cannot handle keywords with more than one-part |
|
1490 |
currently (too much work - maybe Ill do it later when everything else works :-) |
|
1491 |
" |
|
1492 |
(aSelectorString occurrencesOf:$:) > 1 ifTrue:[ |
|
1493 |
self warning:msg position:pos1 to:pos2. |
|
1494 |
^ aSelectorString |
|
1495 |
]. |
|
1496 |
||
1497 |
correctIt := self correctableError:msg position:pos1 to:pos2. |
|
1498 |
correctIt ifFalse:[^ aSelectorString]. |
|
1499 |
||
1500 |
suggestedNames := self findBestSelectorsFor:aSelectorString. |
|
1501 |
suggestedNames notNil ifTrue:[ |
|
1502 |
newSelector := self askForCorrection:'correct selector to: ' fromList:suggestedNames. |
|
1503 |
newSelector isNil ifTrue:[^ aSelectorString]. |
|
1504 |
] ifFalse:[ |
|
1505 |
self information:'no good correction found'. |
|
1506 |
^ aSelectorString |
|
1507 |
]. |
|
1508 |
||
1509 |
" |
|
1510 |
tell requestor (i.e. CodeView) about the change |
|
1511 |
this will update what the requestor shows. |
|
1512 |
" |
|
1513 |
||
1514 |
requestor replaceSelectionBy:newSelector keepCursor:false. |
|
1515 |
" |
|
1516 |
get the updated source-string |
|
1517 |
which is needed, when we eventually install the new method |
|
1518 |
" |
|
1519 |
correctedSource := requestor currentSourceCode. |
|
1520 |
||
1521 |
^ newSelector |
|
1522 |
! |
|
1523 |
||
1524 |
correctVariable |
|
1525 |
"notify error and correct if user wants to; |
|
1526 |
return #Error if there was no correction |
|
1527 |
or a ParseNode as returned by variable" |
|
1528 |
||
1529 |
|correctIt varName suggestedNames newName pos1 pos2| |
|
1530 |
||
1531 |
pos1 := tokenPosition. |
|
1532 |
varName := tokenName. |
|
1533 |
pos2 := pos1 + varName size - 1. |
|
1534 |
||
1535 |
"OLD: |
|
1536 |
(varName at:1) isLowercase ifTrue:[ |
|
223
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1537 |
correctIt := self undefError:varName position:pos1 to:pos2. |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1538 |
correctIt ifFalse:[^ #Error] |
141 | 1539 |
] ifFalse:[ |
223
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1540 |
correctIt := self warning:(varName , ' is undefined') position:pos1 to:pos2. |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1541 |
correctIt ifFalse:[ |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1542 |
^ VariableNode type:#GlobalVariable name:(varName asSymbol) |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1543 |
] |
141 | 1544 |
]. |
1545 |
" |
|
1546 |
||
1547 |
correctIt := self undefError:varName position:pos1 to:pos2. |
|
1548 |
correctIt ifFalse:[ |
|
223
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1549 |
(varName at:1) isLowercase ifTrue:[ |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1550 |
"/ self warning:'no automatic global declaration of lowercase variables' position:pos1 to:pos2. |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1551 |
^ #Error |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1552 |
] ifFalse:[ |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1553 |
^ VariableNode type:#GlobalVariable name:(varName asSymbol) |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1554 |
] |
141 | 1555 |
]. |
1556 |
||
1557 |
suggestedNames := self findBestVariablesFor:varName. |
|
1558 |
suggestedNames notNil ifTrue:[ |
|
223
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1559 |
newName := self askForCorrection:'correct variable to: ' fromList:suggestedNames. |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1560 |
newName isNil ifTrue:[^ #Error]. |
141 | 1561 |
" |
223
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1562 |
newName := suggestedNames at:1. |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1563 |
(self confirm:('confirm correction to: ' , newName)) ifFalse:[^ #Error] |
141 | 1564 |
" |
1565 |
] ifFalse:[ |
|
223
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1566 |
self information:'no good correction found'. |
f1c6e860d495
removed a warning (its annoying)
Claus Gittinger <cg@exept.de>
parents:
221
diff
changeset
|
1567 |
^ #Error |
141 | 1568 |
]. |
1569 |
||
1570 |
" |
|
1571 |
tell requestor (i.e. CodeView) about the change |
|
1572 |
this will update what the requestor shows. |
|
1573 |
" |
|
1574 |
requestor replaceSelectionBy:newName. |
|
1575 |
" |
|
1576 |
get the updated source-string |
|
1577 |
which is needed, when we eventually install the new method |
|
1578 |
" |
|
1579 |
correctedSource := requestor currentSourceCode. |
|
1580 |
||
1581 |
"redo parse with new value" |
|
1582 |
tokenName := newName. |
|
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
1583 |
^ self variableOrError:tokenName |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
1584 |
|
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
1585 |
"Modified: 19.12.1996 / 22:30:13 / cg" |
141 | 1586 |
! |
1587 |
||
1588 |
findBestSelectorsFor:aString |
|
1589 |
"collect known selectors with their spelling distances to aString; |
|
1590 |
return the 10 best suggestions" |
|
1591 |
||
1592 |
|info n| |
|
1593 |
||
1594 |
info := SortedCollection new. |
|
1595 |
info sortBlock:[:a :b | a value > b value]. |
|
1596 |
||
1597 |
n := 0. |
|
1598 |
||
1599 |
Symbol allInstancesDo:[:sym | |
|
1600 |
|dist| |
|
1601 |
||
1602 |
dist := aString spellAgainst:sym. |
|
1603 |
dist > 20 ifTrue:[ |
|
1604 |
info add:(sym -> dist). |
|
1605 |
n := n + 1. |
|
1606 |
n > 10 ifTrue:[ |
|
1607 |
info removeLast. |
|
1608 |
] |
|
1609 |
] |
|
1610 |
]. |
|
1611 |
||
1612 |
^ info asOrderedCollection collect:[:a | a key] |
|
1613 |
||
1614 |
"Time millisecondsToRun:[Parser new findBestSelectorsFor:'foo']" |
|
1615 |
"Parser new findBestSelectorsFor:'findBestSel'" |
|
1616 |
"Parser new findBestSelectorsFor:'fildBestSelectrFr'" |
|
1617 |
! |
|
1618 |
||
1619 |
findBestVariablesFor:aString |
|
1620 |
"collect known variables with their spelling distances to aString; |
|
1621 |
return the 10 best suggestions" |
|
1622 |
||
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1623 |
|names dists searchBlock args vars globalVarName "aClass className baseClass" |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1624 |
n instVarNames| |
141 | 1625 |
|
1626 |
names := OrderedCollection new. |
|
1627 |
dists := OrderedCollection new. |
|
1628 |
||
1629 |
"block arguments" |
|
1630 |
searchBlock := currentBlock. |
|
1631 |
[searchBlock notNil] whileTrue:[ |
|
450 | 1632 |
args := searchBlock arguments. |
1633 |
args notNil ifTrue:[ |
|
1634 |
args do:[:aBlockArg | |
|
1635 |
names add:(aBlockArg name). |
|
1636 |
dists add:(aString spellAgainst: "levenshteinTo:"(aBlockArg name)) |
|
1637 |
] |
|
1638 |
]. |
|
1639 |
||
1640 |
vars := searchBlock variables. |
|
1641 |
vars notNil ifTrue:[ |
|
1642 |
vars do:[:aBlockVar | |
|
1643 |
names add:(aBlockVar name). |
|
1644 |
dists add:(aString spellAgainst: "levenshteinTo:"(aBlockVar name)) |
|
1645 |
] |
|
1646 |
]. |
|
1647 |
searchBlock := searchBlock home |
|
141 | 1648 |
]. |
1649 |
||
1650 |
"method-variables" |
|
1651 |
methodVars notNil ifTrue:[ |
|
450 | 1652 |
methodVarNames do:[:methodVarName | |
1653 |
names add:methodVarName. |
|
1654 |
dists add:(aString spellAgainst: "levenshteinTo:"methodVarName) |
|
1655 |
] |
|
141 | 1656 |
]. |
1657 |
||
1658 |
"method-arguments" |
|
1659 |
methodArgs notNil ifTrue:[ |
|
450 | 1660 |
methodArgNames do:[:methodArgName | |
1661 |
names add:methodArgName. |
|
1662 |
dists add:(aString spellAgainst: "levenshteinTo:"methodArgName) |
|
1663 |
] |
|
141 | 1664 |
]. |
1665 |
||
1666 |
"instance-variables" |
|
1667 |
classToCompileFor notNil ifTrue:[ |
|
450 | 1668 |
self classesInstVarNames do:[:instVarName | |
1669 |
names add:instVarName. |
|
1670 |
dists add:(aString spellAgainst: "levenshteinTo:"instVarName) |
|
1671 |
] |
|
141 | 1672 |
]. |
1673 |
||
1674 |
"class-variables" |
|
1675 |
classToCompileFor notNil ifTrue:[ |
|
450 | 1676 |
self classesClassVarNames do:[:classVarName | |
1677 |
names add:classVarName. |
|
1678 |
dists add:(aString spellAgainst: "levenshteinTo:"classVarName) |
|
1679 |
]. |
|
141 | 1680 |
|
1681 |
"/ aClass := classToCompileFor. |
|
1682 |
"/ aClass isMeta ifTrue:[ |
|
1683 |
"/ className := aClass name. |
|
1684 |
"/ className := className copyWithoutLast:5. |
|
1685 |
"/ baseClass := Smalltalk at:(className asSymbol). |
|
1686 |
"/ baseClass notNil ifTrue:[ |
|
1687 |
"/ aClass := baseClass |
|
1688 |
"/ ] |
|
1689 |
"/ ]. |
|
1690 |
"/ [aClass notNil] whileTrue:[ |
|
1691 |
"/ (aClass classVarNames) do:[:classVarName | |
|
1692 |
"/ names add:classVarName. |
|
1693 |
"/ dists add:(aString spellAgainst: "levenshteinTo:"classVarName) |
|
1694 |
"/ ]. |
|
1695 |
"/ aClass := aClass superclass |
|
1696 |
"/ ] |
|
1697 |
||
1698 |
]. |
|
1699 |
||
1700 |
"globals" |
|
1701 |
Smalltalk keysDo:[:aKey | |
|
450 | 1702 |
globalVarName := aKey asString. |
1703 |
"only compare strings where length is about right" |
|
1704 |
((globalVarName size - aString size) abs < 3) ifTrue:[ |
|
1705 |
names add:globalVarName. |
|
1706 |
dists add:(aString spellAgainst: "levenshteinTo:"globalVarName) |
|
1707 |
] |
|
141 | 1708 |
]. |
1709 |
||
1710 |
"misc" |
|
1711 |
#('self' 'super' 'nil' 'thisContext') do:[:name | |
|
450 | 1712 |
names add:name. |
1713 |
dists add:(aString spellAgainst: "levenshteinTo:"name) |
|
141 | 1714 |
]. |
1715 |
||
1716 |
(dists size ~~ 0) ifTrue:[ |
|
450 | 1717 |
dists sortWith:names. |
1718 |
dists := dists reverse. |
|
1719 |
names := names reverse. |
|
1720 |
n := names size min:10. |
|
1721 |
names := names copyTo:n. |
|
1722 |
||
1723 |
"if it starts with a lower case character, add all local & instvar names" |
|
1724 |
(aString at:1) isLowercase ifTrue:[ |
|
1725 |
methodVarNames size > 0 ifTrue:[ |
|
1726 |
names add:'---- method locals ----'. |
|
1727 |
methodVarNames asSortedCollection do:[:methodVarName | |
|
1728 |
names add:methodVarName. |
|
1729 |
]. |
|
1730 |
]. |
|
1731 |
||
1732 |
||
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1733 |
methodArgs size > 0 ifTrue:[ |
450 | 1734 |
names add:'---- method arguments ----'. |
1735 |
methodArgNames asSortedCollection do:[:methodArgName | |
|
1736 |
names add:methodArgName. |
|
1737 |
] |
|
1738 |
]. |
|
1739 |
||
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1740 |
instVarNames := OrderedCollection new. |
450 | 1741 |
self classesInstVarNames asSortedCollection do:[:instVarName | |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1742 |
(instVarNames includes:instVarName) ifFalse:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1743 |
instVarNames add:instVarName. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1744 |
] |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1745 |
]. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1746 |
|
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1747 |
instVarNames size > 0 ifTrue:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1748 |
names add:'---- instance variables ----'. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1749 |
instVarNames do:[:instVarName | |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1750 |
(names includes:instVarName) ifFalse:[ |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1751 |
names add:instVarName. |
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1752 |
] |
450 | 1753 |
] |
1754 |
] |
|
1755 |
]. |
|
1756 |
||
1757 |
^ names |
|
141 | 1758 |
]. |
1759 |
^ nil |
|
450 | 1760 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1761 |
"Modified: 11.1.1997 / 21:28:28 / cg" |
141 | 1762 |
! |
1763 |
||
1764 |
selectorCheck:aSelectorString for:receiver position:pos1 to:pos2 |
|
1765 |
"just a quick check: if a selector is totally unknown as a symbol, |
|
1766 |
or has the same name as a variable or cannot be understood. |
|
1767 |
Simple, but catches many typos" |
|
1768 |
||
466
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1769 |
|ok err sym rec superCls names recType| |
141 | 1770 |
|
1771 |
" |
|
1772 |
if compiling lazy, or errors are to be ignored, or there |
|
1773 |
is no requestor, do not check |
|
1774 |
" |
|
1775 |
(LazyCompilation == true) ifTrue:[^ aSelectorString]. |
|
1776 |
(ignoreErrors or:[ignoreWarnings]) ifTrue:[^ aSelectorString]. |
|
1777 |
(requestor isNil or:[requestor isStream]) ifTrue:[^ aSelectorString]. |
|
1778 |
||
1779 |
err := ' is currently nowhere implemented'. |
|
1780 |
" |
|
1781 |
if the selector has the name of a variable, use another message |
|
1782 |
" |
|
1783 |
((methodVarNames notNil and:[methodVarNames includes:aSelectorString]) |
|
1784 |
or:[(methodArgNames notNil and:[methodArgNames includes:aSelectorString]) |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
1785 |
or:[((names := self classesInstVarNames) notNil and:[names includes:aSelectorString]) |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
1786 |
or:[((names := self classesClassInstVarNames) notNil and:[names includes:aSelectorString]) |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
1787 |
or:[((names := self classesClassVarNames) notNil and:[names includes:aSelectorString])]]]]) ifTrue:[ |
273 | 1788 |
err := ' is currently nowhere implemented .. |
141 | 1789 |
.. but a variable with that name is defined. |
1790 |
||
143 | 1791 |
Missing ''.'' after the previous expression |
1792 |
or missing keyword/receiver before that word ?'. |
|
141 | 1793 |
]. |
1794 |
||
1795 |
" |
|
1796 |
check if the selector is known at all |
|
1797 |
- if not, it cannot be understood |
|
1798 |
" |
|
1799 |
ok := false. |
|
1800 |
sym := aSelectorString asSymbolIfInterned. |
|
1801 |
sym notNil ifTrue:[ |
|
273 | 1802 |
ok := true. |
1803 |
receiver notNil ifTrue:[ |
|
1804 |
" |
|
1805 |
if the receiver is a constant, we can check if it responds |
|
1806 |
to this selector |
|
1807 |
" |
|
1808 |
receiver isConstant ifTrue:[ |
|
1809 |
rec := receiver evaluate. |
|
1810 |
ok := rec respondsTo:sym. |
|
1811 |
err := ' will not be understood here (message to ' , rec classNameWithArticle , ')'. |
|
1812 |
] ifFalse:[ |
|
1813 |
receiver isBlock ifTrue:[ |
|
1814 |
"/ this should help with typos, sending #ifTrue to blocks ... |
|
1815 |
ok := [] respondsTo:sym. |
|
1816 |
err := ' will not be understood here (message to a Block)'. |
|
1817 |
] ifFalse:[ |
|
1818 |
" |
|
1819 |
if the receiver is a global, we check it too ... |
|
1820 |
" |
|
466
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1821 |
(((recType := receiver type) == #GlobalVariable) |
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1822 |
or:[recType == #PrivateClass]) ifTrue:[ |
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1823 |
"/ dont check autoloaded classes |
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1824 |
"/ - it may work after loading" |
273 | 1825 |
|
1826 |
rec := receiver evaluate. |
|
1827 |
(rec notNil |
|
1828 |
and:[rec isBehavior |
|
1829 |
and:[rec isLoaded not]]) ifTrue:[ |
|
1830 |
^ aSelectorString |
|
1831 |
]. |
|
1832 |
||
1833 |
ok := rec respondsTo:sym. |
|
1834 |
ok ifFalse:[ |
|
1835 |
"if it implements #doesNotUnderstand, assume its ok" |
|
1836 |
(rec class implements:#doesNotUnderstand:) ifTrue:[ |
|
1837 |
^ aSelectorString |
|
1838 |
] |
|
1839 |
]. |
|
1840 |
||
1841 |
err := ' may not be understood here (is currently ' , rec classNameWithArticle , ')'. |
|
1842 |
] ifFalse:[ |
|
1843 |
"if its a super send, we can do more checking" |
|
1844 |
receiver isSuper ifTrue:[ |
|
1845 |
receiver isHere ifFalse:[ |
|
1846 |
((superCls := classToCompileFor superclass) notNil |
|
1847 |
and:[(superCls whichClassIncludesSelector:sym) isNil]) ifTrue:[ |
|
1848 |
err := ' is currently not implemented in any superclass'. |
|
1849 |
ok := false |
|
1850 |
] |
|
1851 |
] ifTrue:[ |
|
1852 |
(classToCompileFor whichClassIncludesSelector:sym) isNil ifTrue:[ |
|
1853 |
err := ' is currently not implemented in this class'. |
|
1854 |
ok := false |
|
1855 |
] |
|
1856 |
] |
|
1857 |
]. |
|
1858 |
||
1859 |
(receiver isUnaryMessage |
|
1860 |
and:[receiver selector == #class |
|
1861 |
and:[receiver receiver type == #Self]]) ifTrue:[ |
|
1862 |
"its a message to self class - can check this too ..." |
|
1863 |
(classToCompileFor class whichClassIncludesSelector:sym) isNil ifTrue:[ |
|
1864 |
ok := false. |
|
1865 |
classToCompileFor allSubclasses do:[:subclass | |
|
1866 |
(subclass class implements:sym) ifTrue:[ |
|
1867 |
ok := true |
|
1868 |
] |
|
1869 |
]. |
|
1870 |
err := ' is currently not implemented in the class'. |
|
1871 |
] |
|
1872 |
] |
|
1873 |
] |
|
1874 |
] |
|
1875 |
] |
|
1876 |
] |
|
141 | 1877 |
]. |
1878 |
||
1879 |
ok ifFalse:[ |
|
423 | 1880 |
(receiver notNil |
466
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1881 |
and:[((recType := receiver type) == #GlobalVariable) |
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1882 |
or:[recType == #PrivateClass]]) ifTrue:[ |
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1883 |
"/ dont check autoloaded classes |
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1884 |
"/ - it may work after loading |
423 | 1885 |
|
1886 |
rec := receiver evaluate. |
|
1887 |
(rec notNil |
|
1888 |
and:[rec isBehavior |
|
1889 |
and:[rec isLoaded not]]) ifTrue:[ |
|
1890 |
^ aSelectorString |
|
1891 |
]. |
|
1892 |
]. |
|
141 | 1893 |
|
1894 |
"OLD: " |
|
341 | 1895 |
self warning:('#' , aSelectorString , '\\' , err) withCRs position:pos1 to:pos2 |
141 | 1896 |
" " |
1897 |
||
1898 |
"NEW: - not finished - need more interfaces |
|
1899 |
(currently produces warning output on Transcript while filing in |
|
1900 |
||
1901 |
||
273 | 1902 |
^ self correctSelector:aSelectorString message:('#' , aSelectorString , err) position:pos1 to:pos2 |
141 | 1903 |
" |
1904 |
]. |
|
1905 |
^ aSelectorString |
|
1906 |
||
1907 |
"Modified: 5.9.1995 / 17:02:11 / claus" |
|
466
7f136821cdd2
dont check selector of messages to autoloaded privateClasses.
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
1908 |
"Modified: 5.1.1997 / 16:50:36 / cg" |
0 | 1909 |
! ! |
1910 |
||
1911 |
!Parser methodsFor:'error handling'! |
|
1912 |
||
141 | 1913 |
correctableError:message position:pos1 to:pos2 |
1914 |
"report an error which can be corrected by compiler - |
|
1915 |
return true if correction is wanted" |
|
1916 |
||
1917 |
|correctIt| |
|
1918 |
||
1919 |
requestor isNil ifTrue:[ |
|
1920 |
self showErrorMessage:message position:pos1. |
|
1921 |
correctIt := false |
|
1922 |
] ifFalse:[ |
|
1923 |
correctIt := requestor correctableError:message position:pos1 to:pos2 from:self |
|
1924 |
]. |
|
1925 |
correctIt ifFalse:[ |
|
1926 |
exitBlock notNil ifTrue:[exitBlock value] |
|
1927 |
]. |
|
1928 |
^ correctIt |
|
1929 |
! |
|
1930 |
||
1931 |
exitWith:something |
|
1932 |
"this is the longjump out of evaluation via a return expression" |
|
1933 |
||
1934 |
evalExitBlock value:something |
|
1935 |
! |
|
1936 |
||
1937 |
identifierExpectedIn:what |
|
1938 |
|msg| |
|
1939 |
||
1940 |
(#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[ |
|
1941 |
msg := 'Reserved keyword in ' |
|
1942 |
] ifFalse:[ |
|
1943 |
msg := 'Identifier expected in ' |
|
1944 |
]. |
|
1945 |
self syntaxError:msg , what position:tokenPosition to:source position - 1. |
|
1946 |
^ #Error |
|
1947 |
! |
|
1948 |
||
1949 |
parseError:aMessage |
|
1950 |
"report an error" |
|
1951 |
||
1952 |
^ self parseError:aMessage position:tokenPosition to:nil |
|
1953 |
! |
|
1954 |
||
1955 |
parseError:aMessage position:position |
|
1956 |
"report an error" |
|
1957 |
||
1958 |
^ self parseError:aMessage position:position to:nil |
|
1959 |
! |
|
1960 |
||
1961 |
parseError:aMessage position:position to:endPos |
|
1962 |
"report an error" |
|
1963 |
||
1964 |
|m| |
|
1965 |
||
1966 |
errorFlag := true. |
|
1967 |
m := 'Error: ' , aMessage. |
|
1968 |
self notifyError:m position:position to:endPos. |
|
1969 |
exitBlock notNil ifTrue:[exitBlock value]. |
|
1970 |
^ false |
|
1971 |
! |
|
1972 |
||
0 | 1973 |
showErrorMessage:aMessage position:pos |
19 | 1974 |
"redefined since parser can give more detailed info about |
1975 |
the class & selector where the error occured." |
|
1976 |
||
71 | 1977 |
|text| |
1978 |
||
19 | 1979 |
ignoreErrors ifFalse:[ |
273 | 1980 |
Smalltalk silentLoading == true ifFalse:[ |
1981 |
Transcript show:(pos printString). |
|
1982 |
Transcript show:' '. |
|
1983 |
selector notNil ifTrue:[ |
|
1984 |
Transcript show:aMessage. |
|
1985 |
classToCompileFor notNil ifTrue:[ |
|
1986 |
text := ' in ' , classToCompileFor name , '>>' , selector |
|
1987 |
] ifFalse:[ |
|
1988 |
text := ' in ' , selector |
|
1989 |
] |
|
1990 |
] ifFalse:[ |
|
1991 |
classToCompileFor notNil ifTrue:[ |
|
1992 |
text := aMessage , ' (' , classToCompileFor name , ')' |
|
1993 |
] ifFalse:[ |
|
1994 |
text := aMessage |
|
1995 |
] |
|
1996 |
]. |
|
1997 |
Transcript showCR:text. |
|
1998 |
] |
|
0 | 1999 |
] |
273 | 2000 |
|
2001 |
"Modified: 18.5.1996 / 15:44:15 / cg" |
|
0 | 2002 |
! |
2003 |
||
171 | 2004 |
showErrorMessageForClass:aClass |
2005 |
"/ compiler parseError:'syntax error'. |
|
2006 |
Transcript show:' '. |
|
2007 |
aClass notNil ifTrue:[ |
|
273 | 2008 |
Transcript show:aClass name , '>>' |
171 | 2009 |
]. |
2010 |
selector notNil ifTrue:[ |
|
273 | 2011 |
Transcript show:(selector) |
171 | 2012 |
]. |
273 | 2013 |
Transcript showCR:' -> Error'. |
171 | 2014 |
|
2015 |
"Created: 13.12.1995 / 20:24:34 / cg" |
|
273 | 2016 |
"Modified: 18.5.1996 / 15:44:17 / cg" |
171 | 2017 |
! |
2018 |
||
0 | 2019 |
undefError:aName position:pos1 to:pos2 |
3 | 2020 |
"report an undefined variable error - return true, if it should be |
86 | 2021 |
corrected. If not corrected, only one warning is made per undefined |
2022 |
variable." |
|
2023 |
||
429 | 2024 |
|doCorrect msg idx| |
86 | 2025 |
|
2026 |
" |
|
2027 |
alredy warned about this one ? |
|
2028 |
" |
|
2029 |
warnedUndefVars notNil ifTrue:[ |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2030 |
(warnedUndefVars includes:aName) ifTrue:[ |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2031 |
"already warned about this one" |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2032 |
^ false |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2033 |
]. |
86 | 2034 |
]. |
2035 |
||
131 | 2036 |
"/ (classToCompileFor notNil |
2037 |
"/ and:[classToCompileFor superclass notNil |
|
2038 |
"/ and:[classToCompileFor superclass instanceVariableString isNil]]) ifTrue:[ |
|
132
5be56a5e90b7
added methods for silent parsing (parseMethod / parseMethodSpec)
Claus Gittinger <cg@exept.de>
parents:
131
diff
changeset
|
2039 |
"/ self showErrorMessage:'Error: no source information (instvar names)' position:pos1. |
5be56a5e90b7
added methods for silent parsing (parseMethod / parseMethodSpec)
Claus Gittinger <cg@exept.de>
parents:
131
diff
changeset
|
2040 |
"/ ^ false |
131 | 2041 |
"/ ]. |
2042 |
||
2043 |
(requestor isNil or:[requestor isStream]) ifTrue:[ |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2044 |
aName first isUppercase ifFalse:[ |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2045 |
self showErrorMessage:('Error: ' , aName , ' is undefined') position:pos1. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2046 |
]. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2047 |
doCorrect := false. |
86 | 2048 |
] ifFalse:[ |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2049 |
" |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2050 |
ask requestor for correct/continue/abort ... |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2051 |
it is supposed to raise abort or return true/false. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2052 |
True return means that correction is wanted. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2053 |
" |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2054 |
msg := 'Warning: ' , aName , ' is undefined'. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2055 |
classToCompileFor notNil ifTrue:[ |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2056 |
"is it an instance-variable marked inaccessable ?" |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2057 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2058 |
idx := (self classesInstVarNames) indexOf:(aName , '*') startingAt:1. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2059 |
idx ~~ 0 ifTrue:[ |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2060 |
msg := 'Warning: ' , aName , ' is a hidden instvar (not accessable from ST-code)'. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2061 |
] |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2062 |
]. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2063 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2064 |
doCorrect := self correctableError:msg position:pos1 to:pos2 |
86 | 2065 |
]. |
2066 |
||
2067 |
doCorrect ifFalse:[ |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2068 |
warnedUndefVars isNil ifTrue:[ |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2069 |
warnedUndefVars := Set new. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2070 |
]. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2071 |
warnedUndefVars add:aName. |
3 | 2072 |
]. |
0 | 2073 |
|
86 | 2074 |
^ doCorrect |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2075 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2076 |
"Modified: 14.10.1996 / 18:00:50 / cg" |
0 | 2077 |
! ! |
2078 |
||
2079 |
!Parser methodsFor:'parsing'! |
|
2080 |
||
141 | 2081 |
array |
2082 |
|arr elements elem pos1| |
|
2083 |
||
2084 |
pos1 := tokenPosition. |
|
2085 |
elements := OrderedCollection new:20. |
|
2086 |
[tokenType ~~ $) ] whileTrue:[ |
|
2087 |
elem := self arrayConstant. |
|
2088 |
(elem == #Error) ifTrue:[ |
|
2089 |
(tokenType == #EOF) ifTrue:[ |
|
2090 |
self syntaxError:'unterminated array-constant; '')'' expected' |
|
2091 |
position:pos1 to:tokenPosition |
|
2092 |
]. |
|
2093 |
^ #Error |
|
2094 |
]. |
|
2095 |
elements add:elem. |
|
2096 |
self nextToken |
|
2097 |
]. |
|
2098 |
arr := Array withAll:elements. |
|
2099 |
||
2100 |
(ArraysAreImmutable and:[ImmutableArray notNil]) ifTrue:[ |
|
2101 |
arr changeClassTo:ImmutableArray. |
|
2102 |
]. |
|
2103 |
^ arr |
|
2104 |
! |
|
2105 |
||
2106 |
arrayConstant |
|
2107 |
(tokenType == #String) ifTrue:[ |
|
2108 |
^ tokenValue |
|
2109 |
]. |
|
2110 |
(tokenType == #Nil) ifTrue:[ |
|
2111 |
^ nil |
|
2112 |
]. |
|
2113 |
(tokenType == #Integer) ifTrue:[ |
|
2114 |
^ tokenValue |
|
2115 |
]. |
|
2116 |
(tokenType == #Character) ifTrue:[ |
|
2117 |
^ tokenValue |
|
2118 |
]. |
|
2119 |
(tokenType == #Float) ifTrue:[ |
|
2120 |
^ tokenValue |
|
2121 |
]. |
|
2122 |
(tokenType == #True) ifTrue:[ |
|
2123 |
^ true |
|
2124 |
]. |
|
2125 |
(tokenType == #False) ifTrue:[ |
|
2126 |
^ false |
|
2127 |
]. |
|
2128 |
(tokenType == #Error) ifTrue:[ |
|
2129 |
^ #Error |
|
2130 |
]. |
|
2131 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
2132 |
^ tokenName asSymbol |
|
2133 |
]. |
|
2134 |
(tokenType == #Keyword) ifTrue:[ |
|
2135 |
^ tokenName asSymbol |
|
2136 |
]. |
|
2137 |
(tokenType == #Identifier) ifTrue:[ |
|
2138 |
^ tokenName asSymbol |
|
2139 |
]. |
|
2140 |
(tokenType == $() ifTrue:[ |
|
2141 |
self nextToken. |
|
2142 |
^ self array |
|
2143 |
]. |
|
2144 |
(tokenType == $[) ifTrue:[ |
|
2145 |
self nextToken. |
|
2146 |
^ self byteArray |
|
2147 |
]. |
|
2148 |
(tokenType == #Symbol) ifTrue:[ |
|
2149 |
" |
|
2150 |
self warning:'no # for symbols within array-constants'. |
|
2151 |
" |
|
2152 |
^ tokenValue |
|
2153 |
]. |
|
2154 |
(tokenType == #HashLeftParen) ifTrue:[ |
|
2155 |
" |
|
2156 |
self warning:'no # for arrays within array-constants'. |
|
2157 |
" |
|
2158 |
self nextToken. |
|
2159 |
^ self array |
|
2160 |
]. |
|
2161 |
(tokenType == #HashLeftBrack) ifTrue:[ |
|
2162 |
" |
|
2163 |
self warning:'no # for arrays within array-constants'. |
|
2164 |
" |
|
2165 |
self nextToken. |
|
2166 |
^ self byteArray |
|
2167 |
]. |
|
2168 |
(tokenType == #EOF) ifTrue:[ |
|
2169 |
"just for the better error-hilight; let caller handle error" |
|
2170 |
^ #Error |
|
2171 |
]. |
|
2172 |
self syntaxError:('error in array-constant; ' |
|
2173 |
, tokenType printString |
|
2174 |
, ' unexpected'). |
|
2175 |
^ #Error |
|
2176 |
! |
|
2177 |
||
2178 |
binaryExpression |
|
2179 |
"parse a binary-expression; return a node-tree, nil or #Error" |
|
2180 |
||
2181 |
|receiver arg sel pos try lno note| |
|
2182 |
||
2183 |
receiver := self unaryExpression. |
|
2184 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
2185 |
||
2186 |
"special kludge: since Scanner cannot know if -digit is a binary |
|
2187 |
expression or a negative constant, handle cases here" |
|
2188 |
||
2189 |
[(tokenType == #BinaryOperator) or:[(tokenType == $|) |
|
2190 |
or:[(tokenType == #Integer) and:[tokenValue < 0]]]] whileTrue:[ |
|
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2191 |
pos := tokenPosition. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2192 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2193 |
lno := tokenLineNr. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2194 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2195 |
"kludge here: bar and minus are not scanned as binop " |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2196 |
(tokenType == $|) ifTrue:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2197 |
sel := '|'. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2198 |
self nextToken |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2199 |
] ifFalse:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2200 |
(tokenType == #BinaryOperator) ifTrue:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2201 |
sel := self selectorCheck:tokenName for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1). |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2202 |
self nextToken |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2203 |
] ifFalse:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2204 |
sel := '-'. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2205 |
tokenValue := tokenValue negated |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2206 |
] |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2207 |
]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2208 |
arg := self unaryExpression. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2209 |
(arg == #Error) ifTrue:[^ #Error]. |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
2210 |
try := BinaryNode receiver:receiver selector:sel arg:arg fold:foldConstants. |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2211 |
(try isMemberOf:String) ifTrue:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2212 |
self parseError:try position:pos to:tokenPosition. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2213 |
errorFlag := false. "ok, user wants it - so he'll get it" |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
2214 |
receiver := BinaryNode receiver:receiver selector:sel arg:arg fold:nil. |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2215 |
note := receiver plausibilityCheck. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2216 |
note notNil ifTrue:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2217 |
self warning:note position:pos to:tokenPosition |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2218 |
]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2219 |
] ifFalse:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2220 |
receiver := try |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2221 |
]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2222 |
receiver lineNumber:lno. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2223 |
parseForCode ifFalse:[self rememberSelectorUsed:sel]. |
141 | 2224 |
]. |
2225 |
^ receiver |
|
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2226 |
|
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
2227 |
"Modified: 21.3.1996 / 16:09:04 / cg" |
141 | 2228 |
! |
2229 |
||
2230 |
block |
|
2231 |
"parse a block; return a node-tree, nil or #Error" |
|
2232 |
||
2233 |
|node args argNames arg pos lno| |
|
2234 |
||
2235 |
lno := tokenLineNr. |
|
2236 |
self nextToken. |
|
2237 |
(tokenType == $: ) ifTrue:[ |
|
2238 |
[tokenType == $:] whileTrue:[ |
|
2239 |
pos := tokenPosition. |
|
2240 |
self nextToken. |
|
2241 |
(tokenType == #Identifier) ifFalse:[ |
|
2242 |
^ self identifierExpectedIn:'block-arg declaration' |
|
2243 |
]. |
|
2244 |
arg := Variable name:tokenName. |
|
2245 |
args isNil ifTrue:[ |
|
2246 |
args := Array with:arg. |
|
2247 |
argNames := Array with:tokenName. |
|
2248 |
] ifFalse:[ |
|
2249 |
(argNames includes:tokenName) ifTrue:[ |
|
2250 |
self syntaxError:'redefinition of ''' , tokenName , ''' in argument list.' |
|
2251 |
position:tokenPosition |
|
2252 |
to:(tokenPosition + tokenName size - 1) |
|
2253 |
]. |
|
2254 |
args := args copyWith:arg. |
|
2255 |
argNames := argNames copyWith:tokenName. |
|
2256 |
]. |
|
2257 |
self nextToken |
|
2258 |
]. |
|
2259 |
(tokenType ~~ $| ) ifTrue:[ |
|
2260 |
"ST-80 allows [:arg ]" |
|
2261 |
(tokenType == $] ) ifTrue:[ |
|
2262 |
node := BlockNode arguments:args home:currentBlock variables:nil. |
|
2263 |
node lineNumber:lno. |
|
2264 |
^ node |
|
2265 |
]. |
|
2266 |
self syntaxError:'| expected after block-arg declaration'. |
|
2267 |
^ #Error |
|
2268 |
]. |
|
2269 |
self nextToken |
|
2270 |
]. |
|
2271 |
node := self blockBody:args. |
|
2272 |
(node notNil and:[node ~~ #Error]) ifTrue:[ |
|
2273 |
node lineNumber:lno. |
|
2274 |
]. |
|
2275 |
^ node |
|
2276 |
! |
|
2277 |
||
2278 |
blockBody:args |
|
2279 |
"parse a blocks body; return a node-tree, nil or #Error" |
|
2280 |
||
2281 |
|stats node var vars lno names| |
|
2282 |
||
2283 |
lno := tokenLineNr. |
|
2284 |
(tokenType == $| ) ifTrue:[ |
|
382 | 2285 |
self nextToken. |
2286 |
[tokenType == $|] whileFalse:[ |
|
2287 |
(tokenType == #Identifier) ifFalse:[ |
|
2288 |
^ self identifierExpectedIn:'block-var declaration' |
|
2289 |
]. |
|
2290 |
var := Variable name:tokenName. |
|
2291 |
vars isNil ifTrue:[ |
|
2292 |
vars := Array with:var. |
|
2293 |
names := Array with:tokenName |
|
2294 |
] ifFalse:[ |
|
2295 |
(names includes:tokenName) ifTrue:[ |
|
2296 |
self parseError:'redefinition of ''' , tokenName , ''' in local variables' |
|
2297 |
position:tokenPosition to:tokenPosition + tokenName size -1. |
|
2298 |
] ifFalse:[ |
|
2299 |
vars := vars copyWith:var. |
|
2300 |
names := names copyWith:tokenName |
|
2301 |
] |
|
2302 |
]. |
|
2303 |
self nextToken. |
|
2304 |
]. |
|
2305 |
self nextToken |
|
141 | 2306 |
]. |
382 | 2307 |
|
141 | 2308 |
node := BlockNode arguments:args home:currentBlock variables:vars. |
2309 |
node lineNumber:lno. |
|
2310 |
currentBlock := node. |
|
2311 |
stats := self blockStatementList. |
|
382 | 2312 |
lineNumberInfo == #full ifTrue:[ |
2313 |
node endLineNumber:tokenLineNr |
|
2314 |
]. |
|
141 | 2315 |
node statements:stats. |
2316 |
currentBlock := node home. |
|
2317 |
(stats == #Error) ifTrue:[^ #Error]. |
|
2318 |
^ node |
|
382 | 2319 |
|
2320 |
"Modified: 21.10.1996 / 14:48:56 / cg" |
|
141 | 2321 |
! |
2322 |
||
2323 |
blockExpression |
|
2324 |
"parse a blockExpression; return a node-tree, nil or #Error. |
|
2325 |
Not used by ST/X's parser, but added for ST-80 compatibility." |
|
2326 |
||
2327 |
tokenType ~~ $[ ifTrue:[ |
|
2328 |
self syntaxError:'[ expected'. |
|
2329 |
^ #Error. |
|
2330 |
]. |
|
2331 |
^ self block |
|
2332 |
! |
|
2333 |
||
2334 |
blockStatementList |
|
2335 |
"parse a blocks statementlist; return a node-tree, nil or #Error" |
|
2336 |
||
2337 |
|thisStatement prevStatement firstStatement| |
|
2338 |
||
2339 |
(tokenType == $] ) ifTrue:[^ nil]. |
|
2340 |
thisStatement := self statement. |
|
2341 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
2342 |
firstStatement := thisStatement. |
|
2343 |
[tokenType == $] ] whileFalse:[ |
|
2344 |
(tokenType == $.) ifFalse:[ |
|
2345 |
((tokenType == #EOF) or:[tokenType == $)]) ifTrue:[ |
|
2346 |
self syntaxError:'missing '']'' in block' |
|
2347 |
] ifFalse:[ |
|
2348 |
self syntaxError:'missing ''.'' in block' |
|
2349 |
]. |
|
2350 |
^ #Error |
|
2351 |
] ifTrue:[ |
|
2352 |
prevStatement := thisStatement. |
|
2353 |
self nextToken. |
|
2354 |
tokenType == $] ifTrue:[ |
|
2355 |
" |
|
2356 |
*** I had a warning here (since it was not defined |
|
2357 |
*** in the blue-book; but PD-code contains a lot of |
|
2358 |
*** code with periods at the end so that the warnings |
|
2359 |
*** became annoying |
|
2360 |
||
2361 |
self warning:'period after last statement in block'. |
|
2362 |
" |
|
2363 |
^ firstStatement |
|
2364 |
]. |
|
2365 |
thisStatement := self statement. |
|
2366 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
2367 |
prevStatement nextStatement:thisStatement |
|
2368 |
] |
|
2369 |
]. |
|
2370 |
^ firstStatement |
|
2371 |
! |
|
2372 |
||
2373 |
byteArray |
|
2374 |
"started with ST-80 R4 - allow byteArray constants as #[ ... ]" |
|
2375 |
||
2376 |
|bytes index limit newArray elem pos1 pos2| |
|
2377 |
||
2378 |
pos1 := tokenPosition. |
|
2379 |
bytes := ByteArray uninitializedNew:5000. |
|
2380 |
index := 0. limit := 5000. |
|
2381 |
[tokenType ~~ $] ] whileTrue:[ |
|
2382 |
pos2 := tokenPosition. |
|
2383 |
" |
|
2384 |
this is not good programming style, but speeds up |
|
2385 |
reading of huge byte arrays (i.e. stored Images ...) |
|
2386 |
" |
|
2387 |
(tokenType == #Integer) ifTrue:[ |
|
2388 |
elem := tokenValue |
|
2389 |
] ifFalse:[ |
|
2390 |
elem := self arrayConstant. |
|
2391 |
(elem == #Error) ifTrue:[ |
|
2392 |
(tokenType == #EOF) ifTrue:[ |
|
2393 |
self syntaxError:'unterminated bytearray-constant; '']'' expected' |
|
2394 |
position:pos1 to:tokenPosition |
|
2395 |
]. |
|
2396 |
^ #Error |
|
2397 |
]. |
|
2398 |
]. |
|
2399 |
((elem isMemberOf:SmallInteger) and:[elem between:0 and:255]) ifTrue:[ |
|
2400 |
index := index + 1. |
|
2401 |
bytes at:index put:elem. |
|
2402 |
index == limit ifTrue:[ |
|
2403 |
newArray := ByteArray uninitializedNew:(limit * 2). |
|
2404 |
newArray replaceFrom:1 to:limit with:bytes startingAt:1. |
|
2405 |
limit := limit * 2. |
|
2406 |
bytes := newArray |
|
2407 |
]. |
|
2408 |
] ifFalse:[ |
|
2409 |
self parseError:'invalid ByteArray element' position:pos2 to:tokenPosition - 1 |
|
2410 |
]. |
|
2411 |
self nextToken. |
|
2412 |
]. |
|
2413 |
newArray := ByteArray uninitializedNew:index. |
|
2414 |
newArray replaceFrom:1 to:index with:bytes startingAt:1. |
|
2415 |
^ newArray |
|
2416 |
! |
|
2417 |
||
2418 |
degeneratedKeywordExpressionForSelector |
|
2419 |
"parse a keyword-expression without receiver - for the selector |
|
2420 |
only. return the selector or nil. This is not used in normal parsing, |
|
2421 |
but instead to extract the selector from a code fragment. |
|
2422 |
(for example, the system browsers implementors-function uses this)" |
|
2423 |
||
2424 |
|sel arg rec| |
|
2425 |
||
2426 |
(tokenType == #Keyword) ifTrue:[ |
|
2427 |
sel := tokenName. |
|
2428 |
self nextToken. |
|
2429 |
arg := self binaryExpression. |
|
2430 |
(arg == #Error) ifTrue:[^ sel]. |
|
2431 |
[tokenType == #Keyword] whileTrue:[ |
|
2432 |
sel := sel , tokenName. |
|
2433 |
self nextToken. |
|
2434 |
arg := self binaryExpression. |
|
2435 |
(arg == #Error) ifTrue:[^ sel]. |
|
2436 |
]. |
|
2437 |
^ sel |
|
2438 |
]. |
|
2439 |
||
2440 |
(rec := self primary) ~~ #Error ifTrue:[ |
|
2441 |
sel := self degeneratedKeywordExpressionForSelector. |
|
2442 |
sel isNil ifTrue:[ |
|
2443 |
rec isMessage ifTrue:[ |
|
2444 |
sel := rec selector |
|
2445 |
] ifFalse:[ |
|
2446 |
rec isAssignment ifTrue:[ |
|
2447 |
rec expression isMessage ifTrue:[ |
|
2448 |
sel := rec expression selector |
|
2449 |
] |
|
2450 |
] |
|
2451 |
] |
|
2452 |
] |
|
2453 |
]. |
|
2454 |
^ sel |
|
2455 |
! |
|
2456 |
||
2457 |
expression |
|
2458 |
"parse a cascade-expression; return a node-tree, nil or #Error. |
|
2459 |
||
2460 |
expression ::= keywordExpression |
|
2461 |
| keywordExpression cascade |
|
2462 |
||
2463 |
cascade ::= ';' expressionSendPart |
|
2464 |
| cascade ';' expressionSendPart |
|
2465 |
||
2466 |
expressionSendPart ::= { KEYWORD binaryExpression } |
|
2467 |
| BINARYOPERATOR unaryExpression |
|
2468 |
| IDENTIFIER |
|
2469 |
" |
|
2470 |
||
2471 |
|receiver arg sel args pos pos2 lno| |
|
2472 |
||
2473 |
pos := tokenPosition. |
|
2474 |
receiver := self keywordExpression. |
|
2475 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
2476 |
(tokenType == $;) ifTrue:[ |
|
2477 |
[tokenType == $;] whileTrue:[ |
|
2478 |
receiver isMessage ifFalse:[ |
|
2479 |
self syntaxError:'left side of cascade must be a message expression' |
|
2480 |
position:pos to:tokenPosition |
|
2481 |
]. |
|
2482 |
self nextToken. |
|
2483 |
(tokenType == #Identifier) ifTrue:[ |
|
2484 |
sel := self selectorCheck:tokenName for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1). |
|
2485 |
receiver := CascadeNode receiver:receiver selector:sel. |
|
2486 |
receiver lineNumber:tokenLineNr. |
|
2487 |
parseForCode ifFalse:[self rememberSelectorUsed:sel]. |
|
2488 |
self nextToken. |
|
2489 |
] ifFalse:[ |
|
2490 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
2491 |
sel := self selectorCheck:tokenName for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1). |
|
2492 |
lno := tokenLineNr. |
|
2493 |
self nextToken. |
|
2494 |
arg := self unaryExpression. |
|
2495 |
(arg == #Error) ifTrue:[^ #Error]. |
|
2496 |
receiver := CascadeNode receiver:receiver selector:sel arg:arg. |
|
2497 |
receiver lineNumber:lno. |
|
2498 |
parseForCode ifFalse:[self rememberSelectorUsed:sel]. |
|
2499 |
] ifFalse:[ |
|
2500 |
(tokenType == #Keyword) ifTrue:[ |
|
2501 |
pos := tokenPosition. |
|
2502 |
lno := tokenLineNr. |
|
2503 |
sel := tokenName. |
|
2504 |
self nextToken. |
|
2505 |
arg := self binaryExpression. |
|
2506 |
(arg == #Error) ifTrue:[^ #Error]. |
|
2507 |
args := Array with:arg. |
|
2508 |
[tokenType == #Keyword] whileTrue:[ |
|
2509 |
sel := sel , tokenName. |
|
2510 |
self nextToken. |
|
2511 |
arg := self binaryExpression. |
|
2512 |
(arg == #Error) ifTrue:[^ #Error]. |
|
2513 |
args := args copyWith:arg. |
|
2514 |
pos2 := tokenPosition |
|
2515 |
]. |
|
2516 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2. |
|
2517 |
receiver := CascadeNode receiver:receiver selector:sel args:args. |
|
2518 |
receiver lineNumber:lno. |
|
2519 |
parseForCode ifFalse:[self rememberSelectorUsed:sel]. |
|
2520 |
] ifFalse:[ |
|
2521 |
(tokenType == #Error) ifTrue:[^ #Error]. |
|
2522 |
self syntaxError:('invalid cascade; ' , tokenType printString , ' unexpected') |
|
2523 |
position:tokenPosition to:source position - 1. |
|
2524 |
^ #Error |
|
2525 |
] |
|
2526 |
] |
|
2527 |
] |
|
2528 |
]. |
|
2529 |
||
144 | 2530 |
"obscure (unspecified ?) if selector follows; Question: |
141 | 2531 |
|
2532 |
is |
|
2533 |
'expr sel1; sel2 sel3' |
|
2534 |
||
2535 |
to be parsed as: |
|
2536 |
(t := expr. |
|
2537 |
t sel1. |
|
2538 |
t sel2) sel3 |
|
2539 |
||
2540 |
or: |
|
2541 |
(t := expr. |
|
2542 |
t sel1. |
|
2543 |
t sel2 sel3) |
|
2544 |
" |
|
2545 |
((tokenType == #Identifier) |
|
2546 |
or:[(tokenType == #BinaryOperator) |
|
2547 |
or:[tokenType == #Keyword]]) ifTrue:[ |
|
2548 |
self syntaxError:'ambigous cascade - please group using ( ...)' |
|
2549 |
position:tokenPosition to:source position - 1. |
|
2550 |
^ #Error |
|
2551 |
] |
|
2552 |
]. |
|
2553 |
^ receiver |
|
2554 |
! |
|
2555 |
||
2556 |
inWhichClassIsClassInstVar:aString |
|
2557 |
"search class-chain for the class-instance variable named aString |
|
2558 |
- return the class or nil if not found" |
|
2559 |
||
2560 |
|aClass| |
|
2561 |
||
2562 |
aClass := classToCompileFor. |
|
2563 |
[aClass notNil] whileTrue:[ |
|
463
2ecdbf7140da
oops - fixed inWhichClassIsClassInstVar; again ?
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
2564 |
(aClass class instVarNames includes:aString) ifTrue:[ ^ aClass]. |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2565 |
aClass := aClass superclass |
141 | 2566 |
]. |
2567 |
^ nil |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
2568 |
|
463
2ecdbf7140da
oops - fixed inWhichClassIsClassInstVar; again ?
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
2569 |
"Modified: 4.1.1997 / 14:42:15 / cg" |
141 | 2570 |
! |
2571 |
||
2572 |
inWhichClassIsClassVar:aString |
|
2573 |
"search class-chain for the classvariable named aString |
|
2574 |
- return the class or nil if not found" |
|
2575 |
||
2576 |
|aClass className baseClass| |
|
2577 |
||
2578 |
aClass := classToCompileFor. |
|
2579 |
aClass isMeta ifTrue:[ |
|
463
2ecdbf7140da
oops - fixed inWhichClassIsClassInstVar; again ?
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
2580 |
className := aClass name copyWithoutLast:6. |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
2581 |
baseClass := Smalltalk at:(className asSymbol). |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
2582 |
baseClass notNil ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
2583 |
aClass := baseClass |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
2584 |
] |
141 | 2585 |
]. |
2586 |
^ aClass whichClassDefinesClassVar:aString |
|
463
2ecdbf7140da
oops - fixed inWhichClassIsClassInstVar; again ?
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
2587 |
|
141 | 2588 |
"/ [aClass notNil] whileTrue:[ |
2589 |
"/ (aClass classVarNames includes:aString) ifTrue:[ ^ aClass]. |
|
2590 |
"/ aClass := aClass superclass |
|
2591 |
"/ ]. |
|
2592 |
"/ ^ nil |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
2593 |
|
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
2594 |
"Modified: 17.6.1996 / 17:18:41 / stefan" |
463
2ecdbf7140da
oops - fixed inWhichClassIsClassInstVar; again ?
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
2595 |
"Modified: 4.1.1997 / 15:57:11 / cg" |
141 | 2596 |
! |
2597 |
||
2598 |
keywordExpression |
|
2599 |
"parse a keyword-expression; return a node-tree, nil or #Error. |
|
2600 |
||
2601 |
keywordExpression ::= binaryexpression |
|
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2602 |
| { KEYWORD-PART binaryExpression } |
141 | 2603 |
" |
2604 |
||
312 | 2605 |
|receiver sel arg args posR1 posR2 pos1 pos2 try lno note| |
2606 |
||
2607 |
posR1 := tokenPosition. |
|
141 | 2608 |
receiver := self binaryExpression. |
2609 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
2610 |
(tokenType == #Keyword) ifTrue:[ |
|
312 | 2611 |
pos1 := posR2 := tokenPosition. |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2612 |
pos2 := tokenPosition + tokenName size - 1. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2613 |
sel := tokenName. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2614 |
lno := tokenLineNr. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2615 |
self nextToken. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2616 |
arg := self binaryExpression. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2617 |
(arg == #Error) ifTrue:[^ #Error]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2618 |
args := Array with:arg. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2619 |
[tokenType == #Keyword] whileTrue:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2620 |
sel := sel , tokenName. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2621 |
pos2 := tokenPosition + tokenName size - 1. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2622 |
self nextToken. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2623 |
arg := self binaryExpression. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2624 |
(arg == #Error) ifTrue:[^ #Error]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2625 |
args := args copyWith:arg. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2626 |
]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2627 |
sel := self selectorCheck:sel for:receiver position:pos1 to:pos2. |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
2628 |
try := MessageNode receiver:receiver selector:sel args:args fold:foldConstants. |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2629 |
(try isMemberOf:String) ifTrue:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2630 |
self parseError:try position:pos1 to:pos2. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2631 |
errorFlag := false. "ok, user wants it - so he'll get it" |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
2632 |
receiver := MessageNode receiver:receiver selector:sel args:args fold:nil. |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2633 |
note := receiver plausibilityCheck. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2634 |
note notNil ifTrue:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2635 |
self warning:note position:pos1 to:pos2 |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2636 |
]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2637 |
] ifFalse:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2638 |
receiver := try |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2639 |
]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2640 |
receiver lineNumber:lno. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2641 |
parseForCode ifFalse:[self rememberSelectorUsed:sel]. |
312 | 2642 |
|
2643 |
(sel = #and: |
|
2644 |
or:[sel = #or:]) ifTrue:[ |
|
2645 |
receiver arg1 isBlock ifFalse:[ |
|
2646 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
|
2647 |
position:pos2+1 to:tokenPosition-1 |
|
2648 |
] |
|
2649 |
]. |
|
2650 |
(sel = #whileTrue: |
|
2651 |
or:[sel = #whileFalse:]) ifTrue:[ |
|
2652 |
receiver receiver isBlock ifFalse:[ |
|
2653 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
|
2654 |
position:posR1 to:posR2-1 |
|
2655 |
] |
|
2656 |
]. |
|
141 | 2657 |
]. |
2658 |
^ receiver |
|
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
2659 |
|
312 | 2660 |
"Modified: 18.7.1996 / 10:33:26 / cg" |
141 | 2661 |
! |
2662 |
||
0 | 2663 |
parseMethod |
19 | 2664 |
"parse a method. |
2665 |
Return the parseTree or #Error. |
|
2666 |
||
2667 |
method ::= methodSpec methodBody |
|
2668 |
" |
|
0 | 2669 |
|
2670 |
|parseTree| |
|
2671 |
||
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2672 |
"/ self nextToken. |
0 | 2673 |
(self parseMethodSpec == #Error) ifTrue:[^ #Error]. |
2674 |
parseTree := self parseMethodBody. |
|
2675 |
(parseTree == #Error) ifFalse:[ |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2676 |
self tree:parseTree |
0 | 2677 |
]. |
2678 |
^ parseTree |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2679 |
|
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2680 |
"Modified: 20.4.1996 / 20:09:26 / cg" |
0 | 2681 |
! |
2682 |
||
19 | 2683 |
parseMethodBody |
2684 |
"parse a methods body (locals & statements). |
|
2685 |
No more tokens may follow. |
|
2686 |
Return a node-tree, or #Error |
|
2687 |
||
2688 |
methodBody ::= '<' st80Primitive '>' #EOF |
|
202
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2689 |
| '<' st80Primitive '>' methodBodyVarSpec statementList #EOF |
19 | 2690 |
|
2691 |
" |
|
429 | 2692 |
|stats| |
19 | 2693 |
|
79 | 2694 |
stats := self parseMethodBodyOrEmpty. |
19 | 2695 |
(stats == #Error) ifFalse:[ |
202
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2696 |
(tokenType ~~ #EOF) ifTrue:[ |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2697 |
"/ just for the nicer error message |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2698 |
(#(Self Nil True False Super Here) includes:tokenType) ifTrue:[ |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2699 |
self parseError:tokenName , ' unexpected (missing ''.'' before ' , tokenName , ' ?)' |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2700 |
position:tokenPosition to:(tokenPosition + tokenName size - 1) |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2701 |
] ifFalse:[ |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2702 |
self parseError:(tokenType printString , ' unexpected (missing ''.'' or selector before it ?)') |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2703 |
position:tokenPosition to:source position-1. |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2704 |
]. |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2705 |
^#Error |
77ac1f0c15df
fix parsing for args/vars if method has an ST-80 resource spec
Claus Gittinger <cg@exept.de>
parents:
176
diff
changeset
|
2706 |
] |
19 | 2707 |
]. |
2708 |
^ stats |
|
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
2709 |
|
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
2710 |
"Modified: 12.12.1995 / 19:40:58 / cg" |
19 | 2711 |
! |
2712 |
||
79 | 2713 |
parseMethodBodyOrEmpty |
0 | 2714 |
"parse a methods body (locals & statements); |
19 | 2715 |
return a node-tree, nil or #Error. |
2716 |
empty (or comment only) input is accepted and returns nil. |
|
2717 |
||
2718 |
methodBodyOrNil ::= '<' st80Primitive '>' |
|
265 | 2719 |
| '<' st80Primitive '>' methodBodyVarSpec statementList |
2720 |
| <empty> |
|
19 | 2721 |
" |
0 | 2722 |
|
265 | 2723 |
|stats| |
0 | 2724 |
|
2725 |
(self parseMethodBodyVarSpec == #Error) ifTrue:[^ #Error]. |
|
2726 |
||
2727 |
(tokenType ~~ #EOF) ifTrue:[ |
|
265 | 2728 |
stats := self statementList |
0 | 2729 |
]. |
2730 |
^ stats |
|
265 | 2731 |
|
2732 |
"Modified: 27.4.1996 / 16:57:56 / cg" |
|
0 | 2733 |
! |
2734 |
||
19 | 2735 |
parseMethodBodyVarSpec |
265 | 2736 |
"parse a methods local variable specification, handling |
2737 |
possible primitive or resourceSpecs. |
|
2738 |
. |
|
19 | 2739 |
Leave spec of locals in methodLocals as a side effect. |
2740 |
Return #Error or nil. |
|
0 | 2741 |
|
19 | 2742 |
methodBodyVarSpec ::= '|' { IDENTIFIER } '|' |
265 | 2743 |
| <empty> |
19 | 2744 |
" |
0 | 2745 |
|
53 | 2746 |
|var pos msg| |
0 | 2747 |
|
265 | 2748 |
((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[ |
2749 |
self parsePrimitiveOrResourceSpecOrEmpty. |
|
2750 |
]. |
|
2751 |
||
0 | 2752 |
(tokenType == $|) ifTrue:[ |
265 | 2753 |
"memorize position for declaration in correction" |
2754 |
localVarDefPosition := tokenPosition. |
|
2755 |
self nextToken. |
|
2756 |
pos := tokenPosition. |
|
2757 |
[tokenType == #Identifier] whileTrue:[ |
|
2758 |
var := Variable name:tokenName. |
|
2759 |
methodVars isNil ifTrue:[ |
|
2760 |
methodVars := Array with:var. |
|
2761 |
methodVarNames := Array with:tokenName |
|
2762 |
] ifFalse:[ |
|
2763 |
(methodVarNames includes:tokenName) ifTrue:[ |
|
2764 |
self parseError:'redefinition of ''' , tokenName , ''' in local variables' |
|
2765 |
position:tokenPosition to:tokenPosition + tokenName size -1. |
|
2766 |
] ifFalse:[ |
|
2767 |
methodVars := methodVars copyWith:var. |
|
2768 |
methodVarNames := methodVarNames copyWith:tokenName |
|
2769 |
] |
|
2770 |
]. |
|
2771 |
methodArgNames notNil ifTrue:[ |
|
2772 |
(methodArgNames includes:tokenName) ifTrue:[ |
|
2773 |
self warning:'local variable ''' , tokenName , ''' hides argument.' |
|
2774 |
position:tokenPosition |
|
2775 |
to:(tokenPosition + tokenName size - 1) |
|
2776 |
] |
|
2777 |
]. |
|
2778 |
self nextToken. |
|
2779 |
pos := tokenPosition |
|
2780 |
]. |
|
2781 |
(tokenType ~~ $|) ifTrue:[ |
|
2782 |
(#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[ |
|
2783 |
msg := 'Reserved keyword in local var declaration' |
|
2784 |
] ifFalse:[ |
|
2785 |
msg := 'Identifier or | expected in local var declaration' |
|
2786 |
]. |
|
2787 |
self syntaxError:msg position:tokenPosition to:source position-1. |
|
2788 |
^ #Error |
|
2789 |
]. |
|
2790 |
self nextToken |
|
0 | 2791 |
]. |
2792 |
^ nil |
|
139
65eaf1a009f5
warn if method local hides method arg
Claus Gittinger <cg@exept.de>
parents:
135
diff
changeset
|
2793 |
|
265 | 2794 |
"Modified: 27.4.1996 / 16:58:28 / cg" |
0 | 2795 |
! |
2796 |
||
141 | 2797 |
parseMethodSpec |
2798 |
"parse a methods selector & arg specification; |
|
2799 |
Set selector and methodArgs in the receiver as a side effect. |
|
2800 |
Return the receiver or #Error. |
|
2801 |
||
2802 |
methodSpec ::= { KEYWORD IDENTIFIER } |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2803 |
| binaryOperator IDENTIFIER |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2804 |
| IDENTIFIER |
141 | 2805 |
" |
2806 |
||
2807 |
|var| |
|
2808 |
||
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2809 |
tokenType isNil ifTrue:[ |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2810 |
self nextToken. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2811 |
]. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2812 |
|
141 | 2813 |
(tokenType == #Keyword) ifTrue:[ |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2814 |
selector := ''. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2815 |
[tokenType == #Keyword] whileTrue:[ |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2816 |
selector := selector , tokenName. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2817 |
self nextToken. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2818 |
(tokenType ~~ #Identifier) ifTrue:[^ #Error]. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2819 |
var := Variable name:tokenName. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2820 |
methodArgs isNil ifTrue:[ |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2821 |
methodArgs := Array with:var. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2822 |
methodArgNames := Array with:tokenName |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2823 |
] ifFalse:[ |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2824 |
(methodArgNames includes:tokenName) ifTrue:[ |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2825 |
self syntaxError:'redefinition of ''' , tokenName , ''' in argument list.' |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2826 |
position:tokenPosition |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2827 |
to:(tokenPosition + tokenName size - 1) |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2828 |
]. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2829 |
methodArgs := methodArgs copyWith:var. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2830 |
methodArgNames := methodArgNames copyWith:tokenName |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2831 |
]. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2832 |
self nextToken |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2833 |
]. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2834 |
selector := selector asSymbol. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2835 |
^ self |
141 | 2836 |
]. |
2837 |
(tokenType == #Identifier) ifTrue:[ |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2838 |
selector := tokenName asSymbol. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2839 |
self nextToken. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2840 |
^ self |
141 | 2841 |
]. |
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2842 |
|
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2843 |
"/ special handling for |, which is also a lexical token |
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2844 |
tokenType == $| ifTrue:[ |
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2845 |
tokenType := #BinaryOperator. |
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2846 |
tokenName := '|' |
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2847 |
]. |
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2848 |
|
141 | 2849 |
(tokenType == #BinaryOperator) ifTrue:[ |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2850 |
selector := tokenName asSymbol. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2851 |
self nextToken. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2852 |
(tokenType ~~ #Identifier) ifTrue:[^ #Error]. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2853 |
var := Variable name:tokenName. |
141 | 2854 |
"/ methodArgs isNil ifTrue:[ |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2855 |
methodArgs := Array with:var. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2856 |
methodArgNames := Array with:tokenName. |
141 | 2857 |
"/ ] ifFalse:[ |
2858 |
"/ methodArgs := methodArgs copyWith:var. |
|
2859 |
"/ methodArgNames := methodArgNames copyWith:tokenName |
|
2860 |
"/ ]. |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2861 |
self nextToken. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2862 |
^ self |
141 | 2863 |
]. |
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2864 |
|
141 | 2865 |
^ #Error |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
2866 |
|
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
2867 |
"Modified: 3.1.1997 / 16:18:04 / cg" |
141 | 2868 |
! |
2869 |
||
265 | 2870 |
parsePrimitiveOrResourceSpecOrEmpty |
2871 |
"parse a methods primitive or resource spec" |
|
2872 |
||
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2873 |
|pos wmsg primNr| |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2874 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2875 |
[(tokenType == #BinaryOperator) and:[tokenName = '<']] whileTrue:[ |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2876 |
"/ an ST-80 primitive or resourceSpec - parsed but ignored |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2877 |
|
265 | 2878 |
pos := tokenPosition. |
2879 |
self nextToken. |
|
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2880 |
primNr := self parseST80Primitive. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2881 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2882 |
(primNr == #Error) ifTrue:[^ #Error]. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2883 |
wmsg := nil. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2884 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2885 |
primNr < 0 ifTrue:[ |
265 | 2886 |
WarnST80Directives == true ifTrue:[ |
2887 |
wmsg := 'ST-80 directive ignored'. |
|
2888 |
]. |
|
2889 |
] ifFalse:[ |
|
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2890 |
primitiveNr := primNr. |
265 | 2891 |
wmsg := 'ST-80 primitive may not work' |
2892 |
]. |
|
2893 |
wmsg notNil ifTrue:[self warning:wmsg position:pos] |
|
2894 |
]. |
|
2895 |
||
2896 |
"Created: 27.4.1996 / 16:55:55 / cg" |
|
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2897 |
"Modified: 29.5.1996 / 17:25:52 / cg" |
265 | 2898 |
! |
2899 |
||
7 | 2900 |
parseST80Primitive |
2901 |
"parse an ST-80 type primitive as '< primitive: nr >'; |
|
19 | 2902 |
return primitive number or #Error. |
97 | 2903 |
Also, ST-80 style resource specs are parsed; the result is |
2904 |
left (as side effect) in primitiveResource. |
|
2905 |
(maybe someone else knows what to do with it ...) |
|
2906 |
||
2907 |
Well, as we now have this mechanism, I'll use it to mark methods which |
|
2908 |
do keyboard processing ... <resource: keyboard ( keys )> |
|
2909 |
For faster finding of used keyboard accelerators. |
|
19 | 2910 |
|
2911 |
st80Primitive ::= 'primitive:' INTEGER |
|
97 | 2912 |
st80Primitive ::= 'resource:' SYMBOL - ignored; leave SYMBOL in primitiveResource |
2913 |
st80Primitive ::= 'resource:' SYMBOL (...) - ignored; leave (SYMBOL (...)) in primitiveResource |
|
19 | 2914 |
" |
0 | 2915 |
|
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2916 |
|primNumber keys resource resourceValue| |
0 | 2917 |
|
60 | 2918 |
(tokenType ~~ #Keyword) ifTrue:[ |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2919 |
self parseError:'bad primitive definition (keyword expected)'. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2920 |
^ #Error |
0 | 2921 |
]. |
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2922 |
|
60 | 2923 |
(tokenName = 'primitive:') ifTrue:[ |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2924 |
self nextToken. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2925 |
(tokenType == #Integer) ifFalse:[ |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2926 |
self parseError:'primitive number expected'. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2927 |
^ #Error |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2928 |
]. |
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2929 |
primitiveNr notNil ifTrue:[ |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2930 |
self parseError:'only one primitive spec allowed'. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2931 |
primNumber := -1. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2932 |
] ifFalse:[ |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2933 |
primNumber := tokenValue. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2934 |
]. |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2935 |
self nextToken. |
60 | 2936 |
] ifFalse:[ |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2937 |
(tokenName = 'resource:') ifTrue:[ |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2938 |
self nextToken. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2939 |
(tokenType ~~ #Symbol) ifTrue:[ |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2940 |
self parseError:'symbol expected'. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2941 |
^ #Error |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2942 |
]. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2943 |
primNumber := -1. |
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2944 |
resource := tokenValue. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2945 |
resourceValue := true. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2946 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2947 |
self nextToken. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2948 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2949 |
tokenType == $( ifTrue:[ |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2950 |
self nextToken. |
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2951 |
keys := OrderedCollection new. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2952 |
[tokenType == $) ] whileFalse:[ |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2953 |
keys add:tokenValue. |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2954 |
self nextToken. |
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2955 |
]. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2956 |
resourceValue := keys. |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2957 |
self nextToken. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2958 |
]. |
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2959 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2960 |
primitiveResource isNil ifTrue:[ |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2961 |
primitiveResource := IdentityDictionary new. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2962 |
]. |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2963 |
primitiveResource at:(resource asSymbol) put:resourceValue. |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2964 |
] ifFalse:[ |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2965 |
self parseError:'unrecognized primitive'. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2966 |
^ #Error |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2967 |
]. |
0 | 2968 |
]. |
97 | 2969 |
|
0 | 2970 |
((tokenType == #BinaryOperator) and:[tokenName = '>']) ifFalse:[ |
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2971 |
self parseError:'bad primitive definition (> expected)'. |
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2972 |
^ #Error |
0 | 2973 |
]. |
2974 |
self nextToken. |
|
2975 |
^ primNumber |
|
221
35b92bf6d9ef
parse style-resource directive
Claus Gittinger <cg@exept.de>
parents:
212
diff
changeset
|
2976 |
|
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
2977 |
"Modified: 29.5.1996 / 17:24:09 / cg" |
0 | 2978 |
! |
2979 |
||
2980 |
primary |
|
2981 |
"parse a primary-expression; return a node-tree, nil or #Error" |
|
2982 |
||
390
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
2983 |
|val var expr pos name t cls nameSpace nameSpaceGlobal globlName lnr node |
432 | 2984 |
pos2 eMsg| |
0 | 2985 |
|
2986 |
pos := tokenPosition. |
|
44 | 2987 |
(tokenType == #Self) ifTrue:[ |
354 | 2988 |
self nextToken. |
2989 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
2990 |
self parseError:'assignment to self' position:pos to:tokenPosition. |
|
2991 |
^ #Error |
|
2992 |
]. |
|
2993 |
selfNode isNil ifTrue:[ |
|
2994 |
selfNode := SelfNode value:selfValue |
|
2995 |
]. |
|
2996 |
^ selfNode |
|
44 | 2997 |
]. |
0 | 2998 |
(tokenType == #Identifier) ifTrue:[ |
354 | 2999 |
" |
3000 |
must check for variable first, to be backward compatible |
|
3001 |
with other smalltalks. |
|
3002 |
" |
|
3003 |
tokenName = 'here' ifTrue:[ |
|
3004 |
self variableOrError == #Error ifTrue:[ |
|
3005 |
tokenType := #Here. |
|
3006 |
warnSTXHereExtensionUsed ifTrue:[ |
|
3007 |
self warning:'here-sends are a nonstandard feature of ST/X' |
|
3008 |
position:pos to:pos+3. |
|
3009 |
" |
|
3010 |
only warn once |
|
3011 |
" |
|
3012 |
warnSTXHereExtensionUsed := false |
|
3013 |
] |
|
3014 |
] |
|
3015 |
] |
|
49 | 3016 |
]. |
3017 |
||
3018 |
(tokenType == #Identifier) ifTrue:[ |
|
354 | 3019 |
name := tokenName. |
3020 |
||
3021 |
var := self variable. |
|
3022 |
(var == #Error) ifTrue:[ |
|
3023 |
errorFlag := true |
|
3024 |
]. |
|
3025 |
self nextToken. |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3026 |
|
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3027 |
(tokenType == #'::') ifTrue:[ |
363
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3028 |
globlName := name. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3029 |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3030 |
"is it in a namespace ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3031 |
nameSpace := self findNameSpaceWith:globlName. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3032 |
nameSpace notNil ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3033 |
globlName := nameSpace name , '::' , globlName |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3034 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3035 |
|
363
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3036 |
[tokenType == #'::'] whileTrue:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3037 |
nameSpace := globlName. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3038 |
|
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3039 |
self nextToken. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3040 |
(tokenType == #Identifier) ifTrue:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3041 |
ignoreWarnings ifFalse:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3042 |
warnSTXNameSpaceUse ifTrue:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3043 |
self warning:'nameSpaces are a nonstandard feature of ST/X' |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3044 |
position:pos to:(source position). |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3045 |
" |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3046 |
only warn once |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3047 |
" |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3048 |
warnSTXNameSpaceUse := false |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3049 |
] |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3050 |
]. |
363
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3051 |
name := tokenName. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3052 |
|
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3053 |
globlName := (nameSpace , '::' , name). |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3054 |
|
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3055 |
nameSpaceGlobal := Smalltalk at:nameSpace asSymbol ifAbsent:nil. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3056 |
nameSpaceGlobal isNil ifTrue:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3057 |
self parseError:('unknown nameSpace: ', nameSpace) position:pos to:tokenPosition-1. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3058 |
errorFlag := true |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3059 |
] ifFalse:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3060 |
nameSpaceGlobal isNamespace ifTrue:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3061 |
"/ for now: only Smalltalk is allowed |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3062 |
nameSpaceGlobal ~~ Smalltalk ifTrue:[ |
424 | 3063 |
"/ self parseError:('(currently) the only valid nameSpace is `Smalltalk''') position:pos to:tokenPosition-1. |
3064 |
"/ errorFlag := true |
|
3065 |
] ifFalse:[ |
|
3066 |
globlName := name |
|
363
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3067 |
]. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3068 |
] ifFalse:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3069 |
nameSpaceGlobal isBehavior ifFalse:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3070 |
self parseError:('invalid nameSpace: ' , nameSpace) position:pos to:tokenPosition-1. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3071 |
errorFlag := true |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3072 |
] ifTrue:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3073 |
(nameSpaceGlobal privateClassesAt:name asSymbol) isNil ifTrue:[ |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3074 |
self parseError:('no private class: ' , name , ' in class: ' , nameSpace) position:pos to:tokenPosition-1. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3075 |
errorFlag := true |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3076 |
] |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3077 |
] |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3078 |
]. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3079 |
]. |
fb9565dd2770
parse nested nameSpace access foo::bar::baz
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
3080 |
self nextToken. |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3081 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3082 |
var := VariableNode |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3083 |
type:#GlobalVariable |
362 | 3084 |
name:globlName asSymbol. |
3085 |
parseForCode ifFalse:[self rememberGlobalUsed:globlName]. |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3086 |
] |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3087 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
358
diff
changeset
|
3088 |
|
354 | 3089 |
((tokenType == $_) or:[tokenType == #':=']) ifFalse:[ |
3090 |
^ var |
|
3091 |
]. |
|
3092 |
||
3093 |
"/ careful: it could already be an implicit self send |
|
3094 |
ImplicitSelfSends ifTrue:[ |
|
3095 |
var isMessage ifTrue:[ |
|
3096 |
self nextToken. |
|
3097 |
expr := self expression. |
|
3098 |
(errorFlag or:[expr == #Error]) ifTrue:[^ #Error]. |
|
3099 |
selfNode isNil ifTrue:[ |
|
3100 |
selfNode := SelfNode value:selfValue |
|
3101 |
]. |
|
3102 |
^ MessageNode receiver:selfNode selector:('implicit_' , name , ':') asSymbol arg:expr. |
|
3103 |
]. |
|
3104 |
]. |
|
3105 |
||
3106 |
(var ~~ #Error) ifTrue:[ |
|
3107 |
t := var type. |
|
3108 |
(t ~~ #MethodVar) ifTrue:[ |
|
3109 |
(t == #PrivateClass) ifTrue:[ |
|
3110 |
self parseError:'assignment to private class' position:pos to:tokenPosition. |
|
3111 |
errorFlag := true |
|
3112 |
] ifFalse:[ |
|
3113 |
(t == #MethodArg) ifTrue:[ |
|
3114 |
self parseError:'assignment to method argument' position:pos to:tokenPosition. |
|
3115 |
errorFlag := true |
|
3116 |
] ifFalse:[ |
|
3117 |
(t == #BlockArg) ifTrue:[ |
|
3118 |
self parseError:'assignment to block argument' position:pos to:tokenPosition. |
|
3119 |
errorFlag := true |
|
3120 |
] ifFalse:[ |
|
3121 |
(t == #InstanceVariable) ifTrue:[ |
|
450 | 3122 |
name := self classesInstVarNames at:(var index). |
387
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3123 |
|
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3124 |
"/ ca once did this to `name' and wondered what happened to his class ... |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3125 |
"/ (not really a beginners bug, but may happen as a typo or missing local variable; |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3126 |
"/ and is hard to track down later) |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3127 |
|
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3128 |
warnCommonMistakes ifTrue:[ |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3129 |
classToCompileFor isMeta ifTrue:[ |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3130 |
(classToCompileFor isSubclassOf:Class) ifTrue:[ |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3131 |
(Class allInstVarNames includes:(var name)) ifTrue:[ |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3132 |
self warning:'assignment to a classInstanceVariable\(see hierarchy of `Class'')' withCRs position:pos to:tokenPosition+1. |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3133 |
] |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3134 |
] |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3135 |
] |
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3136 |
]. |
354 | 3137 |
parseForCode ifFalse:[ |
3138 |
modifiedInstVars isNil ifTrue:[ |
|
3139 |
modifiedInstVars := Set new |
|
3140 |
]. |
|
3141 |
modifiedInstVars add:name |
|
3142 |
] |
|
3143 |
] ifFalse:[ |
|
3144 |
(t == #ClassVariable) ifTrue:[ |
|
3145 |
name := var name. |
|
3146 |
name := name copyFrom:((name indexOf:$:) + 1). |
|
3147 |
parseForCode ifFalse:[ |
|
3148 |
modifiedClassVars isNil ifTrue:[ |
|
3149 |
modifiedClassVars := Set new |
|
3150 |
]. |
|
3151 |
modifiedClassVars add:name |
|
3152 |
] |
|
3153 |
] ifFalse:[ |
|
3154 |
(t == #GlobalVariable) ifTrue:[ |
|
3155 |
(cls := Smalltalk classNamed:var name) notNil ifTrue:[ |
|
3156 |
cls name = var name ifTrue:[ |
|
387
908ee278cdf5
warn if a classInstVar of the Class-hierarchy is modified.
Claus Gittinger <cg@exept.de>
parents:
385
diff
changeset
|
3157 |
self warning:'assignment to global which refers to a class' position:pos to:tokenPosition. |
354 | 3158 |
] |
3159 |
]. |
|
3160 |
parseForCode ifFalse:[ |
|
3161 |
modifiedGlobals isNil ifTrue:[ |
|
3162 |
modifiedGlobals := Set new |
|
3163 |
]. |
|
3164 |
modifiedGlobals add:var name |
|
3165 |
] |
|
3166 |
] |
|
3167 |
] |
|
3168 |
] |
|
3169 |
] |
|
3170 |
] |
|
3171 |
] |
|
3172 |
]. |
|
3173 |
]. |
|
3174 |
||
382 | 3175 |
lnr := tokenLineNr. |
390
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3176 |
|
354 | 3177 |
self nextToken. |
390
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3178 |
pos2 := tokenPosition. |
354 | 3179 |
expr := self expression. |
390
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3180 |
|
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3181 |
"/ a typical beginner error: |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3182 |
"/ expr ifTrue:[ |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3183 |
"/ var := super |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3184 |
"/ ] ifFalse:[ |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3185 |
"/ var := something-else |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3186 |
"/ ]. |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3187 |
"/ var messageSend |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3188 |
"/ |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3189 |
"/ does not what a beginner might think. |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3190 |
|
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3191 |
warnCommonMistakes ifTrue:[ |
412 | 3192 |
(expr ~~ #Error and:[expr isSuper]) ifTrue:[ |
390
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3193 |
self warning:'followup messageSends to `' , var name , ''' will have normal send semantics\(i.e. NO super- or here-sends). Use self to avoid confusion.' withCRs position:pos to:pos2. |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3194 |
]. |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3195 |
]. |
5ba190b979d4
warn about another beginners error
Claus Gittinger <cg@exept.de>
parents:
387
diff
changeset
|
3196 |
|
354 | 3197 |
(errorFlag or:[expr == #Error]) ifTrue:[^ #Error]. |
382 | 3198 |
node := AssignmentNode variable:var expression:expr. |
3199 |
(lineNumberInfo == #full) ifTrue:[node lineNr:lnr]. |
|
3200 |
^ node |
|
0 | 3201 |
]. |
49 | 3202 |
|
44 | 3203 |
((tokenType == #Integer) |
120 | 3204 |
or:[(tokenType == #String) |
44 | 3205 |
or:[(tokenType == #Character) |
3206 |
or:[(tokenType == #Float) |
|
3207 |
or:[(tokenType == #Symbol)]]]]) ifTrue:[ |
|
354 | 3208 |
val := ConstantNode type:tokenType value:tokenValue. |
3209 |
self nextToken. |
|
3210 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3211 |
self parseError:'assignment to a constant' position:pos to:tokenPosition. |
|
3212 |
^ #Error |
|
3213 |
]. |
|
3214 |
^ val |
|
0 | 3215 |
]. |
3216 |
(tokenType == #Nil) ifTrue:[ |
|
354 | 3217 |
self nextToken. |
3218 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3219 |
self parseError:'assignment to nil' position:pos to:tokenPosition. |
|
3220 |
^ #Error |
|
3221 |
]. |
|
3222 |
^ ConstantNode type:#Nil value:nil |
|
0 | 3223 |
]. |
3224 |
(tokenType == #True) ifTrue:[ |
|
354 | 3225 |
self nextToken. |
3226 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3227 |
self parseError:'assignment to true' position:pos to:tokenPosition. |
|
3228 |
^ #Error |
|
3229 |
]. |
|
3230 |
^ ConstantNode type:#True value:true |
|
0 | 3231 |
]. |
3232 |
(tokenType == #False) ifTrue:[ |
|
354 | 3233 |
self nextToken. |
3234 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3235 |
self parseError:'assignment to false' position:pos to:tokenPosition. |
|
3236 |
^ #Error |
|
3237 |
]. |
|
3238 |
^ ConstantNode type:#False value:false |
|
0 | 3239 |
]. |
3240 |
(tokenType == #Super) ifTrue:[ |
|
354 | 3241 |
usesSuper := true. |
3242 |
self nextToken. |
|
3243 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3244 |
self parseError:'assignment to super' position:pos to:tokenPosition. |
|
3245 |
^ #Error |
|
3246 |
]. |
|
3247 |
(classToCompileFor isNil or:[classToCompileFor superclass isNil]) ifTrue:[ |
|
3248 |
self warning:'superclass is (currently ?) nil' position:pos to:(pos + 4). |
|
3249 |
]. |
|
3250 |
superNode isNil ifTrue:[ |
|
3251 |
superNode := SuperNode value:selfValue inClass:classToCompileFor |
|
3252 |
]. |
|
3253 |
^ superNode |
|
0 | 3254 |
]. |
49 | 3255 |
(tokenType == #Here) ifTrue:[ |
354 | 3256 |
self nextToken. |
3257 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3258 |
self parseError:'assignment to here' position:pos to:tokenPosition. |
|
3259 |
^ #Error |
|
3260 |
]. |
|
3261 |
classToCompileFor isNil ifTrue:[ |
|
3262 |
self warning:'in which class are you ?' position:pos to:(pos + 3). |
|
3263 |
]. |
|
3264 |
^ SuperNode value:selfValue inClass:classToCompileFor here:true |
|
49 | 3265 |
]. |
0 | 3266 |
(tokenType == #ThisContext) ifTrue:[ |
354 | 3267 |
self nextToken. |
3268 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3269 |
self parseError:'assignment to thisContext' position:pos to:tokenPosition. |
|
3270 |
^ #Error |
|
3271 |
]. |
|
3272 |
^ VariableNode type:#ThisContext |
|
0 | 3273 |
]. |
3274 |
(tokenType == #HashLeftParen) ifTrue:[ |
|
354 | 3275 |
self nextToken. |
3276 |
val := self array. |
|
3277 |
self nextToken. |
|
3278 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3279 |
self parseError:'assignment to a constant' position:pos to:tokenPosition. |
|
3280 |
^ #Error |
|
3281 |
]. |
|
3282 |
^ ConstantNode type:#Array value:val |
|
0 | 3283 |
]. |
3284 |
(tokenType == #HashLeftBrack) ifTrue:[ |
|
354 | 3285 |
self nextToken. |
3286 |
val := self byteArray. |
|
3287 |
self nextToken. |
|
3288 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3289 |
self parseError:'assignment to a constant' position:pos to:tokenPosition. |
|
3290 |
^ #Error |
|
3291 |
]. |
|
3292 |
^ ConstantNode type:#Array value:val |
|
0 | 3293 |
]. |
432 | 3294 |
|
0 | 3295 |
(tokenType == $() ifTrue:[ |
354 | 3296 |
self nextToken. |
3297 |
val := self expression. |
|
3298 |
(val == #Error) ifTrue:[^ #Error]. |
|
3299 |
(tokenType ~~ $) ) ifTrue:[ |
|
3300 |
tokenType isCharacter ifTrue:[ |
|
432 | 3301 |
eMsg := 'missing '')'' (i.e. ''' , tokenType asString , ''' unexpected)'. |
354 | 3302 |
] ifFalse:[ |
432 | 3303 |
eMsg := 'missing '')'''. |
354 | 3304 |
]. |
432 | 3305 |
self syntaxError:eMsg withCRs position:pos to:tokenPosition. |
354 | 3306 |
^ #Error |
3307 |
]. |
|
3308 |
self nextToken. |
|
3309 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3310 |
self parseError:'invalid assignment' position:pos to:tokenPosition. |
|
3311 |
^ #Error |
|
3312 |
]. |
|
3313 |
val parenthized:true. |
|
3314 |
^ val |
|
0 | 3315 |
]. |
3316 |
(tokenType == $[ ) ifTrue:[ |
|
354 | 3317 |
val := self block. |
3318 |
self nextToken. |
|
3319 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3320 |
self parseError:'invalid assignment' position:pos to:tokenPosition. |
|
3321 |
^ #Error |
|
3322 |
]. |
|
3323 |
^ val |
|
0 | 3324 |
]. |
19 | 3325 |
|
0 | 3326 |
(tokenType == #Error) ifTrue:[^ #Error]. |
44 | 3327 |
tokenType isCharacter ifTrue:[ |
354 | 3328 |
self syntaxError:('error in primary; ' |
3329 |
, tokenType printString , |
|
3330 |
' unexpected') position:tokenPosition to:tokenPosition |
|
0 | 3331 |
] ifFalse:[ |
354 | 3332 |
(#(BinaryOperator Keyword) includes:tokenType) ifTrue:[ |
432 | 3333 |
eMsg := ('error in primary; ' |
3334 |
, tokenType printString , '(' , tokenName , ') ' , |
|
3335 |
' unexpected') |
|
354 | 3336 |
] ifFalse:[ |
432 | 3337 |
eMsg := ('error in primary; ' |
3338 |
, tokenType printString , |
|
3339 |
' unexpected') |
|
3340 |
]. |
|
3341 |
self syntaxError:eMsg |
|
0 | 3342 |
]. |
3343 |
^ #Error |
|
120 | 3344 |
|
3345 |
"Created: 13.9.1995 / 12:50:50 / claus" |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3346 |
"Modified: 20.12.1996 / 00:03:40 / cg" |
0 | 3347 |
! |
3348 |
||
141 | 3349 |
statement |
3350 |
"parse a statement; return a node-tree or #Error. |
|
3351 |
||
3352 |
statement ::= '^' expression |
|
382 | 3353 |
| PRIMITIVECODE |
3354 |
| expression |
|
141 | 3355 |
" |
3356 |
||
382 | 3357 |
|expr node lnr| |
141 | 3358 |
|
3359 |
(tokenType == $^) ifTrue:[ |
|
382 | 3360 |
lnr := tokenLineNr. |
3361 |
self nextToken. |
|
3362 |
expr := self expression. |
|
3363 |
(expr == #Error) ifTrue:[^ #Error]. |
|
3364 |
node := ReturnNode expression:expr. |
|
3365 |
node home:self blockHome:currentBlock. |
|
3366 |
(lineNumberInfo == #full) ifTrue:[node lineNr:lnr]. |
|
3367 |
^ node |
|
141 | 3368 |
]. |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3369 |
|
141 | 3370 |
(tokenType == #Primitive) ifTrue:[ |
382 | 3371 |
self nextToken. |
3372 |
node := PrimitiveNode code:tokenValue. |
|
3373 |
node isOptional ifFalse:[ |
|
3374 |
hasNonOptionalPrimitiveCode := true |
|
3375 |
]. |
|
3376 |
hasPrimitiveCode := true. |
|
3377 |
^ node |
|
141 | 3378 |
]. |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3379 |
|
141 | 3380 |
(tokenType == #EOF) ifTrue:[ |
382 | 3381 |
self syntaxError:'period after last statement'. |
3382 |
^ #Error |
|
141 | 3383 |
]. |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3384 |
|
141 | 3385 |
expr := self expression. |
3386 |
(expr == #Error) ifTrue:[^ #Error]. |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3387 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3388 |
"/ classToCompileFor notNil ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3389 |
"/ currentBlock isNil ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3390 |
"/ expr isPrimary ifTrue:[ |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3391 |
"/ self warning:'useless computation - missing ^ ?' |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3392 |
"/ ] |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3393 |
"/ ] |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3394 |
"/ ]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3395 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3396 |
node := StatementNode expression:expr. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3397 |
(lineNumberInfo == #full) ifTrue:[node lineNr:lnr]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3398 |
^ node |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3399 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3400 |
"Modified: 23.10.1996 / 15:05:37 / cg" |
141 | 3401 |
! |
3402 |
||
3403 |
statementList |
|
3404 |
"parse a statementlist; return a node-tree, nil or #Error. |
|
3405 |
Statements must be separated by periods. |
|
3406 |
||
3407 |
statementList ::= <statement> |
|
3408 |
| <statementList> . <statement> |
|
3409 |
" |
|
3410 |
||
3411 |
|thisStatement prevStatement firstStatement correctIt periodPos| |
|
3412 |
||
3413 |
thisStatement := self statement. |
|
3414 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
3415 |
firstStatement := thisStatement. |
|
3416 |
[tokenType == $.] whileTrue:[ |
|
3417 |
periodPos := tokenPosition. |
|
3418 |
self nextToken. |
|
3419 |
(tokenType == $]) ifTrue:[ |
|
3420 |
currentBlock isNil ifTrue:[ |
|
3421 |
self parseError:'block nesting error'. |
|
3422 |
errorFlag := true |
|
3423 |
" |
|
3424 |
*** I had a warning here (since it was not defined |
|
3425 |
*** in the blue-book; but PD-code contains a lot of |
|
3426 |
*** code with periods at the end so that the warnings |
|
3427 |
*** became annoying |
|
3428 |
||
3429 |
] ifFalse:[ |
|
3430 |
self warning:'period after last statement' position:periodPos |
|
3431 |
" |
|
3432 |
]. |
|
3433 |
^ firstStatement |
|
3434 |
]. |
|
3435 |
(tokenType == #EOF) ifTrue:[ |
|
3436 |
currentBlock notNil ifTrue:[ |
|
3437 |
self parseError:'block nesting error (expected '']'')'. |
|
3438 |
errorFlag := true |
|
3439 |
" |
|
3440 |
*** I had a warning here (since it was not defined |
|
3441 |
*** in the blue-book; but PD-code contains a lot of |
|
3442 |
*** code with periods at the end so that the warnings |
|
3443 |
*** became annoying |
|
3444 |
||
3445 |
] ifFalse:[ |
|
3446 |
self warning:'period after last statement' position:periodPos |
|
3447 |
" |
|
3448 |
]. |
|
3449 |
^ firstStatement |
|
3450 |
]. |
|
3451 |
||
3452 |
prevStatement := thisStatement. |
|
3453 |
prevStatement isReturnNode ifTrue:[ |
|
3454 |
self warning:'statements after return' position:tokenPosition |
|
3455 |
]. |
|
3456 |
" |
|
3457 |
periodPos := tokenPosition. |
|
3458 |
self nextToken. |
|
3459 |
" |
|
3460 |
||
3461 |
((tokenType == $]) or:[tokenType == #EOF]) ifTrue:[ |
|
3462 |
(currentBlock isNil and:[tokenType == $]]) ifTrue:[ |
|
3463 |
self parseError:'block nesting error'. |
|
3464 |
errorFlag := true |
|
3465 |
] ifFalse:[ |
|
3466 |
correctIt := self correctableError:'period after last statement in block' |
|
3467 |
position:periodPos to:(periodPos + 1). |
|
3468 |
correctIt ifTrue:[ |
|
3469 |
(self correctByDeleting == #Error) ifTrue:[ |
|
3470 |
errorFlag := true |
|
3471 |
] |
|
3472 |
] |
|
3473 |
]. |
|
3474 |
^ firstStatement |
|
3475 |
]. |
|
3476 |
thisStatement := self statement. |
|
3477 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
3478 |
prevStatement nextStatement:thisStatement |
|
3479 |
]. |
|
3480 |
^ firstStatement |
|
3481 |
! |
|
3482 |
||
3483 |
unaryExpression |
|
3484 |
"parse a unary-expression; return a node-tree, nil or #Error" |
|
3485 |
||
3486 |
|receiver sel pos pos2 try| |
|
3487 |
||
3488 |
receiver := self primary. |
|
3489 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
3490 |
[tokenType == #Identifier] whileTrue:[ |
|
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3491 |
pos := tokenPosition. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3492 |
pos2 := pos + tokenName size - 1. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3493 |
sel := self selectorCheck:tokenName for:receiver position:pos to:pos2. |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3494 |
try := UnaryNode receiver:receiver selector:sel fold:foldConstants. |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3495 |
(try isMemberOf:String) ifTrue:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3496 |
self parseError:try position:pos to:pos2. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3497 |
errorFlag := false. "ok, user wants it - so he'll get it" |
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3498 |
receiver := UnaryNode receiver:receiver selector:sel fold:nil. |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3499 |
] ifFalse:[ |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3500 |
receiver := try |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3501 |
]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3502 |
receiver lineNumber:tokenLineNr. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3503 |
parseForCode ifFalse:[self rememberSelectorUsed:sel]. |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3504 |
self nextToken. |
141 | 3505 |
]. |
3506 |
^ receiver |
|
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
3507 |
|
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3508 |
"Modified: 21.3.1996 / 16:09:11 / cg" |
141 | 3509 |
! |
3510 |
||
3511 |
variable |
|
3512 |
"parse a variable; if undefined, notify error and correct if user wants to" |
|
3513 |
||
3514 |
|v| |
|
3515 |
||
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3516 |
v := self variableOrError:tokenName. |
141 | 3517 |
(v == #Error) ifFalse:[^ v]. |
3518 |
v := self correctVariable. |
|
3519 |
(v == #Error) ifFalse:[^ v]. |
|
3520 |
parseForCode ifFalse:[ |
|
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3521 |
self rememberGlobalUsed:tokenName |
141 | 3522 |
] ifTrue:[ |
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3523 |
tokenName first isLowercase ifTrue:[ |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3524 |
ImplicitSelfSends ifTrue:[ |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3525 |
selfNode isNil ifTrue:[ |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3526 |
selfNode := SelfNode value:selfValue |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3527 |
]. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3528 |
^ UnaryNode receiver:selfNode selector:('implicit_' , tokenName) asSymbol. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3529 |
]. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3530 |
^ #Error |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3531 |
] |
141 | 3532 |
]. |
3533 |
^ VariableNode type:#GlobalVariable name:tokenName asSymbol |
|
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3534 |
|
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3535 |
"Modified: 19.12.1996 / 22:30:01 / cg" |
141 | 3536 |
! |
3537 |
||
0 | 3538 |
variableOrError |
3539 |
"parse a variable; return a node-tree, nil or #Error" |
|
3540 |
||
21 | 3541 |
^ self variableOrError:tokenName |
3542 |
! |
|
3543 |
||
3544 |
variableOrError:varName |
|
3545 |
"parse a variable; return a node-tree, nil or #Error" |
|
3546 |
||
19 | 3547 |
|var instIndex aClass searchBlock args vars |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3548 |
tokenSymbol space| |
0 | 3549 |
|
3550 |
"is it a block-arg or block-var ?" |
|
3551 |
searchBlock := currentBlock. |
|
3552 |
[searchBlock notNil] whileTrue:[ |
|
353 | 3553 |
vars := searchBlock variables. |
3554 |
vars notNil ifTrue:[ |
|
3555 |
instIndex := vars findFirst:[:aBlockVar | aBlockVar name = varName]. |
|
3556 |
instIndex ~~ 0 ifTrue:[ |
|
3557 |
^ VariableNode type:#BlockVariable |
|
3558 |
name:varName |
|
3559 |
token:(vars at:instIndex) |
|
3560 |
index:instIndex |
|
3561 |
block:searchBlock |
|
3562 |
]. |
|
3563 |
]. |
|
3564 |
||
3565 |
args := searchBlock arguments. |
|
3566 |
args notNil ifTrue:[ |
|
3567 |
instIndex := args findFirst:[:aBlockArg | aBlockArg name = varName]. |
|
3568 |
instIndex ~~ 0 ifTrue:[ |
|
3569 |
^ VariableNode type:#BlockArg |
|
3570 |
name:varName |
|
3571 |
token:(args at:instIndex) |
|
3572 |
index:instIndex |
|
3573 |
block:searchBlock |
|
3574 |
]. |
|
3575 |
||
3576 |
]. |
|
3577 |
||
3578 |
searchBlock := searchBlock home |
|
0 | 3579 |
]. |
3580 |
||
3581 |
"is it a method-variable ?" |
|
3582 |
methodVars notNil ifTrue:[ |
|
353 | 3583 |
instIndex := methodVarNames indexOf:varName. |
3584 |
instIndex ~~ 0 ifTrue:[ |
|
3585 |
var := methodVars at:instIndex. |
|
3586 |
var used:true. |
|
3587 |
^ VariableNode type:#MethodVariable |
|
3588 |
name:varName |
|
3589 |
token:var |
|
3590 |
index:instIndex |
|
3591 |
] |
|
0 | 3592 |
]. |
3593 |
||
3594 |
"is it a method-argument ?" |
|
3595 |
methodArgs notNil ifTrue:[ |
|
353 | 3596 |
instIndex := methodArgNames indexOf:varName. |
3597 |
instIndex ~~ 0 ifTrue:[ |
|
3598 |
^ VariableNode type:#MethodArg |
|
3599 |
name:varName |
|
3600 |
token:(methodArgs at:instIndex) |
|
3601 |
index:instIndex |
|
3602 |
] |
|
0 | 3603 |
]. |
3604 |
||
3605 |
classToCompileFor notNil ifTrue:[ |
|
353 | 3606 |
"is it an instance-variable ?" |
3607 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3608 |
instIndex := (self classesInstVarNames) lastIndexOf:varName. |
353 | 3609 |
instIndex ~~ 0 ifTrue:[ |
3610 |
parseForCode ifFalse:[self rememberInstVarUsed:varName]. |
|
3611 |
^ VariableNode type:#InstanceVariable |
|
3612 |
name:varName |
|
3613 |
index:instIndex |
|
3614 |
selfValue:selfValue |
|
3615 |
]. |
|
3616 |
||
443
e7d0bad68d60
oops - previous versions allowed access to class-instance variables
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
3617 |
"/ "is it a class-instance-variable ?" |
e7d0bad68d60
oops - previous versions allowed access to class-instance variables
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
3618 |
"/ |
e7d0bad68d60
oops - previous versions allowed access to class-instance variables
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
3619 |
"/ it is not allowed to fetch class-instance variables |
e7d0bad68d60
oops - previous versions allowed access to class-instance variables
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
3620 |
"/ from instance methods ... |
e7d0bad68d60
oops - previous versions allowed access to class-instance variables
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
3621 |
"/ |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3622 |
instIndex := (self classesClassInstVarNames) lastIndexOf:varName. |
353 | 3623 |
instIndex ~~ 0 ifTrue:[ |
3624 |
aClass := self inWhichClassIsClassInstVar:varName. |
|
3625 |
aClass notNil ifTrue:[ |
|
3626 |
parseForCode ifFalse:[self rememberClassVarUsed:varName]. |
|
443
e7d0bad68d60
oops - previous versions allowed access to class-instance variables
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
3627 |
self warning:'access to class-inst-var from inst method will soon be no longer supported'. |
353 | 3628 |
^ VariableNode type:#ClassInstanceVariable |
3629 |
name:varName |
|
3630 |
index:instIndex |
|
3631 |
selfClass:aClass |
|
3632 |
] |
|
3633 |
]. |
|
3634 |
||
3635 |
"is it a class-variable ?" |
|
3636 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3637 |
instIndex := (self classesClassVarNames) lastIndexOf:varName. |
353 | 3638 |
instIndex ~~ 0 ifTrue:[ |
3639 |
aClass := self inWhichClassIsClassVar:varName. |
|
3640 |
aClass notNil ifTrue:[ |
|
3641 |
parseForCode ifFalse:[self rememberClassVarUsed:varName]. |
|
3642 |
^ VariableNode type:#ClassVariable class:aClass name:varName |
|
3643 |
] |
|
3644 |
]. |
|
3645 |
||
3646 |
"is it a private-class ?" |
|
3647 |
||
361 | 3648 |
aClass := classToCompileFor. |
3649 |
aClass isMeta ifTrue:[ |
|
3650 |
aClass := aClass soleInstance. |
|
3651 |
]. |
|
3652 |
(aClass privateClassesAt:varName) notNil ifTrue:[ |
|
3653 |
parseForCode ifFalse:[self rememberGlobalUsed:(aClass name , '::' , varName)]. |
|
3654 |
^ VariableNode type:#PrivateClass class:aClass name:varName |
|
418 | 3655 |
]. |
3656 |
]. |
|
3657 |
||
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3658 |
"is it in a namespace ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3659 |
space := self findNameSpaceWith:varName. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3660 |
space notNil ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3661 |
parseForCode ifFalse:[self rememberGlobalUsed:(space name , '::' , varName)]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3662 |
^ VariableNode type:#PrivateClass class:space name:varName |
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3663 |
]. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
3664 |
|
0 | 3665 |
"is it a global-variable ?" |
63 | 3666 |
tokenSymbol := varName asSymbolIfInterned. |
3667 |
tokenSymbol notNil ifTrue:[ |
|
353 | 3668 |
(Smalltalk includesKey:tokenSymbol) ifTrue:[ |
3669 |
parseForCode ifFalse:[self rememberGlobalUsed:varName]. |
|
3670 |
^ VariableNode type:#GlobalVariable name:tokenSymbol |
|
3671 |
] |
|
0 | 3672 |
]. |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3673 |
|
0 | 3674 |
^ #Error |
353 | 3675 |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3676 |
"Modified: 19.12.1996 / 23:53:37 / cg" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3677 |
! ! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3678 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3679 |
!Parser methodsFor:'private'! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3680 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3681 |
currentNameSpace |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3682 |
|spc| |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3683 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3684 |
spc := currentNamespace. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3685 |
spc isNil ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3686 |
(requestor respondsTo:#currentNameSpace) ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3687 |
spc := requestor currentNameSpace |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3688 |
] ifFalse:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3689 |
spc := Class nameSpaceQuerySignal raise. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3690 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3691 |
currentNamespace := spc. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3692 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3693 |
^ spc |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3694 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3695 |
"Created: 19.12.1996 / 23:47:58 / cg" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3696 |
! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3697 |
|
492
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
3698 |
currentNameSpace:aNameSpace |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
3699 |
currentNamespace := aNameSpace. |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
3700 |
|
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
3701 |
"Created: 8.2.1997 / 19:37:03 / cg" |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
3702 |
! |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
3703 |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3704 |
currentUsedNameSpaces |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3705 |
|spaces| |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3706 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3707 |
spaces := currentUsedNamespaces. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3708 |
spaces isNil ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3709 |
(requestor respondsTo:#usedNameSpaces) ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3710 |
spaces := requestor usedNameSpaces |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3711 |
] ifFalse:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3712 |
spaces := Class usedNameSpaceQuerySignal raise. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3713 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3714 |
currentUsedNamespaces := spaces. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3715 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3716 |
^ spaces |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3717 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3718 |
"Created: 19.12.1996 / 23:49:10 / cg" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3719 |
! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3720 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3721 |
findNameSpaceWith:aVariableName |
486
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3722 |
|ns currentSpace usedSpaces| |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3723 |
|
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3724 |
"/ private names have already been searched for. |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3725 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3726 |
classToCompileFor notNil ifTrue:[ |
486
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3727 |
"/ Q: |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3728 |
"/ consider private classes of superclasses. |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3729 |
"/ or search in the top owing classes namespace only ? |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3730 |
|
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3731 |
"/ for now, ignore other private classes - they are only |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3732 |
"/ known to the corresponding ownerClass. |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3733 |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3734 |
"is it in the classes namespace ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3735 |
|
486
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3736 |
classToCompileFor isPrivate ifTrue:[ |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3737 |
ns := classToCompileFor topOwningClass nameSpace |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3738 |
] ifFalse:[ |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3739 |
ns := classToCompileFor nameSpace. |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3740 |
]. |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3741 |
|
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3742 |
(ns notNil |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3743 |
and:[ns ~~ Smalltalk]) ifTrue:[ |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3744 |
(ns privateClassesAt:aVariableName) notNil ifTrue:[ |
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3745 |
^ ns |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3746 |
] |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3747 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3748 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3749 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3750 |
"is it in the current namespace ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3751 |
currentSpace := self currentNameSpace. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3752 |
(currentSpace notNil |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3753 |
and:[currentSpace ~~ Smalltalk]) ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3754 |
(currentSpace privateClassesAt:aVariableName) notNil ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3755 |
^ currentSpace |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3756 |
] |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3757 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3758 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3759 |
"is it in one of the used namespaces ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3760 |
usedSpaces := self currentUsedNameSpaces. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3761 |
usedSpaces notNil ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3762 |
usedSpaces do:[:aNameSpace | |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3763 |
(aNameSpace privateClassesAt:aVariableName) notNil ifTrue:[ |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3764 |
^ aNameSpace |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3765 |
] |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3766 |
] |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3767 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3768 |
^ nil |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3769 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
3770 |
"Created: 19.12.1996 / 23:51:02 / cg" |
486
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
3771 |
"Modified: 23.1.1997 / 00:43:29 / cg" |
141 | 3772 |
! ! |
3773 |
||
3774 |
!Parser methodsFor:'queries'! |
|
3775 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3776 |
classesClassInstVarNames |
141 | 3777 |
"caching allInstVarNames for next compilation saves time ..." |
3778 |
||
3779 |
PrevClassInstVarNames isNil ifTrue:[ |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3780 |
PrevClassInstVarNames := classToCompileFor class allInstVarNames |
98 | 3781 |
]. |
141 | 3782 |
^ PrevClassInstVarNames |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3783 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3784 |
"Created: 14.10.1996 / 18:03:35 / cg" |
0 | 3785 |
! |
3786 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3787 |
classesClassVarNames |
141 | 3788 |
"caching allClassVarNames for next compilation saves time ..." |
3789 |
||
429 | 3790 |
|aClass| |
141 | 3791 |
|
3792 |
PrevClassVarNames isNil ifTrue:[ |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
3793 |
aClass := classToCompileFor. |
337 | 3794 |
aClass isMeta ifTrue:[ |
3795 |
aClass := aClass soleInstance. |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
3796 |
aClass isNil ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
3797 |
aClass := classToCompileFor |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
3798 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
3799 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
3800 |
PrevClassVarNames := aClass allClassVarNames |
0 | 3801 |
]. |
141 | 3802 |
^ PrevClassVarNames |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
3803 |
|
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
3804 |
"Modified: 17.6.1996 / 17:15:53 / stefan" |
337 | 3805 |
"Modified: 21.6.1996 / 15:21:17 / cg" |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3806 |
"Created: 14.10.1996 / 18:02:41 / cg" |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3807 |
! |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3808 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3809 |
classesInstVarNames |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3810 |
"caching allInstVarNames for next compilation saves time ..." |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3811 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3812 |
(PrevInstVarNames isNil or:[PrevClass ~~ classToCompileFor]) ifTrue:[ |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3813 |
PrevClass notNil ifTrue:[ |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3814 |
PrevClass removeDependent:Parser |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3815 |
]. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3816 |
PrevClass := classToCompileFor. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3817 |
PrevInstVarNames := classToCompileFor allInstVarNames. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3818 |
PrevClassInstVarNames := nil. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3819 |
PrevClassVarNames := nil. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3820 |
PrevClass addDependent:Parser |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3821 |
]. |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3822 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3823 |
^ PrevInstVarNames |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3824 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3825 |
"Created: 14.10.1996 / 18:00:26 / cg" |
0 | 3826 |
! |
3827 |
||
141 | 3828 |
hasNonOptionalPrimitiveCode |
3829 |
"return true if there was any ST/X style primitive code (valid after parsing)" |
|
3830 |
||
3831 |
^ hasNonOptionalPrimitiveCode |
|
0 | 3832 |
! |
3833 |
||
141 | 3834 |
hasPrimitiveCode |
3835 |
"return true if there was any ST/X style primitive code (valid after parsing)" |
|
3836 |
||
3837 |
^ hasPrimitiveCode |
|
98 | 3838 |
! |
3839 |
||
385 | 3840 |
lineNumberInfo |
3841 |
^ lineNumberInfo |
|
3842 |
||
3843 |
"Created: 21.10.1996 / 17:06:16 / cg" |
|
3844 |
! |
|
3845 |
||
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3846 |
lineNumberInfo:how |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3847 |
lineNumberInfo := how |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3848 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3849 |
"Created: 23.10.1996 / 15:39:43 / cg" |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3850 |
! |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
3851 |
|
141 | 3852 |
methodArgs |
3853 |
"return an array with methodarg names (valid after parsing spec)" |
|
3854 |
||
3855 |
^ methodArgNames |
|
3856 |
! |
|
3857 |
||
3858 |
methodVars |
|
3859 |
"return a collection with method variablenames (valid after parsing)" |
|
3860 |
||
3861 |
^ methodVarNames |
|
23 | 3862 |
! |
3863 |
||
141 | 3864 |
modifiedClassVars |
3865 |
"return a collection with classvariablenames modified by method (valid after parsing)" |
|
3866 |
||
3867 |
^ modifiedClassVars |
|
3868 |
! |
|
3869 |
||
3870 |
modifiedGlobals |
|
3871 |
"return a collection with globalnames modified by method (valid after parsing)" |
|
3872 |
||
3873 |
^ modifiedGlobals |
|
3874 |
! |
|
3875 |
||
3876 |
modifiedInstVars |
|
3877 |
"return a collection with instvariablenames modified by method (valid after parsing)" |
|
3878 |
||
3879 |
^ modifiedInstVars |
|
0 | 3880 |
! |
3881 |
||
141 | 3882 |
numberOfMethodArgs |
3883 |
"return the number of methodargs (valid after parsing spec)" |
|
3884 |
||
3885 |
^ methodArgs size |
|
3886 |
! |
|
3887 |
||
3888 |
numberOfMethodVars |
|
3889 |
"return the number of method variables (valid after parsing)" |
|
3890 |
||
3891 |
^ methodVars size |
|
3892 |
! |
|
3893 |
||
3894 |
selector |
|
3895 |
"return the selector (valid after parsing spec)" |
|
3896 |
||
3897 |
^ selector |
|
0 | 3898 |
! |
3899 |
||
141 | 3900 |
usedClassVars |
3901 |
"return a collection with classvariablenames refd by method (valid after parsing)" |
|
3902 |
||
3903 |
^ usedClassVars |
|
3904 |
! |
|
3905 |
||
3906 |
usedGlobals |
|
3907 |
"return a collection with globalnames refd by method (valid after parsing)" |
|
3908 |
||
3909 |
^ usedGlobals |
|
3910 |
! |
|
3911 |
||
3912 |
usedInstVars |
|
3913 |
"return a collection with instvariablenames refd by method (valid after parsing)" |
|
3914 |
||
3915 |
^ usedInstVars |
|
3916 |
! |
|
3917 |
||
3918 |
usedVars |
|
3919 |
"return a collection with variablenames refd by method (valid after parsing)" |
|
3920 |
||
3921 |
^ usedVars |
|
0 | 3922 |
! |
3923 |
||
141 | 3924 |
usesSuper |
3925 |
"return true if the parsed method uses super (valid after parsing)" |
|
3926 |
||
3927 |
^ usesSuper |
|
3928 |
! ! |
|
3929 |
||
3930 |
!Parser methodsFor:'setup'! |
|
3931 |
||
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3932 |
foldConstants:aSymbolOrNil |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3933 |
"change the constant folding level. See the classMethod for a description." |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3934 |
|
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3935 |
foldConstants := aSymbolOrNil |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3936 |
|
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3937 |
"Created: 21.3.1996 / 16:03:22 / cg" |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3938 |
"Modified: 21.3.1996 / 16:05:04 / cg" |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3939 |
! |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
3940 |
|
141 | 3941 |
initialize |
3942 |
super initialize. |
|
3943 |
||
3944 |
hasPrimitiveCode := hasNonOptionalPrimitiveCode := false. |
|
3945 |
warnSTXHereExtensionUsed := WarnSTXSpecials. |
|
3946 |
usesSuper := false. |
|
3947 |
parseForCode := false. |
|
377 | 3948 |
foldConstants := FoldConstants. |
3949 |
lineNumberInfo := LineNumberInfo. |
|
3950 |
||
3951 |
"Modified: 21.10.1996 / 12:34:01 / cg" |
|
141 | 3952 |
! |
3953 |
||
3954 |
parseForCode |
|
3955 |
"turns off certain statistics (keeping referenced variables, modified vars etc.) |
|
3956 |
Use this when parsing for compilation or evaluation" |
|
3957 |
||
3958 |
parseForCode := true |
|
0 | 3959 |
! |
3960 |
||
141 | 3961 |
setClassToCompileFor:aClass |
3962 |
"set the class to be used for parsing/evaluating" |
|
3963 |
||
3964 |
classToCompileFor := aClass. |
|
3965 |
(classToCompileFor ~~ PrevClass) ifTrue:[ |
|
3966 |
PrevClass notNil ifTrue:[ |
|
3967 |
Parser update:PrevClass |
|
3968 |
] |
|
3969 |
] |
|
3970 |
! |
|
3971 |
||
3972 |
setContext:aContext |
|
3973 |
"set the context used while evaluating" |
|
3974 |
||
3975 |
contextToEvaluateIn := aContext |
|
3976 |
! |
|
3977 |
||
3978 |
setSelf:anObject |
|
3979 |
"set the value to be used for self while evaluating" |
|
3980 |
||
3981 |
selfValue := anObject. |
|
3982 |
classToCompileFor := anObject class. |
|
3983 |
(classToCompileFor ~~ PrevClass) ifTrue:[ |
|
3984 |
PrevClass notNil ifTrue:[ |
|
3985 |
Parser update:PrevClass |
|
3986 |
] |
|
3987 |
] |
|
0 | 3988 |
! ! |
3989 |
||
84 | 3990 |
!Parser methodsFor:'statistic'! |
3991 |
||
141 | 3992 |
rememberClassVarUsed:name |
3993 |
usedClassVars isNil ifTrue:[ |
|
3994 |
usedClassVars := Set new |
|
3995 |
]. |
|
3996 |
usedClassVars add:name. |
|
3997 |
self rememberVariableUsed:name |
|
3998 |
! |
|
3999 |
||
4000 |
rememberGlobalUsed:name |
|
4001 |
usedGlobals isNil ifTrue:[ |
|
4002 |
usedGlobals := Set new |
|
4003 |
]. |
|
4004 |
usedGlobals add:name. |
|
4005 |
self rememberVariableUsed:name |
|
4006 |
! |
|
4007 |
||
4008 |
rememberInstVarUsed:name |
|
4009 |
usedInstVars isNil ifTrue:[ |
|
4010 |
usedInstVars := Set new |
|
4011 |
]. |
|
4012 |
usedInstVars add:name. |
|
4013 |
self rememberVariableUsed:name |
|
4014 |
! |
|
4015 |
||
84 | 4016 |
rememberSelectorUsed:sel |
4017 |
usedMessages isNil ifTrue:[ |
|
4018 |
usedMessages := IdentitySet new. |
|
4019 |
]. |
|
4020 |
usedMessages add:sel |
|
4021 |
! |
|
4022 |
||
4023 |
rememberVariableUsed:name |
|
4024 |
usedVars isNil ifTrue:[ |
|
4025 |
usedVars := Set new |
|
4026 |
]. |
|
4027 |
usedVars add:name |
|
4028 |
! ! |
|
4029 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
4030 |
!Parser class methodsFor:'documentation'! |
148 | 4031 |
|
4032 |
version |
|
493
77e0d6979865
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
492
diff
changeset
|
4033 |
^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.127 1997-02-08 19:02:43 cg Exp $' |
148 | 4034 |
! ! |
141 | 4035 |
Parser initialize! |