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