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