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