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