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