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