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